use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class UpdateStackRequestV2ToUpdateClusterRequestConverter method convert.
@Override
public UpdateClusterJson convert(StackScaleRequestV2 source) {
UpdateClusterJson updateStackJson = new UpdateClusterJson();
Cluster oneByStackId = clusterRepository.findOneByStackId(source.getStackId());
HostGroup hostGroup = hostGroupRepository.findHostGroupInClusterByName(oneByStackId.getId(), source.getGroup());
if (hostGroup != null) {
HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
hostGroupAdjustmentJson.setWithStackUpdate(true);
hostGroupAdjustmentJson.setValidateNodeCount(true);
hostGroupAdjustmentJson.setHostGroup(source.getGroup());
int scaleNumber = source.getDesiredCount() - hostGroup.getHostMetadata().size();
hostGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
updateStackJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
} else {
throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
}
return updateStackJson;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackService method triggerStackStopIfNeeded.
private void triggerStackStopIfNeeded(Stack stack, Cluster cluster, boolean updateCluster) {
if (!isStopNeeded(stack)) {
return;
}
if (cluster != null && !cluster.isStopped() && !stack.isStopFailed()) {
if (!updateCluster) {
throw new BadRequestException(String.format("Cannot update the status of stack '%s' to STOPPED, because the cluster is not in STOPPED state.", stack.getName()));
} else if (cluster.isClusterReadyForStop() || cluster.isStopFailed()) {
setStackStatusToStopRequested(stack);
ambariClusterService.updateStatus(stack.getId(), StatusRequest.STOPPED);
} else {
throw new BadRequestException(String.format("Cannot update the status of cluster '%s' to STOPPED, because the cluster's state is %s.", cluster.getName(), cluster.getStatus()));
}
} else {
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.STOP_REQUESTED);
flowManager.triggerStackStop(stack.getId());
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackService method validateHostGroupAdjustment.
private void validateHostGroupAdjustment(InstanceGroupAdjustmentJson instanceGroupAdjustmentJson, Stack stack, Integer adjustment) {
Blueprint blueprint = stack.getCluster().getBlueprint();
Optional<HostGroup> hostGroup = stack.getCluster().getHostGroups().stream().filter(input -> input.getConstraint().getInstanceGroup().getGroupName().equals(instanceGroupAdjustmentJson.getInstanceGroup())).findFirst();
if (!hostGroup.isPresent()) {
throw new BadRequestException(String.format("Instancegroup '%s' not found or not part of stack '%s'", instanceGroupAdjustmentJson.getInstanceGroup(), stack.getName()));
}
blueprintValidator.validateHostGroupScalingRequest(blueprint, hostGroup.get(), adjustment);
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class StackService method isStopNeeded.
private boolean isStopNeeded(Stack stack) {
boolean result = true;
StopRestrictionReason reason = stack.isInfrastructureStoppable();
if (stack.isStopped()) {
String statusDesc = cloudbreakMessagesService.getMessage(Msg.STACK_STOP_IGNORED.code());
LOGGER.info(statusDesc);
eventService.fireCloudbreakEvent(stack.getId(), STOPPED.name(), statusDesc);
result = false;
} else if (reason != StopRestrictionReason.NONE) {
throw new BadRequestException(String.format("Cannot stop a stack '%s'. Reason: %s", stack.getName(), reason.getReason()));
} else if (!stack.isAvailable() && !stack.isStopFailed()) {
throw new BadRequestException(String.format("Cannot update the status of stack '%s' to STOPPED, because it isn't in AVAILABLE state.", stack.getName()));
}
return result;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class NetworkService method create.
@Transactional(TxType.NEVER)
public Network create(IdentityUser user, Network network) {
LOGGER.info("Creating network: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
network.setOwner(user.getUserId());
network.setAccount(user.getAccount());
try {
return networkRepository.save(network);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.NETWORK, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
}
Aggregations