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()));
}
}
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;
}
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;
}
}
Aggregations