use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException 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.exception.CloudbreakOrchestratorException 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.orchestrator.exception.CloudbreakOrchestratorException 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.exception.CloudbreakOrchestratorException 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;
}
}
use of com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException in project cloudbreak by hortonworks.
the class ClusterHostServiceRunner method addAmbariServices.
@Transactional
public Map<String, String> addAmbariServices(Long stackId, String hostGroupName, Integer scalingAdjustment) throws CloudbreakException {
Map<String, String> candidates;
try {
Stack stack = stackRepository.findOneWithLists(stackId);
Cluster cluster = stack.getCluster();
candidates = collectUpscaleCandidates(cluster.getId(), hostGroupName, scalingAdjustment);
Set<Node> allNodes = collectNodes(stack);
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
SaltConfig saltConfig = createSaltConfig(stack, cluster, gatewayConfigService.getPrimaryGatewayConfig(stack), gatewayConfigs);
hostOrchestrator.runService(gatewayConfigs, allNodes, saltConfig, clusterDeletionBasedModel(stack.getId(), cluster.getId()));
} catch (CloudbreakOrchestratorCancelledException e) {
throw new CancellationException(e.getMessage());
} catch (CloudbreakOrchestratorException | IOException e) {
throw new CloudbreakException(e);
}
return candidates;
}
Aggregations