Search in sources :

Example 46 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayService method primaryGatewayChanged.

@Transactional
public void primaryGatewayChanged(long stackId, String newPrimaryGatewayFQDN) throws CloudbreakException {
    Set<InstanceMetaData> imds = instanceMetaDataRepository.findNotTerminatedForStack(stackId);
    Optional<InstanceMetaData> formerPrimaryGateway = imds.stream().filter(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).findFirst();
    Optional<InstanceMetaData> newPrimaryGateway = imds.stream().filter(imd -> imd.getDiscoveryFQDN().equals(newPrimaryGatewayFQDN)).findFirst();
    if (newPrimaryGateway.isPresent() && formerPrimaryGateway.isPresent()) {
        InstanceMetaData fpg = formerPrimaryGateway.get();
        fpg.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
        instanceMetaDataRepository.save(fpg);
        InstanceMetaData npg = newPrimaryGateway.get();
        npg.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
        instanceMetaDataRepository.save(npg);
        Stack updatedStack = stackService.getByIdWithLists(stackId);
        String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(updatedStack);
        Cluster cluster = updatedStack.getCluster();
        cluster.setAmbariIp(gatewayIp);
        clusterRepository.save(cluster);
    } else {
        throw new CloudbreakException("Primary gateway change was not successful.");
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) InstanceMetaDataRepository(com.sequenceiq.cloudbreak.repository.InstanceMetaDataRepository) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_FAILED) Msg(com.sequenceiq.cloudbreak.core.flow2.stack.Msg) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.model.Status.UPDATE_IN_PROGRESS) Inject(javax.inject.Inject) Stack(com.sequenceiq.cloudbreak.domain.Stack) AmbariClusterConnector(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariClusterConnector) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) AVAILABLE(com.sequenceiq.cloudbreak.api.model.Status.AVAILABLE) Transactional(javax.transaction.Transactional) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) Set(java.util.Set) FlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.FlowMessageService) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) InstanceMetadataType(com.sequenceiq.cloudbreak.api.model.InstanceMetadataType) ClusterRepository(com.sequenceiq.cloudbreak.repository.ClusterRepository) StackUpdater(com.sequenceiq.cloudbreak.repository.StackUpdater) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) Component(org.springframework.stereotype.Component) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.Stack) Transactional(javax.transaction.Transactional)

Example 47 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster 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 48 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.

the class ClusterStartService method clusterStartFinished.

public void clusterStartFinished(StackView stack) {
    Cluster cluster = clusterService.retrieveClusterByStackId(stack.getId());
    String ambariIp = stackUtil.extractAmbariIp(stack);
    cluster.setUpSince(new Date().getTime());
    clusterService.updateCluster(cluster);
    clusterService.updateClusterStatusByStackId(stack.getId(), Status.AVAILABLE);
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.AVAILABLE, "Ambari cluster started.");
    flowMessageService.fireEventAndLog(stack.getId(), Msg.AMBARI_CLUSTER_STARTED, Status.AVAILABLE.name(), ambariIp);
    if (cluster.getEmailNeeded()) {
        emailSenderService.sendStartSuccessEmail(cluster.getOwner(), cluster.getEmailTo(), ambariIp, cluster.getName());
        flowMessageService.fireEventAndLog(stack.getId(), Msg.AMBARI_CLUSTER_NOTIFICATION_EMAIL, Status.AVAILABLE.name());
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Date(java.util.Date)

Example 49 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.

the class ClusterStopService method updateClusterUptime.

private void updateClusterUptime(long stackId) {
    Cluster cluster = clusterService.retrieveClusterByStackId(stackId);
    cluster.setUptime(Duration.ofMillis(stackUtil.getUptimeForCluster(cluster, true)).toString());
    clusterService.updateCluster(cluster);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster)

Example 50 with Cluster

use of com.sequenceiq.cloudbreak.domain.Cluster in project cloudbreak by hortonworks.

the class ServiceTestUtils method createCluster.

public static Cluster createCluster(String owner, String account, Blueprint blueprint) {
    Cluster cluster = new Cluster();
    cluster.setName("test-cluster");
    cluster.setDescription("test cluster");
    cluster.setEmailNeeded(false);
    cluster.setAmbariIp("168.192.12.13");
    cluster.setStatus(Status.AVAILABLE);
    cluster.setStatusReason("");
    cluster.setCreationStarted(123456789L);
    cluster.setCreationFinished(223456789L);
    cluster.setOwner(owner);
    cluster.setAccount(account);
    cluster.setBlueprint(blueprint);
    return cluster;
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster)

Aggregations

Cluster (com.sequenceiq.cloudbreak.domain.Cluster)144 Stack (com.sequenceiq.cloudbreak.domain.Stack)68 Test (org.junit.Test)64 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)31 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)26 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)22 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)22 HashMap (java.util.HashMap)22 HashSet (java.util.HashSet)15 List (java.util.List)15 ArrayList (java.util.ArrayList)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 BlueprintPreparationObject (com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject)11 Matchers.anyString (org.mockito.Matchers.anyString)11 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)10 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 Json (com.sequenceiq.cloudbreak.domain.json.Json)9 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)9