Search in sources :

Example 66 with HostGroup

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

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

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

the class ContainerConstraintFactory method collectUpscaleCandidates.

private List<String> collectUpscaleCandidates(Long clusterId, String hostGroupName, Integer adjustment) {
    HostGroup hostGroup = hostGroupRepository.findHostGroupInClusterByName(clusterId, hostGroupName);
    if (hostGroup.getConstraint().getInstanceGroup() != null) {
        Long instanceGroupId = hostGroup.getConstraint().getInstanceGroup().getId();
        Set<InstanceMetaData> unusedHostsInInstanceGroup = instanceMetaDataRepository.findUnusedHostsInInstanceGroup(instanceGroupId);
        List<String> hostNames = new ArrayList<>();
        for (InstanceMetaData instanceMetaData : unusedHostsInInstanceGroup) {
            hostNames.add(instanceMetaData.getDiscoveryFQDN());
            if (hostNames.size() >= adjustment) {
                break;
            }
        }
        return hostNames;
    }
    return null;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) ArrayList(java.util.ArrayList) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup)

Example 69 with HostGroup

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

the class ClusterHostServiceRunner method collectUpscaleCandidates.

private Map<String, String> collectUpscaleCandidates(Long clusterId, String hostGroupName, Integer adjustment) {
    HostGroup hostGroup = hostGroupRepository.findHostGroupInClusterByName(clusterId, hostGroupName);
    if (hostGroup.getConstraint().getInstanceGroup() != null) {
        Long instanceGroupId = hostGroup.getConstraint().getInstanceGroup().getId();
        Map<String, String> hostNames = new HashMap<>();
        instanceMetaDataRepository.findUnusedHostsInInstanceGroup(instanceGroupId).stream().sorted(Comparator.comparing(InstanceMetaData::getStartDate)).limit(adjustment.longValue()).forEach(im -> hostNames.put(im.getDiscoveryFQDN(), im.getPrivateIp()));
        return hostNames;
    }
    return Collections.emptyMap();
}
Also used : HashMap(java.util.HashMap) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup)

Example 70 with HostGroup

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

the class UpdateStackRequestV2ToUpdateClusterRequestConverter method convert.

@Override
public UpdateClusterJson convert(StackScaleRequestV2 source) {
    UpdateClusterJson updateStackJson = new UpdateClusterJson();
    Cluster oneByStackId = clusterRepository.findOneByStackId(source.getStackId());
    HostGroup hostGroup = hostGroupRepository.findHostGroupInClusterByName(oneByStackId.getId(), source.getGroup());
    if (hostGroup != null) {
        HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
        hostGroupAdjustmentJson.setWithStackUpdate(true);
        hostGroupAdjustmentJson.setValidateNodeCount(true);
        hostGroupAdjustmentJson.setHostGroup(source.getGroup());
        int scaleNumber = source.getDesiredCount() - hostGroup.getHostMetadata().size();
        hostGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
        updateStackJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
    } else {
        throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
    }
    return updateStackJson;
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) UpdateClusterJson(com.sequenceiq.cloudbreak.api.model.UpdateClusterJson)

Aggregations

HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)94 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)33 Test (org.junit.Test)33 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)31 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)29 HashSet (java.util.HashSet)22 JsonNode (com.fasterxml.jackson.databind.JsonNode)20 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)20 List (java.util.List)20 HashMap (java.util.HashMap)19 Stack (com.sequenceiq.cloudbreak.domain.Stack)18 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)16 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)15 Map (java.util.Map)14 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)13 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)11 ArrayList (java.util.ArrayList)11 Set (java.util.Set)11 Inject (javax.inject.Inject)11