Search in sources :

Example 6 with ConstraintTemplate

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

the class ConstraintTemplateController method getPublics.

@Override
public Set<ConstraintTemplateResponse> getPublics() {
    IdentityUser user = authenticatedUserService.getCbUser();
    Set<ConstraintTemplate> templates = constraintTemplateService.retrieveAccountConstraintTemplates(user);
    return convert(templates);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) ConstraintTemplate(com.sequenceiq.cloudbreak.domain.ConstraintTemplate)

Example 7 with ConstraintTemplate

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

the class ConstraintTemplateController method createConstraintTemplate.

private ConstraintTemplateResponse createConstraintTemplate(IdentityUser user, ConstraintTemplateRequest constraintTemplateRequest, boolean publicInAccount) {
    ConstraintTemplate constraintTemplate = convert(constraintTemplateRequest, publicInAccount);
    constraintTemplate = constraintTemplateService.create(user, constraintTemplate);
    return conversionService.convert(constraintTemplate, ConstraintTemplateResponse.class);
}
Also used : ConstraintTemplate(com.sequenceiq.cloudbreak.domain.ConstraintTemplate)

Example 8 with ConstraintTemplate

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

the class ConstraintTemplateRequestToConstraintTemplateConverter method convert.

@Override
public ConstraintTemplate convert(ConstraintTemplateRequest source) {
    ConstraintTemplate constraintTemplate = new ConstraintTemplate();
    constraintTemplate.setCpu(source.getCpu());
    constraintTemplate.setMemory(source.getMemory());
    constraintTemplate.setDisk(source.getDisk());
    constraintTemplate.setOrchestratorType(source.getOrchestratorType());
    constraintTemplate.setName(source.getName());
    constraintTemplate.setDescription(source.getDescription());
    constraintTemplate.setStatus(ResourceStatus.USER_MANAGED);
    return constraintTemplate;
}
Also used : ConstraintTemplate(com.sequenceiq.cloudbreak.domain.ConstraintTemplate)

Example 9 with ConstraintTemplate

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

the class HostGroupDecorator method decorateConstraint.

private Constraint decorateConstraint(Long stackId, IdentityUser user, Constraint constraint, String instanceGroupName, String constraintTemplateName) {
    if (instanceGroupName != null) {
        InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stackId, instanceGroupName);
        if (instanceGroup == null) {
            LOGGER.error("Instance group not found: {}", instanceGroupName);
            throw new BadRequestException(String.format("Instance group '%s' not found on stack.", instanceGroupName));
        }
        constraint.setInstanceGroup(instanceGroup);
    }
    if (constraintTemplateName != null) {
        ConstraintTemplate constraintTemplate = constraintTemplateRepository.findByNameInAccount(constraintTemplateName, user.getAccount(), user.getUserId());
        if (constraintTemplate == null) {
            throw new BadRequestException(String.format("Couldn't find constraint template with name: %s", constraintTemplateName));
        }
        constraint.setConstraintTemplate(constraintTemplate);
    }
    return constraint;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) ConstraintTemplate(com.sequenceiq.cloudbreak.domain.ConstraintTemplate) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 10 with ConstraintTemplate

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

the class ConstraintTemplateService method getPublicTemplate.

public ConstraintTemplate getPublicTemplate(String name, IdentityUser user) {
    ConstraintTemplate constraintTemplate = constraintTemplateRepository.findOneByName(name, user.getAccount());
    if (constraintTemplate == null) {
        throw new NotFoundException(String.format(CONSTRAINT_NOT_FOUND_MSG, name));
    }
    authorizationService.hasReadPermission(constraintTemplate);
    return constraintTemplate;
}
Also used : ConstraintTemplate(com.sequenceiq.cloudbreak.domain.ConstraintTemplate) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException)

Aggregations

ConstraintTemplate (com.sequenceiq.cloudbreak.domain.ConstraintTemplate)12 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)4 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)4 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)1