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;
}
Aggregations