-
Notifications
You must be signed in to change notification settings - Fork 9.1k
SUBMARINE-72 Kill and destroy the job through the submarine client #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+217
−17
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,5 @@ | |
* Represents a Submarine command. | ||
*/ | ||
public enum Command { | ||
RUN_JOB, SHOW_JOB | ||
RUN_JOB, SHOW_JOB, KILL_JOB | ||
} |
113 changes: 113 additions & 0 deletions
113
...-submarine-core/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/KillJobCli.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* 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) { | ||
LOG.error(("Error parsing command-line options: " + e.getMessage())); | ||
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) { | ||
LOG.error("appAdminClient fail to stop application"); | ||
return false; | ||
} | ||
if (appAdminClient.actionDestroy(jobName) != 0) { | ||
LOG.error("appAdminClient fail to destroy application"); | ||
return false; | ||
} | ||
|
||
appAdminClient.stop(); | ||
return true; | ||
} | ||
|
||
@VisibleForTesting | ||
public KillJobParameters getParameters() { | ||
return (KillJobParameters) parametersHolder.getParameters(); | ||
} | ||
|
||
@Override | ||
public int run(String[] args) throws ParseException, IOException, | ||
YarnException, InterruptedException, SubmarineException { | ||
if (CliUtils.argsForHelp(args)) { | ||
printUsages(); | ||
return 0; | ||
} | ||
parseCommandLineAndGetKillJobParameters(args); | ||
if (killJob() == true) { | ||
LOG.info("Kill job successfully !"); | ||
} | ||
return 0; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...re/src/main/java/org/apache/hadoop/yarn/submarine/client/cli/param/KillJobParameters.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* 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.param; | ||
|
||
public class KillJobParameters extends BaseParameters { | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...core/src/test/java/org/apache/hadoop/yarn/submarine/client/cli/TestKillJobCliParsing.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.hadoop.yarn.submarine.client.cli; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.commons.cli.ParseException; | ||
import org.apache.hadoop.yarn.exceptions.YarnException; | ||
import org.apache.hadoop.yarn.submarine.client.cli.param.KillJobParameters; | ||
import org.apache.hadoop.yarn.submarine.common.MockClientContext; | ||
import org.apache.hadoop.yarn.submarine.common.conf.SubmarineLogs; | ||
import org.apache.hadoop.yarn.submarine.common.exception.SubmarineException; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class TestKillJobCliParsing { | ||
@Before | ||
public void before() { | ||
SubmarineLogs.verboseOff(); | ||
} | ||
|
||
@Test | ||
public void testPrintHelp() { | ||
MockClientContext mockClientContext = new MockClientContext(); | ||
KillJobCli killJobCli = new KillJobCli(mockClientContext); | ||
killJobCli.printUsages(); | ||
} | ||
|
||
@Test | ||
public void testKillJob() | ||
throws InterruptedException, SubmarineException, YarnException, | ||
ParseException, IOException { | ||
MockClientContext mockClientContext = new MockClientContext(); | ||
KillJobCli killJobCli = new KillJobCli(mockClientContext) { | ||
@Override | ||
protected boolean killJob() { | ||
// do nothing | ||
return false; | ||
} | ||
}; | ||
killJobCli.run(new String[] { "--name", "my-job" }); | ||
KillJobParameters parameters = killJobCli.getParameters(); | ||
Assert.assertEquals(parameters.getName(), "my-job"); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.