Search in sources :

Example 31 with CloudbreakException

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

the class ClusterServiceRunner method runAmbariServices.

public void runAmbariServices(Long stackId) throws CloudbreakException {
    Stack stack = stackService.getByIdWithLists(stackId);
    Cluster cluster = stack.getCluster();
    Orchestrator orchestrator = stack.getOrchestrator();
    MDCBuilder.buildMdcContext(cluster);
    OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
    if (orchestratorType.containerOrchestrator()) {
        Map<String, List<Container>> containers = containerRunner.runClusterContainers(stack);
        Container ambariServerContainer = containers.get(DockerContainer.AMBARI_SERVER.name()).stream().findFirst().get();
        String ambariServerIp = ambariServerContainer.getHost();
        HttpClientConfig ambariClientConfig = buildAmbariClientConfig(stack, ambariServerIp);
        clusterService.updateAmbariClientConfig(cluster.getId(), ambariClientConfig);
        Map<String, List<String>> hostsPerHostGroup = new HashMap<>();
        for (Entry<String, List<Container>> containersEntry : containers.entrySet()) {
            List<String> hostNames = new ArrayList<>();
            for (Container container : containersEntry.getValue()) {
                hostNames.add(container.getHost());
            }
            hostsPerHostGroup.put(containersEntry.getKey(), hostNames);
        }
        clusterService.updateHostMetadata(cluster.getId(), hostsPerHostGroup, HostMetadataState.CONTAINER_RUNNING);
    } else if (orchestratorType.hostOrchestrator()) {
        hostRunner.runAmbariServices(stack, cluster);
        String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(stack);
        HttpClientConfig ambariClientConfig = buildAmbariClientConfig(stack, gatewayIp);
        clusterService.updateAmbariClientConfig(cluster.getId(), ambariClientConfig);
        Map<String, List<String>> hostsPerHostGroup = new HashMap<>();
        for (InstanceMetaData instanceMetaData : stack.getRunningInstanceMetaData()) {
            String groupName = instanceMetaData.getInstanceGroup().getGroupName();
            if (!hostsPerHostGroup.keySet().contains(groupName)) {
                hostsPerHostGroup.put(groupName, new ArrayList<>());
            }
            hostsPerHostGroup.get(groupName).add(instanceMetaData.getDiscoveryFQDN());
        }
        clusterService.updateHostMetadata(cluster.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()));
    }
}
Also used : HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) DockerContainer(com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer) Container(com.sequenceiq.cloudbreak.domain.Container) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) EnumMap(java.util.EnumMap)

Example 32 with CloudbreakException

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

the class ClusterServiceRunner method changePrimaryGateway.

public String changePrimaryGateway(Long stackId) throws CloudbreakException {
    Stack stack = stackService.getByIdWithLists(stackId);
    Orchestrator orchestrator = stack.getOrchestrator();
    if (orchestratorTypeResolver.resolveType(orchestrator.getType()).hostOrchestrator()) {
        return hostRunner.changePrimaryGateway(stack);
    }
    throw new CloudbreakException(String.format("Change primary gateway is not supported on orchestrator %s", orchestrator.getType()));
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 33 with CloudbreakException

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

the class ClusterContainerRunner method addClusterContainers.

private Map<String, List<Container>> addClusterContainers(Stack stack, String cloudPlatform, String hostGroupName, Integer adjustment) throws CloudbreakException, CloudbreakOrchestratorException {
    Orchestrator orchestrator = stack.getOrchestrator();
    Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
    OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
    ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
    Map<String, List<ContainerInfo>> containers = new HashMap<>();
    Cluster cluster = clusterService.retrieveClusterByStackId(stack.getId());
    try {
        Set<Container> existingContainers = containerService.findContainersInCluster(cluster.getId());
        String ambariServerHost = existingContainers.stream().filter(input -> input.getImage().contains(AMBARI_SERVER.getName())).findFirst().get().getHost();
        HostGroup hostGroup = hostGroupRepository.findHostGroupInClusterByName(cluster.getId(), hostGroupName);
        String ambariAgentApp = existingContainers.stream().filter(input -> hostGroup.getHostNames().contains(input.getHost()) && input.getImage().contains(AMBARI_AGENT.getName())).findFirst().get().getName();
        List<String> hostBlackList = getOtherHostgroupsAgentHostsFromContainer(existingContainers, hostGroupName);
        ContainerConstraint ambariAgentConstraint = constraintFactory.getAmbariAgentConstraint(ambariServerHost, ambariAgentApp, cloudPlatform, hostGroup, adjustment, hostBlackList, cluster.getId().toString());
        containers.put(hostGroup.getName(), containerOrchestrator.runContainer(containerConfigService.get(stack, AMBARI_AGENT), credential, ambariAgentConstraint, clusterDeletionBasedModel(stack.getId(), cluster.getId())));
        return saveContainers(containers, cluster);
    } catch (CloudbreakOrchestratorException ex) {
        if (!containers.isEmpty()) {
            saveContainers(containers, cluster);
        }
        checkCancellation(ex);
        throw ex;
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ContainerConfigService(com.sequenceiq.cloudbreak.core.bootstrap.service.ContainerConfigService) StackRepository(com.sequenceiq.cloudbreak.repository.StackRepository) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) HashMap(java.util.HashMap) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) HostGroupRepository(com.sequenceiq.cloudbreak.repository.HostGroupRepository) StringUtils(org.apache.commons.lang3.StringUtils) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AMBARI_SERVER(com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer.AMBARI_SERVER) ContainerService(com.sequenceiq.cloudbreak.service.cluster.ContainerService) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) Map(java.util.Map) ContainerConstraint(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint) Stack(com.sequenceiq.cloudbreak.domain.Stack) ConversionService(org.springframework.core.convert.ConversionService) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) AMBARI_AGENT(com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer.AMBARI_AGENT) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) AMBARI_DB(com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer.AMBARI_DB) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Collection(java.util.Collection) Set(java.util.Set) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) Container(com.sequenceiq.cloudbreak.domain.Container) List(java.util.List) Component(org.springframework.stereotype.Component) Entry(java.util.Map.Entry) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) ContainerConstraint(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint) HashMap(java.util.HashMap) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) Container(com.sequenceiq.cloudbreak.domain.Container) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 34 with CloudbreakException

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

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

the class StackRequestToStackConverter method getRegion.

private String getRegion(StackRequest source) {
    boolean containerOrchestrator;
    try {
        containerOrchestrator = orchestratorTypeResolver.resolveType(source.getOrchestrator().getType()).containerOrchestrator();
    } catch (CloudbreakException ignored) {
        throw new BadRequestException("Orchestrator not supported.");
    }
    if (OrchestratorConstants.YARN.equals(source.getOrchestrator().getType())) {
        return OrchestratorConstants.YARN;
    }
    if (isEmpty(source.getRegion()) && !containerOrchestrator) {
        Map<Platform, Region> regions = Maps.newHashMap();
        if (isNoneEmpty(defaultRegions)) {
            for (String entry : defaultRegions.split(",")) {
                String[] keyValue = entry.split(":");
                regions.put(platform(keyValue[0]), Region.region(keyValue[1]));
            }
            Region platformRegion = regions.get(platform(source.getCloudPlatform()));
            if (platformRegion == null || isEmpty(platformRegion.value())) {
                throw new BadRequestException(String.format("No default region specified for: %s. Region cannot be empty.", source.getCloudPlatform()));
            }
            return platformRegion.value();
        } else {
            throw new BadRequestException("No default region is specified. Region cannot be empty.");
        }
    }
    return source.getRegion();
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Region(com.sequenceiq.cloudbreak.cloud.model.Region)

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