Search in sources :

Example 1 with CustomInstanceType

use of com.sequenceiq.cloudbreak.api.model.CustomInstanceType 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)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 CustomInstanceType (com.sequenceiq.cloudbreak.api.model.CustomInstanceType)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 Template (com.sequenceiq.cloudbreak.domain.Template)1 Json (com.sequenceiq.cloudbreak.domain.json.Json)1