yuqi1129 commented on code in PR #7814:
URL: https://github.com/apache/gravitino/pull/7814#discussion_r2242363532


##########
core/src/main/java/org/apache/gravitino/job/local/ShellProcessBuilder.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.job.local;
+
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.job.ShellJobTemplate;
+
+public class ShellProcessBuilder extends LocalProcessBuilder {
+
+  protected ShellProcessBuilder(ShellJobTemplate shellJobTemplate, Map<String, 
String> configs) {
+    super(shellJobTemplate, configs);
+  }
+
+  @Override
+  public Process start() {
+    ShellJobTemplate shellJobTemplate = (ShellJobTemplate) jobTemplate;
+    File executableFile = new File(shellJobTemplate.executable());
+    if (!executableFile.canExecute()) {
+      executableFile.setExecutable(true);
+    }
+
+    List<String> commandList = 
Lists.newArrayList(shellJobTemplate.executable());
+    commandList.addAll(shellJobTemplate.arguments());
+
+    ProcessBuilder builder = new ProcessBuilder(commandList);
+    builder.directory(workingDirectory);
+    builder.environment().putAll(shellJobTemplate.environments());
+
+    File outputFile = new File(workingDirectory, "output.log");

Review Comment:
   Do we need to add a method like `clear` to remove those files after the 
process is done successfully. 



##########
core/src/main/java/org/apache/gravitino/job/local/LocalJobExecutor.java:
##########
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.job.local;
+
+import static 
org.apache.gravitino.job.local.LocalJobExecutorConfigs.DEFAULT_JOB_STATUS_KEEP_TIME_MS;
+import static 
org.apache.gravitino.job.local.LocalJobExecutorConfigs.DEFAULT_MAX_RUNNING_JOBS;
+import static 
org.apache.gravitino.job.local.LocalJobExecutorConfigs.DEFAULT_WAITING_QUEUE_SIZE;
+import static 
org.apache.gravitino.job.local.LocalJobExecutorConfigs.JOB_STATUS_KEEP_TIME_MS;
+import static 
org.apache.gravitino.job.local.LocalJobExecutorConfigs.MAX_RUNNING_JOBS;
+import static 
org.apache.gravitino.job.local.LocalJobExecutorConfigs.WAITING_QUEUE_SIZE;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.gravitino.connector.job.JobExecutor;
+import org.apache.gravitino.exceptions.NoSuchJobException;
+import org.apache.gravitino.job.JobHandle;
+import org.apache.gravitino.job.JobTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LocalJobExecutor implements JobExecutor {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(LocalJobExecutor.class);
+
+  private static final String LOCAL_JOB_PREFIX = "local-job-";
+
+  private static final long UNEXPIRED_TIME_IN_MS = -1L;
+
+  private Map<String, String> configs;
+
+  private BlockingQueue<Pair<String, JobTemplate>> waitingQueue;
+
+  private ExecutorService jobExecutorService;
+
+  private ExecutorService jobPollingExecutorService;
+
+  // The job status map to keep track of the status of each job. In the 
meantime, the job status
+  // will be stored in the entity store, so we will clean the finished, 
cancelled and failed jobs
+  // from the map periodically to save the memory.
+  private Map<String, Pair<JobHandle.Status, Long>> jobStatus;
+  private final Object lock = new Object();
+
+  private long jobStatusKeepTimInMs;
+  private ScheduledExecutorService jobStatusCleanupExecutor;
+
+  private volatile boolean finished = false;
+
+  private Map<String, Process> runningProcesses;
+
+  @Override
+  public void initialize(Map<String, String> configs) {
+    this.configs = configs;
+
+    int waitingQueueSize =
+        configs.containsKey(WAITING_QUEUE_SIZE)
+            ? Integer.parseInt(configs.get(WAITING_QUEUE_SIZE))
+            : DEFAULT_WAITING_QUEUE_SIZE;
+    Preconditions.checkArgument(
+        waitingQueueSize > 0,
+        "Waiting queue size must be greater than 0, but got: %s",
+        waitingQueueSize);
+
+    this.waitingQueue = new LinkedBlockingQueue<>(waitingQueueSize);
+
+    this.jobPollingExecutorService =
+        Executors.newSingleThreadExecutor(
+            runnable -> {
+              Thread thread = new Thread(runnable);
+              thread.setName("LocalJobPollingExecutor-" + thread.getId());
+              thread.setDaemon(true);
+              return thread;
+            });
+    jobPollingExecutorService.submit(this::pollJob);
+
+    int maxRunningJobs =
+        configs.containsKey(MAX_RUNNING_JOBS)
+            ? Integer.parseInt(configs.get(MAX_RUNNING_JOBS))
+            : DEFAULT_MAX_RUNNING_JOBS;
+    Preconditions.checkArgument(
+        maxRunningJobs > 0, "Max running jobs must be greater than 0, but got: 
%s", maxRunningJobs);
+
+    this.jobExecutorService =
+        new ThreadPoolExecutor(
+            0,
+            maxRunningJobs,
+            60L,
+            TimeUnit.SECONDS,
+            new LinkedBlockingQueue<>(),
+            runnable -> {
+              Thread thread = new Thread(runnable);
+              thread.setName("LocalJobExecutor-" + thread.getId());
+              thread.setDaemon(true);
+              return thread;
+            });
+
+    this.jobStatus = Maps.newHashMap();
+
+    this.jobStatusKeepTimInMs =

Review Comment:
   jobStatusKeepTimInMs -> jobStatusKeepTimeInMs



##########
core/src/main/java/org/apache/gravitino/job/local/LocalJobExecutorConfigs.java:
##########
@@ -0,0 +1,38 @@
+package org.apache.gravitino.job.local;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+public class LocalJobExecutorConfigs {
+
+  private LocalJobExecutorConfigs() {
+    // Private constructor to prevent instantiation
+  }
+
+  public static final String LOCAL_JOB_EXECUTOR_NAME = "local";
+
+  public static final String WAITING_QUEUE_SIZE = "waitingQueueSize";
+  public static final int DEFAULT_WAITING_QUEUE_SIZE = 100;
+
+  public static final String MAX_RUNNING_JOBS = "maxRunningJobs";
+  public static final int DEFAULT_MAX_RUNNING_JOBS =
+      Math.min(Runtime.getRuntime().availableProcessors() / 2, 10);

Review Comment:
   The value of `Runtime.getRuntime().availableProcessors()/ 2` will be 0 if we 
running Gravitino server in single core machine like container, do we need to 
handle it? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to