use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterCommonService method put.
public FlowIdentifier put(String crn, UpdateClusterV4Request updateJson) {
Stack stack = stackService.getByCrnWithLists(crn);
Long stackId = stack.getId();
MDCBuilder.buildMdcContext(stack);
UserNamePasswordV4Request userNamePasswordJson = updateJson.getUserNamePassword();
FlowIdentifier flowIdentifier;
if (userNamePasswordJson != null) {
flowIdentifier = clusterManagerUserNamePasswordChange(stack, userNamePasswordJson);
} else if (updateJson.getStatus() != null) {
LOGGER.debug("Cluster status update request received. Stack id: {}, status: {} ", stackId, updateJson.getStatus());
flowIdentifier = clusterOperationService.updateStatus(stackId, updateJson.getStatus());
} else if (updateJson.getBlueprintName() != null && updateJson.getHostgroups() != null && stack.getCluster().isCreateFailed()) {
LOGGER.debug("Cluster rebuild request received. Stack id: {}", stackId);
try {
flowIdentifier = recreateCluster(stack, updateJson);
} catch (TransactionExecutionException e) {
throw new TransactionRuntimeExecutionException(e);
}
} else if (updateJson.getHostGroupAdjustment() != null) {
environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
flowIdentifier = clusterHostgroupAdjustmentChange(stackId, updateJson, stack);
} else {
LOGGER.info("Invalid cluster update request received. Stack id: {}", stackId);
throw new BadRequestException("Invalid update cluster request!");
}
return flowIdentifier;
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterCommonService method setMaintenanceMode.
public FlowIdentifier setMaintenanceMode(Stack stack, MaintenanceModeStatus maintenanceMode) {
Cluster cluster = stack.getCluster();
if (cluster == null) {
throw new BadRequestException(String.format("Cluster does not exist on stack with '%s' id.", stack.getId()));
} else if (!stack.isAvailable() && !stack.isMaintenanceModeEnabled()) {
throw new BadRequestException(String.format("Cluster '%s' is currently in '%s' state. Maintenance mode can be set to a cluster if it is 'AVAILABLE'.", stack.getId(), stack.getStatus()));
}
FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
switch(maintenanceMode) {
case ENABLED:
saveAndFireEventOnClusterStatusChange(stack, DetailedStackStatus.MAINTENANCE_MODE_ENABLED, ResourceEvent.MAINTENANCE_MODE_ENABLED);
break;
case DISABLED:
saveAndFireEventOnClusterStatusChange(stack, DetailedStackStatus.AVAILABLE, ResourceEvent.MAINTENANCE_MODE_DISABLED);
break;
case VALIDATION_REQUESTED:
if (!MAINTENANCE_MODE_ENABLED.equals(stack.getStatus())) {
throw new BadRequestException(String.format("Maintenance mode is not enabled for cluster '%s' (status:'%s'), it should be enabled before validation.", cluster.getId(), stack.getStatus()));
}
flowIdentifier = clusterOperationService.triggerMaintenanceModeValidation(stack);
clusterService.save(cluster);
break;
default:
// Nothing to do here
break;
}
return flowIdentifier;
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterCreationSetupService method validate.
@Measure(ClusterCreationSetupService.class)
public void validate(ClusterV4Request request, Stack stack, User user, Workspace workspace, DetailedEnvironmentResponse environment) {
MdcContext.builder().userCrn(user.getUserCrn()).tenant(user.getTenant().getName()).buildMdc();
rdsConfigValidator.validateRdsConfigs(request, user, workspace);
ValidationResult.ValidationResultBuilder resultBuilder = ValidationResult.builder();
environmentValidator.validateRdsConfigNames(request.getDatabases(), resultBuilder, stack.getWorkspace().getId());
environmentValidator.validateProxyConfig(request.getProxyConfigCrn(), resultBuilder);
String parentEnvironmentCloudPlatform = environment.getParentEnvironmentCloudPlatform();
environmentValidator.validateAutoTls(request, stack, resultBuilder, parentEnvironmentCloudPlatform);
ValidationResult build = resultBuilder.build();
if (build.hasError()) {
throw new BadRequestException(build.getFormattedErrors());
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterOperationService method stop.
private FlowIdentifier stop(Stack stack) {
StopRestrictionReason reason = stackStopRestrictionService.isInfrastructureStoppable(stack);
FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
if (stack.isStopped()) {
eventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_STOP_IGNORED);
} else if (reason != StopRestrictionReason.NONE) {
throw new BadRequestException(String.format("Cannot stop the cluster. Reason: %s", reason.getReason()));
} else if (!stack.isReadyForStop() && !stack.isStopFailed()) {
throw NotAllowedStatusUpdate.cluster(stack).to(STOPPED).expectedIn(AVAILABLE).badRequest();
} else {
flowIdentifier = flowManager.triggerClusterStop(stack.getId());
}
return flowIdentifier;
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterOperationService method updateHosts.
public FlowIdentifier updateHosts(Long stackId, HostGroupAdjustmentV4Request hostGroupAdjustment) {
Stack stack = stackService.getById(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 = updateHostsValidator.validateRequest(stack, hostGroupAdjustment);
if (downscaleRequest) {
stackUpdater.updateStackStatus(stackId, DetailedStackStatus.DOWNSCALE_REQUESTED, "Requested node count for downscaling: " + abs(hostGroupAdjustment.getScalingAdjustment()));
return flowManager.triggerClusterDownscale(stackId, hostGroupAdjustment);
} else {
stackUpdater.updateStackStatus(stackId, DetailedStackStatus.UPSCALE_REQUESTED, "Requested node count for upscaling: " + hostGroupAdjustment.getScalingAdjustment());
return flowManager.triggerClusterUpscale(stackId, hostGroupAdjustment);
}
}
Aggregations