Search in sources :

Example 26 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig in project cloudbreak by hortonworks.

the class SaltOrchestratorTest method setUp.

@Before
public void setUp() throws Exception {
    gatewayConfig = new GatewayConfig("1.1.1.1", "10.0.0.1", "172.16.252.43", "10-0-0-1", 9443, "servercert", "clientcert", "clientkey", "saltpasswd", "saltbootpassword", "signkey", false, true, null, null);
    targets = new HashSet<>();
    targets.add(new Node("10.0.0.1", "1.1.1.1", "10-0-0-1.example.com", "hg"));
    targets.add(new Node("10.0.0.2", "1.1.1.2", "10-0-0-2.example.com", "hg"));
    targets.add(new Node("10.0.0.3", "1.1.1.3", "10-0-0-3.example.com", "hg"));
    saltConnector = mock(SaltConnector.class);
    whenNew(SaltConnector.class).withAnyArguments().thenReturn(saltConnector);
    parallelOrchestratorComponentRunner = mock(ParallelOrchestratorComponentRunner.class);
    when(parallelOrchestratorComponentRunner.submit(any())).thenReturn(CompletableFuture.completedFuture(true));
    when(hostDiscoveryService.determineDomain("test", "test", false)).thenReturn(".example.com");
    exitCriteria = mock(ExitCriteria.class);
    exitCriteriaModel = mock(ExitCriteriaModel.class);
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) ParallelOrchestratorComponentRunner(com.sequenceiq.cloudbreak.orchestrator.executor.ParallelOrchestratorComponentRunner) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Before(org.junit.Before)

Example 27 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig in project cloudbreak by hortonworks.

the class SaltOrchestrator method runService.

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
@Override
public void runService(List<GatewayConfig> allGateway, Set<Node> allNodes, SaltConfig saltConfig, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
    LOGGER.info("Run Services on nodes: {}", allNodes);
    GatewayConfig primaryGateway = getPrimaryGatewayConfig(allGateway);
    Set<String> gatewayTargets = getGatewayPrivateIps(allGateway);
    String ambariServerAddress = primaryGateway.getPrivateAddress();
    try (SaltConnector sc = new SaltConnector(primaryGateway, restDebug)) {
        OrchestratorBootstrap hostSave = new PillarSave(sc, gatewayTargets, allNodes);
        Callable<Boolean> saltPillarRunner = runner(hostSave, exitCriteria, exitModel);
        Future<Boolean> saltPillarRunnerFuture = parallelOrchestratorComponentRunner.submit(saltPillarRunner);
        saltPillarRunnerFuture.get();
        for (Entry<String, SaltPillarProperties> propertiesEntry : saltConfig.getServicePillarConfig().entrySet()) {
            OrchestratorBootstrap pillarSave = new PillarSave(sc, gatewayTargets, propertiesEntry.getValue());
            saltPillarRunner = runner(pillarSave, exitCriteria, exitModel);
            saltPillarRunnerFuture = parallelOrchestratorComponentRunner.submit(saltPillarRunner);
            saltPillarRunnerFuture.get();
        }
        Set<String> server = Sets.newHashSet(ambariServerAddress);
        Set<String> all = allNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
        // knox
        if (primaryGateway.getKnoxGatewayEnabled()) {
            runSaltCommand(sc, new GrainAddRunner(gatewayTargets, allNodes, "gateway"), exitModel);
        }
        setPostgreRoleIfNeeded(allNodes, saltConfig, exitModel, sc, server);
        // ambari server
        runSaltCommand(sc, new GrainAddRunner(server, allNodes, "ambari_server_install"), exitModel);
        runSaltCommand(sc, new GrainAddRunner(server, allNodes, "ambari_server"), exitModel);
        // ambari server standby
        Set<String> standbyServers = gatewayTargets.stream().filter(ip -> !server.contains(ip)).collect(Collectors.toSet());
        if (!standbyServers.isEmpty()) {
            runSaltCommand(sc, new GrainAddRunner(standbyServers, allNodes, "ambari_server_install"), exitModel);
            runSaltCommand(sc, new GrainAddRunner(standbyServers, allNodes, "ambari_server_standby"), exitModel);
        }
        // ambari agent
        runSaltCommand(sc, new GrainAddRunner(all, allNodes, "ambari_agent_install"), exitModel);
        runSaltCommand(sc, new GrainAddRunner(all, allNodes, "ambari_agent"), exitModel);
        // kerberos
        if (saltConfig.getServicePillarConfig().containsKey("kerberos")) {
            runSaltCommand(sc, new GrainAddRunner(server, allNodes, "kerberos_server_master"), exitModel);
            if (!standbyServers.isEmpty()) {
                runSaltCommand(sc, new GrainAddRunner(standbyServers, allNodes, "kerberos_server_slave"), exitModel);
            }
        }
        // smartsense
        if (configureSmartSense) {
            runSaltCommand(sc, new GrainAddRunner(gatewayTargets, allNodes, "smartsense"), exitModel);
            runSaltCommand(sc, new GrainAddRunner(all, allNodes, "smartsense_agent_update"), exitModel);
        }
        uploadGrains(allNodes, saltConfig.getGrainsProperties(), exitModel, sc);
        runSaltCommand(sc, new SyncGrainsRunner(all, allNodes), exitModel);
        runSaltCommand(sc, new MineUpdateRunner(gatewayTargets, allNodes), exitModel);
        runNewService(sc, new HighStateRunner(all, allNodes), exitModel);
    } catch (Exception e) {
        LOGGER.error("Error occurred during ambari bootstrap", e);
        if (e instanceof ExecutionException && e.getCause() instanceof CloudbreakOrchestratorFailedException) {
            throw (CloudbreakOrchestratorFailedException) e.getCause();
        }
        throw new CloudbreakOrchestratorFailedException(e);
    }
    LOGGER.info("Run services on nodes finished: {}", allNodes);
}
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) HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) 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) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) MineUpdateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.MineUpdateRunner) SyncGrainsRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncGrainsRunner) ExecutionException(java.util.concurrent.ExecutionException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 28 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig 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)

Example 29 with GatewayConfig

use of com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig in project cloudbreak by hortonworks.

the class SaltOrchestrator method uploadRecipes.

@Override
public void uploadRecipes(List<GatewayConfig> allGatewayConfigs, Map<String, List<RecipeModel>> recipes, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorFailedException {
    GatewayConfig primaryGateway = allGatewayConfigs.stream().filter(GatewayConfig::isPrimary).findFirst().get();
    Set<String> gatewayTargets = getGatewayPrivateIps(allGatewayConfigs);
    try (SaltConnector sc = new SaltConnector(primaryGateway, restDebug)) {
        OrchestratorBootstrap scriptPillarSave = new PillarSave(sc, gatewayTargets, recipes);
        Callable<Boolean> saltPillarRunner = runner(scriptPillarSave, exitCriteria, exitModel);
        Future<Boolean> saltPillarRunnerFuture = parallelOrchestratorComponentRunner.submit(saltPillarRunner);
        saltPillarRunnerFuture.get();
        for (List<RecipeModel> recipeList : recipes.values()) {
            for (RecipeModel model : recipeList) {
                uploadRecipe(sc, gatewayTargets, exitModel, model.getName(), model.getScript(), RecipeExecutionPhase.convert(model.getRecipeType()));
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error occurred during recipe upload", e);
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) 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) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)

Aggregations

GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)29 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)17 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)15 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)13 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)13 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)12 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)12 Stack (com.sequenceiq.cloudbreak.domain.Stack)11 ArrayList (java.util.ArrayList)10 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)9 IOException (java.io.IOException)9 HashSet (java.util.HashSet)9 Map (java.util.Map)9 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)8 List (java.util.List)8 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)7 Set (java.util.Set)7 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)6 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)6 Collection (java.util.Collection)6