use of com.sequenceiq.cloudbreak.common.model.OrchestratorType in project cloudbreak by hortonworks.
the class ClusterCreationService method startingAmbariServices.
public void startingAmbariServices(StackView stack) throws CloudbreakException {
OrchestratorView orchestrator = stack.getOrchestrator();
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.STARTING_AMBARI_SERVICES, "Running cluster services.");
if (orchestratorType.containerOrchestrator()) {
flowMessageService.fireEventAndLog(stack.getId(), Msg.AMBARI_CLUSTER_RUN_CONTAINERS, UPDATE_IN_PROGRESS.name());
} else if (orchestratorType.hostOrchestrator()) {
flowMessageService.fireEventAndLog(stack.getId(), Msg.AMBARI_CLUSTER_RUN_SERVICES, UPDATE_IN_PROGRESS.name());
} 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.common.model.OrchestratorType in project cloudbreak by hortonworks.
the class AmbariClusterResetService method resetCluster.
public void resetCluster(Long stackId) throws CloudbreakOrchestratorException {
Stack stack = stackRepository.findOneWithLists(stackId);
try {
InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, stack.getCluster().getGateway().getEnableGateway());
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
if (orchestratorType.hostOrchestrator()) {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId());
hostOrchestrator.resetAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), exitCriteriaModel);
} else {
throw new UnsupportedOperationException("ambari reset cluster works only with host orchestrator");
}
} catch (CloudbreakException e) {
throw new CloudbreakOrchestratorFailedException(e);
}
}
use of com.sequenceiq.cloudbreak.common.model.OrchestratorType in project cloudbreak by hortonworks.
the class AmbariClusterUpgradeService method upgradeCluster.
public void upgradeCluster(Long stackId) throws CloudbreakOrchestratorException {
Stack stack = stackRepository.findOneWithLists(stackId);
Cluster cluster = stack.getCluster();
try {
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
if (orchestratorType.hostOrchestrator()) {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, cluster.getGateway().getEnableGateway());
Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
AmbariRepo ambariRepo = componentConfigProvider.getAmbariRepo(cluster.getId());
Map<String, SaltPillarProperties> servicePillar = new HashMap<>();
Map<String, Object> credentials = new HashMap<>();
credentials.put("username", ambariSecurityConfigProvider.getAmbariUserName(cluster));
credentials.put("password", ambariSecurityConfigProvider.getAmbariPassword(cluster));
servicePillar.put("ambari-credentials", new SaltPillarProperties("/ambari/credentials.sls", singletonMap("ambari", credentials)));
if (ambariRepo != null) {
servicePillar.put("ambari-repo", new SaltPillarProperties("/ambari/repo.sls", singletonMap("ambari", singletonMap("repo", ambariRepo))));
}
SaltConfig pillar = new SaltConfig(servicePillar);
hostOrchestrator.upgradeAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), pillar, exitCriteriaModel);
} else {
throw new UnsupportedOperationException("Ambari upgrade works only with host orchestrator");
}
} catch (CloudbreakException e) {
throw new CloudbreakOrchestratorFailedException(e);
}
}
use of com.sequenceiq.cloudbreak.common.model.OrchestratorType in project cloudbreak by hortonworks.
the class AmbariClusterUpscaleService method upscaleAmbari.
public void upscaleAmbari(Long stackId, String hostGroupName, Integer scalingAdjustment) throws CloudbreakException {
Stack stack = stackService.getByIdWithLists(stackId);
LOGGER.info("Start adding cluster containers");
Orchestrator orchestrator = stack.getOrchestrator();
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(orchestrator.getType());
Map<String, List<String>> hostsPerHostGroup = new HashMap<>();
if (orchestratorType.containerOrchestrator()) {
Map<String, List<Container>> containers = containerRunner.addClusterContainers(stackId, hostGroupName, scalingAdjustment);
for (Entry<String, List<Container>> containersEntry : containers.entrySet()) {
List<String> hostNames = containersEntry.getValue().stream().map(Container::getHost).collect(Collectors.toList());
hostsPerHostGroup.put(containersEntry.getKey(), hostNames);
}
clusterService.updateHostMetadata(stack.getCluster().getId(), hostsPerHostGroup, HostMetadataState.CONTAINER_RUNNING);
} else if (orchestratorType.hostOrchestrator()) {
Map<String, String> hosts = hostRunner.addAmbariServices(stackId, hostGroupName, scalingAdjustment);
for (String hostName : hosts.keySet()) {
if (!hostsPerHostGroup.keySet().contains(hostGroupName)) {
hostsPerHostGroup.put(hostGroupName, new ArrayList<>());
}
hostsPerHostGroup.get(hostGroupName).add(hostName);
}
clusterService.updateHostMetadata(stack.getCluster().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()));
}
Set<String> allHosts = new HashSet<>();
for (Entry<String, List<String>> hostsPerHostGroupEntry : hostsPerHostGroup.entrySet()) {
allHosts.addAll(hostsPerHostGroupEntry.getValue());
}
clusterService.updateHostCountWithAdjustment(stack.getCluster().getId(), hostGroupName, allHosts.size());
instanceMetadataService.updateInstanceStatus(stack.getInstanceGroups(), InstanceStatus.UNREGISTERED, allHosts);
ambariClusterConnector.waitForHosts(stackService.getByIdWithLists(stackId));
}
use of com.sequenceiq.cloudbreak.common.model.OrchestratorType 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;
}
Aggregations