use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class StackRequestToStackConverter method convertInstanceGroups.
private Set<InstanceGroup> convertInstanceGroups(StackRequest source, Stack stack) {
List<InstanceGroupRequest> instanceGroupRequests = source.getInstanceGroups();
Set<InstanceGroup> convertedSet = new HashSet<>();
for (InstanceGroupRequest instanceGroupRequest : instanceGroupRequests) {
InstanceGroup instanceGroup = getConversionService().convert(instanceGroupRequest, InstanceGroup.class);
if (instanceGroup != null) {
convertedSet.add(getConversionService().convert(instanceGroupRequest, InstanceGroup.class));
}
}
boolean gatewaySpecified = false;
for (InstanceGroup instanceGroup : convertedSet) {
instanceGroup.setStack(stack);
if (!gatewaySpecified) {
if (InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType())) {
gatewaySpecified = true;
}
}
}
boolean containerOrchestrator;
try {
containerOrchestrator = orchestratorTypeResolver.resolveType(source.getOrchestrator().getType()).containerOrchestrator();
} catch (CloudbreakException ignored) {
throw new BadRequestException("Orchestrator not supported.");
}
if (!gatewaySpecified && !containerOrchestrator) {
throw new BadRequestException("Ambari server must be specified");
}
return convertedSet;
}
use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class AmbariClusterService method recreate.
@Override
public Cluster recreate(Long stackId, Long blueprintId, Set<HostGroup> hostGroups, boolean validateBlueprint, StackRepoDetails stackRepoDetails, String kerberosPassword, String kerberosPrincipal) {
if (blueprintId == null || hostGroups == null) {
throw new BadRequestException("Blueprint id and hostGroup assignments can not be null.");
}
Stack stack = stackService.getByIdWithLists(stackId);
Cluster cluster = getCluster(stack);
if (cluster != null && stack.getCluster().isSecure()) {
List<String> missing = Stream.of(Pair.of("password", kerberosPassword), Pair.of("principal", kerberosPrincipal)).filter(p -> !StringUtils.hasLength(p.getRight())).map(Pair::getLeft).collect(Collectors.toList());
if (!missing.isEmpty()) {
throw new BadRequestException(String.format("Missing Kerberos credential detail(s): %s", String.join(", ", missing)));
}
KerberosConfig kerberosConfig = cluster.getKerberosConfig();
kerberosConfig.setPassword(kerberosPassword);
kerberosConfig.setPrincipal(kerberosPrincipal);
kerberosConfigRepository.save(kerberosConfig);
}
Blueprint blueprint = blueprintService.get(blueprintId);
if (!withEmbeddedAmbariDB(cluster)) {
throw new BadRequestException("Ambari doesn't support resetting external DB automatically. To reset Ambari Server schema you must first drop " + "and then create it using DDL scripts from /var/lib/ambari-server/resources");
}
if (validateBlueprint) {
blueprintValidator.validateBlueprintForStack(cluster, blueprint, hostGroups, stack.getInstanceGroups());
}
Boolean containerOrchestrator;
try {
containerOrchestrator = orchestratorTypeResolver.resolveType(stack.getOrchestrator()).containerOrchestrator();
} catch (CloudbreakException ignored) {
containerOrchestrator = false;
}
if (containerOrchestrator) {
clusterTerminationService.deleteClusterComponents(cluster.getId());
cluster = clusterRepository.findById(stack.getCluster().getId());
}
hostGroups = hostGroupService.saveOrUpdateWithMetadata(hostGroups, cluster);
cluster = prepareCluster(hostGroups, stackRepoDetails, blueprint, stack, cluster);
try {
triggerClusterInstall(stack, cluster);
} catch (CloudbreakException e) {
throw new CloudbreakServiceException(e);
}
return stack.getCluster();
}
use of com.sequenceiq.cloudbreak.service.CloudbreakException 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);
}
use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class OrchestratorRecipeExecutor method postInstall.
public void postInstall(Stack stack) throws CloudbreakException {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
try {
hostOrchestrator.postInstallRecipes(gatewayConfig, collectNodes(stack), clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
} catch (CloudbreakOrchestratorFailedException e) {
throw new CloudbreakException(e);
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakException in project cloudbreak by hortonworks.
the class OrchestratorRecipeExecutor method preTerminationRecipesOnNodes.
public void preTerminationRecipesOnNodes(Stack stack, Set<Node> nodes) throws CloudbreakException {
if (stack.getCluster() == null) {
throw new NotFoundException("Cluster does not found, pre-termination will not be run.");
}
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
try {
hostOrchestrator.preTerminationRecipes(gatewayConfig, nodes, clusterDeletionBasedModel(stack.getId(), stack.getCluster().getId()));
} catch (CloudbreakOrchestratorFailedException e) {
throw new CloudbreakException(e);
}
}
Aggregations