SLIDER-554 slide exists --state may pick up KILLED/FINISHED app reports and then fail
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/0254e9d0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/0254e9d0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/0254e9d0 Branch: refs/heads/feature/SLIDER-460-stderr Commit: 0254e9d00af363eba280c05824b8ae8b67c3873c Parents: 1e4edc2 Author: Steve Loughran <ste...@apache.org> Authored: Wed Oct 22 12:34:14 2014 +0100 Committer: Steve Loughran <ste...@apache.org> Committed: Thu Oct 23 11:35:54 2014 +0100 ---------------------------------------------------------------------- .../org/apache/slider/client/SliderClient.java | 57 ++++++++++++-------- .../slider/client/SliderYarnClientImpl.java | 22 ++++++++ .../agent/actions/TestActionExists.groovy | 16 ++++-- 3 files changed, 69 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0254e9d0/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 e89ca65..6ea305e 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 @@ -1752,36 +1752,49 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe log.info("Application {} exists", name); return EXIT_SUCCESS; } - + //test for liveness/state - ApplicationReport instance = findInstance(name); + boolean inDesiredState = false; + ApplicationReport instance; + instance = findInstance(name); if (instance == null) { log.info("Application {} not running", name); return EXIT_FALSE; - } else { - // the app exists, but it may be in a terminated state - SliderUtils.OnDemandReportStringifier report = - new SliderUtils.OnDemandReportStringifier(instance); - YarnApplicationState appstate = - instance.getYarnApplicationState(); - boolean inDesiredState; - if (checkLive) { - inDesiredState = + } + if (checkLive) { + // the app exists, check that it is not in any terminated state + YarnApplicationState appstate = instance.getYarnApplicationState(); + inDesiredState = appstate.ordinal() < YarnApplicationState.FINISHED.ordinal(); - } else { - state = state.toUpperCase(Locale.ENGLISH); - inDesiredState = state.equals(appstate.toString()); - } - if (!inDesiredState) { - //cluster in the list of apps but not running - log.info("Application {} found but is in wrong state {}", name, appstate); - log.debug("State {}", report); - return EXIT_FALSE; + } else { + // scan for instance in single --state state + List<ApplicationReport> userInstances = yarnClient.listInstances(""); + state = state.toUpperCase(Locale.ENGLISH); + YarnApplicationState desiredState = + YarnApplicationState.valueOf(state); + ApplicationReport foundInstance = + yarnClient.findClusterInInstanceList(userInstances, name, desiredState); + if (foundInstance != null) { + // found in selected state: success + inDesiredState = true; + // mark this as the instance to report + instance = foundInstance; } - log.info("Application {} is {}\n{}", name, appstate, report); } - return EXIT_SUCCESS; + SliderUtils.OnDemandReportStringifier report = + new SliderUtils.OnDemandReportStringifier(instance); + if (!inDesiredState) { + //cluster in the list of apps but not running + log.info("Application {} found but is in wrong state {}", name, + instance.getYarnApplicationState()); + log.debug("State {}", report); + return EXIT_FALSE; + } else { + log.info("Application {} is {}\n{}", name, + instance.getYarnApplicationState(), report); + return EXIT_SUCCESS; + } } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0254e9d0/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java ---------------------------------------------------------------------- diff --git a/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java b/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java index 3151a09..c793bd1 100644 --- a/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java +++ b/slider-core/src/main/java/org/apache/slider/client/SliderYarnClientImpl.java @@ -250,6 +250,12 @@ public class SliderYarnClientImpl extends YarnClientImpl { return results; } + /** + * Find a cluster in the instance list; biased towards live instances + * @param instances + * @param appname + * @return + */ public ApplicationReport findClusterInInstanceList(List<ApplicationReport> instances, String appname) { ApplicationReport found = null; @@ -268,5 +274,21 @@ public class SliderYarnClientImpl extends YarnClientImpl { return found; } + public ApplicationReport findClusterInInstanceList(List<ApplicationReport> instances, + String appname, + YarnApplicationState desiredState) { + ApplicationReport found = null; + ApplicationReport foundAndLive = null; + for (ApplicationReport app : instances) { + if (app.getName().equals(appname)) { + if (app.getYarnApplicationState().equals(desiredState)) { + return app; + } + } + } + // nothing found in desired state + return null; + } + } http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/0254e9d0/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionExists.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionExists.groovy b/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionExists.groovy index 277fa7d..202734c 100644 --- a/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionExists.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/agent/actions/TestActionExists.groovy @@ -112,9 +112,9 @@ class TestActionExists extends AgentMiniClusterTestBase { assert 0 == sliderClient.actionExists(clustername, true) // assert that the cluster is in the running state - ActionExistsArgs args = new ActionExistsArgs() - args.state = YarnApplicationState.RUNNING.toString() - assert 0 == sliderClient.actionExists(clustername, args) + ActionExistsArgs running = new ActionExistsArgs() + running.state = YarnApplicationState.RUNNING.toString() + assert 0 == sliderClient.actionExists(clustername, running) // stop the cluster clusterActionFreeze(sliderClient, clustername) @@ -124,7 +124,15 @@ class TestActionExists extends AgentMiniClusterTestBase { //but the cluster is still there for the default assert 0 == sliderClient.actionExists(clustername, false) - assert LauncherExitCodes.EXIT_FALSE == sliderClient.actionExists(clustername, args) + assert LauncherExitCodes.EXIT_FALSE == sliderClient.actionExists(clustername, running) + + // verify that on a cluster thaw the existence probes still work, that is + // they do not discover the previous instance and return false when there + // is actually a live cluster + ServiceLauncher launcher2 = thawCluster(clustername, [], true); + addToTeardown(launcher2) + assert 0 == sliderClient.actionExists(clustername, running) + assert 0 == sliderClient.actionExists(clustername, true) } }