use of com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator in project cloudbreak by hortonworks.
the class ContainerOrchestratorResolverTest method getOrchestratorWhenExist.
@Test
public void getOrchestratorWhenExist() throws CloudbreakException {
Map<String, ContainerOrchestrator> map = new HashMap<>();
TestOneMockContainerOrchestrator testOneMockContainerOrchestrator = new TestOneMockContainerOrchestrator();
map.put(testOneMockContainerOrchestrator.name(), testOneMockContainerOrchestrator);
TestTwoMockContainerOrchestrator testTwoMockContainerOrchestrator = new TestTwoMockContainerOrchestrator();
map.put(testTwoMockContainerOrchestrator.name(), testTwoMockContainerOrchestrator);
ReflectionTestUtils.setField(underTest, "containerOrchestrators", map);
ContainerOrchestrator containerOrchestrator = underTest.get("YARN");
assertNotNull(containerOrchestrator);
}
use of com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator 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;
}
}
use of com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator 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