Search in sources :

Example 1 with GrainRemoveRunner

use of com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner 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 2 with GrainRemoveRunner

use of com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner in project cloudbreak by hortonworks.

the class SaltOrchestrator method upgradeAmbari.

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@Override
public void upgradeAmbari(GatewayConfig gatewayConfig, Set<String> target, Set<Node> allNodes, SaltConfig pillarConfig, ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorException {
    try (SaltConnector sc = new SaltConnector(gatewayConfig, restDebug)) {
        for (Entry<String, SaltPillarProperties> propertiesEntry : pillarConfig.getServicePillarConfig().entrySet()) {
            OrchestratorBootstrap pillarSave = new PillarSave(sc, Sets.newHashSet(gatewayConfig.getPrivateAddress()), propertiesEntry.getValue());
            Callable<Boolean> saltPillarRunner = runner(pillarSave, exitCriteria, exitCriteriaModel);
            Future<Boolean> saltPillarRunnerFuture = parallelOrchestratorComponentRunner.submit(saltPillarRunner);
            saltPillarRunnerFuture.get();
        }
        // add 'ambari_upgrade' role to all nodes
        Set<String> targets = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
        runSaltCommand(sc, new GrainAddRunner(targets, allNodes, "roles", "ambari_upgrade", 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, true);
        // remove 'ambari_upgrade' role from all nodes
        targets = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
        runSaltCommand(sc, new GrainRemoveRunner(targets, allNodes, "roles", "ambari_upgrade", CompoundType.IP), exitCriteriaModel);
    } catch (Exception e) {
        LOGGER.error("Error occurred during ambari upgrade", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) SyncGrainsRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with GrainRemoveRunner

use of com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner in project cloudbreak by hortonworks.

the class SaltOrchestrator method changePrimaryGateway.

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@Override
public void changePrimaryGateway(GatewayConfig formerGateway, GatewayConfig newPrimaryGateway, List<GatewayConfig> allGatewayConfigs, Set<Node> allNodes, ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorException {
    LOGGER.info("Change primary gateway: {}", formerGateway);
    String ambariServerAddress = newPrimaryGateway.getPrivateAddress();
    try (SaltConnector sc = new SaltConnector(newPrimaryGateway, restDebug)) {
        SaltStates.stopMinions(sc, Collections.singletonMap(formerGateway.getHostname(), formerGateway.getPrivateAddress()));
        // change ambari_server_standby role to ambari_server
        Set<String> server = Collections.singleton(ambariServerAddress);
        runSaltCommand(sc, new GrainAddRunner(server, allNodes, "ambari_server"), exitCriteriaModel);
        runSaltCommand(sc, new GrainRemoveRunner(server, allNodes, "roles", "ambari_server_standby", CompoundType.IP), exitCriteriaModel);
        // add ambari_server_standby role to the standby servers and remove ambari_server role from them.
        Set<String> standByServers = allGatewayConfigs.stream().filter(gwc -> !gwc.getHostname().equals(newPrimaryGateway.getHostname()) && !gwc.getHostname().equals(formerGateway.getHostname())).map(GatewayConfig::getPrivateAddress).collect(Collectors.toSet());
        runSaltCommand(sc, new GrainAddRunner(standByServers, allNodes, "ambari_server_standby"), exitCriteriaModel);
        runSaltCommand(sc, new GrainRemoveRunner(standByServers, allNodes, "roles", "ambari_server", CompoundType.IP), exitCriteriaModel);
        // remove minion key from all remaining gateway nodes
        for (GatewayConfig gatewayConfig : allGatewayConfigs) {
            if (!gatewayConfig.getHostname().equals(formerGateway.getHostname())) {
                try (SaltConnector sc1 = new SaltConnector(gatewayConfig, restDebug)) {
                    LOGGER.info("Removing minion key '{}' from gateway '{}'", formerGateway.getHostname(), gatewayConfig.getHostname());
                    sc1.wheel("key.delete", Collections.singleton(formerGateway.getHostname()), Object.class);
                } catch (Exception ex) {
                    LOGGER.error("Unsuccessful key removal from gateway: " + gatewayConfig.getHostname(), ex);
                }
            }
        }
        // salt '*' state.highstate
        runNewService(sc, new HighStateRunner(server, allNodes), exitCriteriaModel);
    } catch (Exception e) {
        LOGGER.error("Error occurred during primary gateway change", e);
        if (e instanceof ExecutionException && e.getCause() instanceof CloudbreakOrchestratorFailedException) {
            throw (CloudbreakOrchestratorFailedException) e.getCause();
        }
        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) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) ExecutionException(java.util.concurrent.ExecutionException) 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) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)3 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)3 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)3 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)3 GrainRemoveRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner)3 HighStateRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 IOException (java.io.IOException)3 ExecutionException (java.util.concurrent.ExecutionException)3 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)2 SyncGrainsRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner)2 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 SaltPillarProperties (com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)1 PillarSave (com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)1