use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class BlueprintService method validate.
private void validate(Blueprint blueprint, boolean internalCreation) {
MapBindingResult errors = new MapBindingResult(new HashMap(), "blueprint");
blueprintValidator.validate(blueprint, errors);
if (errors.hasErrors()) {
throw new BadRequestException(errors.getAllErrors().stream().map(e -> (e instanceof FieldError ? ((FieldError) e).getField() + ": " : "") + e.getDefaultMessage()).collect(Collectors.joining("; ")));
}
if (!internalCreation) {
blueprintConfigValidator.validate(blueprint);
}
hueWorkaroundValidatorService.validateForBlueprintRequest(getHueHostGroups(blueprint.getBlueprintText()));
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class BlueprintService method prepareDeletion.
@Override
protected void prepareDeletion(Blueprint blueprint) {
Set<Cluster> notDeletedClustersWithThisCd = getNotDeletedClustersWithBlueprint(blueprint);
if (!notDeletedClustersWithThisCd.isEmpty()) {
if (notDeletedClustersWithThisCd.size() > 1) {
List<String> clusters = notDeletedClustersWithThisCd.stream().filter(it -> !it.getStack().getType().equals(StackType.TEMPLATE)).map(it -> it.getStack().getName()).collect(Collectors.toList());
List<Long> stackTemplateIds = notDeletedClustersWithThisCd.stream().filter(it -> it.getStack().getType().equals(StackType.TEMPLATE)).map(it -> it.getStack().getId()).collect(Collectors.toList());
Set<String> clusterDefinitions = getClusterDefinitionNameByStackTemplateIds(stackTemplateIds);
throw new BadRequestException(String.format("There are clusters or cluster definitions associated with cluster template '%s'. " + "The cluster template used by %s cluster(s) (%s) and %s cluster definitions (%s). " + "Please remove these before deleting the cluster template.", blueprint.getName(), clusters.size(), String.join(", ", clusters), clusterDefinitions.size(), String.join(", ", clusterDefinitions)));
}
Cluster cluster = notDeletedClustersWithThisCd.iterator().next();
String clusterType = getClusterType(cluster);
String clusterDefinitionName = getClusterDefinitionNameByStackTemplateIds(List.of(cluster.getStack().getId())).stream().findFirst().orElseThrow(() -> new NotFoundException("Cannot find the cluster definition for the stack template"));
throw new BadRequestException(String.format("There is a %s ['%s'] which uses cluster template '%s'. Please remove this " + "cluster before deleting the cluster template.", clusterType, clusterDefinitionName, blueprint.getName()));
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterService method getStackRepositoryJson.
public String getStackRepositoryJson(Long stackId) {
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()));
}
StackRepoDetails repoDetails = clusterComponentConfigProvider.getStackRepoDetails(cluster.getId());
String stackRepoId = repoDetails.getStack().get(REPO_ID_TAG);
return clusterApiConnectors.getConnector(stack).clusterModificationService().getStackRepositoryJson(repoDetails, stackRepoId);
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackCommonService method putStopInWorkspace.
public FlowIdentifier putStopInWorkspace(NameOrCrn nameOrCrn, Long workspaceId) {
Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId);
MDCBuilder.buildMdcContext(stack);
if (!cloudParameterCache.isStartStopSupported(stack.cloudPlatform())) {
throw new BadRequestException(String.format("Stop is not supported on %s cloudplatform", stack.cloudPlatform()));
}
UpdateStackV4Request updateStackJson = new UpdateStackV4Request();
updateStackJson.setStatus(StatusRequest.STOPPED);
updateStackJson.setWithClusterEvent(true);
return put(stack, updateStackJson);
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class StackDecorator method setupDatabaseAttachedVolume.
private void setupDatabaseAttachedVolume(Stack subject, InstanceGroup instanceGroup, Template template) {
InstanceGroupType instanceGroupType = instanceGroup.getInstanceGroupType();
if (instanceGroupType == InstanceGroupType.GATEWAY && embeddedDatabaseService.isEmbeddedDatabaseOnAttachedDiskEnabled(subject, subject.getCluster())) {
String databaseVolumeType = embeddedDatabaseConfig.getPlatformVolumeType(subject.cloudPlatform()).orElseThrow(() -> new BadRequestException(String.format("If embedded db is enabled on attached disk, database volumetype" + " have to be defined for cloudprovider in app config! Missing database volumetype on %s provider", subject.cloudPlatform())));
VolumeTemplate databaseVolumeTemplate = new VolumeTemplate();
databaseVolumeTemplate.setUsageType(VolumeUsageType.DATABASE);
databaseVolumeTemplate.setVolumeSize(embeddedDatabaseConfig.getSize());
databaseVolumeTemplate.setVolumeCount(1);
databaseVolumeTemplate.setVolumeType(databaseVolumeType);
databaseVolumeTemplate.setTemplate(template);
template.getVolumeTemplates().add(databaseVolumeTemplate);
LOGGER.debug("Extra disk is attached with {} type and {}GB size for the embedded database.", databaseVolumeTemplate.getVolumeType(), databaseVolumeTemplate.getVolumeSize());
} else {
if (instanceGroupType == InstanceGroupType.GATEWAY) {
LOGGER.debug("No extra disk will be attached to the gateway instance as db volume because it is disabled or external database is used.");
} else {
LOGGER.debug("No extra disk will be attached to the instance as db volume because it is CORE instance.");
}
}
}
Aggregations