Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

APEXCORE-626 shutdown-app in cli supports app-name as argument #564

Conversation

florianschmidt1994
Copy link
Contributor

The command shutdown-app now supports not only the app-id but also the
app name as an argument.

This commit adds both the functionality as well as the documentation to
the cli help messages

@pramodin
Copy link
Contributor

Are there any unit tests for shutdown?

@florianschmidt1994
Copy link
Contributor Author

I looked into ApexCliTest and ApexCliMiscTest and they both don't seem to contain tests related to the shutdown command

@florianschmidt1994 florianschmidt1994 changed the title APEXCORE-626.shutdown-app in cli supports app-name as argument APEXCORE-626 shutdown-app in cli supports app-name as argument Jul 25, 2017
Copy link
Contributor

@tushargosavi tushargosavi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the provided comment. The reset looks good.

{
ApplicationReport app = null;

if (getApplication(appNameOrId) != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app = getApplication(appNameOrId)
if (app == null) {
app = getApplicationByName(appNameOrId)
}

To avoid calling getApplication and getApplicationByName twice.

@@ -2178,6 +2178,19 @@ public void execute(String[] args, ConsoleReader reader) throws Exception

}

private ApplicationReport findApplicationReportFromAppNameOrId(String appNameOrId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function could be used in KillAppCommand#execute too

@@ -738,7 +738,7 @@ void printUsage(String cmd)
"Kill a container"));
connectedCommands.put("shutdown-app", new CommandSpec(new ShutdownAppCommand(),
null,
new Arg[]{new VarArg("app-id")},
new Arg[]{new VarArg("app-id/app-name")},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar change is needed at
globalCommands.put("shutdown-app", new CommandSpec(new ShutdownAppCommand(),
new Arg[]{new Arg("app-id")},
new Arg[]{new VarArg("app-id")},

line number 634

@tushargosavi
Copy link
Contributor

Looks good, can you squash all the commits and add JIRA id in the final commit message as per contributing guidelines (http://apex.apache.org/contributing.html). I will merge it after that

@florianschmidt1994 florianschmidt1994 force-pushed the APEXCORE-626.add-app-name-support-to-shutdown-app branch from 3175b88 to bc30b09 Compare July 25, 2017 17:56
@florianschmidt1994
Copy link
Contributor Author

Jenkins, test me again!

@sanjaypujare
Copy link
Contributor

I added the following comment to the JIRA and it will be nice to address it in this PR:

"Can we extend this to all the commands that accept the app-id? I see the following:

connect app-id
get-app-info app-id"

if (app == null) {
app = getApplicationByName(appNameOrId);
}
return app;
Copy link
Contributor

@sanjaypujare sanjaypujare Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the callers throw the identical exception when the returned app is null. Can we just throw that exception here and the caller can always assume app is non-null?

Thinking further, the current behavior - even with my proposed suggestion - fails the whole command if a single app-id/app-name is not found. Do we want to keep that behavior or modify it to only ignore the invalid app-id/app-name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior seems to be inconsistent between different CL tools. I just checked docker start valid_container_name invalid_container_name: this would start valid_container but not invalid_container. Then again when using apt-get install valid_package_name invalid_package_name it just fails completely, installing neither of those packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making findApplicationReportFromAppNameOrId() throw a CLIException could

  • on one hand clean up the code so we don't need to rewrite it every time
  • on the other hand it would make it inconsistent with getApplication and getApplicationByName, where no exception is thrown.

Also if we leave the exception out of the method, we would still have the possibility of implementing the logic for "fail all vs. fail only for invalid appName" in the respective commands, which we do not have if we move it into the method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it should be the best effort attempt. If application id or name is not found, the error needs to be reported, but it is necessary to continue to the next id/name. At the end, command should report all applications that were shutdown.

throw new CliException("Streaming application with id " + args[i] + " is not found.");
ApplicationReport ap = findApplicationReportFromAppNameOrId(args[i]);
if (ap == null) {
throw new CliException("Streaming application with id or name " + args[i] + " is not found.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls see my comment above about failing the command for the whole list when a single app is not found.

new Arg[]{new Arg("app-id")},
new Arg[]{new VarArg("app-id")},
new Arg[]{new Arg("app-id/app-name")},
new Arg[]{new VarArg("app-id/app-name")},
"Shutdown an app"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> "Shutdown app or apps"

Copy link
Contributor

@sanjaypujare sanjaypujare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested extending this to other commands. Let me know what you think

@florianschmidt1994
Copy link
Contributor Author

florianschmidt1994 commented Jul 27, 2017

Thanks for the reviews! Adding the support for the other commands will make it more consistent, so I would go with adding that functionality everywhere.

EDIT: Actually it is tricky to add support for e.g get-app-info with using an app-name, since get-app-info also works for apps that are killed / shutdown / ... already and therefore multiple apps with that name can exist. Maybe open another issue / pr for those cases?

Regarding the question whether a command should fail completely or not if one of the apps is not found, I would go with not running the command at all, the reason being that it feels nicer to me in terms of usability, when one mistypes an app name or app id and wants to make a correction to it afterwards. (Instead of having to retype the whole command only for the failed app-names or app-ids). I'd be happy to get some more input on that though!

@florianschmidt1994 florianschmidt1994 force-pushed the APEXCORE-626.add-app-name-support-to-shutdown-app branch from bc30b09 to f092ad9 Compare July 27, 2017 18:15
@sanjaypujare
Copy link
Contributor

Okay, good point about multiple app-ids for the same name. Then it is not worth extending only for connect....

@vrozov
Copy link
Member

vrozov commented Jul 27, 2017

@sanjaypujare @florianschmidt1994 Whether other commands can support application name in addition to application id should be considered separatly for each command. I'd prefer not to block this PR and have separate JIRAs and PRs for each command that can take application name as an argument in addition to application id.

@tushargosavi
Copy link
Contributor

I agree with @vrozov to have separate Jiras for supporting app-name in other commands.

@florianschmidt1994
Copy link
Contributor Author

Are there any open issues left to do then?

Copy link
Contributor

@tushargosavi tushargosavi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sanjaypujare can you merge this if you don't have any additional comments.

"Shutdown an app"));
new Arg[]{new Arg("app-id/app-name")},
new Arg[]{new VarArg("app-id/app-name")},
"Shutdown app or apps"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shutdown application(s) by id or name?

if (app == null) {
app = getApplicationByName(appNameOrId);
}
return app;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it should be the best effort attempt. If application id or name is not found, the error needs to be reported, but it is necessary to continue to the next id/name. At the end, command should report all applications that were shutdown.

@florianschmidt1994
Copy link
Contributor Author

@vrozov I have both the best effort and the existing approach at hand. How / Who will it be decided with option we will go with? Do we need more input from others for that?

@vrozov
Copy link
Member

vrozov commented Aug 4, 2017

@florianschmidt1994 The best approach is to bring the discussion to dev@apex. Once dev community comes to an agreement, summarize the discussion in JIRA.

@florianschmidt1994 florianschmidt1994 force-pushed the APEXCORE-626.add-app-name-support-to-shutdown-app branch 6 times, most recently from af20bee to f5677d3 Compare August 7, 2017 21:53
@florianschmidt1994
Copy link
Contributor Author

florianschmidt1994 commented Aug 7, 2017

Thanks for all your input! As discussed on the mailing list we will go with the "best effort" approach. The "latest" commit (thanks rebase :D ) contains the discussed functionality as well as an additional test to ensure proper behavior.
@sanjaypujare could you have a look at this again?

@florianschmidt1994 florianschmidt1994 force-pushed the APEXCORE-626.add-app-name-support-to-shutdown-app branch 5 times, most recently from b2473fd to 480d8b8 Compare August 8, 2017 18:09
@florianschmidt1994
Copy link
Contributor Author

Run tests again

if (apps[i - 1] == null) {
throw new CliException("Streaming application with id " + args[i] + " is not found.");
}
String[] appNamesOrIds = Arrays.copyOfRange(args, 1, args.length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to check for duplicates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote for going with the way it currently behaves, which is shutting down an app if it is found, and if it is specified as argument twice: printing an error message on the second time, because the app is already shut down.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if (app == null) {
throw new CliException("Streaming application with id or name " + args[i] + " is not found.");
}
throw new CliException("Streaming application with id or name " + args[i] + " is not found.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we throw exception and stop processing the kill command as opposed to what we decided to do for the shutdown command e.g. continue processing the remaining arguments? In that case we can also achieve some code reuse between shutdown and kill commands - building the app report list etc can be common code.

}

yarnClient.killApplication(app.getApplicationId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - if an exception is thrown the processing stops.

// When processing the shutdown command for two valid and one invalid appNames
String shutdownAppsCommand = "shutdown-app app1 notExisting app2";
cliUnderTest.processLine(shutdownAppsCommand, new ConsoleReader(), true);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be a good idea to flush the current System.out and System.err (or close them) to ensure you get complete/consistent output in your stdOut and stdErr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New squashed version uses autoflush on PrintStream now

"org.apache.log4j.*"
})
@PrepareForTest({YarnClient.class, ApexCli.class, StramAgent.class})
public class ApexCliShutdownCommandTest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a test for the kill command as well? You can add it here and rename the class .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment below on how to go from here

Copy link
Contributor

@sanjaypujare sanjaypujare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls check the comments

@florianschmidt1994 florianschmidt1994 force-pushed the APEXCORE-626.add-app-name-support-to-shutdown-app branch from 480d8b8 to 8ccd1f0 Compare August 9, 2017 00:31
@florianschmidt1994
Copy link
Contributor Author

florianschmidt1994 commented Aug 9, 2017

The current version now implements the best effort approach as discussed on the mailing list. Unfortunately this is now inconsistent to how the kill-app command behaves, being that kill-app stops when an error occurs during killing of an application.

I think there are two ways to go from here now:

  1. Merge this PR (when approved), introducing inconsistent behavior for some time and fixing that inconsistent behavior for all other commands in a new JIRA / PR
  2. Extend this PR & JIRA Issue to introduce consistent behavior for all commands that support multiple appNames / appIds as arguments

@sanjaypujare
Copy link
Contributor

@florianschmidt1994 after thinking about this a bit, we should address the kill command inconsistency in a separate JIRA and merge this PR as soon as comments are addressed. Will finish my review....

Copy link
Contributor

@sanjaypujare sanjaypujare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@florianschmidt1994 florianschmidt1994 force-pushed the APEXCORE-626.add-app-name-support-to-shutdown-app branch from 8ccd1f0 to 454e149 Compare August 9, 2017 21:35
@florianschmidt1994
Copy link
Contributor Author

Added a minor change to fix a bug where the cli would wrongfully disconnect from currentApp

} finally {
if (currentApp != null) {
if (app.getApplicationId().equals(currentApp.getApplicationId())) {
currentApp = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In doing this you are assuming that shutdown succeeded or will succeed. If shutdown doesn't succeed why set currentApp to null?

@pramod
Copy link

pramod commented Aug 9, 2017 via email

@florianschmidt1994
Copy link
Contributor Author

florianschmidt1994 commented Aug 10, 2017

My apologies, sorry about that! Unfortunately I think we can't do that, but you should be able to unsubscribe at the top right of the page, in the section notification. Also your email show have a link called "mute this thread", which should do the same.

@vrozov
Copy link
Member

vrozov commented Oct 1, 2017

@florianschmidt1994 Please rebase

The command shutdown-app now supports not only the app-id but also the
app name as an argument.
In case of multiple appIds or appNames the shutdown-app command follows
a "best effort" approach, meaning that it tries to shutdown each app
individually and prints an error message if the shutdown of an app
fails, but continues to shutdown all the others.

This commit adds the described functionality, documentation to the cli
help messages and a test to ensure correct best effort behaviour.
@florianschmidt1994 florianschmidt1994 force-pushed the APEXCORE-626.add-app-name-support-to-shutdown-app branch from 454e149 to 9ea2cfb Compare October 2, 2017 17:03
@florianschmidt1994
Copy link
Contributor Author

@vrozov vrozov merged commit 10d22df into apache:master Oct 4, 2017
@florianschmidt1994 florianschmidt1994 deleted the APEXCORE-626.add-app-name-support-to-shutdown-app branch October 5, 2017 17:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants