use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class CredentialSourceDecorator method decorate.
public Credential decorate(Credential credential, CredentialSourceRequest credentialSourceRequest, IdentityUser user) {
if (credential == null) {
credential = Strings.isNullOrEmpty(credentialSourceRequest.getSourceName()) ? credentialService.get(credentialSourceRequest.getSourceId()) : credentialService.get(credentialSourceRequest.getSourceName(), user.getAccount());
if (credential == null) {
throw new BadRequestException("Source credential does not exist!");
} else {
Map<String, Object> map = credential.getAttributes().getMap();
for (Entry<String, Object> stringObjectEntry : credentialSourceRequest.getParameters().entrySet()) {
map.put(stringObjectEntry.getKey(), stringObjectEntry.getValue().toString());
}
credential.setId(null);
credential.setName(missingResourceNameGenerator.generateName(APIResourceType.CREDENTIAL));
try {
credential.setAttributes(new Json(map));
} catch (JsonProcessingException ignored) {
throw new BadRequestException("Could not create credential from source credential!");
}
}
}
return credential;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class HostGroupDecorator method getHostGroup.
private HostGroup getHostGroup(Long stackId, Constraint constraint, ConstraintJson constraintJson, HostGroup subject, IdentityUser user) {
if (constraintJson == null) {
throw new BadRequestException("The constraint field must be set in the reinstall request!");
}
HostGroup result = subject;
String instanceGroupName = constraintJson.getInstanceGroupName();
String constraintTemplateName = constraintJson.getConstraintTemplateName();
Cluster cluster = clusterService.retrieveClusterByStackId(stackId);
Constraint decoratedConstraint = decorateConstraint(stackId, user, constraint, instanceGroupName, constraintTemplateName);
if (!isEmpty(instanceGroupName)) {
result = getHostGroupByInstanceGroupName(decoratedConstraint, subject, cluster, instanceGroupName);
} else if (!isEmpty(constraintTemplateName)) {
subject.setConstraint(constraintRepository.save(constraint));
} else {
throw new BadRequestException("The constraint field must contain the 'constraintTemplateName' or 'instanceGroupName' parameter!");
}
return result;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class HostGroupDecorator method decorateConstraint.
private Constraint decorateConstraint(Long stackId, IdentityUser user, Constraint constraint, String instanceGroupName, String constraintTemplateName) {
if (instanceGroupName != null) {
InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stackId, instanceGroupName);
if (instanceGroup == null) {
LOGGER.error("Instance group not found: {}", instanceGroupName);
throw new BadRequestException(String.format("Instance group '%s' not found on stack.", instanceGroupName));
}
constraint.setInstanceGroup(instanceGroup);
}
if (constraintTemplateName != null) {
ConstraintTemplate constraintTemplate = constraintTemplateRepository.findByNameInAccount(constraintTemplateName, user.getAccount(), user.getUserId());
if (constraintTemplate == null) {
throw new BadRequestException(String.format("Couldn't find constraint template with name: %s", constraintTemplateName));
}
constraint.setConstraintTemplate(constraintTemplate);
}
return constraint;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class ClusterTemplateService method create.
@Transactional(TxType.NEVER)
public ClusterTemplate create(IdentityUser user, ClusterTemplate clusterTemplate) {
LOGGER.debug("Creating clusterTemplate: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
ClusterTemplate savedClusterTemplate;
clusterTemplate.setOwner(user.getUserId());
clusterTemplate.setAccount(user.getAccount());
try {
savedClusterTemplate = clusterTemplateRepository.save(clusterTemplate);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.CLUSTER_TEMPLATE, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
return savedClusterTemplate;
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class CredentialService method saveCredentialAndNotify.
private Credential saveCredentialAndNotify(Credential credential, ResourceEvent resourceEvent) {
credential = credentialAdapter.init(credential);
Credential savedCredential;
try {
savedCredential = credentialRepository.save(credential);
userProfileCredentialHandler.createProfilePreparation(credential);
sendCredentialNotification(credential, resourceEvent);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.CREDENTIAL, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
return savedCredential;
}
Aggregations