use of groovyx.net.http.HttpResponseException in project cloudbreak by hortonworks.
the class AmbariRepositoryVersionService method setBaseRepoURL.
public void setBaseRepoURL(String stackName, long clusterId, Orchestrator orchestrator, StackService ambariClient) throws CloudbreakException {
StackRepoDetails stackRepoDetails = getStackRepoDetails(clusterId, orchestrator);
if (stackRepoDetails != null) {
try {
LOGGER.info("Use specific Ambari repository: {}", stackRepoDetails);
AmbariRepo ambariRepoDetails = clusterComponentConfigProvider.getAmbariRepo(clusterId);
if (isVersionNewerOrEqualThanLimited(ambariRepoDetails::getVersion, AMBARI_VERSION_2_6_0_0)) {
addVersionDefinitionFileToAmbari(stackName, ambariClient, stackRepoDetails);
} else {
setRepositoryVersionOnApi(ambariClient, stackRepoDetails);
}
} catch (HttpResponseException e) {
String exceptionErrorMsg = AmbariClientExceptionUtil.getErrorMessage(e);
String msg = String.format("Cannot use the specified Ambari stack: %s. Error: %s", stackRepoDetails.toString(), exceptionErrorMsg);
throw new AmbariServiceException(msg, e);
}
} else {
LOGGER.info("Using latest HDP repository");
}
}
use of groovyx.net.http.HttpResponseException in project cloudbreak by hortonworks.
the class AmbariClusterSetupService method buildCluster.
@Override
public void buildCluster(Stack stack) {
Cluster cluster = stack.getCluster();
try {
clusterService.updateCreationDateOnCluster(cluster);
AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
BlueprintPreparationObject blueprintPreparationObject = conversionService.convert(stack, BlueprintPreparationObject.class);
Map<String, List<Map<String, String>>> hostGroupMappings = hostGroupAssociationBuilder.buildHostGroupAssociations(hostGroups);
Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(cluster.getId());
recipeEngine.executePostAmbariStartRecipes(stack, hostGroups);
ambariRepositoryVersionService.setBaseRepoURL(stack.getName(), cluster.getId(), stack.getOrchestrator(), ambariClient);
String blueprintText = centralBlueprintUpdater.getBlueprintText(blueprintPreparationObject);
addBlueprint(stack.getId(), ambariClient, blueprintText, cluster.getTopologyValidation());
cluster.setExtendedBlueprintText(blueprintText);
clusterService.updateCluster(cluster);
PollingResult waitForHostsResult = ambariPollingServiceProvider.hostsPollingService(stack, ambariClient, hostsInCluster);
ambariClusterConnectorPollingResultChecker.checkPollingResult(waitForHostsResult, cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_HOST_JOIN_FAILED.code()));
ambariClusterTemplateService.addClusterTemplate(cluster, hostGroupMappings, ambariClient);
Pair<PollingResult, Exception> pollingResult = ambariOperationService.waitForOperationsToStart(stack, ambariClient, singletonMap("INSTALL_START", 1), START_OPERATION_STATE);
String message = pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()) : pollingResult.getRight().getMessage();
ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResult.getLeft(), message);
Pair<PollingResult, Exception> pollingResultExceptionPair = ambariOperationService.waitForOperations(stack, ambariClient, new HashMap<String, Integer>() {
{
put("CLUSTER_INSTALL", 1);
}
}, INSTALL_AMBARI_PROGRESS_STATE);
ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResultExceptionPair.getLeft(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()));
recipeEngine.executePostInstall(stack);
ambariSmartSenseCapturer.capture(0, ambariClient);
cluster = ambariViewProvider.provideViewInformation(ambariClient, cluster);
ambariClusterCreationSuccessHandler.handleClusterCreationSuccess(stack, cluster);
} catch (CancellationException cancellationException) {
throw cancellationException;
} catch (HttpResponseException hre) {
throw new AmbariOperationFailedException("Ambari could not create the cluster: " + AmbariClientExceptionUtil.getErrorMessage(hre), hre);
} catch (Exception e) {
LOGGER.error("Error while building the Ambari cluster. Message {}, throwable: {}", e.getMessage(), e);
throw new AmbariOperationFailedException(e.getMessage(), e);
}
}
use of groovyx.net.http.HttpResponseException 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 groovyx.net.http.HttpResponseException 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 groovyx.net.http.HttpResponseException 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