Search in sources :

Example 1 with DuplicateKeyValueException

use of com.sequenceiq.cloudbreak.service.DuplicateKeyValueException in project cloudbreak by hortonworks.

the class ConstraintTemplateService method create.

public ConstraintTemplate create(IdentityUser user, ConstraintTemplate constraintTemplate) {
    LOGGER.debug("Creating constraint template: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
    constraintTemplate.setOwner(user.getUserId());
    constraintTemplate.setAccount(user.getAccount());
    try {
        return constraintTemplateRepository.save(constraintTemplate);
    } catch (RuntimeException e) {
        throw new DuplicateKeyValueException(APIResourceType.CONSTRAINT_TEMPLATE, constraintTemplate.getName(), e);
    }
}
Also used : DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException)

Example 2 with DuplicateKeyValueException

use of com.sequenceiq.cloudbreak.service.DuplicateKeyValueException in project cloudbreak by hortonworks.

the class AmbariClusterService method create.

@Override
@Transactional(TxType.NEVER)
public Cluster create(IdentityUser user, Stack stack, Cluster cluster, List<ClusterComponent> components) {
    LOGGER.info("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();
    if (clusterRepository.findByNameInAccount(cluster.getName(), user.getAccount()) != null) {
        throw new DuplicateKeyValueException(APIResourceType.CLUSTER, cluster.getName());
    }
    LOGGER.info("Cluster name collision check took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    if (Status.CREATE_FAILED.equals(stack.getStatus())) {
        throw new BadRequestException("Stack creation failed, cannot create cluster.");
    }
    start = System.currentTimeMillis();
    for (HostGroup hostGroup : cluster.getHostGroups()) {
        constraintRepository.save(hostGroup.getConstraint());
    }
    LOGGER.info("Host group constrainst saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    start = System.currentTimeMillis();
    if (cluster.getFileSystem() != null) {
        fileSystemRepository.save(cluster.getFileSystem());
    }
    LOGGER.info("Filesystem config saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    if (cluster.getKerberosConfig() != null) {
        kerberosConfigRepository.save(cluster.getKerberosConfig());
    }
    cluster.setStack(stack);
    cluster.setOwner(user.getUserId());
    cluster.setAccount(user.getAccount());
    stack.setCluster(cluster);
    start = System.currentTimeMillis();
    generateSignKeys(cluster.getGateway());
    LOGGER.info("Sign key generated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    try {
        start = System.currentTimeMillis();
        cluster = clusterRepository.save(cluster);
        LOGGER.info("Cluster object saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        clusterComponentConfigProvider.store(components, cluster);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.CLUSTER, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
    if (stack.isAvailable()) {
        flowManager.triggerClusterInstall(stack.getId());
        InMemoryStateStore.putCluster(cluster.getId(), statusToPollGroupConverter.convert(cluster.getStatus()));
        if (InMemoryStateStore.getStack(stack.getId()) == null) {
            InMemoryStateStore.putStack(stack.getId(), statusToPollGroupConverter.convert(stack.getStatus()));
        }
    }
    return cluster;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Example 3 with DuplicateKeyValueException

use of com.sequenceiq.cloudbreak.service.DuplicateKeyValueException in project cloudbreak by hortonworks.

the class InteractiveCredentialCreationHandler method accept.

@Override
public void accept(Event<InteractiveCredentialCreationRequest> interactiveCredentialCreationRequestEvent) {
    InteractiveCredentialCreationRequest interactiveCredentialCreationRequest = interactiveCredentialCreationRequestEvent.getData();
    ExtendedCloudCredential extendedCloudCredential = interactiveCredentialCreationRequest.getExtendedCloudCredential();
    Credential credential = extendedCloudCredentialToCredentialConverter.convert(extendedCloudCredential);
    try {
        credentialService.createWithRetry(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), credential);
    } catch (DuplicateKeyValueException e) {
        sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), DuplicatedKeyValueExceptionMapper.errorMessage(e));
    } catch (BadRequestException e) {
        sendErrorNotification(extendedCloudCredential.getOwner(), extendedCloudCredential.getAccount(), extendedCloudCredential.getCloudPlatform(), e.getMessage());
    }
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) Credential(com.sequenceiq.cloudbreak.domain.Credential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InteractiveCredentialCreationRequest(com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationRequest) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException)

Example 4 with DuplicateKeyValueException

use of com.sequenceiq.cloudbreak.service.DuplicateKeyValueException in project cloudbreak by hortonworks.

the class TemplateService method create.

@Transactional(TxType.NEVER)
public Template create(IdentityUser user, Template template) {
    LOGGER.debug("Creating template: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
    Template savedTemplate;
    template.setOwner(user.getUserId());
    template.setAccount(user.getAccount());
    try {
        savedTemplate = templateRepository.save(template);
    } catch (Exception ex) {
        throw new DuplicateKeyValueException(APIResourceType.TEMPLATE, template.getName(), ex);
    }
    return savedTemplate;
}
Also used : DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Template(com.sequenceiq.cloudbreak.domain.Template) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException) Transactional(javax.transaction.Transactional)

Aggregations

DuplicateKeyValueException (com.sequenceiq.cloudbreak.service.DuplicateKeyValueException)4 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)3 Transactional (javax.transaction.Transactional)2 InteractiveCredentialCreationRequest (com.sequenceiq.cloudbreak.cloud.event.credential.InteractiveCredentialCreationRequest)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 Credential (com.sequenceiq.cloudbreak.domain.Credential)1 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)1 Template (com.sequenceiq.cloudbreak.domain.Template)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1