Search in sources :

Example 11 with CloudbreakServiceException

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();
}
Also used : Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) KerberosConfig(com.sequenceiq.cloudbreak.domain.KerberosConfig) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 12 with CloudbreakServiceException

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);
        }
    }
}
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 13 with CloudbreakServiceException

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!");
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) AmbariClientPollerObject(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariClientPollerObject) AmbariDFSSpaceRetrievalTask(com.sequenceiq.cloudbreak.service.cluster.flow.AmbariDFSSpaceRetrievalTask)

Example 14 with CloudbreakServiceException

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

Example 15 with CloudbreakServiceException

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

Aggregations

CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)15 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)4 IOException (java.io.IOException)4 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)3 Component (com.sequenceiq.cloudbreak.domain.Component)3 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 HttpResponseException (groovyx.net.http.HttpResponseException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 BlueprintProcessingException (com.sequenceiq.cloudbreak.blueprint.BlueprintProcessingException)2 BlueprintView (com.sequenceiq.cloudbreak.blueprint.template.views.BlueprintView)2 FileSystemConfigurationView (com.sequenceiq.cloudbreak.blueprint.template.views.FileSystemConfigurationView)2 BlueprintStackInfo (com.sequenceiq.cloudbreak.blueprint.templates.BlueprintStackInfo)2 CheckImageResult (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 KerberosConfig (com.sequenceiq.cloudbreak.domain.KerberosConfig)2 LdapConfig (com.sequenceiq.cloudbreak.domain.LdapConfig)2 Json (com.sequenceiq.cloudbreak.domain.json.Json)2