@Test public void testOozieAdminUserUpdated() 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(cluster, hrc); FixOozieAdminUsers action = new FixOozieAdminUsers(); clustersField.set(action, clusters); action.setExecutionCommand(executionCommand); action.setHostRoleCommand(hrc); CommandReport report = action.execute(null); assertNotNull(report); Cluster c = clusters.getCluster("c1"); Config oozieConfig = c.getDesiredConfigByType("oozie-env"); Config falconConfig = c.getDesiredConfigByType("falcon-env"); Map<String, String> oozieConfigMap = oozieConfig.getProperties(); Map<String, String> falconConfigMap = falconConfig.getProperties(); assertTrue(oozieConfigMap.containsKey("oozie_admin_users")); assertTrue(falconConfigMap.containsKey("falcon_user")); String oozieAdminUsers = oozieConfigMap.get("oozie_admin_users"); String falconUser = falconConfigMap.get("falcon_user"); assertTrue(oozieAdminUsers.indexOf(falconUser) != -1); }
@Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config oozieConfig = cluster.getDesiredConfigByType(TARGET_OOZIE_CONFIG_TYPE); Config falconConfig = cluster.getDesiredConfigByType(FALCON_CONFIG_TYPE); if (falconConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon configuration unavailable", ""); } if (oozieConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Oozie configuration unavailable", ""); } Map<String, String> oozieProperties = oozieConfig.getProperties(); String currentOozieAdmins = oozieProperties.get(OOZIE_ADMIN_USERS_PROP); if (currentOozieAdmins.isEmpty()) { currentOozieAdmins = ""; } Map<String, String> falconProperties = falconConfig.getProperties(); String falconUser = falconProperties.get(FALCON_USER_PROP); if (StringUtils.isBlank(falconUser)) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user not set", ""); } if (currentOozieAdmins.indexOf(falconUser) >= 0) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user already member of Oozie admins", ""); } String newOozieAdminUsers = currentOozieAdmins + "," + falconUser; oozieProperties.put(OOZIE_ADMIN_USERS_PROP, newOozieAdminUsers); oozieConfig.setProperties(oozieProperties); oozieConfig.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Set oozie admin users to %s", newOozieAdminUsers), ""); }
FixOozieAdminUsers extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config oozieConfig = cluster.getDesiredConfigByType(TARGET_OOZIE_CONFIG_TYPE); Config falconConfig = cluster.getDesiredConfigByType(FALCON_CONFIG_TYPE); if (falconConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon configuration unavailable", ""); } if (oozieConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Oozie configuration unavailable", ""); } Map<String, String> oozieProperties = oozieConfig.getProperties(); String currentOozieAdmins = oozieProperties.get(OOZIE_ADMIN_USERS_PROP); if (currentOozieAdmins.isEmpty()) { currentOozieAdmins = ""; } Map<String, String> falconProperties = falconConfig.getProperties(); String falconUser = falconProperties.get(FALCON_USER_PROP); if (StringUtils.isBlank(falconUser)) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user not set", ""); } if (currentOozieAdmins.indexOf(falconUser) >= 0) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user already member of Oozie admins", ""); } String newOozieAdminUsers = currentOozieAdmins + "," + falconUser; oozieProperties.put(OOZIE_ADMIN_USERS_PROP, newOozieAdminUsers); oozieConfig.setProperties(oozieProperties); oozieConfig.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Set oozie admin users to %s", newOozieAdminUsers), ""); } }
FixOozieAdminUsers extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config oozieConfig = cluster.getDesiredConfigByType(TARGET_OOZIE_CONFIG_TYPE); Config falconConfig = cluster.getDesiredConfigByType(FALCON_CONFIG_TYPE); if (falconConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon configuration unavailable", ""); } if (oozieConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Oozie configuration unavailable", ""); } Map<String, String> oozieProperties = oozieConfig.getProperties(); String currentOozieAdmins = oozieProperties.get(OOZIE_ADMIN_USERS_PROP); if (currentOozieAdmins.isEmpty()) { currentOozieAdmins = ""; } Map<String, String> falconProperties = falconConfig.getProperties(); String falconUser = falconProperties.get(FALCON_USER_PROP); if (StringUtils.isBlank(falconUser)) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user not set", ""); } if (currentOozieAdmins.indexOf(falconUser) >= 0) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user already member of Oozie admins", ""); } String newOozieAdminUsers = currentOozieAdmins + "," + falconUser; oozieProperties.put(OOZIE_ADMIN_USERS_PROP, newOozieAdminUsers); oozieConfig.setProperties(oozieProperties); oozieConfig.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Set oozie admin users to %s", newOozieAdminUsers), ""); }  }
FixOozieAdminUsers extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config oozieConfig = cluster.getDesiredConfigByType(TARGET_OOZIE_CONFIG_TYPE); Config falconConfig = cluster.getDesiredConfigByType(FALCON_CONFIG_TYPE); if (falconConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon configuration unavailable", ""); } if (oozieConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Oozie configuration unavailable", ""); } Map<String, String> oozieProperties = oozieConfig.getProperties(); String currentOozieAdmins = oozieProperties.get(OOZIE_ADMIN_USERS_PROP); if (currentOozieAdmins.isEmpty()) { currentOozieAdmins = ""; } Map<String, String> falconProperties = falconConfig.getProperties(); String falconUser = falconProperties.get(FALCON_USER_PROP); if (StringUtils.isBlank(falconUser)) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user not set", ""); } if (currentOozieAdmins.indexOf(falconUser) >= 0) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user already member of Oozie admins", ""); } String newOozieAdminUsers = currentOozieAdmins + "," + falconUser; oozieProperties.put(OOZIE_ADMIN_USERS_PROP, newOozieAdminUsers); oozieConfig.setProperties(oozieProperties); oozieConfig.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Set oozie admin users to %s", newOozieAdminUsers), ""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext); }
FixOozieAdminUsers extends AbstractServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String clusterName = getExecutionCommand().getClusterName(); Cluster cluster = clusters.getCluster(clusterName); Config oozieConfig = cluster.getDesiredConfigByType(TARGET_OOZIE_CONFIG_TYPE); Config falconConfig = cluster.getDesiredConfigByType(FALCON_CONFIG_TYPE); if (falconConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon configuration unavailable", ""); } if (oozieConfig == null) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Oozie configuration unavailable", ""); } Map<String, String> oozieProperties = oozieConfig.getProperties(); String currentOozieAdmins = oozieProperties.get(OOZIE_ADMIN_USERS_PROP); if (currentOozieAdmins.isEmpty()) { currentOozieAdmins = ""; } Map<String, String> falconProperties = falconConfig.getProperties(); String falconUser = falconProperties.get(FALCON_USER_PROP); if (StringUtils.isBlank(falconUser)) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user not set", ""); } if (currentOozieAdmins.indexOf(falconUser) >= 0) { return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", "Falcon user already member of Oozie admins", ""); } String newOozieAdminUsers = currentOozieAdmins + "," + falconUser; oozieProperties.put(OOZIE_ADMIN_USERS_PROP, newOozieAdminUsers); oozieConfig.setProperties(oozieProperties); oozieConfig.save(); return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", String.format("Set oozie admin users to %s", newOozieAdminUsers), ""); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext);  }