Search in sources :

Example 16 with Template

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

the class TemplateRequestToTemplateConverter method convert.

@Override
public Template convert(TemplateRequest source) {
    Template template = new Template();
    if (Strings.isNullOrEmpty(source.getName())) {
        template.setName(missingResourceNameGenerator.generateName(APIResourceType.TEMPLATE));
    } else {
        template.setName(source.getName());
    }
    template.setDescription(source.getDescription());
    template.setStatus(ResourceStatus.USER_MANAGED);
    convertVolume(source, template);
    template.setCloudPlatform(source.getCloudPlatform());
    template.setInstanceType(source.getInstanceType() == null ? "" : source.getInstanceType());
    Map<String, Object> parameters = source.getParameters() == null ? Maps.newHashMap() : source.getParameters();
    CustomInstanceType customInstanceType = source.getCustomInstanceType();
    if (customInstanceType != null) {
        parameters.put(PlatformParametersConsts.CUSTOM_INSTANCETYPE_MEMORY, customInstanceType.getMemory());
        parameters.put(PlatformParametersConsts.CUSTOM_INSTANCETYPE_CPUS, customInstanceType.getCpus());
    }
    if (!parameters.isEmpty()) {
        try {
            template.setAttributes(new Json(parameters));
        } catch (JsonProcessingException ignored) {
            throw new BadRequestException("Invalid parameters");
        }
    }
    if (source.getTopologyId() != null) {
        template.setTopology(topologyService.getById(source.getTopologyId()));
    }
    return template;
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CustomInstanceType(com.sequenceiq.cloudbreak.api.model.CustomInstanceType) Json(com.sequenceiq.cloudbreak.domain.json.Json) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 17 with Template

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

the class InstanceGroupRequestToInstanceGroupConverter method convert.

@Override
public InstanceGroup convert(InstanceGroupRequest json) {
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName(json.getGroup());
    instanceGroup.setNodeCount(json.getNodeCount());
    instanceGroup.setInstanceGroupType(json.getType());
    try {
        if (json.getSecurityGroupId() != null) {
            instanceGroup.setSecurityGroup(securityGroupService.get(json.getSecurityGroupId()));
        }
    } catch (AccessDeniedException e) {
        throw new AccessDeniedException(String.format("Access to securitygroup '%s' is denied or securitygroup doesn't exist.", json.getSecurityGroupId()), e);
    }
    try {
        if (json.getTemplateId() != null) {
            instanceGroup.setTemplate(templateService.get(json.getTemplateId()));
        }
    } catch (AccessDeniedException e) {
        throw new AccessDeniedException(String.format("Access to template '%s' is denied or template doesn't exist.", json.getTemplateId()), e);
    }
    if (json.getTemplate() != null) {
        Template template = getConversionService().convert(json.getTemplate(), Template.class);
        instanceGroup.setTemplate(template);
    }
    if (json.getSecurityGroup() != null) {
        instanceGroup.setSecurityGroup(getConversionService().convert(json.getSecurityGroup(), SecurityGroup.class));
    }
    try {
        Json jsonProperties = new Json(json.getParameters());
        instanceGroup.setAttributes(jsonProperties);
    } catch (JsonProcessingException ignored) {
        instanceGroup.setAttributes(null);
    }
    return instanceGroup;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Json(com.sequenceiq.cloudbreak.domain.json.Json) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 18 with Template

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

the class StackDecorator method prepareInstanceGroups.

private void prepareInstanceGroups(Stack subject, StackRequest request, Credential credential, IdentityUser user) {
    Map<String, InstanceGroupParameterResponse> instanceGroupParameterResponse = cloudParameterService.getInstanceGroupParameters(credential, getInstanceGroupParameterRequests(subject));
    for (InstanceGroup instanceGroup : subject.getInstanceGroups()) {
        updateInstanceGroupParameters(instanceGroupParameterResponse, instanceGroup);
        if (instanceGroup.getTemplate() != null) {
            Template template = instanceGroup.getTemplate();
            if (template.getId() == null) {
                template.setPublicInAccount(subject.isPublicInAccount());
                template.setCloudPlatform(getCloudPlatform(subject, request, template.cloudPlatform()));
                templateValidator.validateTemplateRequest(credential, instanceGroup.getTemplate(), request.getRegion(), request.getAvailabilityZone(), request.getPlatformVariant());
                template = templateDecorator.decorate(credential, template, request.getRegion(), request.getAvailabilityZone(), request.getPlatformVariant());
                template = templateService.create(user, template);
            }
            instanceGroup.setTemplate(template);
        }
        if (instanceGroup.getSecurityGroup() != null) {
            SecurityGroup securityGroup = instanceGroup.getSecurityGroup();
            if (securityGroup.getId() == null) {
                securityGroup.setPublicInAccount(subject.isPublicInAccount());
                securityGroup.setCloudPlatform(getCloudPlatform(subject, request, securityGroup.getCloudPlatform()));
                securityGroup = securityGroupService.create(user, securityGroup);
                instanceGroup.setSecurityGroup(securityGroup);
            }
        }
    }
}
Also used : InstanceGroupParameterResponse(com.sequenceiq.cloudbreak.cloud.model.InstanceGroupParameterResponse) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 19 with Template

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

the class TestUtil method gcpTemplate.

public static Template gcpTemplate(Long id) {
    Template gcpTemplate = new Template();
    gcpTemplate.setInstanceType(N1_HIGHCPU_16_INSTANCE);
    gcpTemplate.setId(id);
    gcpTemplate.setCloudPlatform(GCP);
    gcpTemplate.setVolumeCount(1);
    gcpTemplate.setVolumeSize(100);
    gcpTemplate.setDescription(DUMMY_DESCRIPTION);
    gcpTemplate.setPublicInAccount(true);
    gcpTemplate.setStatus(ResourceStatus.DEFAULT);
    gcpTemplate.setName(DUMMY_NAME);
    return gcpTemplate;
}
Also used : Template(com.sequenceiq.cloudbreak.domain.Template)

Example 20 with Template

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

the class TestUtil method openstackTemplate.

public static Template openstackTemplate(Long id) {
    Template openStackTemplate = new Template();
    openStackTemplate.setInstanceType("Big");
    openStackTemplate.setCloudPlatform(OPENSTACK);
    openStackTemplate.setId(id);
    openStackTemplate.setVolumeCount(1);
    openStackTemplate.setVolumeSize(100);
    openStackTemplate.setName(DUMMY_NAME);
    openStackTemplate.setPublicInAccount(true);
    openStackTemplate.setStatus(ResourceStatus.DEFAULT);
    openStackTemplate.setDescription(DUMMY_DESCRIPTION);
    return openStackTemplate;
}
Also used : Template(com.sequenceiq.cloudbreak.domain.Template)

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