Search in sources :

Example 1 with SaltConfig

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

the class ClusterHostServiceRunner method runAmbariServices.

@Transactional
public void runAmbariServices(Stack stack, Cluster cluster) throws CloudbreakException {
    try {
        Set<Node> nodes = collectNodes(stack);
        HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
        GatewayConfig primaryGatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        SaltConfig saltConfig = createSaltConfig(stack, cluster, primaryGatewayConfig, gatewayConfigs);
        hostOrchestrator.runService(gatewayConfigs, nodes, saltConfig, clusterDeletionBasedModel(stack.getId(), cluster.getId()));
    } catch (CloudbreakOrchestratorCancelledException e) {
        throw new CancellationException(e.getMessage());
    } catch (CloudbreakOrchestratorException | IOException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) IOException(java.io.IOException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Transactional(javax.transaction.Transactional)

Example 2 with SaltConfig

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

the class AmbariClusterUpgradeService method upgradeCluster.

public void upgradeCluster(Long stackId) throws CloudbreakOrchestratorException {
    Stack stack = stackRepository.findOneWithLists(stackId);
    Cluster cluster = stack.getCluster();
    try {
        OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
        if (orchestratorType.hostOrchestrator()) {
            HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
            InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
            GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, cluster.getGateway().getEnableGateway());
            Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
            ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
            AmbariRepo ambariRepo = componentConfigProvider.getAmbariRepo(cluster.getId());
            Map<String, SaltPillarProperties> servicePillar = new HashMap<>();
            Map<String, Object> credentials = new HashMap<>();
            credentials.put("username", ambariSecurityConfigProvider.getAmbariUserName(cluster));
            credentials.put("password", ambariSecurityConfigProvider.getAmbariPassword(cluster));
            servicePillar.put("ambari-credentials", new SaltPillarProperties("/ambari/credentials.sls", singletonMap("ambari", credentials)));
            if (ambariRepo != null) {
                servicePillar.put("ambari-repo", new SaltPillarProperties("/ambari/repo.sls", singletonMap("ambari", singletonMap("repo", ambariRepo))));
            }
            SaltConfig pillar = new SaltConfig(servicePillar);
            hostOrchestrator.upgradeAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), pillar, exitCriteriaModel);
        } else {
            throw new UnsupportedOperationException("Ambari upgrade works only with host orchestrator");
        }
    } catch (CloudbreakException e) {
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 3 with SaltConfig

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

the class ClusterHostServiceRunner method createSaltConfig.

private SaltConfig createSaltConfig(Stack stack, Cluster cluster, GatewayConfig primaryGatewayConfig, Iterable<GatewayConfig> gatewayConfigs) throws IOException, CloudbreakOrchestratorException {
    Map<String, SaltPillarProperties> servicePillar = new HashMap<>();
    saveDatalakeNameservers(stack, servicePillar);
    saveSharedRangerService(stack, servicePillar);
    if (cluster.isSecure() && kerberosDetailService.isAmbariManagedKerberosPackages(cluster.getKerberosConfig())) {
        Map<String, String> kerberosPillarConf = new HashMap<>();
        KerberosConfig kerberosConfig = cluster.getKerberosConfig();
        putIfNotNull(kerberosPillarConf, kerberosConfig.getMasterKey(), "masterKey");
        putIfNotNull(kerberosPillarConf, kerberosConfig.getAdmin(), "user");
        putIfNotNull(kerberosPillarConf, kerberosConfig.getPassword(), "password");
        if (StringUtils.isEmpty(kerberosConfig.getDescriptor())) {
            putIfNotNull(kerberosPillarConf, kerberosConfig.getUrl(), "url");
            putIfNotNull(kerberosPillarConf, kerberosConfig.getAdminUrl(), "adminUrl");
            putIfNotNull(kerberosPillarConf, kerberosConfig.getRealm(), "realm");
        } else {
            Map<String, Object> properties = kerberosDetailService.getKerberosEnvProperties(kerberosConfig);
            putIfNotNull(kerberosPillarConf, properties.get("kdc_hosts"), "url");
            putIfNotNull(kerberosPillarConf, properties.get("admin_server_host"), "adminUrl");
            putIfNotNull(kerberosPillarConf, properties.get("realm"), "realm");
        }
        putIfNotNull(kerberosPillarConf, cluster.getUserName(), "clusterUser");
        putIfNotNull(kerberosPillarConf, cluster.getPassword(), "clusterPassword");
        servicePillar.put("kerberos", new SaltPillarProperties("/kerberos/init.sls", singletonMap("kerberos", kerberosPillarConf)));
    }
    servicePillar.put("discovery", new SaltPillarProperties("/discovery/init.sls", singletonMap("platform", stack.cloudPlatform())));
    servicePillar.put("metadata", new SaltPillarProperties("/metadata/init.sls", singletonMap("cluster", singletonMap("name", stack.getCluster().getName()))));
    saveGatewayPillar(primaryGatewayConfig, cluster, servicePillar);
    AmbariRepo ambariRepo = clusterComponentConfigProvider.getAmbariRepo(cluster.getId());
    if (ambariRepo != null) {
        servicePillar.put("ambari-repo", new SaltPillarProperties("/ambari/repo.sls", singletonMap("ambari", singletonMap("repo", ambariRepo))));
    }
    servicePillar.put("ambari-gpl-repo", new SaltPillarProperties("/ambari/gpl.sls", singletonMap("ambari", singletonMap("gpl", singletonMap("enabled", clusterComponentConfigProvider.getHDPRepo(cluster.getId()).isEnableGplRepo())))));
    decoratePillarWithAmbariDatabase(cluster, servicePillar);
    saveLdapPillar(cluster.getLdapConfig(), servicePillar);
    saveDockerPillar(cluster.getExecutorType(), servicePillar);
    saveHDPPillar(cluster.getId(), servicePillar);
    Map<String, Object> credentials = new HashMap<>();
    credentials.put("username", ambariSecurityConfigProvider.getAmbariUserName(stack.getCluster()));
    credentials.put("password", ambariSecurityConfigProvider.getAmbariPassword(stack.getCluster()));
    credentials.put("securityMasterKey", ambariSecurityConfigProvider.getAmbariSecurityMasterKey(cluster));
    servicePillar.put("ambari-credentials", new SaltPillarProperties("/ambari/credentials.sls", singletonMap("ambari", credentials)));
    if (smartSenseCredentialConfigService.areCredentialsSpecified()) {
        Map<String, Object> smartSenseCredentials = smartSenseCredentialConfigService.getCredentials();
        servicePillar.put("smartsense-credentials", new SaltPillarProperties("/smartsense/credentials.sls", smartSenseCredentials));
    }
    postgresConfigService.decorateServicePillarWithPostgresIfNeeded(servicePillar, stack, cluster);
    proxyConfigProvider.decoratePillarWithProxyDataIfNeeded(servicePillar, cluster);
    return new SaltConfig(servicePillar, createGrainProperties(gatewayConfigs));
}
Also used : HashMap(java.util.HashMap) KerberosConfig(com.sequenceiq.cloudbreak.domain.KerberosConfig) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)

Example 4 with SaltConfig

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

the class ClusterHostServiceRunner method addAmbariServices.

@Transactional
public Map<String, String> addAmbariServices(Long stackId, String hostGroupName, Integer scalingAdjustment) throws CloudbreakException {
    Map<String, String> candidates;
    try {
        Stack stack = stackRepository.findOneWithLists(stackId);
        Cluster cluster = stack.getCluster();
        candidates = collectUpscaleCandidates(cluster.getId(), hostGroupName, scalingAdjustment);
        Set<Node> allNodes = collectNodes(stack);
        HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        SaltConfig saltConfig = createSaltConfig(stack, cluster, gatewayConfigService.getPrimaryGatewayConfig(stack), gatewayConfigs);
        hostOrchestrator.runService(gatewayConfigs, allNodes, saltConfig, clusterDeletionBasedModel(stack.getId(), cluster.getId()));
    } catch (CloudbreakOrchestratorCancelledException e) {
        throw new CancellationException(e.getMessage());
    } catch (CloudbreakOrchestratorException | IOException e) {
        throw new CloudbreakException(e);
    }
    return candidates;
}
Also used : HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) IOException(java.io.IOException) Stack(com.sequenceiq.cloudbreak.domain.Stack) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Transactional(javax.transaction.Transactional)

Example 5 with SaltConfig

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

the class SaltOrchestratorTest method runServiceTest.

@Test
public void runServiceTest() throws Exception {
    whenNew(SaltBootstrap.class).withAnyArguments().thenReturn(mock(SaltBootstrap.class));
    whenNew(OrchestratorBootstrapRunner.class).withAnyArguments().thenReturn(mock(OrchestratorBootstrapRunner.class));
    PillarSave pillarSave = mock(PillarSave.class);
    whenNew(PillarSave.class).withAnyArguments().thenReturn(pillarSave);
    GrainAddRunner addRemoveGrainRunner = mock(GrainAddRunner.class);
    whenNew(GrainAddRunner.class).withAnyArguments().thenReturn(addRemoveGrainRunner);
    SaltCommandTracker roleCheckerSaltCommandTracker = mock(SaltCommandTracker.class);
    whenNew(SaltCommandTracker.class).withArguments(eq(saltConnector), eq(addRemoveGrainRunner)).thenReturn(roleCheckerSaltCommandTracker);
    SyncGrainsRunner syncGrainsRunner = mock(SyncGrainsRunner.class);
    whenNew(SyncGrainsRunner.class).withAnyArguments().thenReturn(syncGrainsRunner);
    SaltCommandTracker syncGrainsCheckerSaltCommandTracker = mock(SaltCommandTracker.class);
    whenNew(SaltCommandTracker.class).withArguments(eq(saltConnector), eq(syncGrainsRunner)).thenReturn(syncGrainsCheckerSaltCommandTracker);
    HighStateRunner highStateRunner = mock(HighStateRunner.class);
    whenNew(HighStateRunner.class).withAnyArguments().thenReturn(highStateRunner);
    SaltJobIdTracker saltJobIdTracker = mock(SaltJobIdTracker.class);
    whenNew(SaltJobIdTracker.class).withAnyArguments().thenReturn(saltJobIdTracker);
    saltOrchestrator.init(parallelOrchestratorComponentRunner, exitCriteria);
    SaltConfig saltConfig = new SaltConfig();
    saltOrchestrator.runService(Collections.singletonList(gatewayConfig), targets, saltConfig, exitCriteriaModel);
    // verify pillar save
    verifyNew(OrchestratorBootstrapRunner.class, times(1)).withArguments(eq(pillarSave), eq(exitCriteria), eq(exitCriteriaModel), any(), anyInt(), anyInt());
    // verify ambari server role
    verifyNew(GrainAddRunner.class, times(1)).withArguments(eq(Sets.newHashSet(gatewayConfig.getPrivateAddress())), eq(targets), eq("ambari_server_install"));
    // verify ambari server role
    verifyNew(GrainAddRunner.class, times(1)).withArguments(eq(Sets.newHashSet(gatewayConfig.getPrivateAddress())), eq(targets), eq("ambari_server"));
    // verify ambari agent role
    Set<String> allNodes = targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
    verifyNew(GrainAddRunner.class, times(1)).withArguments(eq(allNodes), eq(targets), eq("ambari_agent_install"));
    // verify ambari agent role
    allNodes = targets.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
    verifyNew(GrainAddRunner.class, times(1)).withArguments(eq(allNodes), eq(targets), eq("ambari_agent"));
    // verify two role command (amabari server, ambari agent)
    verifyNew(SaltCommandTracker.class, times(4)).withArguments(eq(saltConnector), eq(addRemoveGrainRunner));
    // verify two OrchestratorBootstrapRunner call with rolechecker command tracker
    verifyNew(OrchestratorBootstrapRunner.class, times(4)).withArguments(eq(roleCheckerSaltCommandTracker), eq(exitCriteria), eq(exitCriteriaModel), any(), anyInt(), anyInt());
    // verify syncgrains command
    verifyNew(SyncGrainsRunner.class, times(1)).withArguments(eq(allNodes), eq(targets));
    verifyNew(SaltCommandTracker.class, times(1)).withArguments(eq(saltConnector), eq(syncGrainsRunner));
    verifyNew(OrchestratorBootstrapRunner.class, times(1)).withArguments(eq(syncGrainsCheckerSaltCommandTracker), eq(exitCriteria), eq(exitCriteriaModel), any(), anyInt(), anyInt());
    // verify run new service
    verifyNew(HighStateRunner.class, atLeastOnce()).withArguments(eq(allNodes), eq(targets));
    verifyNew(SaltJobIdTracker.class, atLeastOnce()).withArguments(eq(saltConnector), eq(highStateRunner), eq(true));
}
Also used : HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) 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) SaltCommandTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltCommandTracker) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) OrchestratorBootstrapRunner(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrapRunner) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)6 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)4 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)4 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)4 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)3 SaltPillarProperties (com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)3 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)3 IOException (java.io.IOException)3 AmbariRepo (com.sequenceiq.cloudbreak.cloud.model.AmbariRepo)2 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)2 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 OrchestratorBootstrapRunner (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrapRunner)2 CloudbreakOrchestratorCancelledException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException)2 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)2 PillarSave (com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave)2 SaltBootstrap (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap)2 SaltCommandTracker (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltCommandTracker)2 SaltJobIdTracker (com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker)2 GrainAddRunner (com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner)2