Search in sources :

Example 6 with Container

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

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

the class ClusterContainerRunner method convert.

private List<Container> convert(Iterable<ContainerInfo> containerInfo, Cluster cluster) {
    List<Container> containers = new ArrayList<>();
    for (ContainerInfo source : containerInfo) {
        Container container = conversionService.convert(source, Container.class);
        container.setCluster(cluster);
        containers.add(container);
    }
    return containers;
}
Also used : Container(com.sequenceiq.cloudbreak.domain.Container) ArrayList(java.util.ArrayList) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo)

Example 8 with Container

use of com.sequenceiq.cloudbreak.domain.Container 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)

Aggregations

Container (com.sequenceiq.cloudbreak.domain.Container)8 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)6 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)4 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)4 Stack (com.sequenceiq.cloudbreak.domain.Stack)4 ContainerInfo (com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)3 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)3 ContainerOrchestrator (com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator)3 DockerContainer (com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer)3 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)3 OrchestrationCredential (com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Set (java.util.Set)3