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);
}
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));
}
}
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);
}
}
}
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;
}
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);
}
}
Aggregations