Search in sources :

Example 31 with BadRequestException

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);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Example 32 with BadRequestException

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);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 33 with BadRequestException

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);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 34 with BadRequestException

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);
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Transactional(javax.transaction.Transactional)

Example 35 with BadRequestException

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;
}
Also used : FlexSubscription(com.sequenceiq.cloudbreak.domain.FlexSubscription) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)87 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 Transactional (javax.transaction.Transactional)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 Json (com.sequenceiq.cloudbreak.domain.json.Json)12 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)12 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)11 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 IOException (java.io.IOException)7 Credential (com.sequenceiq.cloudbreak.domain.Credential)6 HashMap (java.util.HashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)5 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashSet (java.util.HashSet)4 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)3