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