@Test public void executeMITKDCOption() throws Exception { String clusterName = "c1"; Injector injector = setup(clusterName); File dataDirectory = createDataDirectory(); Map<String, String> commandParams = new HashMap<>(); commandParams.put(KerberosServerAction.KDC_TYPE, KDCType.MIT_KDC.name()); commandParams.put(KerberosServerAction.DATA_DIRECTORY, dataDirectory.getAbsolutePath()); ExecutionCommand executionCommand = createMockExecutionCommand(clusterName, commandParams); HostRoleCommand hostRoleCommand = createMockHostRoleCommand(); PrincipalKeyCredential principleKeyCredential = createMock(PrincipalKeyCredential.class); KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class); expect(kerberosHelper.getKDCAdministratorCredentials(clusterName)).andReturn(principleKeyCredential).anyTimes(); replayAll(); ConcurrentMap<String, Object> requestSharedDataContext = new ConcurrentHashMap<String, Object>(); FinalizeKerberosServerAction action = injector.getInstance(FinalizeKerberosServerAction.class); action.setExecutionCommand(executionCommand); action.setHostRoleCommand(hostRoleCommand); Assert.assertTrue(dataDirectory.exists()); CommandReport commandReport = action.execute(requestSharedDataContext); assertSuccess(commandReport); Assert.assertTrue(!dataDirectory.exists()); verifyAll(); }
@Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String dataDirectoryPath = getCommandParameterValue(DATA_DIRECTORY); Map<String, Host> hosts = getClusters().getHostsForCluster(getClusterName()); if ((hosts != null) && !hosts.isEmpty()) { Cluster cluster = getCluster(); for (String hostname : hosts.keySet()) { List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname); for (ServiceComponentHost sch : serviceComponentHosts) { SecurityState securityState = sch.getSecurityState(); if (securityState.isTransitional()) { String message = String.format("Setting securityState for %s/%s on host %s to state %s", sch.getServiceName(), sch.getServiceComponentName(), sch.getHostName(), sch.getDesiredSecurityState().toString()); LOG.info(message); actionLog.writeStdOut(message); sch.setSecurityState(sch.getDesiredSecurityState()); ChangeSecurityStateKerberosAuditEvent auditEvent = ChangeSecurityStateKerberosAuditEvent.builder() .withTimestamp(System.currentTimeMillis()) .withService(sch.getServiceName()) .withComponent(sch.getServiceComponentName()) .withHostName(sch.getHostName()) .withState(sch.getDesiredSecurityState().toString()) .withRequestId(getHostRoleCommand().getRequestId()) .withTaskId(getHostRoleCommand().getTaskId()) .build(); auditLog(auditEvent); } } } } if(getKDCType(getCommandParameters()) != KDCType.NONE) { requestSharedDataContext.put(this.getClass().getName() + "_visited", new HashSet<String>()); processIdentities(requestSharedDataContext); requestSharedDataContext.remove(this.getClass().getName() + "_visited"); } if ((dataDirectoryPath != null) && dataDirectoryPath.contains("/" + DATA_DIRECTORY_PREFIX)) { File dataDirectory = new File(dataDirectoryPath); File dataDirectoryParent = dataDirectory.getParentFile(); if ((dataDirectoryParent != null) && dataDirectory.isDirectory() && dataDirectoryParent.isDirectory() && dataDirectoryParent.canWrite()) { try { FileUtils.deleteDirectory(dataDirectory); } catch (IOException e) { String message = String.format("The data directory (%s) was not deleted due to an error condition - {%s}", dataDirectory.getAbsolutePath(), e.getMessage()); LOG.warn(message, e); } } } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr()); }
FinalizeKerberosServerAction extends KerberosServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String dataDirectoryPath = getCommandParameterValue(DATA_DIRECTORY); Map<String, Host> hosts = getClusters().getHostsForCluster(getClusterName()); if ((hosts != null) && !hosts.isEmpty()) { Cluster cluster = getCluster(); for (String hostname : hosts.keySet()) { List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname); for (ServiceComponentHost sch : serviceComponentHosts) { SecurityState securityState = sch.getSecurityState(); if (securityState.isTransitional()) { String message = String.format("Setting securityState for %s/%s on host %s to state %s", sch.getServiceName(), sch.getServiceComponentName(), sch.getHostName(), sch.getDesiredSecurityState().toString()); LOG.info(message); actionLog.writeStdOut(message); sch.setSecurityState(sch.getDesiredSecurityState()); ChangeSecurityStateKerberosAuditEvent auditEvent = ChangeSecurityStateKerberosAuditEvent.builder() .withTimestamp(System.currentTimeMillis()) .withService(sch.getServiceName()) .withComponent(sch.getServiceComponentName()) .withHostName(sch.getHostName()) .withState(sch.getDesiredSecurityState().toString()) .withRequestId(getHostRoleCommand().getRequestId()) .withTaskId(getHostRoleCommand().getTaskId()) .build(); auditLog(auditEvent); } } } } if(getKDCType(getCommandParameters()) != KDCType.NONE) { requestSharedDataContext.put(this.getClass().getName() + "_visited", new HashSet<String>()); processIdentities(requestSharedDataContext); requestSharedDataContext.remove(this.getClass().getName() + "_visited"); } if ((dataDirectoryPath != null) && dataDirectoryPath.contains("/" + DATA_DIRECTORY_PREFIX)) { File dataDirectory = new File(dataDirectoryPath); File dataDirectoryParent = dataDirectory.getParentFile(); if ((dataDirectoryParent != null) && dataDirectory.isDirectory() && dataDirectoryParent.isDirectory() && dataDirectoryParent.canWrite()) { try { FileUtils.deleteDirectory(dataDirectory); } catch (IOException e) { String message = String.format("The data directory (%s) was not deleted due to an error condition - {%s}", dataDirectory.getAbsolutePath(), e.getMessage()); LOG.warn(message, e); } } } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr()); } }
FinalizeKerberosServerAction extends KerberosServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String dataDirectoryPath = getCommandParameterValue(DATA_DIRECTORY); Map<String, Host> hosts = getClusters().getHostsForCluster(getClusterName()); if ((hosts != null) && !hosts.isEmpty()) { Cluster cluster = getCluster(); for (String hostname : hosts.keySet()) { List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname); for (ServiceComponentHost sch : serviceComponentHosts) { SecurityState securityState = sch.getSecurityState(); if (securityState.isTransitional()) { String message = String.format("Setting securityState for %s/%s on host %s to state %s", sch.getServiceName(), sch.getServiceComponentName(), sch.getHostName(), sch.getDesiredSecurityState().toString()); LOG.info(message); actionLog.writeStdOut(message); sch.setSecurityState(sch.getDesiredSecurityState()); ChangeSecurityStateKerberosAuditEvent auditEvent = ChangeSecurityStateKerberosAuditEvent.builder() .withTimestamp(System.currentTimeMillis()) .withService(sch.getServiceName()) .withComponent(sch.getServiceComponentName()) .withHostName(sch.getHostName()) .withState(sch.getDesiredSecurityState().toString()) .withRequestId(getHostRoleCommand().getRequestId()) .withTaskId(getHostRoleCommand().getTaskId()) .build(); auditLog(auditEvent); } } } } if(getKDCType(getCommandParameters()) != KDCType.NONE) { requestSharedDataContext.put(this.getClass().getName() + "_visited", new HashSet<String>()); processIdentities(requestSharedDataContext); requestSharedDataContext.remove(this.getClass().getName() + "_visited"); } if ((dataDirectoryPath != null) && dataDirectoryPath.contains("/" + DATA_DIRECTORY_PREFIX)) { File dataDirectory = new File(dataDirectoryPath); File dataDirectoryParent = dataDirectory.getParentFile(); if ((dataDirectoryParent != null) && dataDirectory.isDirectory() && dataDirectoryParent.isDirectory() && dataDirectoryParent.canWrite()) { try { FileUtils.deleteDirectory(dataDirectory); } catch (IOException e) { String message = String.format("The data directory (%s) was not deleted due to an error condition - {%s}", dataDirectory.getAbsolutePath(), e.getMessage()); LOG.warn(message, e); } } } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr()); }  }
FinalizeKerberosServerAction extends KerberosServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String dataDirectoryPath = getCommandParameterValue(DATA_DIRECTORY); Map<String, Host> hosts = getClusters().getHostsForCluster(getClusterName()); if ((hosts != null) && !hosts.isEmpty()) { Cluster cluster = getCluster(); for (String hostname : hosts.keySet()) { List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname); for (ServiceComponentHost sch : serviceComponentHosts) { SecurityState securityState = sch.getSecurityState(); if (securityState.isTransitional()) { String message = String.format("Setting securityState for %s/%s on host %s to state %s", sch.getServiceName(), sch.getServiceComponentName(), sch.getHostName(), sch.getDesiredSecurityState().toString()); LOG.info(message); actionLog.writeStdOut(message); sch.setSecurityState(sch.getDesiredSecurityState()); ChangeSecurityStateKerberosAuditEvent auditEvent = ChangeSecurityStateKerberosAuditEvent.builder() .withTimestamp(System.currentTimeMillis()) .withService(sch.getServiceName()) .withComponent(sch.getServiceComponentName()) .withHostName(sch.getHostName()) .withState(sch.getDesiredSecurityState().toString()) .withRequestId(getHostRoleCommand().getRequestId()) .withTaskId(getHostRoleCommand().getTaskId()) .build(); auditLog(auditEvent); } } } } if(getKDCType(getCommandParameters()) != KDCType.NONE) { requestSharedDataContext.put(this.getClass().getName() + "_visited", new HashSet<String>()); processIdentities(requestSharedDataContext); requestSharedDataContext.remove(this.getClass().getName() + "_visited"); } if ((dataDirectoryPath != null) && dataDirectoryPath.contains("/" + DATA_DIRECTORY_PREFIX)) { File dataDirectory = new File(dataDirectoryPath); File dataDirectoryParent = dataDirectory.getParentFile(); if ((dataDirectoryParent != null) && dataDirectory.isDirectory() && dataDirectoryParent.isDirectory() && dataDirectoryParent.canWrite()) { try { FileUtils.deleteDirectory(dataDirectory); } catch (IOException e) { String message = String.format("The data directory (%s) was not deleted due to an error condition - {%s}", dataDirectory.getAbsolutePath(), e.getMessage()); LOG.warn(message, e); } } } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr()); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext); }
FinalizeKerberosServerAction extends KerberosServerAction { @Override public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws AmbariException, InterruptedException { String dataDirectoryPath = getCommandParameterValue(DATA_DIRECTORY); Map<String, Host> hosts = getClusters().getHostsForCluster(getClusterName()); if ((hosts != null) && !hosts.isEmpty()) { Cluster cluster = getCluster(); for (String hostname : hosts.keySet()) { List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname); for (ServiceComponentHost sch : serviceComponentHosts) { SecurityState securityState = sch.getSecurityState(); if (securityState.isTransitional()) { String message = String.format("Setting securityState for %s/%s on host %s to state %s", sch.getServiceName(), sch.getServiceComponentName(), sch.getHostName(), sch.getDesiredSecurityState().toString()); LOG.info(message); actionLog.writeStdOut(message); sch.setSecurityState(sch.getDesiredSecurityState()); ChangeSecurityStateKerberosAuditEvent auditEvent = ChangeSecurityStateKerberosAuditEvent.builder() .withTimestamp(System.currentTimeMillis()) .withService(sch.getServiceName()) .withComponent(sch.getServiceComponentName()) .withHostName(sch.getHostName()) .withState(sch.getDesiredSecurityState().toString()) .withRequestId(getHostRoleCommand().getRequestId()) .withTaskId(getHostRoleCommand().getTaskId()) .build(); auditLog(auditEvent); } } } } if(getKDCType(getCommandParameters()) != KDCType.NONE) { requestSharedDataContext.put(this.getClass().getName() + "_visited", new HashSet<String>()); processIdentities(requestSharedDataContext); requestSharedDataContext.remove(this.getClass().getName() + "_visited"); } if ((dataDirectoryPath != null) && dataDirectoryPath.contains("/" + DATA_DIRECTORY_PREFIX)) { File dataDirectory = new File(dataDirectoryPath); File dataDirectoryParent = dataDirectory.getParentFile(); if ((dataDirectoryParent != null) && dataDirectory.isDirectory() && dataDirectoryParent.isDirectory() && dataDirectoryParent.canWrite()) { try { FileUtils.deleteDirectory(dataDirectory); } catch (IOException e) { String message = String.format("The data directory (%s) was not deleted due to an error condition - {%s}", dataDirectory.getAbsolutePath(), e.getMessage()); LOG.warn(message, e); } } } return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr()); }  @Override CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext);  }