@Test public void testAction() throws Exception { Pattern regex = Pattern.compile("^.*\\s*(HBASE_MASTER_OPTS)\\s*=.*(XX:MaxDirectMemorySize).*$", Pattern.MULTILINE); Map<String, String> commandParams = new HashMap<String, String>(); commandParams.put("clusterName", "c1"); ExecutionCommand executionCommand = new ExecutionCommand(); executionCommand.setCommandParams(commandParams); executionCommand.setClusterName("c1"); HostRoleCommand hrc = EasyMock.createMock(HostRoleCommand.class); expect(hrc.getRequestId()).andReturn(1L).anyTimes(); expect(hrc.getStageId()).andReturn(2L).anyTimes(); expect(hrc.getExecutionCommandWrapper()).andReturn(new ExecutionCommandWrapper(executionCommand)).anyTimes(); replay(hrc); HBaseEnvMaxDirectMemorySizeAction action = new HBaseEnvMaxDirectMemorySizeAction(); m_clusterField.set(action, clusters); action.setExecutionCommand(executionCommand); action.setHostRoleCommand(hrc); CommandReport report = action.execute(null); assertNotNull(report); Cluster c = clusters.getCluster("c1"); Config config = c.getDesiredConfigByType("hbase-env"); Map<String, String> map = config.getProperties(); Assert.assertTrue(map.containsKey("content")); String content = map.get("content"); Matcher m = regex.matcher(content); assertEquals(true, m.find()); }
@Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config config = cluster.getDesiredConfigByType(SOURCE_CONFIG_TYPE); if (config == null) { return createCommandReport(0, HostRoleStatus.FAILED,"{}", String.format("Source type %s not found", SOURCE_CONFIG_TYPE), ""); } Map<String, String> properties = config.getProperties(); String content = properties.get(CONTENT_NAME); if (content == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was not found. The -XX:MaxDirectMemorySize will not be added", SOURCE_CONFIG_TYPE, CONTENT_NAME), ""); } Matcher m = REGEX.matcher(content); if (m.find()){ return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property already contains an entry for %s and will not be modified", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE), ""); } String appendedContent = content + "\n" + APPEND_CONTENT_LINE; properties.put(CONTENT_NAME, appendedContent); config.setProperties(properties); config.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was appended with %s", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE),""); }
HBaseEnvMaxDirectMemorySizeAction extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config config = cluster.getDesiredConfigByType(SOURCE_CONFIG_TYPE); if (config == null) { return createCommandReport(0, HostRoleStatus.FAILED,"{}", String.format("Source type %s not found", SOURCE_CONFIG_TYPE), ""); } Map<String, String> properties = config.getProperties(); String content = properties.get(CONTENT_NAME); if (content == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was not found. The -XX:MaxDirectMemorySize will not be added", SOURCE_CONFIG_TYPE, CONTENT_NAME), ""); } Matcher m = REGEX.matcher(content); if (m.find()){ return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property already contains an entry for %s and will not be modified", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE), ""); } String appendedContent = content + "\n" + APPEND_CONTENT_LINE; properties.put(CONTENT_NAME, appendedContent); config.setProperties(properties); config.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was appended with %s", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE),""); } }
HBaseEnvMaxDirectMemorySizeAction extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config config = cluster.getDesiredConfigByType(SOURCE_CONFIG_TYPE); if (config == null) { return createCommandReport(0, HostRoleStatus.FAILED,"{}", String.format("Source type %s not found", SOURCE_CONFIG_TYPE), ""); } Map<String, String> properties = config.getProperties(); String content = properties.get(CONTENT_NAME); if (content == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was not found. The -XX:MaxDirectMemorySize will not be added", SOURCE_CONFIG_TYPE, CONTENT_NAME), ""); } Matcher m = REGEX.matcher(content); if (m.find()){ return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property already contains an entry for %s and will not be modified", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE), ""); } String appendedContent = content + "\n" + APPEND_CONTENT_LINE; properties.put(CONTENT_NAME, appendedContent); config.setProperties(properties); config.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was appended with %s", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE),""); }  }
HBaseEnvMaxDirectMemorySizeAction extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config config = cluster.getDesiredConfigByType(SOURCE_CONFIG_TYPE); if (config == null) { return createCommandReport(0, HostRoleStatus.FAILED,"{}", String.format("Source type %s not found", SOURCE_CONFIG_TYPE), ""); } Map<String, String> properties = config.getProperties(); String content = properties.get(CONTENT_NAME); if (content == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was not found. The -XX:MaxDirectMemorySize will not be added", SOURCE_CONFIG_TYPE, CONTENT_NAME), ""); } Matcher m = REGEX.matcher(content); if (m.find()){ return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property already contains an entry for %s and will not be modified", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE), ""); } String appendedContent = content + "\n" + APPEND_CONTENT_LINE; properties.put(CONTENT_NAME, appendedContent); config.setProperties(properties); config.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was appended with %s", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE),""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext); }
HBaseEnvMaxDirectMemorySizeAction extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config config = cluster.getDesiredConfigByType(SOURCE_CONFIG_TYPE); if (config == null) { return createCommandReport(0, HostRoleStatus.FAILED,"{}", String.format("Source type %s not found", SOURCE_CONFIG_TYPE), ""); } Map<String, String> properties = config.getProperties(); String content = properties.get(CONTENT_NAME); if (content == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was not found. The -XX:MaxDirectMemorySize will not be added", SOURCE_CONFIG_TYPE, CONTENT_NAME), ""); } Matcher m = REGEX.matcher(content); if (m.find()){ return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property already contains an entry for %s and will not be modified", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE), ""); } String appendedContent = content + "\n" + APPEND_CONTENT_LINE; properties.put(CONTENT_NAME, appendedContent); config.setProperties(properties); config.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("The %s/%s property was appended with %s", SOURCE_CONFIG_TYPE, CONTENT_NAME, APPEND_CONTENT_LINE),""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext);  }