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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations