use of com.sequenceiq.cloudbreak.orchestrator.model.NodeReachabilityResult 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.NodeReachabilityResult in project cloudbreak by hortonworks.
the class StackUtil method collectReachableAndUnreachableCandidateNodes.
public NodeReachabilityResult collectReachableAndUnreachableCandidateNodes(Stack stack, Collection<String> necessaryNodes) {
NodeReachabilityResult nodeReachabilityResult = collectReachableAndUnreachableNodes(stack);
Set<Node> reachableCandidateNodes = nodeReachabilityResult.getReachableNodes().stream().filter(node -> necessaryNodes.contains(node.getHostname())).collect(Collectors.toSet());
Set<Node> unreachableCandidateNodes = nodeReachabilityResult.getUnreachableNodes().stream().filter(node -> necessaryNodes.contains(node.getHostname())).collect(Collectors.toSet());
NodeReachabilityResult nodeReachabilityResultWithCandidates = new NodeReachabilityResult(reachableCandidateNodes, unreachableCandidateNodes);
if (!unreachableCandidateNodes.isEmpty()) {
LOGGER.warn("Some candidate nodes are unreachable: {}", nodeReachabilityResultWithCandidates.getUnreachableHosts());
}
LOGGER.debug("Candidate node reachability result: {}", nodeReachabilityResultWithCandidates);
return nodeReachabilityResultWithCandidates;
}
use of com.sequenceiq.cloudbreak.orchestrator.model.NodeReachabilityResult in project cloudbreak by hortonworks.
the class ClusterHostServiceRunnerTest method testDecoratePillarWithMountInfoAndTargetedSaltCall.
@Test
void testDecoratePillarWithMountInfoAndTargetedSaltCall() throws CloudbreakOrchestratorException {
setupMocksForRunClusterServices();
Set<Node> nodes = Sets.newHashSet(node("fqdn3"), node("gateway1"), node("gateway3"));
when(stackUtil.collectReachableAndUnreachableCandidateNodes(any(), any())).thenReturn(new NodeReachabilityResult(nodes, Set.of()));
underTest.runTargetedClusterServices(stack, cluster, Map.of("fqdn3", "1.1.1.1"));
ArgumentCaptor<Set<Node>> reachableCandidates = ArgumentCaptor.forClass(Set.class);
ArgumentCaptor<SaltConfig> saltConfig = ArgumentCaptor.forClass(SaltConfig.class);
verify(hostOrchestrator).runService(any(), reachableCandidates.capture(), saltConfig.capture(), any());
Set<Node> reachableNodes = reachableCandidates.getValue();
assertTrue(reachableNodes.stream().anyMatch(node -> StringUtils.equals("gateway1", node.getHostname())));
assertTrue(reachableNodes.stream().anyMatch(node -> StringUtils.equals("gateway2", node.getHostname())));
assertTrue(reachableNodes.stream().anyMatch(node -> StringUtils.equals("gateway3", node.getHostname())));
assertTrue(reachableNodes.stream().anyMatch(node -> StringUtils.equals("fqdn3", node.getHostname())));
assertFalse(reachableNodes.stream().anyMatch(node -> StringUtils.equals("fqdn1", node.getHostname())));
assertFalse(reachableNodes.stream().anyMatch(node -> StringUtils.equals("fqdn2", node.getHostname())));
assertTrue(saltConfig.getValue().getServicePillarConfig().keySet().stream().allMatch(Objects::nonNull));
}
use of com.sequenceiq.cloudbreak.orchestrator.model.NodeReachabilityResult in project cloudbreak by hortonworks.
the class StackUtilTest method collectReachableNodesTest.
@Test
void collectReachableNodesTest() {
Stack stack = createStack();
Set<Node> nodes = new HashSet<>();
nodes.add(new Node("1.1.1.1", "1.1.1.1", "1", "m5.xlarge", "node1.example.com", "worker"));
when(hostOrchestrator.getResponsiveNodes(nodesCaptor.capture(), any())).thenReturn(new NodeReachabilityResult(nodes, Set.of()));
stackUtil.collectReachableNodes(stack);
verify(hostOrchestrator).getResponsiveNodes(nodesCaptor.capture(), any());
List<String> fqdns = nodesCaptor.getValue().stream().map(Node::getHostname).collect(Collectors.toList());
assertTrue(fqdns.contains("node1.example.com"));
assertFalse("Terminated node should be filtered out", fqdns.contains("node2.example.com"));
assertTrue(fqdns.contains("node3.example.com"));
}
use of com.sequenceiq.cloudbreak.orchestrator.model.NodeReachabilityResult in project cloudbreak by hortonworks.
the class StackUtilTest method collectAndCheckReachableNodesButSomeNodeMissing.
@Test
void collectAndCheckReachableNodesButSomeNodeMissing() {
Stack stack = createStack();
ArrayList<String> necessaryNodes = new ArrayList<>();
necessaryNodes.add("node1.example.com");
necessaryNodes.add("node3.example.com");
Set<Node> nodes = new HashSet<>();
nodes.add(new Node("1.1.1.1", "1.1.1.1", "1", "m5.xlarge", "node1.example.com", "worker"));
when(hostOrchestrator.getResponsiveNodes(nodesCaptor.capture(), any())).thenReturn(new NodeReachabilityResult(nodes, Set.of()));
NodesUnreachableException nodesUnreachableException = Assertions.assertThrows(NodesUnreachableException.class, () -> stackUtil.collectAndCheckReachableNodes(stack, necessaryNodes));
assertEquals(1, nodesUnreachableException.getUnreachableNodes().size());
assertEquals("node3.example.com", nodesUnreachableException.getUnreachableNodes().iterator().next());
}
Aggregations