use of com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator 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.container.ContainerOrchestrator 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.container.ContainerOrchestrator in project cloudbreak by hortonworks.
the class ContainerConfigService method create.
private Component create(Stack stack, DockerContainer dc) throws CloudbreakException {
try {
ContainerConfig config;
ContainerOrchestrator orchestrator = containerOrchestratorResolver.get(stack.getOrchestrator().getType());
Map<String, String> customContainerConfig = getCustomContainerConfig(stack);
Optional<String> customContainerName = Optional.ofNullable(customContainerConfig.get(dc.name()));
Optional<String> customQueue = getCustomQueue(stack);
switch(dc) {
case AMBARI_SERVER:
config = new Builder(orchestrator.ambariServerContainer(customContainerName), customQueue).build();
break;
case AMBARI_AGENT:
config = new Builder(orchestrator.ambariClientContainer(customContainerName), customQueue).build();
break;
case AMBARI_DB:
config = new Builder(orchestrator.ambariDbContainer(customContainerName), customQueue).build();
break;
default:
throw new CloudbreakServiceException(String.format("No configuration exist for %s", dc));
}
Component component = new Component(ComponentType.CONTAINER, dc.name(), new Json(config), stack);
return componentConfigProvider.store(component);
} catch (IOException ignored) {
throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
}
}
use of com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator in project cloudbreak by hortonworks.
the class StackService method validateOrchestrator.
public void validateOrchestrator(Orchestrator orchestrator) {
try {
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
containerOrchestrator.validateApiEndpoint(new OrchestrationCredential(orchestrator.getApiEndpoint(), orchestrator.getAttributes().getMap()));
} catch (CloudbreakException e) {
throw new BadRequestException(String.format("Invalid orchestrator type: %s", e.getMessage()));
} catch (CloudbreakOrchestratorException e) {
throw new BadRequestException(String.format("Error occurred when trying to reach orchestrator API: %s", e.getMessage()));
}
}
use of com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator in project cloudbreak by hortonworks.
the class AppConfig method containerOrchestrators.
@Bean
public Map<String, ContainerOrchestrator> containerOrchestrators() {
Map<String, ContainerOrchestrator> map = new HashMap<>();
for (ContainerOrchestrator containerOrchestrator : containerOrchestrators) {
containerOrchestrator.init(simpleParallelContainerRunnerExecutor(), clusterDeletionBasedExitCriteria());
map.put(containerOrchestrator.name(), containerOrchestrator);
}
return map;
}
Aggregations