use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo in project cloudbreak by hortonworks.
the class AmbariDecommissioner method removeHostsFromOrchestrator.
private PollingResult removeHostsFromOrchestrator(Stack stack, AmbariClient ambariClient, List<String> hostNames) throws CloudbreakException {
Orchestrator orchestrator = stack.getOrchestrator();
Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
try {
if (orchestratorType.containerOrchestrator()) {
OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
Set<Container> containers = containerRepository.findContainersInCluster(stack.getCluster().getId());
List<ContainerInfo> containersToDelete = containers.stream().filter(input -> hostNames.contains(input.getHost()) && input.getImage().contains(AMBARI_AGENT.getName())).map(input -> new ContainerInfo(input.getContainerId(), input.getName(), input.getHost(), input.getImage())).collect(Collectors.toList());
containerOrchestrator.deleteContainer(containersToDelete, credential);
containerRepository.delete(containers);
return waitForHostsToLeave(stack, ambariClient, hostNames);
} else if (orchestratorType.hostOrchestrator()) {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
Map<String, String> privateIpsByFQDN = new HashMap<>();
stack.getInstanceMetaDataAsList().stream().filter(instanceMetaData -> hostNames.stream().anyMatch(hn -> hn.contains(instanceMetaData.getDiscoveryFQDN().split("\\.")[0]))).forEach(instanceMetaData -> privateIpsByFQDN.put(instanceMetaData.getDiscoveryFQDN(), instanceMetaData.getPrivateIp()));
List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
hostOrchestrator.tearDown(allGatewayConfigs, privateIpsByFQDN);
}
} catch (CloudbreakOrchestratorException e) {
LOGGER.error("Failed to delete orchestrator components while decommissioning: ", e);
throw new CloudbreakException("Failed to delete orchestrator components while decommissioning: ", e);
}
return SUCCESS;
}
use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo in project cloudbreak by hortonworks.
the class ClusterTerminationService method deleteClusterContainers.
public Boolean deleteClusterContainers(Cluster cluster) {
try {
Orchestrator orchestrator = cluster.getStack().getOrchestrator();
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
try {
Map<String, Object> map = new HashMap<>(orchestrator.getAttributes().getMap());
OrchestrationCredential credential = new OrchestrationCredential(orchestrator.getApiEndpoint(), map);
Set<Container> containers = containerRepository.findContainersInCluster(cluster.getId());
List<ContainerInfo> containerInfo = containers.stream().map(c -> new ContainerInfo(c.getContainerId(), c.getName(), c.getHost(), c.getImage())).collect(Collectors.toList());
containerOrchestrator.deleteContainer(containerInfo, credential);
containerRepository.delete(containers);
deleteClusterHostGroupsWithItsMetadata(cluster);
} catch (CloudbreakOrchestratorException e) {
throw new TerminationFailedException(String.format("Failed to delete containers of cluster (id:'%s',name:'%s').", cluster.getId(), cluster.getName()), e);
}
return Boolean.TRUE;
} catch (CloudbreakException ignored) {
return Boolean.FALSE;
}
}
use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo in project cloudbreak by hortonworks.
the class YarnContainerOrchestrator method runContainer.
@Override
public List<ContainerInfo> runContainer(ContainerConfig config, OrchestrationCredential cred, ContainerConstraint constraint, ExitCriteriaModel exitCriteriaModel) throws CloudbreakOrchestratorException {
// Create an application per component
List<ContainerInfo> containerInfos = new ArrayList<>();
for (int componentNumber = 1; componentNumber <= constraint.getInstances(); componentNumber++) {
try {
submitHandler.submitApplication(config, cred, constraint, componentNumber);
String applicationName = applicationUtils.getApplicationName(constraint, componentNumber);
OrchestratorBootstrap bootstrap = new YarnAppBootstrap(applicationName, cred.getApiEndpoint());
Callable<Boolean> runner = runner(bootstrap, getExitCriteria(), exitCriteriaModel);
Future<Boolean> appFuture = getParallelOrchestratorComponentRunner().submit(runner);
appFuture.get();
containerInfos.add(detailHandler.getContainerInfo(config, cred, constraint, componentNumber));
} catch (CloudbreakOrchestratorException | InterruptedException | ExecutionException e) {
throw new CloudbreakOrchestratorFailedException(e);
}
}
return containerInfos;
}
use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo in project cloudbreak by hortonworks.
the class YarnContainerOrchestrator method deleteContainer.
@Override
public void deleteContainer(List<ContainerInfo> containerInfo, OrchestrationCredential cred) throws CloudbreakOrchestratorException {
for (ContainerInfo container : containerInfo) {
DeleteApplicationRequest deleteApplicationRequest = new DeleteApplicationRequest();
deleteApplicationRequest.setName(container.getName());
YarnClient yarnHttpClient = new YarnHttpClient(cred.getApiEndpoint());
try {
yarnHttpClient.deleteApplication(deleteApplicationRequest);
} catch (Exception e) {
throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
}
}
}
use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerInfo 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;
}
}
Aggregations