@Test public void testAction() throws Exception { 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); RangerKmsProxyConfig action = new RangerKmsProxyConfig(); m_clusterField.set(action, m_clusters); action.setExecutionCommand(executionCommand); action.setHostRoleCommand(hrc); CommandReport report = action.execute(null); assertNotNull(report); Cluster c = m_clusters.getCluster("c1"); Config config = c.getDesiredConfigByType("kms-site"); Map<String, String> map = config.getProperties(); assertTrue(map.containsKey("hadoop.kms.proxyuser.ranger.users")); assertTrue(map.containsKey("hadoop.kms.proxyuser.ranger.groups")); assertTrue(map.containsKey("hadoop.kms.proxyuser.ranger.hosts")); assertEquals("*", map.get("hadoop.kms.proxyuser.ranger.users")); assertEquals("*", map.get("hadoop.kms.proxyuser.ranger.groups")); assertEquals("*", map.get("hadoop.kms.proxyuser.ranger.hosts")); report = action.execute(null); assertNotNull(report); }
@Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); String outputMsg = ""; Config rangerEnv = cluster.getDesiredConfigByType(RANGER_ENV_CONFIG_TYPE); if (null == rangerEnv) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config source type {0} not found, skipping adding properties to {1}.", RANGER_ENV_CONFIG_TYPE, RANGER_KMS_SITE_CONFIG_TYPE), ""); } String rangerUserProp = "ranger_user"; String rangerUser = rangerEnv.getProperties().get(rangerUserProp); if (null == rangerUser) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Required user service user value from {0}/{1} not found, skipping adding properties to {2}.", RANGER_ENV_CONFIG_TYPE, rangerUserProp, RANGER_KMS_SITE_CONFIG_TYPE), ""); } Config kmsSite = cluster.getDesiredConfigByType(RANGER_KMS_SITE_CONFIG_TYPE); if (null == kmsSite) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config type {0} not found, skipping adding properties to it.", RANGER_KMS_SITE_CONFIG_TYPE), ""); } Map<String, String> targetValues = kmsSite.getProperties(); if (cluster.getSecurityType() == SecurityType.KERBEROS) { String userProp = "hadoop.kms.proxyuser." + rangerUser + ".users"; String groupProp = "hadoop.kms.proxyuser." + rangerUser + ".groups"; String hostProp = "hadoop.kms.proxyuser." + rangerUser + ".hosts"; targetValues.put(userProp, "*"); targetValues.put(groupProp, "*"); targetValues.put(hostProp, "*"); kmsSite.setProperties(targetValues); kmsSite.save(); outputMsg = outputMsg + MessageFormat.format("Successfully added properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } else { outputMsg = outputMsg + MessageFormat.format("Kerberos not enable, not setting proxy properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outputMsg, ""); }
RangerKmsProxyConfig extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); String outputMsg = ""; Config rangerEnv = cluster.getDesiredConfigByType(RANGER_ENV_CONFIG_TYPE); if (null == rangerEnv) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config source type {0} not found, skipping adding properties to {1}.", RANGER_ENV_CONFIG_TYPE, RANGER_KMS_SITE_CONFIG_TYPE), ""); } String rangerUserProp = "ranger_user"; String rangerUser = rangerEnv.getProperties().get(rangerUserProp); if (null == rangerUser) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Required user service user value from {0}/{1} not found, skipping adding properties to {2}.", RANGER_ENV_CONFIG_TYPE, rangerUserProp, RANGER_KMS_SITE_CONFIG_TYPE), ""); } Config kmsSite = cluster.getDesiredConfigByType(RANGER_KMS_SITE_CONFIG_TYPE); if (null == kmsSite) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config type {0} not found, skipping adding properties to it.", RANGER_KMS_SITE_CONFIG_TYPE), ""); } Map<String, String> targetValues = kmsSite.getProperties(); if (cluster.getSecurityType() == SecurityType.KERBEROS) { String userProp = "hadoop.kms.proxyuser." + rangerUser + ".users"; String groupProp = "hadoop.kms.proxyuser." + rangerUser + ".groups"; String hostProp = "hadoop.kms.proxyuser." + rangerUser + ".hosts"; targetValues.put(userProp, "*"); targetValues.put(groupProp, "*"); targetValues.put(hostProp, "*"); kmsSite.setProperties(targetValues); kmsSite.save(); outputMsg = outputMsg + MessageFormat.format("Successfully added properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } else { outputMsg = outputMsg + MessageFormat.format("Kerberos not enable, not setting proxy properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outputMsg, ""); } }
RangerKmsProxyConfig extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); String outputMsg = ""; Config rangerEnv = cluster.getDesiredConfigByType(RANGER_ENV_CONFIG_TYPE); if (null == rangerEnv) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config source type {0} not found, skipping adding properties to {1}.", RANGER_ENV_CONFIG_TYPE, RANGER_KMS_SITE_CONFIG_TYPE), ""); } String rangerUserProp = "ranger_user"; String rangerUser = rangerEnv.getProperties().get(rangerUserProp); if (null == rangerUser) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Required user service user value from {0}/{1} not found, skipping adding properties to {2}.", RANGER_ENV_CONFIG_TYPE, rangerUserProp, RANGER_KMS_SITE_CONFIG_TYPE), ""); } Config kmsSite = cluster.getDesiredConfigByType(RANGER_KMS_SITE_CONFIG_TYPE); if (null == kmsSite) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config type {0} not found, skipping adding properties to it.", RANGER_KMS_SITE_CONFIG_TYPE), ""); } Map<String, String> targetValues = kmsSite.getProperties(); if (cluster.getSecurityType() == SecurityType.KERBEROS) { String userProp = "hadoop.kms.proxyuser." + rangerUser + ".users"; String groupProp = "hadoop.kms.proxyuser." + rangerUser + ".groups"; String hostProp = "hadoop.kms.proxyuser." + rangerUser + ".hosts"; targetValues.put(userProp, "*"); targetValues.put(groupProp, "*"); targetValues.put(hostProp, "*"); kmsSite.setProperties(targetValues); kmsSite.save(); outputMsg = outputMsg + MessageFormat.format("Successfully added properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } else { outputMsg = outputMsg + MessageFormat.format("Kerberos not enable, not setting proxy properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outputMsg, ""); }  }
RangerKmsProxyConfig extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); String outputMsg = ""; Config rangerEnv = cluster.getDesiredConfigByType(RANGER_ENV_CONFIG_TYPE); if (null == rangerEnv) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config source type {0} not found, skipping adding properties to {1}.", RANGER_ENV_CONFIG_TYPE, RANGER_KMS_SITE_CONFIG_TYPE), ""); } String rangerUserProp = "ranger_user"; String rangerUser = rangerEnv.getProperties().get(rangerUserProp); if (null == rangerUser) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Required user service user value from {0}/{1} not found, skipping adding properties to {2}.", RANGER_ENV_CONFIG_TYPE, rangerUserProp, RANGER_KMS_SITE_CONFIG_TYPE), ""); } Config kmsSite = cluster.getDesiredConfigByType(RANGER_KMS_SITE_CONFIG_TYPE); if (null == kmsSite) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config type {0} not found, skipping adding properties to it.", RANGER_KMS_SITE_CONFIG_TYPE), ""); } Map<String, String> targetValues = kmsSite.getProperties(); if (cluster.getSecurityType() == SecurityType.KERBEROS) { String userProp = "hadoop.kms.proxyuser." + rangerUser + ".users"; String groupProp = "hadoop.kms.proxyuser." + rangerUser + ".groups"; String hostProp = "hadoop.kms.proxyuser." + rangerUser + ".hosts"; targetValues.put(userProp, "*"); targetValues.put(groupProp, "*"); targetValues.put(hostProp, "*"); kmsSite.setProperties(targetValues); kmsSite.save(); outputMsg = outputMsg + MessageFormat.format("Successfully added properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } else { outputMsg = outputMsg + MessageFormat.format("Kerberos not enable, not setting proxy properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outputMsg, ""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext); }
RangerKmsProxyConfig extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = m_clusters.getCluster(clusterName); String outputMsg = ""; Config rangerEnv = cluster.getDesiredConfigByType(RANGER_ENV_CONFIG_TYPE); if (null == rangerEnv) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config source type {0} not found, skipping adding properties to {1}.", RANGER_ENV_CONFIG_TYPE, RANGER_KMS_SITE_CONFIG_TYPE), ""); } String rangerUserProp = "ranger_user"; String rangerUser = rangerEnv.getProperties().get(rangerUserProp); if (null == rangerUser) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Required user service user value from {0}/{1} not found, skipping adding properties to {2}.", RANGER_ENV_CONFIG_TYPE, rangerUserProp, RANGER_KMS_SITE_CONFIG_TYPE), ""); } Config kmsSite = cluster.getDesiredConfigByType(RANGER_KMS_SITE_CONFIG_TYPE); if (null == kmsSite) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", MessageFormat.format("Config type {0} not found, skipping adding properties to it.", RANGER_KMS_SITE_CONFIG_TYPE), ""); } Map<String, String> targetValues = kmsSite.getProperties(); if (cluster.getSecurityType() == SecurityType.KERBEROS) { String userProp = "hadoop.kms.proxyuser." + rangerUser + ".users"; String groupProp = "hadoop.kms.proxyuser." + rangerUser + ".groups"; String hostProp = "hadoop.kms.proxyuser." + rangerUser + ".hosts"; targetValues.put(userProp, "*"); targetValues.put(groupProp, "*"); targetValues.put(hostProp, "*"); kmsSite.setProperties(targetValues); kmsSite.save(); outputMsg = outputMsg + MessageFormat.format("Successfully added properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } else { outputMsg = outputMsg + MessageFormat.format("Kerberos not enable, not setting proxy properties to {0}", RANGER_KMS_SITE_CONFIG_TYPE); } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outputMsg, ""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext);  }