use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterOperationService method create.
@Measure(ClusterOperationService.class)
public Cluster create(Stack stack, Cluster cluster, List<ClusterComponent> components, User user) throws TransactionService.TransactionExecutionException {
LOGGER.debug("Cluster requested [BlueprintId: {}]", cluster.getBlueprint().getId());
String stackName = stack.getName();
if (stack.getCluster() != null) {
throw new BadRequestException(String.format("A cluster is already created on this stack! [cluster: '%s']", stack.getCluster().getName()));
}
long start = System.currentTimeMillis();
return transactionService.required(() -> {
setWorkspace(cluster, stack.getWorkspace());
cluster.setEnvironmentCrn(stack.getEnvironmentCrn());
if (Status.CREATE_FAILED.equals(stack.getStatus())) {
throw new BadRequestException("Stack creation failed, cannot create cluster.");
}
if (cluster.getFileSystem() != null) {
cluster.setFileSystem(fileSystemConfigService.createWithMdcContextRestore(cluster.getFileSystem(), cluster.getWorkspace(), user));
}
removeGatewayIfNotSupported(cluster, components);
cluster.setStack(stack);
stack.setCluster(cluster);
Cluster savedCluster = measure(() -> clusterService.saveClusterAndComponent(cluster, components, stackName), LOGGER, "saveClusterAndComponent {} ms");
measure(() -> usageLoggingUtil.logClusterRequestedUsageEvent(cluster), LOGGER, "logClusterRequestedUsageEvent {} ms");
LOGGER.info("cluster saved {} ms", System.currentTimeMillis() - start);
return savedCluster;
});
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class ClusterOperationService method updateUserNamePassword.
public FlowIdentifier updateUserNamePassword(Long stackId, UserNamePasswordV4Request userNamePasswordJson) {
Stack stack = stackService.getById(stackId);
Cluster cluster = stack.getCluster();
String oldUserName = cluster.getUserName();
String oldPassword = cluster.getPassword();
String newUserName = userNamePasswordJson.getUserName();
String newPassword = userNamePasswordJson.getPassword();
if (!newUserName.equals(oldUserName)) {
return flowManager.triggerClusterCredentialReplace(stack.getId(), userNamePasswordJson.getUserName(), userNamePasswordJson.getPassword());
} else if (!newPassword.equals(oldPassword)) {
return flowManager.triggerClusterCredentialUpdate(stack.getId(), userNamePasswordJson.getPassword());
} else {
throw new BadRequestException("The request may not change credential");
}
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class UpdateHostsValidator method validateRequest.
public boolean validateRequest(Stack stack, HostGroupAdjustmentV4Request 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.");
}
if (!downScale && hostGroup.getInstanceGroup() != null) {
validateUnusedHosts(hostGroup.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.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class UpdateHostsValidator method validateRegisteredHosts.
private void validateRegisteredHosts(Stack stack, HostGroupAdjustmentV4Request hostGroupAdjustment) {
String hostGroupName = hostGroupAdjustment.getHostGroup();
hostGroupService.getByClusterIdAndName(stack.getCluster().getId(), hostGroupName).ifPresentOrElse(hostGroup -> {
if (hostGroup.getInstanceGroup() == null) {
throw new BadRequestException(String.format("Can't find instancegroup for hostgroup: %s", hostGroupName));
} else {
InstanceGroup instanceGroup = hostGroup.getInstanceGroup();
int hostsCount = instanceGroup.getNotDeletedAndNotZombieInstanceMetaDataSet().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]", hostGroupName, 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", hostGroupName));
}
}
}, () -> {
throw new BadRequestException(String.format("Can't find hostgroup: %s", hostGroupName));
});
}
use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.
the class BlueprintConfigValidator method validate.
public void validate(Blueprint blueprint) {
CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(blueprint.getBlueprintText());
if (cmTemplateProcessor.isInstantiatorPresent()) {
throw new BadRequestException("Instantiator is present in your Cloudera Manager template which is probably incorrect.");
}
if (cmTemplateProcessor.isRepositoriesPresent()) {
throw new BadRequestException("Repositories are present in your Cloudera Manager template, this must be removed.");
}
Pattern passwordPattern = Pattern.compile("\\*\\*\\*");
Matcher passwordMatch = passwordPattern.matcher(blueprint.getBlueprintText());
if (passwordMatch.find()) {
throw new BadRequestException("Password placeholder with **** is present in your Cloudera Manager template which is probably incorrect.");
}
Pattern volumePattern = Pattern.compile("/hadoopfs/fs(.*?)");
Matcher volumeMatch = volumePattern.matcher(blueprint.getBlueprintText());
if (volumeMatch.find()) {
throw new BadRequestException("Volume configuration should not be part of your Cloudera Manager template.");
}
if (!cmTemplateProcessor.everyHostTemplateHasRoleConfigGroupsRefNames()) {
throw new BadRequestException("RoleConfigGroupsRefNames is probably missing or misspelled in your Cloudera Manager template.");
}
if (!cmTemplateProcessor.everyServiceHasRoleConfigGroups()) {
throw new BadRequestException("RoleConfigGroups is probably missing or misspelled in your Cloudera Manager template.");
}
}
Aggregations