Search in sources :

Example 36 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project cloudbreak by hortonworks.

the class StackService method create.

@Transactional(TxType.NEVER)
public Stack create(IdentityUser user, Stack stack, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) {
    Stack savedStack;
    stack.setOwner(user.getUserId());
    stack.setAccount(user.getAccount());
    stack.setGatewayPort(nginxPort);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    try {
        if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
            long start = System.currentTimeMillis();
            rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
            LOGGER.info("RSA key has been validated in {} ms fot stack {}", System.currentTimeMillis() - start, stackName);
        }
        if (stack.getOrchestrator() != null) {
            orchestratorRepository.save(stack.getOrchestrator());
        }
        stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
        long start = System.currentTimeMillis();
        String template = connector.getTemplate(stack);
        LOGGER.info("Get cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        savedStack = stackRepository.save(stack);
        LOGGER.info("Stackrepository save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addTemplateForStack(stack, template);
        LOGGER.info("Save cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addCloudbreakDetailsForStack(stack);
        LOGGER.info("Add Cloudbreak template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        MDCBuilder.buildMdcContext(savedStack);
        start = System.currentTimeMillis();
        instanceGroupRepository.save(savedStack.getInstanceGroups());
        LOGGER.info("Instance groups saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        SecurityConfig securityConfig = tlsSecurityService.storeSSHKeys();
        LOGGER.info("Generating SSH keys took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        securityConfig.setSaltPassword(PasswordUtil.generatePassword());
        securityConfig.setSaltBootPassword(PasswordUtil.generatePassword());
        securityConfig.setKnoxMasterSecret(PasswordUtil.generatePassword());
        LOGGER.info("Generating salt passwords took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        securityConfig.setStack(stack);
        start = System.currentTimeMillis();
        securityConfigRepository.save(securityConfig);
        LOGGER.info("Security config save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        savedStack.setSecurityConfig(securityConfig);
        start = System.currentTimeMillis();
        imageService.create(savedStack, connector.getPlatformParameters(stack), imageCatalog, imageId, blueprint);
        LOGGER.info("Image creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.error("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.error("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    return savedStack;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) Stack(com.sequenceiq.cloudbreak.domain.Stack) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Transactional(javax.transaction.Transactional)

Example 37 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException 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 38 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException 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 39 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project cloudbreak by hortonworks.

the class LdapConfigService method create.

@Transactional(TxType.NEVER)
public LdapConfig create(IdentityUser user, LdapConfig ldapConfig) {
    ldapConfig.setOwner(user.getUserId());
    ldapConfig.setAccount(user.getAccount());
    try {
        return ldapConfigRepository.save(ldapConfig);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.LDAP_CONFIG, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Example 40 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project cloudbreak by hortonworks.

the class RecipeService method create.

@Transactional(TxType.NEVER)
public Recipe create(IdentityUser user, Recipe recipe) {
    recipe.setOwner(user.getUserId());
    recipe.setAccount(user.getAccount());
    try {
        return recipeRepository.save(recipe);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.RECIPE, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Aggregations

DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)117 Test (org.junit.Test)26 HashMap (java.util.HashMap)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.junit.jupiter.api.Test)10 Transactional (javax.transaction.Transactional)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 User (ca.corefacility.bioinformatics.irida.model.user.User)8 SQLException (java.sql.SQLException)8 ConstraintViolation (javax.validation.ConstraintViolation)8 HashSet (java.util.HashSet)7 Locale (java.util.Locale)6 ConstraintViolationException (javax.validation.ConstraintViolationException)6 Date (java.util.Date)5 List (java.util.List)5 Set (java.util.Set)5 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)4 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)4 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)4