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 ClusterBootstrapper method bootstrapNewNodes.
public void bootstrapNewNodes(Long stackId, Set<String> upscaleCandidateAddresses, Collection<String> recoveryHostNames) throws CloudbreakException {
Stack stack = stackRepository.findOneWithLists(stackId);
Set<Node> nodes = new HashSet<>();
Set<Node> allNodes = new HashSet<>();
boolean recoveredNodes = Integer.valueOf(recoveryHostNames.size()).equals(upscaleCandidateAddresses.size());
Set<InstanceMetaData> metaDataSet = stack.getRunningInstanceMetaData().stream().filter(im -> im.getPrivateIp() != null && im.getPublicIpWrapper() != null).collect(Collectors.toSet());
String clusterDomain = metaDataSet.stream().filter(im -> isNoneBlank(im.getDiscoveryFQDN())).findAny().get().getDomain();
for (InstanceMetaData im : metaDataSet) {
Node node = createNode(stack.getCustomHostname(), im, clusterDomain, stack.isHostgroupNameAsHostname());
if (upscaleCandidateAddresses.contains(im.getPrivateIp())) {
// but only when we would have generated a hostname, otherwise use the cloud provider's default mechanism
if (recoveredNodes && isNoneBlank(node.getHostname())) {
Iterator<String> iterator = recoveryHostNames.iterator();
node.setHostname(iterator.next().split("\\.")[0]);
iterator.remove();
LOGGER.info("Set the hostname to {} for address: {}", node.getHostname(), im.getPrivateIp());
}
nodes.add(node);
}
allNodes.add(node);
}
try {
String stackOrchestratorType = stack.getOrchestrator().getType();
OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
if (orchestratorType.hostOrchestrator()) {
List<GatewayConfig> allGatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
bootstrapNewNodesOnHost(stack, allGatewayConfigs, nodes, allNodes);
} else if (orchestratorType.containerOrchestrator()) {
LOGGER.info("Skipping bootstrap of the new machines because the stack's orchestrator type is '{}'.", stackOrchestratorType);
} else {
LOGGER.error("Orchestrator not found: {}", stackOrchestratorType);
throw new CloudbreakException("HostOrchestrator not found: " + stackOrchestratorType);
}
} catch (CloudbreakOrchestratorCancelledException e) {
throw new CancellationException(e.getMessage());
} catch (CloudbreakOrchestratorException e) {
throw new CloudbreakException(e);
}
}
use of com.sequenceiq.cloudbreak.common.model.OrchestratorType 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.common.model.OrchestratorType in project cloudbreak by hortonworks.
the class ClusterTerminationService method deleteClusterComponents.
public Boolean deleteClusterComponents(Long clusterId) {
Cluster cluster = clusterRepository.findById(clusterId);
if (cluster == null) {
LOGGER.warn("Failed to delete containers of cluster (id:'{}'), because the cluster could not be found in the database.", clusterId);
return Boolean.TRUE;
}
OrchestratorType orchestratorType;
try {
orchestratorType = orchestratorTypeResolver.resolveType(cluster.getStack().getOrchestrator().getType());
} catch (CloudbreakException e) {
throw new TerminationFailedException(String.format("Failed to delete containers of cluster (id:'%s',name:'%s').", cluster.getId(), cluster.getName()), e);
}
if (orchestratorType.hostOrchestrator()) {
return Boolean.TRUE;
}
return deleteClusterContainers(cluster);
}
Aggregations