use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class SecurityGroupService method create.
@Transactional(TxType.NEVER)
public SecurityGroup create(IdentityUser user, SecurityGroup securityGroup) {
LOGGER.info("Creating SecurityGroup: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
securityGroup.setOwner(user.getUserId());
securityGroup.setAccount(user.getAccount());
try {
return groupRepository.save(securityGroup);
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.SECURITY_GROUP, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class SmartSenseSubscriptionService method create.
public SmartSenseSubscription create(SmartSenseSubscription subscription) {
long count = repository.count();
if (count != 0L) {
throw new BadRequestException("Only one SmartSense subscription is allowed by deployment.");
}
try {
subscription = repository.save(subscription);
LOGGER.info("SmartSense subscription has been created: {}", subscription);
return subscription;
} catch (DataIntegrityViolationException ex) {
String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.SMARTSENSE_SUBSCRIPTION, getProperSqlErrorMessage(ex));
throw new BadRequestException(msg);
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class ConstraintTemplateService method delete.
private void delete(ConstraintTemplate constraintTemplate) {
authorizationService.hasWritePermission(constraintTemplate);
LOGGER.debug("Deleting constraint template. {} - {}", new Object[] { constraintTemplate.getId(), constraintTemplate.getName() });
List<Cluster> clusters = clusterRepository.findAllClustersForConstraintTemplate(constraintTemplate.getId());
if (clusters.isEmpty()) {
if (ResourceStatus.USER_MANAGED.equals(constraintTemplate.getStatus())) {
constraintTemplateRepository.delete(constraintTemplate);
} else {
constraintTemplate.setName(NameUtil.postfixWithTimestamp(constraintTemplate.getName()));
constraintTemplate.setStatus(ResourceStatus.DEFAULT_DELETED);
constraintTemplateRepository.save(constraintTemplate);
}
} else if (isRunningClusterReferToTemplate(clusters)) {
throw new BadRequestException(String.format("There are stacks associated with template '%s'. Please remove these before deleting the template.", constraintTemplate.getName()));
} else {
constraintTemplate.setName(NameUtil.postfixWithTimestamp(constraintTemplate.getName()));
constraintTemplate.setDeleted(true);
if (ResourceStatus.DEFAULT.equals(constraintTemplate.getStatus())) {
constraintTemplate.setStatus(ResourceStatus.DEFAULT_DELETED);
}
constraintTemplateRepository.save(constraintTemplate);
}
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class CredentialService method modify.
@Transactional(TxType.NEVER)
public Credential modify(IdentityUser user, Credential credential) {
LOGGER.debug("Modifying credential: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
Credential credentialToModify = credential.isPublicInAccount() ? getPublicCredential(credential.getName(), user) : getPrivateCredential(credential.getName(), user);
authorizationService.hasWritePermission(credentialToModify);
if (!credentialToModify.cloudPlatform().equals(credential.cloudPlatform())) {
throw new BadRequestException("Modifying credential platform is forbidden");
}
if (credential.getAttributes() != null) {
credentialToModify.setAttributes(credential.getAttributes());
}
if (credential.getDescription() != null) {
credentialToModify.setDescription(credential.getDescription());
}
if (credential.getTopology() != null) {
credentialToModify.setTopology(credential.getTopology());
}
return saveCredentialAndNotify(credentialToModify, ResourceEvent.CREDENTIAL_MODIFIED);
}
use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.
the class FlexSubscriptionService method create.
public FlexSubscription create(FlexSubscription subscription) {
if (!flexRepo.countByNameAndAccount(subscription.getName(), subscription.getAccount()).equals(0L)) {
throw new BadRequestException(String.format("The name: '%s' has already taken by an other FlexSubscription.", subscription.getName()));
} else if (!flexRepo.countBySubscriptionId(subscription.getSubscriptionId()).equals(0L)) {
throw new BadRequestException(String.format("The subscriptionId: '%s' has already taken by an other FlexSubscription.", subscription.getSubscriptionId()));
}
subscription = flexRepo.save(subscription);
List<FlexSubscription> allInAccount = flexRepo.findAllByAccount(subscription.getAccount());
setSubscriptionAsDefaultIfNeeded(subscription, allInAccount);
updateSubscriptionsDefaultFlagsIfNeeded(subscription, allInAccount);
LOGGER.info("Flex subscription has been created: {}", subscription);
return subscription;
}
Aggregations