use of com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags in project cloudbreak by hortonworks.
the class SaltOrchestrator method stopClusterManagerAgent.
@Override
public void stopClusterManagerAgent(OrchestratorAware stack, GatewayConfig gatewayConfig, Set<Node> allNodes, Set<Node> nodesUnderStopping, ExitCriteriaModel exitCriteriaModel, CmAgentStopFlags flags) throws CloudbreakOrchestratorFailedException {
try (SaltConnector sc = saltService.createSaltConnector(gatewayConfig)) {
NodeReachabilityResult nodeReachabilityResult = getResponsiveNodes(allNodes, sc);
Set<Node> responsiveNodes = nodeReachabilityResult.getReachableNodes();
Set<String> nodesUnderStoppingIPs = nodesUnderStopping.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
Set<Node> responsiveNodesUnderStopping = responsiveNodes.stream().filter(responsiveNode -> nodesUnderStoppingIPs.contains(responsiveNode.getPrivateIp())).collect(Collectors.toSet());
if (!responsiveNodesUnderStopping.isEmpty()) {
LOGGER.debug("Applying role 'cloudera_manager_agent_stop' on nodes: [{}]", responsiveNodesUnderStopping);
Set<String> targetHostnames = responsiveNodesUnderStopping.stream().map(Node::getHostname).collect(Collectors.toSet());
saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(targetHostnames, responsiveNodesUnderStopping, "roles", "cloudera_manager_agent_stop"), exitCriteriaModel, exitCriteria);
if (flags.isAdJoinable() || flags.isIpaJoinable()) {
String identityRole = flags.isAdJoinable() ? "ad_leave" : "ipa_leave";
LOGGER.debug("Applying role '{}' on nodes: [{}]", identityRole, responsiveNodesUnderStopping);
saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(targetHostnames, responsiveNodesUnderStopping, "roles", identityRole), exitCriteriaModel, exitCriteria);
String removeIdentityRole = flags.isAdJoinable() ? "ad_member" : "ipa_member";
LOGGER.debug("Removing role '{}' on nodes: [{}]", removeIdentityRole, responsiveNodesUnderStopping);
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(targetHostnames, responsiveNodesUnderStopping, "roles", removeIdentityRole), exitCriteriaModel, exitCriteria);
}
Set<String> allHostnames = responsiveNodesUnderStopping.stream().map(Node::getHostname).collect(Collectors.toSet());
runSyncAll(sc, allHostnames, responsiveNodesUnderStopping, exitCriteriaModel);
saveHostsPillar(stack, exitCriteriaModel, getGatewayPrivateIps(Collections.singleton(gatewayConfig)), sc);
runNewService(sc, new HighStateRunner(allHostnames, responsiveNodesUnderStopping), exitCriteriaModel, maxRetry, true);
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(targetHostnames, responsiveNodesUnderStopping, "roles", "cloudera_manager_agent_stop"), exitCriteriaModel, exitCriteria);
if (flags.isAdJoinable() || flags.isIpaJoinable()) {
String identityRole = flags.isAdJoinable() ? "ad_leave" : "ipa_leave";
saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(targetHostnames, responsiveNodesUnderStopping, "roles", identityRole), exitCriteriaModel, exitCriteria);
}
}
} catch (Exception e) {
LOGGER.info("Error occurred during executing highstate (for cluster manager agent stop).", e);
throwExceptionIfNotForced(flags.isForced(), e);
}
}
use of com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags in project cloudbreak by hortonworks.
the class SaltOrchestratorTest method testStopClusterManagerAgent.
@Test
public void testStopClusterManagerAgent() throws Exception {
Set<Node> downscaleTargets = new HashSet<>();
downscaleTargets.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg", "fqdn2", null));
downscaleTargets.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg", "fqdn3", null));
PowerMockito.mockStatic(SaltStates.class);
Set<String> responsiveAddresses = new HashSet<>();
responsiveAddresses.add("10.0.0.1");
responsiveAddresses.add("10.0.0.2");
responsiveAddresses.add("10.0.0.3");
PowerMockito.when(SaltStates.collectMinionIpAddresses(any(), any())).thenReturn(responsiveAddresses);
Set<OrchestrationNode> allNodes = new HashSet<>();
allNodes.add(() -> new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg", "fqdn3", null));
allNodes.addAll(downscaleTargets.stream().map(node -> (OrchestrationNode) () -> node).collect(Collectors.toSet()));
Callable pillarSaveCallable = mock(Callable.class);
when(saltRunner.runner(any(), any(), any())).thenReturn(pillarSaveCallable);
when(saltRunner.runner(any(), any(), any(), anyInt(), anyBoolean())).thenReturn(mock(Callable.class));
saltOrchestrator.stopClusterManagerAgent(() -> allNodes, gatewayConfig, targets, downscaleTargets, exitCriteriaModel, new CmAgentStopFlags(false, false, false));
ArgumentCaptor<ModifyGrainBase> modifyGrainBaseArgumentCaptor = ArgumentCaptor.forClass(ModifyGrainBase.class);
ArgumentCaptor<PillarSave> pillarSaveArgumentCaptor = ArgumentCaptor.forClass(PillarSave.class);
verify(pillarSaveCallable, times(1)).call();
InOrder inOrder = inOrder(saltCommandRunner, saltRunner);
inOrder.verify(saltCommandRunner).runModifyGrainCommand(any(), modifyGrainBaseArgumentCaptor.capture(), any(), any());
ModifyGrainBase modifyGrainBase = modifyGrainBaseArgumentCaptor.getValue();
assertThat(modifyGrainBase, instanceOf(GrainAddRunner.class));
assertEquals("roles", modifyGrainBase.getKey());
assertEquals("cloudera_manager_agent_stop", modifyGrainBase.getValue());
inOrder.verify(saltRunner).runner(pillarSaveArgumentCaptor.capture(), any(), any());
PillarSave capturedPillarSave = pillarSaveArgumentCaptor.getValue();
ArgumentCaptor<SaltJobIdTracker> saltJobIdCaptor = ArgumentCaptor.forClass(SaltJobIdTracker.class);
inOrder.verify(saltRunner).runner(saltJobIdCaptor.capture(), any(), any(), anyInt(), anyBoolean());
inOrder.verify(saltCommandRunner).runModifyGrainCommand(any(), modifyGrainBaseArgumentCaptor.capture(), any(), any());
inOrder.verifyNoMoreInteractions();
modifyGrainBase = modifyGrainBaseArgumentCaptor.getValue();
assertThat(modifyGrainBase, instanceOf(GrainRemoveRunner.class));
assertEquals("roles", modifyGrainBase.getKey());
assertEquals("cloudera_manager_agent_stop", modifyGrainBase.getValue());
Set<String> targets = Whitebox.getInternalState(capturedPillarSave, "targets");
assertTrue(targets.contains("10.0.0.1"));
Pillar pillar = Whitebox.getInternalState(capturedPillarSave, "pillar");
Map<String, Map> hosts = (Map) ((Map) pillar.getJson()).get("hosts");
assertTrue(hosts.keySet().contains("10.0.0.1"));
assertTrue(hosts.keySet().contains("10.0.0.2"));
assertTrue(hosts.keySet().contains("10.0.0.3"));
}
use of com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags in project cloudbreak by hortonworks.
the class DecommissionHandler method stopClusterManagerAgent.
private void stopClusterManagerAgent(Stack stack, Set<String> decommissionedHostNames, boolean forced) throws CloudbreakOrchestratorFailedException {
KerberosConfig kerberosConfig = kerberosConfigService.get(stack.getEnvironmentCrn(), stack.getName()).orElse(null);
Set<Node> decommissionedNodes = stackUtil.collectNodesFromHostnames(stack, decommissionedHostNames);
GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
Set<Node> allNodes = stackUtil.collectNodes(stack);
hostOrchestrator.stopClusterManagerAgent(stack, gatewayConfig, allNodes, decommissionedNodes, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()), new CmAgentStopFlags(kerberosDetailService.isAdJoinable(kerberosConfig), kerberosDetailService.isIpaJoinable(kerberosConfig), forced));
}
Aggregations