Search in sources :

Example 1 with CmAgentStopFlags

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);
    }
}
Also used : GrainOperation(com.sequenceiq.cloudbreak.orchestrator.host.GrainOperation) FileReaderUtils.readFileFromClasspath(com.sequenceiq.cloudbreak.util.FileReaderUtils.readFileFromClasspath) SaltCommandRunner(com.sequenceiq.cloudbreak.orchestrator.salt.runner.SaltCommandRunner) Target(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Target) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) SyncAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner) LoggerFactory(org.slf4j.LoggerFactory) HostList(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList) SaltUploadWithPermission(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltUploadWithPermission) HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) HighStateAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateAllRunner) StringUtils(org.apache.commons.lang3.StringUtils) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) HostAndRoleTarget(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostAndRoleTarget) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) StateAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.StateAllRunner) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakOrchestratorTimeoutException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) MineUpdateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.MineUpdateRunner) ModifyGrainBase(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ModifyGrainBase) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Collection(java.util.Collection) Set(java.util.Set) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Retry(com.sequenceiq.cloudbreak.service.Retry) RecipeExecutionPhase.convert(com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase.convert) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) StandardCharsets(java.nio.charset.StandardCharsets) Sets(com.google.common.collect.Sets) ParameterizedStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ParameterizedStateRunner) SALT(com.sequenceiq.cloudbreak.common.type.OrchestratorConstants.SALT) List(java.util.List) MinionStatusSaltResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatusSaltResponse) SaltStates(com.sequenceiq.cloudbreak.orchestrator.salt.states.SaltStates) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CollectionUtils(org.springframework.util.CollectionUtils) Entry(java.util.Map.Entry) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) NodeVolumes(com.sequenceiq.cloudbreak.common.orchestration.NodeVolumes) Predicate.not(java.util.function.Predicate.not) RecipeExecutionPhase(com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Joiner(com.google.common.base.Joiner) SaltUpload(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltUpload) OrchestratorGrainRunnerParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorGrainRunnerParams) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) CompressUtil(com.sequenceiq.cloudbreak.util.CompressUtil) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ArrayList(java.util.ArrayList) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) OrchestratorStateRetryParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateRetryParams) CmAgentStopFlags(com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags) KeytabModel(com.sequenceiq.cloudbreak.orchestrator.model.KeytabModel) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Retryable(org.springframework.retry.annotation.Retryable) Glob(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Glob) ConcurrentParameterizedStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ConcurrentParameterizedStateRunner) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) StateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.StateRunner) Logger(org.slf4j.Logger) PackageInfo(com.sequenceiq.cloudbreak.common.model.PackageInfo) OrchestratorAware(com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware) NodeReachabilityResult(com.sequenceiq.cloudbreak.orchestrator.model.NodeReachabilityResult) GrainUploader(com.sequenceiq.cloudbreak.orchestrator.salt.grain.GrainUploader) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) IOException(java.io.IOException) PRE_CLOUDERA_MANAGER_START(com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase.PRE_CLOUDERA_MANAGER_START) ExecutionException(java.util.concurrent.ExecutionException) GrainsJsonPropertyUtil(com.sequenceiq.cloudbreak.orchestrator.salt.utils.GrainsJsonPropertyUtil) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) BaseSaltJobRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.BaseSaltJobRunner) SaltRunner(com.sequenceiq.cloudbreak.orchestrator.salt.runner.SaltRunner) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Collections(java.util.Collections) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) JsonNode(com.fasterxml.jackson.databind.JsonNode) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) NodeReachabilityResult(com.sequenceiq.cloudbreak.orchestrator.model.NodeReachabilityResult) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakOrchestratorTimeoutException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 2 with CmAgentStopFlags

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"));
}
Also used : InOrder(org.mockito.InOrder) JsonNode(com.fasterxml.jackson.databind.JsonNode) OrchestrationNode(com.sequenceiq.cloudbreak.common.orchestration.OrchestrationNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) OrchestrationNode(com.sequenceiq.cloudbreak.common.orchestration.OrchestrationNode) Callable(java.util.concurrent.Callable) ModifyGrainBase(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ModifyGrainBase) CmAgentStopFlags(com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with CmAgentStopFlags

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));
}
Also used : CmAgentStopFlags(com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags) KerberosConfig(com.sequenceiq.cloudbreak.dto.KerberosConfig) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Aggregations

Node (com.sequenceiq.cloudbreak.common.orchestration.Node)3 CmAgentStopFlags (com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)2 PillarSave (com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)2 SaltJobIdTracker (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker)2 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)2 GrainRemoveRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner)2 ModifyGrainBase (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ModifyGrainBase)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Callable (java.util.concurrent.Callable)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Joiner (com.google.common.base.Joiner)1 Sets (com.google.common.collect.Sets)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 PackageInfo (com.sequenceiq.cloudbreak.common.model.PackageInfo)1 NodeVolumes (com.sequenceiq.cloudbreak.common.orchestration.NodeVolumes)1