@Test public void testAddInstallCommand() throws Exception { InputStream metainfo_1 = new ByteArrayInputStream(metainfo_1_str.getBytes()); Metainfo metainfo = new MetainfoParser().fromXmlStream(metainfo_1); AgentProviderService aps = createAgentProviderService(new Configuration()); HeartBeatResponse hbr = new HeartBeatResponse(); StateAccessForProviders access = createNiceMock(StateAccessForProviders.class); AgentProviderService mockAps = Mockito.spy(aps); doReturn(access).when(mockAps).getAmState(); AggregateConf aggConf = new AggregateConf(); ConfTreeOperations treeOps = aggConf.getAppConfOperations(); treeOps.getGlobalOptions().put(AgentKeys.JAVA_HOME, "java_home"); treeOps.set(OptionKeys.APPLICATION_NAME, "HBASE"); treeOps.set("site.fs.defaultFS", "hdfs: treeOps.set("internal.data.dir.path", "hdfs: treeOps.set(OptionKeys.ZOOKEEPER_HOSTS, "HOST1"); expect(access.getAppConfSnapshot()).andReturn(treeOps).anyTimes(); expect(access.getInternalsSnapshot()).andReturn(treeOps).anyTimes(); expect(access.isApplicationLive()).andReturn(true).anyTimes(); doReturn("HOST1").when(mockAps).getClusterInfoPropertyValue(anyString()); doReturn(metainfo).when(mockAps).getMetaInfo(anyString()); doReturn(new HashMap<String, DefaultConfig>()).when(mockAps).getDefaultConfigs(anyString()); Map<String, Map<String, ClusterNode>> roleClusterNodeMap = new HashMap<String, Map<String, ClusterNode>>(); Map<String, ClusterNode> container = new HashMap<String, ClusterNode>(); ClusterNode cn1 = new ClusterNode(new MockContainerId(1)); cn1.host = "HOST1"; container.put("cid1", cn1); roleClusterNodeMap.put("HBASE_MASTER", container); doReturn(roleClusterNodeMap).when(mockAps).getRoleClusterNodeMapping(); replay(access); mockAps.addInstallCommand("HBASE_MASTER", "HBASE_MASTER", "cid1", hbr, "", null, 0, null); ExecutionCommand cmd = hbr.getExecutionCommands().get(0); String pkgs = cmd.getHostLevelParams().get(AgentKeys.PACKAGE_LIST); Assert.assertEquals("[{\"type\":\"tarball\",\"name\":\"files/hbase-0.96.1-hadoop2-bin.tar.gz\"}]", pkgs); Assert.assertEquals("java_home", cmd.getHostLevelParams().get(AgentKeys.JAVA_HOME)); Assert.assertEquals("cid1", cmd.getHostLevelParams().get("container_id")); Assert.assertEquals(Command.INSTALL.toString(), cmd.getRoleCommand()); Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_log_dir")); Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_pid_dir")); Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_install_dir")); Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_input_conf_dir")); Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_container_id")); Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("pid_file")); Assert.assertTrue(cmd.getConfigurations().get("global").containsKey("app_root")); }
@VisibleForTesting protected void addInstallCommand(String roleName, String roleGroup, String containerId, HeartBeatResponse response, String scriptPath, ComponentCommand compCmd, long timeout, String pkg) throws SliderException { assert getAmState().isApplicationLive(); ConfTreeOperations appConf = getAmState().getAppConfSnapshot(); ExecutionCommand cmd = new ExecutionCommand(AgentCommandType.EXECUTION_COMMAND); prepareExecutionCommand(cmd); String clusterName = getClusterName(); cmd.setClusterName(clusterName); cmd.setRoleCommand(Command.INSTALL.toString()); cmd.setServiceName(clusterName); cmd.setComponentName(roleName); cmd.setRole(roleName); cmd.setPkg(pkg); Map<String, String> hostLevelParams = new TreeMap<String, String>(); hostLevelParams.put(JAVA_HOME, appConf.getGlobalOptions().getOption(JAVA_HOME, getJDKDir())); hostLevelParams.put(PACKAGE_LIST, getPackageList(roleGroup)); hostLevelParams.put(CONTAINER_ID, containerId); cmd.setHostLevelParams(hostLevelParams); Map<String, Map<String, String>> configurations = buildCommandConfigurations(appConf, containerId, roleName, roleGroup); cmd.setConfigurations(configurations); Map<String, Map<String, String>> componentConfigurations = buildComponentConfigurations(appConf); cmd.setComponentConfigurations(componentConfigurations); if (SliderUtils.isSet(scriptPath)) { cmd.setCommandParams(commandParametersSet(scriptPath, timeout, false)); } else { ComponentCommand effectiveCommand = compCmd; if (effectiveCommand == null) { effectiveCommand = ComponentCommand.getDefaultComponentCommand("INSTALL"); } cmd.setCommandParams(commandParametersSet(effectiveCommand, timeout, false)); configurations.get("global").put("exec_cmd", effectiveCommand.getExec()); } cmd.setHostname(getClusterInfoPropertyValue(StatusKeys.INFO_AM_HOSTNAME)); response.addExecutionCommand(cmd); log.debug("command looks like: {} ", cmd); }
AgentProviderService extends AbstractProviderService implements
    ProviderCore,
    AgentKeys,
    SliderKeys, AgentRestOperations { @VisibleForTesting protected void addInstallCommand(String roleName, String roleGroup, String containerId, HeartBeatResponse response, String scriptPath, ComponentCommand compCmd, long timeout, String pkg) throws SliderException { assert getAmState().isApplicationLive(); ConfTreeOperations appConf = getAmState().getAppConfSnapshot(); ExecutionCommand cmd = new ExecutionCommand(AgentCommandType.EXECUTION_COMMAND); prepareExecutionCommand(cmd); String clusterName = getClusterName(); cmd.setClusterName(clusterName); cmd.setRoleCommand(Command.INSTALL.toString()); cmd.setServiceName(clusterName); cmd.setComponentName(roleName); cmd.setRole(roleName); cmd.setPkg(pkg); Map<String, String> hostLevelParams = new TreeMap<String, String>(); hostLevelParams.put(JAVA_HOME, appConf.getGlobalOptions().getOption(JAVA_HOME, getJDKDir())); hostLevelParams.put(PACKAGE_LIST, getPackageList(roleGroup)); hostLevelParams.put(CONTAINER_ID, containerId); cmd.setHostLevelParams(hostLevelParams); Map<String, Map<String, String>> configurations = buildCommandConfigurations(appConf, containerId, roleName, roleGroup); cmd.setConfigurations(configurations); Map<String, Map<String, String>> componentConfigurations = buildComponentConfigurations(appConf); cmd.setComponentConfigurations(componentConfigurations); if (SliderUtils.isSet(scriptPath)) { cmd.setCommandParams(commandParametersSet(scriptPath, timeout, false)); } else { ComponentCommand effectiveCommand = compCmd; if (effectiveCommand == null) { effectiveCommand = ComponentCommand.getDefaultComponentCommand("INSTALL"); } cmd.setCommandParams(commandParametersSet(effectiveCommand, timeout, false)); configurations.get("global").put("exec_cmd", effectiveCommand.getExec()); } cmd.setHostname(getClusterInfoPropertyValue(StatusKeys.INFO_AM_HOSTNAME)); response.addExecutionCommand(cmd); log.debug("command looks like: {} ", cmd); } }
AgentProviderService extends AbstractProviderService implements
    ProviderCore,
    AgentKeys,
    SliderKeys, AgentRestOperations { @VisibleForTesting protected void addInstallCommand(String roleName, String roleGroup, String containerId, HeartBeatResponse response, String scriptPath, ComponentCommand compCmd, long timeout, String pkg) throws SliderException { assert getAmState().isApplicationLive(); ConfTreeOperations appConf = getAmState().getAppConfSnapshot(); ExecutionCommand cmd = new ExecutionCommand(AgentCommandType.EXECUTION_COMMAND); prepareExecutionCommand(cmd); String clusterName = getClusterName(); cmd.setClusterName(clusterName); cmd.setRoleCommand(Command.INSTALL.toString()); cmd.setServiceName(clusterName); cmd.setComponentName(roleName); cmd.setRole(roleName); cmd.setPkg(pkg); Map<String, String> hostLevelParams = new TreeMap<String, String>(); hostLevelParams.put(JAVA_HOME, appConf.getGlobalOptions().getOption(JAVA_HOME, getJDKDir())); hostLevelParams.put(PACKAGE_LIST, getPackageList(roleGroup)); hostLevelParams.put(CONTAINER_ID, containerId); cmd.setHostLevelParams(hostLevelParams); Map<String, Map<String, String>> configurations = buildCommandConfigurations(appConf, containerId, roleName, roleGroup); cmd.setConfigurations(configurations); Map<String, Map<String, String>> componentConfigurations = buildComponentConfigurations(appConf); cmd.setComponentConfigurations(componentConfigurations); if (SliderUtils.isSet(scriptPath)) { cmd.setCommandParams(commandParametersSet(scriptPath, timeout, false)); } else { ComponentCommand effectiveCommand = compCmd; if (effectiveCommand == null) { effectiveCommand = ComponentCommand.getDefaultComponentCommand("INSTALL"); } cmd.setCommandParams(commandParametersSet(effectiveCommand, timeout, false)); configurations.get("global").put("exec_cmd", effectiveCommand.getExec()); } cmd.setHostname(getClusterInfoPropertyValue(StatusKeys.INFO_AM_HOSTNAME)); response.addExecutionCommand(cmd); log.debug("command looks like: {} ", cmd); } AgentProviderService(); }
AgentProviderService extends AbstractProviderService implements
    ProviderCore,
    AgentKeys,
    SliderKeys, AgentRestOperations { @VisibleForTesting protected void addInstallCommand(String roleName, String roleGroup, String containerId, HeartBeatResponse response, String scriptPath, ComponentCommand compCmd, long timeout, String pkg) throws SliderException { assert getAmState().isApplicationLive(); ConfTreeOperations appConf = getAmState().getAppConfSnapshot(); ExecutionCommand cmd = new ExecutionCommand(AgentCommandType.EXECUTION_COMMAND); prepareExecutionCommand(cmd); String clusterName = getClusterName(); cmd.setClusterName(clusterName); cmd.setRoleCommand(Command.INSTALL.toString()); cmd.setServiceName(clusterName); cmd.setComponentName(roleName); cmd.setRole(roleName); cmd.setPkg(pkg); Map<String, String> hostLevelParams = new TreeMap<String, String>(); hostLevelParams.put(JAVA_HOME, appConf.getGlobalOptions().getOption(JAVA_HOME, getJDKDir())); hostLevelParams.put(PACKAGE_LIST, getPackageList(roleGroup)); hostLevelParams.put(CONTAINER_ID, containerId); cmd.setHostLevelParams(hostLevelParams); Map<String, Map<String, String>> configurations = buildCommandConfigurations(appConf, containerId, roleName, roleGroup); cmd.setConfigurations(configurations); Map<String, Map<String, String>> componentConfigurations = buildComponentConfigurations(appConf); cmd.setComponentConfigurations(componentConfigurations); if (SliderUtils.isSet(scriptPath)) { cmd.setCommandParams(commandParametersSet(scriptPath, timeout, false)); } else { ComponentCommand effectiveCommand = compCmd; if (effectiveCommand == null) { effectiveCommand = ComponentCommand.getDefaultComponentCommand("INSTALL"); } cmd.setCommandParams(commandParametersSet(effectiveCommand, timeout, false)); configurations.get("global").put("exec_cmd", effectiveCommand.getExec()); } cmd.setHostname(getClusterInfoPropertyValue(StatusKeys.INFO_AM_HOSTNAME)); response.addExecutionCommand(cmd); log.debug("command looks like: {} ", cmd); } AgentProviderService(); @Override String getHumanName(); @Override List<ProviderRole> getRoles(); @Override Configuration loadProviderConfigurationInformation(File confDir); @Override void validateInstanceDefinition(AggregateConf instanceDefinition); @Override void initializeApplicationConfiguration(
      AggregateConf instanceDefinition, SliderFileSystem fileSystem,
      String roleGroup); @Override void buildContainerLaunchContext(ContainerLauncher launcher,
                                          AggregateConf instanceDefinition,
                                          Container container,
                                          ProviderRole providerRole,
                                          SliderFileSystem fileSystem,
                                          Path generatedConfPath,
                                          MapOperations resourceComponent,
                                          MapOperations appComponent,
                                          Path containerTmpDirPath); @Override void rebuildContainerDetails(List<Container> liveContainers,
                                      String applicationId, Map<Integer, ProviderRole> providerRoleMap); @Override boolean isSupportedRole(String role); @Override RegistrationResponse handleRegistration(Register registration); @Override HeartBeatResponse handleHeartBeat(HeartBeat heartBeat); @Override Map<String, MonitorDetail> buildMonitorDetails(ClusterDescription clusterDesc); @Override void applyInitialRegistryDefinitions(URL amWebURI,
      URL agentOpsURI,
      URL agentStatusURI,
      ServiceRecord serviceRecord); @Override void notifyContainerCompleted(ContainerId containerId); void setInUpgradeMode(boolean inUpgradeMode); void addUpgradeContainers(Set<String> upgradeContainers); void setAppStopInitiated(boolean appStopInitiated); Map<String, String> buildProviderStatus(); }
AgentProviderService extends AbstractProviderService implements
    ProviderCore,
    AgentKeys,
    SliderKeys, AgentRestOperations { @VisibleForTesting protected void addInstallCommand(String roleName, String roleGroup, String containerId, HeartBeatResponse response, String scriptPath, ComponentCommand compCmd, long timeout, String pkg) throws SliderException { assert getAmState().isApplicationLive(); ConfTreeOperations appConf = getAmState().getAppConfSnapshot(); ExecutionCommand cmd = new ExecutionCommand(AgentCommandType.EXECUTION_COMMAND); prepareExecutionCommand(cmd); String clusterName = getClusterName(); cmd.setClusterName(clusterName); cmd.setRoleCommand(Command.INSTALL.toString()); cmd.setServiceName(clusterName); cmd.setComponentName(roleName); cmd.setRole(roleName); cmd.setPkg(pkg); Map<String, String> hostLevelParams = new TreeMap<String, String>(); hostLevelParams.put(JAVA_HOME, appConf.getGlobalOptions().getOption(JAVA_HOME, getJDKDir())); hostLevelParams.put(PACKAGE_LIST, getPackageList(roleGroup)); hostLevelParams.put(CONTAINER_ID, containerId); cmd.setHostLevelParams(hostLevelParams); Map<String, Map<String, String>> configurations = buildCommandConfigurations(appConf, containerId, roleName, roleGroup); cmd.setConfigurations(configurations); Map<String, Map<String, String>> componentConfigurations = buildComponentConfigurations(appConf); cmd.setComponentConfigurations(componentConfigurations); if (SliderUtils.isSet(scriptPath)) { cmd.setCommandParams(commandParametersSet(scriptPath, timeout, false)); } else { ComponentCommand effectiveCommand = compCmd; if (effectiveCommand == null) { effectiveCommand = ComponentCommand.getDefaultComponentCommand("INSTALL"); } cmd.setCommandParams(commandParametersSet(effectiveCommand, timeout, false)); configurations.get("global").put("exec_cmd", effectiveCommand.getExec()); } cmd.setHostname(getClusterInfoPropertyValue(StatusKeys.INFO_AM_HOSTNAME)); response.addExecutionCommand(cmd); log.debug("command looks like: {} ", cmd); } AgentProviderService(); @Override String getHumanName(); @Override List<ProviderRole> getRoles(); @Override Configuration loadProviderConfigurationInformation(File confDir); @Override void validateInstanceDefinition(AggregateConf instanceDefinition); @Override void initializeApplicationConfiguration(
      AggregateConf instanceDefinition, SliderFileSystem fileSystem,
      String roleGroup); @Override void buildContainerLaunchContext(ContainerLauncher launcher,
                                          AggregateConf instanceDefinition,
                                          Container container,
                                          ProviderRole providerRole,
                                          SliderFileSystem fileSystem,
                                          Path generatedConfPath,
                                          MapOperations resourceComponent,
                                          MapOperations appComponent,
                                          Path containerTmpDirPath); @Override void rebuildContainerDetails(List<Container> liveContainers,
                                      String applicationId, Map<Integer, ProviderRole> providerRoleMap); @Override boolean isSupportedRole(String role); @Override RegistrationResponse handleRegistration(Register registration); @Override HeartBeatResponse handleHeartBeat(HeartBeat heartBeat); @Override Map<String, MonitorDetail> buildMonitorDetails(ClusterDescription clusterDesc); @Override void applyInitialRegistryDefinitions(URL amWebURI,
      URL agentOpsURI,
      URL agentStatusURI,
      ServiceRecord serviceRecord); @Override void notifyContainerCompleted(ContainerId containerId); void setInUpgradeMode(boolean inUpgradeMode); void addUpgradeContainers(Set<String> upgradeContainers); void setAppStopInitiated(boolean appStopInitiated); Map<String, String> buildProviderStatus();  }