Search in sources :

Example 71 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method delete.

@Override
public void delete(Long stackId, Boolean withStackDelete, Boolean deleteDependencies) {
    Stack stack = stackService.get(stackId);
    authorizationService.hasWritePermission(stack);
    if (stack.getCluster() == null || stack.getCluster() != null && Status.DELETE_COMPLETED.equals(stack.getCluster().getStatus())) {
        throw new BadRequestException("Clusters is already deleted.");
    }
    LOGGER.info("Cluster delete requested.");
    flowManager.triggerClusterTermination(stackId, withStackDelete, deleteDependencies);
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 72 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method validateRegisteredHosts.

private void validateRegisteredHosts(Stack stack, HostGroupAdjustmentJson hostGroupAdjustment) {
    String hostGroup = hostGroupAdjustment.getHostGroup();
    int hostsCount = hostGroupService.getByClusterIdAndName(stack.getCluster().getId(), hostGroup).getHostMetadata().size();
    int adjustment = Math.abs(hostGroupAdjustment.getScalingAdjustment());
    Boolean validateNodeCount = hostGroupAdjustment.getValidateNodeCount();
    if (validateNodeCount == null || validateNodeCount) {
        if (hostsCount <= adjustment) {
            String errorMessage = String.format("[hostGroup: '%s', current hosts: %s, decommissions requested: %s]", hostGroup, hostsCount, adjustment);
            throw new BadRequestException(String.format("The host group must contain at least 1 host after the decommission: %s", errorMessage));
        }
    } else if (hostsCount - adjustment < 0) {
        throw new BadRequestException(String.format("There are not enough hosts in host group: %s to remove", hostGroup));
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Constraint(com.sequenceiq.cloudbreak.domain.Constraint)

Example 73 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException 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 74 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method validateRequest.

private boolean validateRequest(Stack stack, HostGroupAdjustmentJson hostGroupAdjustment) {
    HostGroup hostGroup = getHostGroup(stack, hostGroupAdjustment);
    int scalingAdjustment = hostGroupAdjustment.getScalingAdjustment();
    boolean downScale = scalingAdjustment < 0;
    if (scalingAdjustment == 0) {
        throw new BadRequestException("No scaling adjustments specified. Nothing to do.");
    }
    blueprintValidator.validateHostGroupScalingRequest(stack.getCluster().getBlueprint(), hostGroup, scalingAdjustment);
    if (!downScale && hostGroup.getConstraint().getInstanceGroup() != null) {
        validateUnusedHosts(hostGroup.getConstraint().getInstanceGroup(), scalingAdjustment);
    } else {
        validateRegisteredHosts(stack, hostGroupAdjustment);
        if (hostGroupAdjustment.getWithStackUpdate() && hostGroupAdjustment.getScalingAdjustment() > 0) {
            throw new BadRequestException("ScalingAdjustment has to be decommission if you define withStackUpdate = 'true'.");
        }
    }
    return downScale;
}
Also used : HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Constraint(com.sequenceiq.cloudbreak.domain.Constraint)

Example 75 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class AmbariClusterService method updateHosts.

@Override
public void updateHosts(Long stackId, HostGroupAdjustmentJson hostGroupAdjustment) {
    Stack stack = stackService.get(stackId);
    Cluster cluster = stack.getCluster();
    if (cluster == null) {
        throw new BadRequestException(String.format("There is no cluster installed on stack '%s'.", stack.getName()));
    }
    boolean downscaleRequest = validateRequest(stack, hostGroupAdjustment);
    if (downscaleRequest) {
        updateClusterStatusByStackId(stackId, UPDATE_REQUESTED);
        flowManager.triggerClusterDownscale(stackId, hostGroupAdjustment);
    } else {
        flowManager.triggerClusterUpscale(stackId, hostGroupAdjustment);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)87 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 Transactional (javax.transaction.Transactional)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 Json (com.sequenceiq.cloudbreak.domain.json.Json)12 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)12 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)11 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 IOException (java.io.IOException)7 Credential (com.sequenceiq.cloudbreak.domain.Credential)6 HashMap (java.util.HashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)5 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashSet (java.util.HashSet)4 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)3