Search in sources :

Example 11 with CloudbreakOrchestratorException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException in project cloudbreak by hortonworks.

the class StackService method validateOrchestrator.

public void validateOrchestrator(Orchestrator orchestrator) {
    try {
        ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
        containerOrchestrator.validateApiEndpoint(new OrchestrationCredential(orchestrator.getApiEndpoint(), orchestrator.getAttributes().getMap()));
    } catch (CloudbreakException e) {
        throw new BadRequestException(String.format("Invalid orchestrator type: %s", e.getMessage()));
    } catch (CloudbreakOrchestratorException e) {
        throw new BadRequestException(String.format("Error occurred when trying to reach orchestrator API: %s", e.getMessage()));
    }
}
Also used : CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 12 with CloudbreakOrchestratorException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException in project cloudbreak by hortonworks.

the class ClusterBootstrapper method bootstrapNewNodes.

public void bootstrapNewNodes(Long stackId, Set<String> upscaleCandidateAddresses, Collection<String> recoveryHostNames) throws CloudbreakException {
    Stack stack = stackRepository.findOneWithLists(stackId);
    Set<Node> nodes = new HashSet<>();
    Set<Node> allNodes = new HashSet<>();
    boolean recoveredNodes = Integer.valueOf(recoveryHostNames.size()).equals(upscaleCandidateAddresses.size());
    Set<InstanceMetaData> metaDataSet = stack.getRunningInstanceMetaData().stream().filter(im -> im.getPrivateIp() != null && im.getPublicIpWrapper() != null).collect(Collectors.toSet());
    String clusterDomain = metaDataSet.stream().filter(im -> isNoneBlank(im.getDiscoveryFQDN())).findAny().get().getDomain();
    for (InstanceMetaData im : metaDataSet) {
        Node node = createNode(stack.getCustomHostname(), im, clusterDomain, stack.isHostgroupNameAsHostname());
        if (upscaleCandidateAddresses.contains(im.getPrivateIp())) {
            // but only when we would have generated a hostname, otherwise use the cloud provider's default mechanism
            if (recoveredNodes && isNoneBlank(node.getHostname())) {
                Iterator<String> iterator = recoveryHostNames.iterator();
                node.setHostname(iterator.next().split("\\.")[0]);
                iterator.remove();
                LOGGER.info("Set the hostname to {} for address: {}", node.getHostname(), im.getPrivateIp());
            }
            nodes.add(node);
        }
        allNodes.add(node);
    }
    try {
        String stackOrchestratorType = stack.getOrchestrator().getType();
        OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
        if (orchestratorType.hostOrchestrator()) {
            List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
            bootstrapNewNodesOnHost(stack, allGatewayConfigs, nodes, allNodes);
        } else if (orchestratorType.containerOrchestrator()) {
            LOGGER.info("Skipping bootstrap of the new machines because the stack's orchestrator type is '{}'.", stackOrchestratorType);
        } else {
            LOGGER.error("Orchestrator not found: {}", stackOrchestratorType);
            throw new CloudbreakException("HostOrchestrator not found: " + stackOrchestratorType);
        }
    } catch (CloudbreakOrchestratorCancelledException e) {
        throw new CancellationException(e.getMessage());
    } catch (CloudbreakOrchestratorException e) {
        throw new CloudbreakException(e);
    }
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) CloudbreakOrchestratorCancelledException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException) LoggerFactory(org.slf4j.LoggerFactory) HostDiscoveryService(com.sequenceiq.cloudbreak.common.service.HostDiscoveryService) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Base64(org.apache.commons.codec.binary.Base64) TIMEOUT(com.sequenceiq.cloudbreak.service.PollingResult.TIMEOUT) OrchestratorRepository(com.sequenceiq.cloudbreak.repository.OrchestratorRepository) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ContainerOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.container.context.ContainerOrchestratorClusterContext) Collection(java.util.Collection) Set(java.util.Set) EXIT(com.sequenceiq.cloudbreak.service.PollingResult.EXIT) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) HostOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) ContainerClusterAvailabilityCheckerTask(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerClusterAvailabilityCheckerTask) HostOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostOrchestratorResolver) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) ContainerBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.container.context.ContainerBootstrapApiContext) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) StringUtils.isNoneBlank(org.apache.commons.lang3.StringUtils.isNoneBlank) PollingService(com.sequenceiq.cloudbreak.service.PollingService) StackRepository(com.sequenceiq.cloudbreak.repository.StackRepository) ContainerOrchestratorResolver(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerOrchestratorResolver) ContainerBootstrapApiCheckerTask(com.sequenceiq.cloudbreak.core.bootstrap.service.container.ContainerBootstrapApiCheckerTask) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) HostBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) Collections.singletonMap(java.util.Collections.singletonMap) Json(com.sequenceiq.cloudbreak.domain.json.Json) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.service.ClusterComponentConfigProvider) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Stack(com.sequenceiq.cloudbreak.domain.Stack) HostClusterAvailabilityCheckerTask(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostClusterAvailabilityCheckerTask) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostBootstrapApiCheckerTask(com.sequenceiq.cloudbreak.core.bootstrap.service.host.HostBootstrapApiCheckerTask) Component(org.springframework.stereotype.Component) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) 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) HashSet(java.util.HashSet) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 13 with CloudbreakOrchestratorException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException in project cloudbreak by hortonworks.

the class ClusterContainerRunner method initializeClusterContainers.

private Map<String, List<Container>> initializeClusterContainers(Stack stack, String cloudPlatform) 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());
    String gatewayHostname = getGatewayHostName(stack);
    try {
        ContainerConstraint ambariServerDbConstraint = constraintFactory.getAmbariServerDbConstraint(gatewayHostname, cluster.getName(), cluster.getId().toString());
        List<ContainerInfo> dbContainer = containerOrchestrator.runContainer(containerConfigService.get(stack, AMBARI_DB), credential, ambariServerDbConstraint, clusterDeletionBasedModel(stack.getId(), cluster.getId()));
        containers.put(AMBARI_DB.name(), dbContainer);
        String serverDbHostName = dbContainer.get(0).getHost();
        ContainerConstraint ambariServerConstraint = constraintFactory.getAmbariServerConstraint(serverDbHostName, gatewayHostname, cloudPlatform, cluster.getName(), cluster.getId().toString());
        List<ContainerInfo> ambariServerContainer = containerOrchestrator.runContainer(containerConfigService.get(stack, AMBARI_SERVER), credential, ambariServerConstraint, clusterDeletionBasedModel(stack.getId(), cluster.getId()));
        containers.put(AMBARI_SERVER.name(), ambariServerContainer);
        String ambariServerHost = ambariServerContainer.get(0).getHost();
        List<String> hostBlackList = new ArrayList<>();
        for (HostGroup hostGroup : hostGroupRepository.findHostGroupsInCluster(stack.getCluster().getId())) {
            ContainerConstraint ambariAgentConstraint = constraintFactory.getAmbariAgentConstraint(ambariServerHost, null, cloudPlatform, hostGroup, null, hostBlackList, cluster.getId().toString());
            List<ContainerInfo> containerInfos = containerOrchestrator.runContainer(containerConfigService.get(stack, AMBARI_AGENT), credential, ambariAgentConstraint, clusterDeletionBasedModel(stack.getId(), cluster.getId()));
            containers.put(hostGroup.getName(), containerInfos);
            hostBlackList.addAll(getHostsFromContainerInfo(containerInfos));
        }
        return saveContainers(containers, cluster);
    } catch (CloudbreakOrchestratorException ex) {
        if (!containers.isEmpty()) {
            saveContainers(containers, cluster);
        }
        checkCancellation(ex);
        throw ex;
    }
}
Also used : ContainerConstraint(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with CloudbreakOrchestratorException

use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException 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 15 with CloudbreakOrchestratorException

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

Aggregations

CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)19 IOException (java.io.IOException)11 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)10 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)10 Node (com.sequenceiq.cloudbreak.orchestrator.model.Node)9 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)9 ArrayList (java.util.ArrayList)9 List (java.util.List)9 ExecutionException (java.util.concurrent.ExecutionException)9 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 Component (org.springframework.stereotype.Component)8 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)7 OrchestratorBootstrap (com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap)7 SaltConnector (com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector)7 Collection (java.util.Collection)7 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)6 Stack (com.sequenceiq.cloudbreak.domain.Stack)6 CloudbreakOrchestratorCancelledException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorCancelledException)6