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