Search in sources :

Example 1 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltOrchestrator method bootstrapNewNodes.

@Override
public void bootstrapNewNodes(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, Set<Node> allNodes, byte[] stateConfigZip, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
    GatewayConfig primaryGateway = getPrimaryGatewayConfig(allGatewayConfigs);
    Set<String> gatewayTargets = allGatewayConfigs.stream().filter(gc -> targets.stream().anyMatch(n -> gc.getPrivateAddress().equals(n.getPrivateIp()))).map(GatewayConfig::getPrivateAddress).collect(Collectors.toSet());
    try (SaltConnector sc = new SaltConnector(primaryGateway, restDebug)) {
        if (!gatewayTargets.isEmpty()) {
            uploadSaltConfig(sc, gatewayTargets, stateConfigZip, exitModel);
        }
        uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel);
        // if there is a new salt master then re-bootstrap all nodes
        Set<Node> nodes = gatewayTargets.isEmpty() ? targets : allNodes;
        OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, nodes);
        Callable<Boolean> saltBootstrapRunner = runner(saltBootstrap, exitCriteria, exitModel);
        Future<Boolean> saltBootstrapRunnerFuture = parallelOrchestratorComponentRunner.submit(saltBootstrapRunner);
        saltBootstrapRunnerFuture.get();
    } catch (Exception e) {
        LOGGER.error("Error occurred during salt upscale", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : ParallelOrchestratorComponentRunner(com.sequenceiq.cloudbreak.orchestrator.executor.ParallelOrchestratorComponentRunner) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) LoggerFactory(org.slf4j.LoggerFactory) HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Future(java.util.concurrent.Future) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) Map(java.util.Map) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) ZipEntry(java.util.zip.ZipEntry) Resource(org.springframework.core.io.Resource) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) MineUpdateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.MineUpdateRunner) OrchestratorBootstrapRunner(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrapRunner) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Collection(java.util.Collection) CompoundType(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound.CompoundType) Set(java.util.Set) SaltCommandTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltCommandTracker) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) StandardCharsets(java.nio.charset.StandardCharsets) Sets(com.google.common.collect.Sets) SALT(com.sequenceiq.cloudbreak.common.type.OrchestratorConstants.SALT) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) SaltStates(com.sequenceiq.cloudbreak.orchestrator.salt.states.SaltStates) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) Entry(java.util.Map.Entry) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) Compound(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound) RecipeExecutionPhase(com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SaltUpload(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltUpload) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) Value(org.springframework.beans.factory.annotation.Value) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) Logger(org.slf4j.Logger) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) BaseSaltJobRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.BaseSaltJobRunner) TreeMap(java.util.TreeMap) SyncGrainsRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner) MDC(org.slf4j.MDC) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Collections(java.util.Collections) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) InputStream(java.io.InputStream) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltOrchestrator method tearDown.

@Override
public void tearDown(List<GatewayConfig> allGatewayConfigs, Map<String, String> privateIPsByFQDN) throws CloudbreakOrchestratorException {
    GatewayConfig primaryGateway = getPrimaryGatewayConfig(allGatewayConfigs);
    try (SaltConnector saltConnector = new SaltConnector(primaryGateway, restDebug)) {
        SaltStates.stopMinions(saltConnector, privateIPsByFQDN);
    } catch (Exception e) {
        LOGGER.error("Error occurred during salt minion tear down", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
    List<GatewayConfig> liveGateways = allGatewayConfigs.stream().filter(gw -> !privateIPsByFQDN.values().contains(gw.getPrivateAddress())).collect(Collectors.toList());
    for (GatewayConfig gatewayConfig : liveGateways) {
        try (SaltConnector sc = new SaltConnector(gatewayConfig, restDebug)) {
            sc.wheel("key.delete", privateIPsByFQDN.keySet(), Object.class);
        } catch (Exception e) {
            LOGGER.error("Error occurred during salt minion tear down", e);
            throw new CloudbreakOrchestratorFailedException(e);
        }
    }
}
Also used : ParallelOrchestratorComponentRunner(com.sequenceiq.cloudbreak.orchestrator.executor.ParallelOrchestratorComponentRunner) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) LoggerFactory(org.slf4j.LoggerFactory) HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Future(java.util.concurrent.Future) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) Map(java.util.Map) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) ZipEntry(java.util.zip.ZipEntry) Resource(org.springframework.core.io.Resource) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) MineUpdateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.MineUpdateRunner) OrchestratorBootstrapRunner(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrapRunner) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Collection(java.util.Collection) CompoundType(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound.CompoundType) Set(java.util.Set) SaltCommandTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltCommandTracker) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) StandardCharsets(java.nio.charset.StandardCharsets) Sets(com.google.common.collect.Sets) SALT(com.sequenceiq.cloudbreak.common.type.OrchestratorConstants.SALT) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) SaltStates(com.sequenceiq.cloudbreak.orchestrator.salt.states.SaltStates) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) Entry(java.util.Map.Entry) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) Compound(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound) RecipeExecutionPhase(com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SaltUpload(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltUpload) Callable(java.util.concurrent.Callable) ArrayList(java.util.ArrayList) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) Value(org.springframework.beans.factory.annotation.Value) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) Logger(org.slf4j.Logger) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) BaseSaltJobRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.BaseSaltJobRunner) TreeMap(java.util.TreeMap) SyncGrainsRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner) MDC(org.slf4j.MDC) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Collections(java.util.Collections) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) InputStream(java.io.InputStream) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 3 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltOrchestrator method executeRecipes.

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
private void executeRecipes(GatewayConfig gatewayConfig, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel, RecipeExecutionPhase phase) throws CloudbreakOrchestratorFailedException {
    try (SaltConnector sc = new SaltConnector(gatewayConfig, restDebug)) {
        // add 'recipe' grain to all nodes
        Set<String> targets = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
        runSaltCommand(sc, new GrainAddRunner(targets, allNodes, "recipes", phase.value(), CompoundType.IP), exitCriteriaModel);
        // Add Deprecated 'PRE/POST' recipe execution for backward compatibility (since version 2.2.0)
        boolean postRecipe = phase.isPostRecipe();
        if (postRecipe) {
            runSaltCommand(sc, new GrainAddRunner(targets, allNodes, "recipes", RecipeExecutionPhase.POST.value(), CompoundType.IP), exitCriteriaModel);
        } else {
            runSaltCommand(sc, new GrainAddRunner(targets, allNodes, "recipes", RecipeExecutionPhase.PRE.value(), CompoundType.IP), exitCriteriaModel);
        }
        Set<String> all = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
        runSaltCommand(sc, new SyncGrainsRunner(all, allNodes), exitCriteriaModel);
        runNewService(sc, new HighStateRunner(all, allNodes), exitCriteriaModel, maxRetryRecipe, false);
        // remove 'recipe' grain from all nodes
        targets = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
        runSaltCommand(sc, new GrainRemoveRunner(targets, allNodes, "recipes", phase.value(), CompoundType.IP), exitCriteriaModel);
        // Remove Deprecated 'PRE/POST' recipe execution for backward compatibility (since version 2.2.0)
        if (postRecipe) {
            runSaltCommand(sc, new GrainRemoveRunner(targets, allNodes, "recipes", RecipeExecutionPhase.POST.value(), CompoundType.IP), exitCriteriaModel);
        } else {
            runSaltCommand(sc, new GrainRemoveRunner(targets, allNodes, "recipes", RecipeExecutionPhase.PRE.value(), CompoundType.IP), exitCriteriaModel);
        }
    } catch (Exception e) {
        LOGGER.error("Error occurred during recipe execution", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) SyncGrainsRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class SaltOrchestrator method bootstrap.

@Override
public void bootstrap(List<GatewayConfig> allGatewayConfigs, Set<Node> targets, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
    LOGGER.info("Start SaltBootstrap on nodes: {}", targets);
    GatewayConfig primaryGateway = getPrimaryGatewayConfig(allGatewayConfigs);
    Set<String> gatewayTargets = getGatewayPrivateIps(allGatewayConfigs);
    try (SaltConnector sc = new SaltConnector(primaryGateway, restDebug)) {
        uploadSaltConfig(sc, gatewayTargets, exitModel);
        uploadSignKey(sc, primaryGateway, gatewayTargets, targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet()), exitModel);
        OrchestratorBootstrap saltBootstrap = new SaltBootstrap(sc, allGatewayConfigs, targets);
        Callable<Boolean> saltBootstrapRunner = runner(saltBootstrap, exitCriteria, exitModel);
        Future<Boolean> saltBootstrapRunnerFuture = parallelOrchestratorComponentRunner.submit(saltBootstrapRunner);
        saltBootstrapRunnerFuture.get();
    } catch (Exception e) {
        LOGGER.error("Error occurred during the salt bootstrap", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
    LOGGER.info("SaltBootstrap finished");
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 5 with SaltConnector

use of com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector in project cloudbreak by hortonworks.

the class BaseSaltJobRunnerTest method collectNodesTest.

@Test
public void collectNodesTest() {
    Set<Node> allNode = allNodeWithPostFix();
    baseSaltJobRunner = new BaseSaltJobRunner(targets, allNode) {

        @Override
        public String submit(SaltConnector saltConnector) {
            return "";
        }
    };
    ApplyResponse applyResponse = new ApplyResponse();
    List<Map<String, Object>> resultList = new ArrayList<>();
    Map<String, Object> resultMap = new HashMap<>();
    resultMap.put("host-10-0-0-1.example.com", "10.0.0.1");
    resultMap.put("host-10-0-0-2.example.com", "10.0.0.2");
    resultMap.put("host-10-0-0-3.example.com", "10.0.0.3");
    resultList.add(resultMap);
    applyResponse.setResult(resultList);
    Set<String> collectedNodes = baseSaltJobRunner.collectNodes(applyResponse);
    Assert.assertEquals(3, collectedNodes.size());
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-1.example.com"));
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-2.example.com"));
    Assert.assertTrue(collectedNodes.contains("host-10-0-0-3.example.com"));
}
Also used : HashMap(java.util.HashMap) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ArrayList(java.util.ArrayList) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) Map(java.util.Map) HashMap(java.util.HashMap) ApplyResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse) Test(org.junit.Test)

Aggregations

SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)24 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)14 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)12 Test (org.junit.Test)12 HashSet (java.util.HashSet)10 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)9 IOException (java.io.IOException)9 ExecutionException (java.util.concurrent.ExecutionException)9 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)8 Map (java.util.Map)8 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)7 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)7 ArrayList (java.util.ArrayList)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)6 GrainRemoveRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner)6 HighStateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner)6 Compound (com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Compound)5 PillarSave (com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)5 SyncGrainsRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner)5