use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException 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.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AmbariClusterService method getClusterJson.
@Override
public String getClusterJson(String ambariIp, Long stackId) {
try {
AmbariClient ambariClient = getAmbariClient(stackId);
String clusterJson = ambariClient.getClusterAsJson();
if (clusterJson == null) {
throw new BadRequestException(String.format("Cluster response coming from Ambari server was null. [Ambari Server IP: '%s']", ambariIp));
}
return clusterJson;
} catch (HttpResponseException e) {
if ("Not Found".equals(e.getMessage())) {
throw new NotFoundException("Ambari validation not found.", e);
} else {
String errorMessage = AmbariClientExceptionUtil.getErrorMessage(e);
throw new CloudbreakServiceException("Could not get Cluster from Ambari as JSON: " + errorMessage, e);
}
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AmbariDecommissioner method getDFSSpace.
private Map<String, Map<Long, Long>> getDFSSpace(Stack stack, AmbariClient client) {
AmbariDFSSpaceRetrievalTask dfsSpaceTask = new AmbariDFSSpaceRetrievalTask();
PollingResult result = ambariClientPollingService.pollWithTimeoutSingleFailure(dfsSpaceTask, new AmbariClientPollerObject(stack, client), AmbariDFSSpaceRetrievalTask.AMBARI_RETRYING_INTERVAL, AmbariDFSSpaceRetrievalTask.AMBARI_RETRYING_COUNT);
if (result == SUCCESS) {
return dfsSpaceTask.getDfsSpace();
} else {
throw new CloudbreakServiceException("Failed to get dfs space from ambari!");
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AmbariClusterModificationService method installServices.
private Map<String, Integer> installServices(List<String> hosts, Stack stack, AmbariClient ambariClient, String hostGroup) {
try {
String blueprintName = stack.getCluster().getBlueprint().getAmbariName();
// In case If we changed the blueprintName field we need to query the validation name information from ambari
Map<String, String> blueprintsMap = ambariClient.getBlueprintsMap();
if (!blueprintsMap.entrySet().isEmpty()) {
blueprintName = blueprintsMap.keySet().iterator().next();
}
return singletonMap("UPSCALE_REQUEST", ambariClient.addHostsWithBlueprint(blueprintName, hostGroup, hosts));
} catch (HttpResponseException e) {
if ("Conflict".equals(e.getMessage())) {
throw new BadRequestException("Host already exists.", e);
} else {
String errorMessage = AmbariClientExceptionUtil.getErrorMessage(e);
throw new CloudbreakServiceException("Ambari could not install services. " + errorMessage, e);
}
}
}
use of com.sequenceiq.cloudbreak.service.CloudbreakServiceException in project cloudbreak by hortonworks.
the class AmbariClusterSetupService method addBlueprint.
private void addBlueprint(Long stackId, AmbariClient ambariClient, String blueprintText, Boolean topologyValidation) {
try {
LOGGER.info("Adding generated blueprint to Ambari: {}", JsonUtil.minify(blueprintText));
ambariClient.addBlueprint(blueprintText, topologyValidation);
} catch (HttpResponseException hre) {
if (hre.getStatusCode() == HttpStatus.SC_CONFLICT) {
LOGGER.info("Ambari blueprint already exists for stack: {}", stackId);
} else {
throw new CloudbreakServiceException("Ambari blueprint could not be added: " + AmbariClientExceptionUtil.getErrorMessage(hre), hre);
}
}
}
Aggregations