Search in sources :

Example 21 with Template

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

the class TemplateService method getPublicTemplate.

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

Example 22 with Template

use of com.sequenceiq.cloudbreak.domain.Template 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;
}
Also used : DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Template(com.sequenceiq.cloudbreak.domain.Template) DuplicateKeyValueException(com.sequenceiq.cloudbreak.service.DuplicateKeyValueException) Transactional(javax.transaction.Transactional)

Example 23 with Template

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

the class UsageService method openUsagesForStack.

public void openUsagesForStack(Stack stack) {
    LocalDateTime ldt = LocalDateTime.now();
    List<CloudbreakUsage> usages = Lists.newArrayList();
    for (InstanceGroup ig : stack.getInstanceGroups()) {
        Template template = ig.getTemplate();
        String instanceType = template == null ? "undefined" : template.getInstanceType();
        String groupName = ig.getGroupName();
        Integer instanceNum = ig.getNodeCount();
        usages.add(usageGeneratorService.openNewUsage(stack, instanceType, instanceNum, groupName, ldt));
    }
    usageRepository.save(usages);
}
Also used : LocalDateTime(java.time.LocalDateTime) CloudbreakUsage(com.sequenceiq.cloudbreak.domain.CloudbreakUsage) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 24 with Template

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

the class InstanceGroupToInstanceGroupDetailsConverter method convert.

@Override
public InstanceGroupDetails convert(InstanceGroup source) {
    InstanceGroupDetails instanceGroupDetails = new InstanceGroupDetails();
    instanceGroupDetails.setGroupName(source.getGroupName());
    instanceGroupDetails.setGroupType(source.getInstanceGroupType().name());
    instanceGroupDetails.setNodeCount(source.getNodeCount());
    Template template = source.getTemplate();
    if (template != null) {
        instanceGroupDetails.setInstanceType(source.getTemplate().getInstanceType());
        instanceGroupDetails.setVolumeType(source.getTemplate().getVolumeType());
        instanceGroupDetails.setVolumeSize(source.getTemplate().getVolumeSize());
        instanceGroupDetails.setVolumeCount(source.getTemplate().getVolumeCount());
    }
    instanceGroupDetails.setSecurityGroup(conversionService.convert(source.getSecurityGroup(), SecurityGroupDetails.class));
    return instanceGroupDetails;
}
Also used : InstanceGroupDetails(com.sequenceiq.cloudbreak.structuredevent.event.InstanceGroupDetails) SecurityGroupDetails(com.sequenceiq.cloudbreak.structuredevent.event.SecurityGroupDetails) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 25 with Template

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

the class UserResourceCheck method hasResources.

@Transactional(readOnly = true)
public boolean hasResources(IdentityUser admin, String userId) {
    IdentityUser user = userDetailsService.getDetails(userId, UserFilterField.USERID);
    LOGGER.info("{} / {} checks resources of {}", admin.getUserId(), admin.getUsername(), userId);
    String errorMessage = null;
    if (!admin.getRoles().contains(IdentityUserRole.ADMIN)) {
        errorMessage = "Forbidden: user (%s) is not authorized for this operation on %s";
    }
    if (!admin.getAccount().equals(user.getAccount())) {
        errorMessage = "Forbidden: admin (%s) and user (%s) are not under the same account.";
    }
    if (!Strings.isNullOrEmpty(errorMessage)) {
        throw new AccessDeniedException(String.format(errorMessage, admin.getUsername(), user.getUsername()));
    }
    Set<Template> templates = templateRepository.findForUser(user.getUserId());
    Set<Credential> credentials = credentialRepository.findForUser(user.getUserId());
    Set<Blueprint> blueprints = blueprintRepository.findForUser(user.getUserId());
    Set<Network> networks = networkRepository.findForUser(user.getUserId());
    Set<Stack> stacks = stackRepository.findForUser(user.getUserId());
    return !(stacks.isEmpty() && templates.isEmpty() && credentials.isEmpty() && blueprints.isEmpty() && networks.isEmpty());
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Credential(com.sequenceiq.cloudbreak.domain.Credential) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Template(com.sequenceiq.cloudbreak.domain.Template) Stack(com.sequenceiq.cloudbreak.domain.Stack) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Network(com.sequenceiq.cloudbreak.domain.Network) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Template (com.sequenceiq.cloudbreak.domain.Template)25 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)6 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)5 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)5 Credential (com.sequenceiq.cloudbreak.domain.Credential)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Json (com.sequenceiq.cloudbreak.domain.json.Json)3 Test (org.junit.Test)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)2 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)2 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)2 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 SecurityGroup (com.sequenceiq.cloudbreak.domain.SecurityGroup)2