use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class CustomImageCatalogService method delete.
public ImageCatalog delete(Long workspaceId, String imageCatalogName) {
LOGGER.debug(String.format("Delete custom image catalog '%s' in workspace '%d'", imageCatalogName, workspaceId));
ImageCatalog imageCatalog = imageCatalogService.getImageCatalogByName(workspaceId, imageCatalogName);
if (Strings.isNullOrEmpty(imageCatalog.getImageCatalogUrl())) {
return imageCatalogService.delete(workspaceId, imageCatalogName);
} else {
throw new BadRequestException(String.format("'%s' is not a custom image catalog.", imageCatalog.getName()));
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackService method validateOrchestrator.
public void validateOrchestrator(Orchestrator orchestrator) {
try {
ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
containerOrchestrator.validateApiEndpoint(new OrchestrationCredential(orchestrator.getApiEndpoint(), orchestrator.getAttributes().getMap()));
} catch (CloudbreakException e) {
throw new BadRequestException(format("Invalid orchestrator type: %s", e.getMessage()));
} catch (CloudbreakOrchestratorException e) {
throw new BadRequestException(format("Error occurred when trying to reach orchestrator API: %s", e.getMessage()));
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackService method setDefaultTags.
private void setDefaultTags(Stack stack) {
try {
StackTags stackTag = stack.getTags().get(StackTags.class);
Map<String, String> userDefinedTags = stackTag.getUserDefinedTags();
String accountId = Crn.safeFromString(stack.getResourceCrn()).getAccountId();
boolean internalTenant = entitlementService.internalTenant(accountId);
CDPTagGenerationRequest request = CDPTagGenerationRequest.Builder.builder().withCreatorCrn(stack.getCreator().getUserCrn()).withEnvironmentCrn(stack.getEnvironmentCrn()).withPlatform(stack.getCloudPlatform()).withAccountId(accountId).withResourceCrn(stack.getResourceCrn()).withIsInternalTenant(internalTenant).withUserName(stack.getCreator().getUserName()).withAccountTags(accountTagClientService.list()).withUserDefinedTags(userDefinedTags).build();
Map<String, String> defaultTags = stackTag.getDefaultTags();
defaultTags.putAll(costTagging.prepareDefaultTags(request));
stack.setTags(new Json(new StackTags(userDefinedTags, stackTag.getApplicationTags(), defaultTags)));
} catch (AccountTagValidationFailed aTVF) {
throw new BadRequestException(aTVF.getMessage(), aTVF);
} catch (Exception e) {
LOGGER.debug("Exception during reading default tags.", e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackOperationService method updateNodeCount.
public FlowIdentifier updateNodeCount(Stack stack, InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson, boolean withClusterEvent) {
environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
try {
return transactionService.required(() -> {
boolean upscale = instanceGroupAdjustmentJson.getScalingAdjustment() > 0;
Stack stackWithLists = stackService.getByIdWithLists(stack.getId());
updateNodeCountValidator.validateServiceRoles(stackWithLists, instanceGroupAdjustmentJson);
updateNodeCountValidator.validateStackStatus(stackWithLists, upscale);
updateNodeCountValidator.validateInstanceGroup(stackWithLists, instanceGroupAdjustmentJson.getInstanceGroup());
updateNodeCountValidator.validateScalabilityOfInstanceGroup(stackWithLists, instanceGroupAdjustmentJson);
updateNodeCountValidator.validateScalingAdjustment(instanceGroupAdjustmentJson, stackWithLists);
boolean instanceStatusValidationNeeded = !upscale || !targetedUpscaleSupportService.targetedUpscaleOperationSupported(stackWithLists);
if (instanceStatusValidationNeeded) {
updateNodeCountValidator.validateInstanceStatuses(stackWithLists, instanceGroupAdjustmentJson);
}
if (withClusterEvent) {
updateNodeCountValidator.validateClusterStatus(stackWithLists, upscale);
updateNodeCountValidator.validateHostGroupIsPresent(instanceGroupAdjustmentJson, stackWithLists);
if (instanceStatusValidationNeeded) {
updateNodeCountValidator.validataHostMetadataStatuses(stackWithLists, instanceGroupAdjustmentJson);
}
}
if (upscale) {
stackUpdater.updateStackStatus(stackWithLists.getId(), DetailedStackStatus.UPSCALE_REQUESTED, "Requested node count for upscaling: " + instanceGroupAdjustmentJson.getScalingAdjustment());
return flowManager.triggerStackUpscale(stackWithLists.getId(), instanceGroupAdjustmentJson, withClusterEvent);
} else {
stackUpdater.updateStackStatus(stackWithLists.getId(), DetailedStackStatus.DOWNSCALE_REQUESTED, "Requested node count for downscaling: " + abs(instanceGroupAdjustmentJson.getScalingAdjustment()));
return flowManager.triggerStackDownscale(stackWithLists.getId(), instanceGroupAdjustmentJson);
}
});
} catch (TransactionExecutionException e) {
if (e.getCause() instanceof ConcurrencyFailureException) {
LOGGER.info("A concurrent update arrived to this cluster.", e.getCause());
throw new BadRequestException("A concurrent update arrived to this cluster. Please try again later.");
}
if (e.getCause() instanceof BadRequestException) {
throw e.getCause();
}
throw new TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackOperationService method updateStatus.
public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster) {
Stack stack = stackService.getByIdWithLists(stackId);
Cluster cluster = null;
if (stack.getCluster() != null) {
cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null);
}
switch(status) {
case SYNC:
return sync(stack, false);
case FULL_SYNC:
return sync(stack, true);
case REPAIR_FAILED_NODES:
return repairFailedNodes(stack);
case STOPPED:
return stop(stack, cluster, updateCluster);
case STARTED:
return start(stack);
default:
throw new BadRequestException("Cannot update the status of stack because status request not valid.");
}
}
Aggregations