SLIDER-863 TestUpgradeCommandOptionsTestActionList
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/69856ad1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/69856ad1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/69856ad1 Branch: refs/heads/develop Commit: 69856ad1e67029fffa26b1cdf998fed4eb97e2ad Parents: fc0343b Author: Steve Loughran <[email protected]> Authored: Tue Apr 28 17:35:04 2015 +0100 Committer: Steve Loughran <[email protected]> Committed: Tue Apr 28 17:35:04 2015 +0100 ---------------------------------------------------------------------- .../org/apache/slider/client/SliderClient.java | 21 ++-- .../client/TestUpgradeCommandOptions.groovy | 125 ++++++++++--------- 2 files changed, 77 insertions(+), 69 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/69856ad1/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 51e2b16..5d5e217 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 @@ -247,6 +247,8 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe = "A valid application type name is required (e.g. HBASE)."; public static final String E_USE_REPLACEPKG_TO_OVERWRITE = "Use --replacepkg to overwrite."; public static final String E_PACKAGE_DOES_NOT_EXIST = "Package does not exist"; + public static final String E_NO_ZOOKEEPER_QUORUM = "No Zookeeper quorum defined"; + public static final String E_NO_RESOURCE_MANAGER = "No valid Resource Manager address provided"; private static PrintStream clientOutputStream = System.out; // value should not be changed without updating string find in slider.py @@ -1687,7 +1689,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe quorum = registryQuorum; } if (isUnset(quorum)) { - throw new BadConfigException("No Zookeeper quorum defined"); + throw new BadConfigException(E_NO_ZOOKEEPER_QUORUM); } ZKPathBuilder zkPaths = new ZKPathBuilder(getAppName(), getUsername(), @@ -1699,7 +1701,8 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe if (isSet(zookeeperRoot)) { zkPaths.setAppPath(zookeeperRoot); } else { - String createDefaultZkNode = appConf.getGlobalOptions().getOption(AgentKeys.CREATE_DEF_ZK_NODE, "false"); + String createDefaultZkNode = appConf.getGlobalOptions() + .getOption(AgentKeys.CREATE_DEF_ZK_NODE, "false"); if (createDefaultZkNode.equals("true")) { String defaultZKPath = createZookeeperNode(clustername, false); log.debug("ZK node created for application instance: {}", defaultZKPath); @@ -1764,7 +1767,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe } catch (LockAcquireFailedException e) { log.warn("Failed to get a Lock on cluster resource : {}", e); throw new BadClusterStateException( - "Failed to validate client resource definition " + clustername + ": " + "Failed to load client resource definition " + clustername + ": " + e); } Map<String, Integer> clusterComponentInstances = new HashMap<>(); @@ -1802,8 +1805,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe log.error("Mismatch found in upgrade resource definition and cluster " + "resource state"); if (!clientComponentInstances.isEmpty()) { - log.info(" Following are the upgrade resource definitions that do " - + "not match"); + log.info("The upgrade resource definitions that do not match are:"); for (Map.Entry<String, Integer> clientComponentInstanceEntry : clientComponentInstances .entrySet()) { log.info(" Component Name: {}, Instance count: {}", @@ -1812,7 +1814,7 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe } } if (!clusterComponentInstances.isEmpty()) { - log.info(" Following are the cluster resources that do not match"); + log.info("The cluster resources that do not match are:"); for (Map.Entry<String, Integer> clusterComponentInstanceEntry : clusterComponentInstances .entrySet()) { log.info(" Component Name: {}, Instance count: {}", @@ -1820,10 +1822,10 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe clusterComponentInstanceEntry.getValue()); } } - throw new BadConfigException("\n\nResource definition provided for " + throw new BadConfigException("Resource definition provided for " + "upgrade does not match with that of the currently running " + "cluster.\nIf you are aware of what you are doing, rerun the " - + "command with " + Arguments.ARG_FORCE + " option.\n"); + + "command with " + Arguments.ARG_FORCE + " option."); } } @@ -1881,7 +1883,8 @@ public class SliderClient extends AbstractSliderLaunchedService implements RunSe if (!getConfig().getBoolean(YarnConfiguration.RM_HA_ENABLED, false) && !SliderUtils.isAddressDefined(rmAddr)) { throw new BadCommandArgumentsException( - "No valid Resource Manager address provided in the argument " + E_NO_RESOURCE_MANAGER + + " in the argument " + Arguments.ARG_MANAGER + " or the configuration property " + YarnConfiguration.RM_ADDRESS http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/69856ad1/slider-core/src/test/groovy/org/apache/slider/client/TestUpgradeCommandOptions.groovy ---------------------------------------------------------------------- diff --git a/slider-core/src/test/groovy/org/apache/slider/client/TestUpgradeCommandOptions.groovy b/slider-core/src/test/groovy/org/apache/slider/client/TestUpgradeCommandOptions.groovy index 17f807d..8d5aef1 100644 --- a/slider-core/src/test/groovy/org/apache/slider/client/TestUpgradeCommandOptions.groovy +++ b/slider-core/src/test/groovy/org/apache/slider/client/TestUpgradeCommandOptions.groovy @@ -26,12 +26,15 @@ import org.apache.hadoop.fs.RawLocalFileSystem import org.apache.hadoop.yarn.api.records.ApplicationReport import org.apache.hadoop.yarn.conf.YarnConfiguration import org.apache.slider.agent.AgentMiniClusterTestBase +import org.apache.slider.common.SliderExitCodes +import org.apache.slider.common.params.Arguments import org.apache.slider.common.params.ClientArgs import org.apache.slider.common.tools.SliderFileSystem import org.apache.slider.common.tools.SliderUtils import org.apache.slider.core.exceptions.BadConfigException import org.apache.slider.core.exceptions.SliderException import org.apache.slider.core.exceptions.UnknownApplicationInstanceException +import org.apache.slider.core.main.LauncherExitCodes import org.apache.slider.core.main.ServiceLauncher import org.junit.Before import org.junit.Test @@ -66,8 +69,7 @@ class TestUpgradeCommandOptions extends AgentMiniClusterTestBase { public void testUpgradeAppNotRunning() throws Throwable { describe("Calling upgrade") YarnConfiguration conf = SliderUtils.createConfiguration() - File tmpDir = File.createTempFile("test",".dir") - tmpDir.delete() + File tmpDir = createTempDir() try { ServiceLauncher launcher = launch(TestSliderClient, conf, @@ -87,6 +89,12 @@ class TestUpgradeCommandOptions extends AgentMiniClusterTestBase { } } + public File createTempDir() { + File tmpDir = File.createTempFile("test", ".dir") + tmpDir.delete() + return tmpDir + } + @Test public void testAll() { // Create a single test to reduce the amount of test execution time @@ -115,8 +123,9 @@ class TestUpgradeCommandOptions extends AgentMiniClusterTestBase { public void testUpgradeInvalidResourcesFile(String clustername) throws Throwable { - String appConfigFile = Path.getPathWithoutSchemeAndAuthority(testFileSystem - .buildClusterDirPath(clustername)).toString() + "/app_config.json" + Path appConfigFile = getClusterFile(clustername, "app_config.json") + File tmpDir = createTempDir() + File resourcesJson = new File(tmpDir, "resources.json") describe("Calling upgrade - testUpgradeInvalidResourcesFile") try { @@ -130,23 +139,27 @@ class TestUpgradeCommandOptions extends AgentMiniClusterTestBase { ClientArgs.ARG_TEMPLATE, appConfigFile, ClientArgs.ARG_RESOURCES, - "/tmp/resources.json" + resourcesJson.absolutePath ] ) fail("Upgrade command should have failed") - } catch (SliderException e) { - log.info(e.toString()) - assert e instanceof BadConfigException - assert e.getMessage().contains("incorrect argument to --resources: " + - "\"/tmp/resources.json\" : java.io.FileNotFoundException: " + - "/tmp/resources.json (No such file or directory)") + } catch (BadConfigException e) { + assertExceptionDetails(e, SliderExitCodes.EXIT_BAD_CONFIGURATION, + Arguments.ARG_RESOURCES) } } + public Path getClusterFile(String clustername, String clusterfile) { + Path path = new Path(testFileSystem.buildClusterDirPath(clustername), clusterfile) + return Path.getPathWithoutSchemeAndAuthority(path) + } + public void testUpgradeInvalidConfigFile(String clustername) throws Throwable { - String resourceFile = Path.getPathWithoutSchemeAndAuthority(testFileSystem - .buildClusterDirPath(clustername)).toString() + "/resources.json" + Path resourceFile = getClusterFile(clustername, "resources.json") + File tmpDir = createTempDir() + File appconfig = new File(tmpDir, "appConfig.json") + describe("Calling upgrade - testUpgradeInvalidConfigFile") try { @@ -158,18 +171,15 @@ class TestUpgradeCommandOptions extends AgentMiniClusterTestBase { ClientArgs.ACTION_UPGRADE, clustername, ClientArgs.ARG_TEMPLATE, - "/tmp/appConfig.json", + appconfig.absolutePath, ClientArgs.ARG_RESOURCES, resourceFile ] ) fail("Upgrade command should have failed") - } catch (SliderException e) { - log.info(e.toString()) - assert e instanceof BadConfigException - assert e.getMessage().contains("incorrect argument to --template: " + - "\"/tmp/appConfig.json\" : java.io.FileNotFoundException: " + - "/tmp/appConfig.json (No such file or directory)") + } catch (BadConfigException e) { + assertExceptionDetails(e, SliderExitCodes.EXIT_BAD_CONFIGURATION, + Arguments.ARG_TEMPLATE) } } @@ -181,48 +191,43 @@ class TestUpgradeCommandOptions extends AgentMiniClusterTestBase { .buildClusterDirPath(clustername)).toString() + "/app_config.json" describe("Calling upgrade - testUpgradeSpecSuccess") - try { - log.info("Listing application containers before upgrade spec") - launcher = launchClientAgainstMiniMR( - //config includes RM binding info - yarnConfig, - //varargs list of command line params - [ - ClientArgs.ACTION_LIST, - clustername, - ClientArgs.ARG_CONTAINERS - ] - ) + log.info("Listing application containers before upgrade spec") + launcher = launchClientAgainstMiniMR( + //config includes RM binding info + yarnConfig, + //varargs list of command line params + [ + ClientArgs.ACTION_LIST, + clustername, + ClientArgs.ARG_CONTAINERS + ] + ) - launcher = launchClientAgainstMiniMR( - //config includes RM binding info - yarnConfig, - //varargs list of command line params - [ - ClientArgs.ACTION_UPGRADE, - clustername, - ClientArgs.ARG_TEMPLATE, - appConfigFile, - ClientArgs.ARG_RESOURCES, - resourceFile - ] - ) + launcher = launchClientAgainstMiniMR( + //config includes RM binding info + yarnConfig, + //varargs list of command line params + [ + ClientArgs.ACTION_UPGRADE, + clustername, + ClientArgs.ARG_TEMPLATE, + appConfigFile, + ClientArgs.ARG_RESOURCES, + resourceFile + ] + ) - log.info("Listing application containers after upgrade spec") - launcher = launchClientAgainstMiniMR( - //config includes RM binding info - yarnConfig, - //varargs list of command line params - [ - ClientArgs.ACTION_LIST, - clustername, - ClientArgs.ARG_CONTAINERS - ] - ) - } catch (SliderException e) { - log.info(e.toString()) - fail("Upgrade command should not have failed") - } + log.info("Listing application containers after upgrade spec") + launcher = launchClientAgainstMiniMR( + //config includes RM binding info + yarnConfig, + //varargs list of command line params + [ + ClientArgs.ACTION_LIST, + clustername, + ClientArgs.ARG_CONTAINERS + ] + ) assert launcher.serviceExitCode == 0 }
