SLIDER-306 changes pulled in, reviewed tests set up and working
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/c4575bde Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/c4575bde Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/c4575bde Branch: refs/heads/develop Commit: c4575bdecab3bbc38e3f302688fc1b3c6992046b Parents: 894f5c1 Author: Steve Loughran <[email protected]> Authored: Tue Aug 19 12:52:16 2014 +0100 Committer: Steve Loughran <[email protected]> Committed: Fri Oct 24 21:51:10 2014 +0100 ---------------------------------------------------------------------- .../org/apache/slider/client/SliderClient.java | 65 ++++++++++++++------ .../apache/slider/common/tools/SliderUtils.java | 6 +- .../slider/agent/actions/TestActionList.groovy | 9 +-- .../agent/freezethaw/TestFreezeCommands.groovy | 3 +- .../standalone/TestStandaloneAMDestroy.groovy | 16 +++++ .../slider/client/TestCommonArgParsing.groovy | 3 +- 6 files changed, 71 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c4575bde/slider-core/src/main/java/org/apache/slider/client/SliderClient.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java index 30d3b05..bded128 100644 --- a/slider-core/src/main/java/org/apache/slider/client/SliderClient.java +++ b/slider-core/src/main/java/org/apache/slider/client/SliderClient.java @@ -1698,29 +1698,42 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe String user = UserGroupInformation.getCurrentUser().getUserName(); List<ApplicationReport> instances = listSliderInstances(user); SliderUtils.sortApplicationReport(instances); + boolean live = args.live; + boolean history = args.history; if (isUnset(clustername)) { + // no cluster name: list all log.info("Instances for {}: {}", - (user != null ? user : "all users"), - instances.size()); + (user != null ? user : "all users"), + instances.size()); for (ApplicationReport report : instances) { - logAppReport(report, args.live, args.history); + logAppReport(report, live, history); } + // and always succeed return EXIT_SUCCESS; } else { + // cluster name provided SliderUtils.validateClusterName(clustername); - log.debug("Listing cluster named {}", clustername); - if (args.history) { + log.debug("Listing cluster named {}, live={}, history={}", + clustername, live, history); + boolean instanceFound = false; + if (history) { for (ApplicationReport report : instances) { if (report.getName().equals(clustername)) { - logAppReport(report, args.live, args.history); + logAppReport(report, live, true); + instanceFound = true; } } - return EXIT_SUCCESS; + } else { + // no history flag, only list live value + ApplicationReport report = + findClusterInInstanceList(instances, clustername); + if (report != null) { + logAppReport(report, true, true); + instanceFound = true; + } } - ApplicationReport report = findClusterInInstanceList(instances, - clustername); - if (report != null) { - logAppReport(report, true, false); + // exit code if the instance was found + if (instanceFound) { return EXIT_SUCCESS; } else { throw unknownClusterException(clustername); @@ -1731,20 +1744,34 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe /** * Log the application report at INFO * @param report report to log + * @param live only list live apps + * @param history list historical containers */ public void logAppReport(ApplicationReport report, boolean live, boolean history) { - boolean active = report.getYarnApplicationState() == YarnApplicationState.RUNNING - || report.getYarnApplicationState() == - YarnApplicationState.ACCEPTED; - if (active && live && !history) { - log.info(SliderUtils.appReportToString(report, "\n")); - } else if (!active && history && !live) { - log.info(SliderUtils.appReportToString(report, "\n")); - } else { + // app is active if it is accepted or running + boolean active = isApplicationActive(report); + + boolean toLog = (active && live) || (!active && history); + if (toLog) { log.info(SliderUtils.appReportToString(report, "\n")); } } + /** + * Is an application active: accepted or running + * @param report the application report + * @return true if it is running or scheduled to run. + */ + public boolean isApplicationActive(ApplicationReport report) { + return report.getYarnApplicationState() == YarnApplicationState.RUNNING + || report.getYarnApplicationState() == YarnApplicationState.ACCEPTED; + } + + /** + * Implement the islive action: probe for a cluster of the given name existing + * @return exit code + */ + @Override @VisibleForTesting public int actionFlex(String name, ActionFlexArgs args) throws YarnException, IOException { http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c4575bde/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java index 2f15a6d..106a052 100644 --- a/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java +++ b/slider-core/src/main/java/org/apache/slider/common/tools/SliderUtils.java @@ -623,9 +623,9 @@ public final class SliderUtils { * Sorts the given list of application reports * Finished instances are ordered by finished time and running/accepted instances are * ordered by start time - * Finally Instance are order by finished instances and running instances + * Finally Instance are order by finished instances coming after running instances * - * @param instances + * @param instances list of intances */ public static void sortApplicationReport(List<ApplicationReport> instances) { if (instances.size() <= 1) { @@ -662,8 +662,8 @@ public final class SliderUtils { Collections.sort(nonLiveInstance, nonLiveInstanceComparator); } instances.clear(); - instances.addAll(nonLiveInstance); instances.addAll(liveInstance); + instances.addAll(nonLiveInstance); } /** http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c4575bde/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy index dc0f620..4a6b7ca 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionList.groovy @@ -173,15 +173,11 @@ class TestActionList extends AgentMiniClusterTestBase { args.live = true; args.history = false; - try { - int exitCode = sliderClient.actionList(clustername, args); - fail("expected an exception, got a status code $exitCode") - } catch (UnknownApplicationInstanceException expected) { - } + assert 0 == sliderClient.actionList(clustername, args); // historical list will work args.history = true; - assert sliderClient.actionList(clustername, args) == 0; + assert 0 == sliderClient.actionList(clustername, args) // thaw ActionThawArgs thawArgs = new ActionThawArgs(); @@ -192,7 +188,6 @@ class TestActionList extends AgentMiniClusterTestBase { args.live = true; args.history = false; assert 0 == sliderClient.actionList(clustername, args); - assert launcher.serviceExitCode == 0 //Listing all the instance both history (previously freezed instance) and live args.live = true http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c4575bde/slider-core/src/test/groovy/org/apache/slider/agent/freezethaw/TestFreezeCommands.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/freezethaw/TestFreezeCommands.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/freezethaw/TestFreezeCommands.groovy index 60ffa3e..0473e02 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/freezethaw/TestFreezeCommands.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/freezethaw/TestFreezeCommands.groovy @@ -107,7 +107,8 @@ class TestFreezeCommands extends AgentMiniClusterTestBase { ServiceLauncher thawCommand = execSliderCommand(conf, commands); assertSucceeded(thawCommand) assertSucceeded(execSliderCommand(conf, - [SliderActions.ACTION_LIST, clustername])) + [SliderActions.ACTION_LIST, clustername, + Arguments.ARG_LIVE])) assertSucceeded(execSliderCommand(conf, [SliderActions.ACTION_EXISTS, clustername])) http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c4575bde/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAMDestroy.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAMDestroy.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAMDestroy.groovy index 49814e7..ed716e0 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAMDestroy.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/standalone/TestStandaloneAMDestroy.groovy @@ -58,6 +58,22 @@ class TestStandaloneAMDestroy extends AgentMiniClusterTestBase { ]) assert launcher1.serviceExitCode == 0 + // try to list it and expect failures + try { + launchClientAgainstMiniMR( + configuration, + [ + SliderActions.ACTION_LIST, + "no-cluster-of-this-name", + Arguments.ARG_LIVE, Arguments.ARG_HISTORY + ]) + fail("expected a failure") + } catch (UnknownApplicationInstanceException e) { + assertExceptionDetails(e, + SliderExitCodes.EXIT_UNKNOWN_INSTANCE, + ErrorStrings.E_UNKNOWN_INSTANCE) + } + ServiceLauncher<SliderClient> launcher = createStandaloneAM( clustername, true, http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/c4575bde/slider-core/src/test/groovy/org/apache/slider/client/TestCommonArgParsing.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/client/TestCommonArgParsing.groovy b/slider-core/src/test/groovy/org/apache/slider/client/TestCommonArgParsing.groovy index 95d3483..8b013e5 100644 --- a/slider-core/src/test/groovy/org/apache/slider/client/TestCommonArgParsing.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/client/TestCommonArgParsing.groovy @@ -74,7 +74,8 @@ class TestCommonArgParsing implements SliderActions, Arguments { @Test public void testSliderBasePath() throws Throwable { - ClientArgs clientArgs = createClientArgs([ACTION_LIST, "--basepath", "/projects/slider/clusters"]) + ClientArgs clientArgs = createClientArgs([ACTION_LIST, + ARG_BASE_PATH, "/projects/slider/clusters"]) assert clientArgs.basePath == new Path("/projects/slider/clusters") }
