jojochuang commented on a change in pull request #1090: SUBMARINE-72 Kill and 
destroy the job through the submarine client
URL: https://github.com/apache/hadoop/pull/1090#discussion_r308909022
 
 

 ##########
 File path: 
hadoop-submarine/hadoop-submarine-core/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/KillJobCli.java
 ##########
 @@ -0,0 +1,109 @@
+/**
+ * Licensed 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. See accompanying LICENSE file.
+ */
+
+package org.apache.hadoop.yarn.submarine.client.cli;
+
+import static org.apache.hadoop.yarn.client.api.AppAdminClient.DEFAULT_TYPE;
+
+import java.io.IOException;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.hadoop.yarn.client.api.AppAdminClient;
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.submarine.client.cli.param.KillJobParameters;
+import org.apache.hadoop.yarn.submarine.client.cli.param.ParametersHolder;
+import org.apache.hadoop.yarn.submarine.common.ClientContext;
+import org.apache.hadoop.yarn.submarine.common.exception.SubmarineException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class KillJobCli extends AbstractCli {
+  private static final Logger LOG = LoggerFactory.getLogger(ShowJobCli.class);
+
+  private Options options;
+  private ParametersHolder parametersHolder;
+
+  public KillJobCli(ClientContext cliContext) {
+    super(cliContext);
+    options = generateOptions();
+  }
+
+  public void printUsages() {
+    new HelpFormatter().printHelp("job kill", options);
+  }
+
+  private Options generateOptions() {
+    Options options = new Options();
+    options.addOption(CliConstants.NAME, true, "Name of the job");
+    options.addOption("h", "help", false, "Print help");
+    return options;
+  }
+
+  private void parseCommandLineAndGetKillJobParameters(String[] args)
+      throws IOException, YarnException {
+    // Do parsing
+    GnuParser parser = new GnuParser();
+    CommandLine cli;
+    try {
+      cli = parser.parse(options, args);
+      parametersHolder =
+          ParametersHolder.createWithCmdLine(cli, Command.KILL_JOB);
+      parametersHolder.updateParameters(clientContext);
+    } catch (ParseException e) {
+      printUsages();
+    }
+  }
+
+  @VisibleForTesting
+  protected boolean KillJob() throws IOException, YarnException {
+    String jobName = getParameters().getName();
+    AppAdminClient appAdminClient = AppAdminClient
+        .createAppAdminClient(DEFAULT_TYPE, clientContext.getYarnConfig());
+
+    if (appAdminClient.actionStop(jobName) != 0
+        || appAdminClient.actionDestroy(jobName) != 0) {
+      LOG.error("Fail to kill job !");
 
 Review comment:
   Additional info meaning: whether the job fails to be killed because it was 
unable to stop the job or because it was unable to destroy the job.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to