Search in sources :

Example 1 with HttpResponseException

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");
    }
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) HttpResponseException(groovyx.net.http.HttpResponseException) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo)

Example 2 with HttpResponseException

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);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HttpResponseException(groovyx.net.http.HttpResponseException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HttpResponseException(groovyx.net.http.HttpResponseException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) BlueprintPreparationObject(com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject) List(java.util.List) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Example 3 with HttpResponseException

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);
        }
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) HttpResponseException(groovyx.net.http.HttpResponseException) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 4 with HttpResponseException

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);
        }
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HttpResponseException(groovyx.net.http.HttpResponseException)

Example 5 with HttpResponseException

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);
        }
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) HttpResponseException(groovyx.net.http.HttpResponseException)

Aggregations

HttpResponseException (groovyx.net.http.HttpResponseException)5 CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)4 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 BlueprintPreparationObject (com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject)1 AmbariRepo (com.sequenceiq.cloudbreak.cloud.model.AmbariRepo)1 StackRepoDetails (com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails)1 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 CloudbreakSecuritySetupException (com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException)1 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)1 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)1 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)1 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)1 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)1 List (java.util.List)1