Search in sources :

Example 6 with ContainerInfo

use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo 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 7 with ContainerInfo

use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo 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 8 with ContainerInfo

use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo in project cloudbreak by hortonworks.

the class ApplicationDetailHandler method getContainerInfo.

public ContainerInfo getContainerInfo(ContainerConfig config, OrchestrationCredential cred, ContainerConstraint constraint, int componentNumber) throws CloudbreakOrchestratorFailedException {
    String applicationName = applicationUtils.getApplicationName(constraint, componentNumber);
    // Build the ApplicationDetailRequest
    ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
    applicationDetailRequest.setName(applicationName);
    try {
        // Validate that the app exists
        YarnClient yarnHttpClient = new YarnHttpClient(cred.getApiEndpoint());
        ResponseContext appDetailResponseContext = yarnHttpClient.getApplicationDetail(applicationDetailRequest);
        if (appDetailResponseContext.getResponseError() != null) {
            ApplicationErrorResponse applicationErrorResponse = appDetailResponseContext.getResponseError();
            throw new CloudbreakOrchestratorFailedException(String.format("ERROR: HTTP Return: %d Error: %s.", appDetailResponseContext.getStatusCode(), applicationErrorResponse.getDiagnostics()));
        }
        // Return the details
        String componentHostName = applicationUtils.getComponentHostName(constraint, cred, componentNumber);
        String image = String.format("%s:%s", config.getName(), config.getVersion());
        return new ContainerInfo(applicationName, applicationName, componentHostName, image);
    } catch (MalformedURLException e) {
        String msg = String.format("ERROR: URL is malformed: %s", cred.getApiEndpoint());
        throw new CloudbreakOrchestratorFailedException(msg, e);
    }
}
Also used : YarnHttpClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnHttpClient) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) MalformedURLException(java.net.MalformedURLException) ApplicationDetailRequest(com.sequenceiq.cloudbreak.orchestrator.yarn.model.request.ApplicationDetailRequest) ResponseContext(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ResponseContext) ContainerInfo(com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo) ApplicationErrorResponse(com.sequenceiq.cloudbreak.orchestrator.yarn.model.response.ApplicationErrorResponse) YarnClient(com.sequenceiq.cloudbreak.orchestrator.yarn.client.YarnClient)

Aggregations

ContainerInfo (com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo)8 CloudbreakOrchestratorException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException)6 ArrayList (java.util.ArrayList)5 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)4 Container (com.sequenceiq.cloudbreak.domain.Container)4 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)4 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)4 ContainerOrchestrator (com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator)4 OrchestrationCredential (com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential)4 HashMap (java.util.HashMap)4 List (java.util.List)4 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)3 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 OrchestratorType (com.sequenceiq.cloudbreak.common.model.OrchestratorType)2 OrchestratorTypeResolver (com.sequenceiq.cloudbreak.core.bootstrap.service.OrchestratorTypeResolver)2