Search in sources :

Example 1 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class ClusterCreationService method startingAmbariServices.

public void startingAmbariServices(StackView stack) throws CloudbreakException {
    OrchestratorView orchestrator = stack.getOrchestrator();
    OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
    stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.STARTING_AMBARI_SERVICES, "Running cluster services.");
    if (orchestratorType.containerOrchestrator()) {
        flowMessageService.fireEventAndLog(stack.getId(), Msg.AMBARI_CLUSTER_RUN_CONTAINERS, UPDATE_IN_PROGRESS.name());
    } else if (orchestratorType.hostOrchestrator()) {
        flowMessageService.fireEventAndLog(stack.getId(), Msg.AMBARI_CLUSTER_RUN_SERVICES, UPDATE_IN_PROGRESS.name());
    } else {
        LOGGER.info(String.format("Please implement %s orchestrator because it is not on classpath.", orchestrator.getType()));
        throw new CloudbreakException(String.format("Please implement %s orchestrator because it is not on classpath.", orchestrator.getType()));
    }
}
Also used : OrchestratorView(com.sequenceiq.cloudbreak.domain.view.OrchestratorView) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType)

Example 2 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException 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 3 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class AmbariClusterResetService method resetCluster.

public void resetCluster(Long stackId) throws CloudbreakOrchestratorException {
    Stack stack = stackRepository.findOneWithLists(stackId);
    try {
        InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
        GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, stack.getCluster().getGateway().getEnableGateway());
        OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
        if (orchestratorType.hostOrchestrator()) {
            HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
            Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
            ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId());
            hostOrchestrator.resetAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), exitCriteriaModel);
        } else {
            throw new UnsupportedOperationException("ambari reset cluster works only with host orchestrator");
        }
    } catch (CloudbreakException e) {
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Stack(com.sequenceiq.cloudbreak.domain.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 4 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException 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 5 with CloudbreakException

use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.

the class AmbariClusterUpscaleService method upscaleAmbari.

public void upscaleAmbari(Long stackId, String hostGroupName, Integer scalingAdjustment) throws CloudbreakException {
    Stack stack = stackService.getByIdWithLists(stackId);
    LOGGER.info("Start adding cluster containers");
    Orchestrator orchestrator = stack.getOrchestrator();
    OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
    Map<String, List<String>> hostsPerHostGroup = new HashMap<>();
    if (orchestratorType.containerOrchestrator()) {
        Map<String, List<Container>> containers = containerRunner.addClusterContainers(stackId, hostGroupName, scalingAdjustment);
        for (Entry<String, List<Container>> containersEntry : containers.entrySet()) {
            List<String> hostNames = containersEntry.getValue().stream().map(Container::getHost).collect(Collectors.toList());
            hostsPerHostGroup.put(containersEntry.getKey(), hostNames);
        }
        clusterService.updateHostMetadata(stack.getCluster().getId(), hostsPerHostGroup, HostMetadataState.CONTAINER_RUNNING);
    } else if (orchestratorType.hostOrchestrator()) {
        Map<String, String> hosts = hostRunner.addAmbariServices(stackId, hostGroupName, scalingAdjustment);
        for (String hostName : hosts.keySet()) {
            if (!hostsPerHostGroup.keySet().contains(hostGroupName)) {
                hostsPerHostGroup.put(hostGroupName, new ArrayList<>());
            }
            hostsPerHostGroup.get(hostGroupName).add(hostName);
        }
        clusterService.updateHostMetadata(stack.getCluster().getId(), hostsPerHostGroup, HostMetadataState.SERVICES_RUNNING);
    } else {
        LOGGER.info(String.format("Please implement %s orchestrator because it is not on classpath.", orchestrator.getType()));
        throw new CloudbreakException(String.format("Please implement %s orchestrator because it is not on classpath.", orchestrator.getType()));
    }
    Set<String> allHosts = new HashSet<>();
    for (Entry<String, List<String>> hostsPerHostGroupEntry : hostsPerHostGroup.entrySet()) {
        allHosts.addAll(hostsPerHostGroupEntry.getValue());
    }
    clusterService.updateHostCountWithAdjustment(stack.getCluster().getId(), hostGroupName, allHosts.size());
    instanceMetadataService.updateInstanceStatus(stack.getInstanceGroups(), InstanceStatus.UNREGISTERED, allHosts);
    ambariClusterConnector.waitForHosts(stackService.getByIdWithLists(stackId));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)45 Stack (com.sequenceiq.cloudbreak.domain.Stack)23 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)22 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)14 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)13 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)11 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)11 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)10 HashMap (java.util.HashMap)10 List (java.util.List)10 Map (java.util.Map)10 Set (java.util.Set)9 Inject (javax.inject.Inject)9 AmbariConnectionException (com.sequenceiq.ambari.client.AmbariConnectionException)8 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)8 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8