Search in sources :

Example 1 with OrchestratorAware

use of com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware in project cloudbreak by hortonworks.

the class SaltOrchestrator method tearDown.

@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
@Override
public void tearDown(OrchestratorAware stack, List<GatewayConfig> allGatewayConfigs, Map<String, String> removeNodePrivateIPsByFQDN, Set<Node> remainingNodes, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
    LOGGER.debug("Tear down hosts: {},", removeNodePrivateIPsByFQDN);
    LOGGER.debug("Gateway config for tear down: {}", allGatewayConfigs);
    Set<String> remainingIps = remainingNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
    LOGGER.debug("Remaining IPs: {}", remainingIps);
    Set<String> minionsToStop = removeNodePrivateIPsByFQDN.values().stream().filter(not(remainingIps::contains)).collect(Collectors.toSet());
    LOGGER.debug("Minions to stop: {}", minionsToStop);
    GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGatewayConfigs);
    Set<String> gatewayTargetIpAddresses = getGatewayPrivateIps(allGatewayConfigs);
    try (SaltConnector saltConnector = saltService.createSaltConnector(primaryGateway)) {
        SaltStates.stopMinions(saltConnector, minionsToStop);
        if (!CollectionUtils.isEmpty(remainingNodes)) {
            saveHostsPillar(stack, exitModel, gatewayTargetIpAddresses, saltConnector);
        }
    } catch (Exception e) {
        LOGGER.info("Error occurred during salt minion tear down", e);
        throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
    }
    List<GatewayConfig> liveGateways = allGatewayConfigs.stream().filter(gw -> remainingIps.contains(gw.getPrivateAddress())).collect(Collectors.toList());
    for (GatewayConfig gatewayConfig : liveGateways) {
        try (SaltConnector sc = saltService.createSaltConnector(gatewayConfig)) {
            sc.wheel("key.delete", removeNodePrivateIPsByFQDN.keySet(), Object.class);
            removeDeadSaltMinions(gatewayConfig);
        } catch (Exception e) {
            LOGGER.info("Error occurred during salt minion tear down", e);
            throw new CloudbreakOrchestratorFailedException(e.getMessage(), 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) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) 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) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Retryable(org.springframework.retry.annotation.Retryable)

Example 2 with OrchestratorAware

use of com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware 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 3 with OrchestratorAware

use of com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware in project cloudbreak by hortonworks.

the class SaltOrchestrator method formatAndMountDisksOnNodes.

@Override
@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
public Map<String, Map<String, String>> formatAndMountDisksOnNodes(OrchestratorAware stack, List<GatewayConfig> allGateway, Set<Node> nodesWithDiskData, Set<Node> allNodes, ExitCriteriaModel exitModel, String platformVariant) throws CloudbreakOrchestratorFailedException {
    GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGateway);
    Set<String> gatewayTargetIpAddresses = getGatewayPrivateIps(allGateway);
    Target<String> allHosts = new HostList(nodesWithDiskData.stream().map(Node::getHostname).collect(Collectors.toSet()));
    try (SaltConnector sc = saltService.createSaltConnector(primaryGateway)) {
        saveHostsPillar(stack, exitModel, gatewayTargetIpAddresses, sc);
        Callable<Boolean> saltPillarRunner;
        Map<String, String> dataVolumeMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getDataVolumes()));
        Map<String, String> serialIdMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getSerialIds()));
        Map<String, String> fstabMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getFstab()));
        Map<String, String> temporaryStorageMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getTemporaryStorage().name()));
        Map<String, Integer> dataBaseVolumeIndexMap = nodesWithDiskData.stream().collect(Collectors.toMap(Node::getHostname, node -> node.getNodeVolumes().getDatabaseVolumeIndex()));
        Map<String, Object> hostnameDiskMountMap = nodesWithDiskData.stream().map(Node::getHostname).collect(Collectors.toMap(hn -> hn, hn -> Map.of("attached_volume_name_list", dataVolumeMap.getOrDefault(hn, ""), "attached_volume_serial_list", serialIdMap.getOrDefault(hn, ""), "cloud_platform", platformVariant, "previous_fstab", fstabMap.getOrDefault(hn, ""), "database_volume_index", dataBaseVolumeIndexMap.getOrDefault(hn, -1), "temporary_storage", temporaryStorageMap.getOrDefault(hn, TemporaryStorage.ATTACHED_VOLUMES.name()))));
        SaltPillarProperties mounDiskProperties = new SaltPillarProperties("/mount/disk.sls", Collections.singletonMap("mount_data", hostnameDiskMountMap));
        OrchestratorBootstrap pillarSave = PillarSave.createCustomPillar(sc, gatewayTargetIpAddresses, mounDiskProperties);
        saltPillarRunner = saltRunner.runner(pillarSave, exitCriteria, exitModel);
        saltPillarRunner.call();
        saltCommandRunner.runModifyGrainCommand(sc, new GrainAddRunner(hostnameDiskMountMap.keySet(), allNodes, "mount_disks"), exitModel, exitCriteria);
        StateAllRunner stateAllRunner = new StateAllRunner(gatewayTargetIpAddresses, allNodes, "disks.format-and-mount");
        OrchestratorBootstrap saltJobIdTracker = new SaltJobIdTracker(sc, stateAllRunner);
        Callable<Boolean> saltJobRunBootstrapRunner = saltRunner.runner(saltJobIdTracker, exitCriteria, exitModel);
        saltJobRunBootstrapRunner.call();
        Map<String, String> uuidResponse = SaltStates.getUuidList(sc);
        saltCommandRunner.runModifyGrainCommand(sc, new GrainRemoveRunner(hostnameDiskMountMap.keySet(), allNodes, "mount_disks"), exitModel, exitCriteria);
        Map<String, String> fstabResponse = SaltStates.runCommandOnHosts(retry, sc, allHosts, "cat /etc/fstab");
        return nodesWithDiskData.stream().map(node -> {
            String fstab = fstabResponse.getOrDefault(node.getHostname(), "");
            String uuidList = uuidResponse.getOrDefault(node.getHostname(), "");
            return new SimpleImmutableEntry<>(node.getHostname(), Map.of("uuids", uuidList, "fstab", fstab));
        }).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
    } catch (Exception e) {
        LOGGER.info("Error occurred during the salt bootstrap", e);
        throw new CloudbreakOrchestratorFailedException(e.getMessage(), 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) HighStateAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateAllRunner) StateAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.StateAllRunner) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) JsonNode(com.fasterxml.jackson.databind.JsonNode) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) HostList(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) 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) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Retryable(org.springframework.retry.annotation.Retryable)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Joiner (com.google.common.base.Joiner)3 Sets (com.google.common.collect.Sets)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)3 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)3 PackageInfo (com.sequenceiq.cloudbreak.common.model.PackageInfo)3 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)3 NodeVolumes (com.sequenceiq.cloudbreak.common.orchestration.NodeVolumes)3 OrchestratorAware (com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware)3 SALT (com.sequenceiq.cloudbreak.common.type.OrchestratorConstants.SALT)3 RecipeExecutionPhase (com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase)3 PRE_CLOUDERA_MANAGER_START (com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase.PRE_CLOUDERA_MANAGER_START)3 RecipeExecutionPhase.convert (com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase.convert)3 TemporaryStorage (com.sequenceiq.cloudbreak.common.type.TemporaryStorage)3 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)3 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)3 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)3 CloudbreakOrchestratorTimeoutException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException)3 GrainOperation (com.sequenceiq.cloudbreak.orchestrator.host.GrainOperation)3 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)3