Search in sources :

Example 6 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateController method createClusterTemplateRequest.

private ClusterTemplateResponse createClusterTemplateRequest(IdentityUser user, ClusterTemplateRequest clusterTemplateRequest, boolean publicInAccount) {
    ClusterTemplate clusterTemplate = conversionService.convert(clusterTemplateRequest, ClusterTemplate.class);
    clusterTemplate.setPublicInAccount(publicInAccount);
    clusterTemplate = clusterTemplateService.create(user, clusterTemplate);
    notify(user, ResourceEvent.CLUSTER_TEMPLATE_CREATED);
    return conversionService.convert(clusterTemplate, ClusterTemplateResponse.class);
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.ClusterTemplate)

Example 7 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateController method getPrivate.

@Override
public ClusterTemplateResponse getPrivate(String name) {
    IdentityUser user = authenticatedUserService.getCbUser();
    ClusterTemplate clusterTemplate = clusterTemplateService.getPrivateClusterTemplate(name, user);
    return conversionService.convert(clusterTemplate, ClusterTemplateResponse.class);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) ClusterTemplate(com.sequenceiq.cloudbreak.domain.ClusterTemplate)

Example 8 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateRequestToClusterTemplateConverter method convert.

@Override
public ClusterTemplate convert(ClusterTemplateRequest json) {
    ClusterTemplate clusterTemplate = new ClusterTemplate();
    clusterTemplate.setName(json.getName());
    try {
        clusterTemplate.setTemplate(new Json(json.getTemplate()));
    } catch (JsonProcessingException e) {
        LOGGER.error("Cloudtemplate cannot be converted to JSON: " + json.getTemplate(), e);
        throw new BadRequestException("Cloudtemplate cannot be converted to JSON", e);
    }
    clusterTemplate.setType(json.getType());
    return clusterTemplate;
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.ClusterTemplate) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 9 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateService method getByName.

public ClusterTemplate getByName(String name, IdentityUser user) {
    ClusterTemplate clusterTemplate = clusterTemplateRepository.findByNameInAccount(name, user.getAccount(), user.getUserId());
    if (clusterTemplate == null) {
        throw new NotFoundException(String.format("Blueprint '%s' not found.", name));
    }
    authorizationService.hasReadPermission(clusterTemplate);
    return clusterTemplate;
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.ClusterTemplate) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException)

Example 10 with ClusterTemplate

use of com.sequenceiq.cloudbreak.domain.ClusterTemplate in project cloudbreak by hortonworks.

the class ClusterTemplateService method create.

@Transactional(TxType.NEVER)
public ClusterTemplate create(IdentityUser user, ClusterTemplate clusterTemplate) {
    LOGGER.debug("Creating clusterTemplate: [User: '{}', Account: '{}']", user.getUsername(), user.getAccount());
    ClusterTemplate savedClusterTemplate;
    clusterTemplate.setOwner(user.getUserId());
    clusterTemplate.setAccount(user.getAccount());
    try {
        savedClusterTemplate = clusterTemplateRepository.save(clusterTemplate);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.CLUSTER_TEMPLATE, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    }
    return savedClusterTemplate;
}
Also used : ClusterTemplate(com.sequenceiq.cloudbreak.domain.ClusterTemplate) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Transactional(javax.transaction.Transactional)

Aggregations

ClusterTemplate (com.sequenceiq.cloudbreak.domain.ClusterTemplate)11 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)4 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)4 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Json (com.sequenceiq.cloudbreak.domain.json.Json)1 Transactional (javax.transaction.Transactional)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1