use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.
the class StackToCreateFreeIpaRequestConverter method getInstanceTemplateRequest.
private InstanceTemplateRequest getInstanceTemplateRequest(Template template) {
InstanceTemplateRequest request = null;
if (template != null) {
request = new InstanceTemplateRequest();
request.setInstanceType(template.getInstanceType());
Integer spotPercentage = template.getAttributes().getValue(AwsInstanceTemplate.EC2_SPOT_PERCENTAGE);
Double maxPrice = template.getAttributes().getValue(AwsInstanceTemplate.EC2_SPOT_MAX_PRICE);
if (spotPercentage != null) {
LOGGER.debug("EC2 spot percentage found in the instances template attributes");
AwsInstanceTemplateParameters aws = new AwsInstanceTemplateParameters();
AwsInstanceTemplateSpotParameters spot = new AwsInstanceTemplateSpotParameters();
spot.setPercentage(spotPercentage);
if (maxPrice != null) {
LOGGER.debug("EC2 max price found in the instances template attributes");
spot.setMaxPrice(maxPrice);
}
aws.setSpot(spot);
request.setAws(aws);
}
VolumeRequest volumeRequest = new VolumeRequest();
volumeRequest.setType(template.getVolumeType());
volumeRequest.setCount(template.getVolumeCount());
volumeRequest.setSize(template.getVolumeSize());
request.setAttachedVolumes(Optional.of(volumeRequest).filter(v -> v.getCount() != null && v.getCount() > 0 && v.getSize() != null && v.getSize() > 0).stream().collect(Collectors.toSet()));
}
LOGGER.debug("Created instance template request {} from instance template {}", request, template);
return request;
}
use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.
the class InstanceTemplateRequestToTemplateConverter method convert.
public Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId, String diskEncryptionSetId, String gcpKmsEncryptionKey, String awsKmsEncryptionKey) {
Template template = new Template();
template.setAccountId(accountId);
template.setName(missingResourceNameGenerator.generateName(APIResourceType.TEMPLATE));
template.setStatus(ResourceStatus.USER_MANAGED);
setVolumesProperty(source.getAttachedVolumes(), template, cloudPlatform);
template.setInstanceType(Objects.requireNonNullElse(source.getInstanceType(), defaultInstanceTypeProvider.getForPlatform(cloudPlatform.name())));
Map<String, Object> attributes = new HashMap<>();
if (cloudPlatform == CloudPlatform.AWS) {
if (awsKmsEncryptionKey != null) {
attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE);
attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM.name());
attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, awsKmsEncryptionKey);
} else {
attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE);
attributes.put(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.DEFAULT.name());
}
}
Optional.ofNullable(source.getAws()).map(AwsInstanceTemplateParameters::getSpot).ifPresent(spotParameters -> {
attributes.put(AwsInstanceTemplate.EC2_SPOT_PERCENTAGE, spotParameters.getPercentage());
if (Objects.nonNull(spotParameters.getMaxPrice())) {
attributes.put(AwsInstanceTemplate.EC2_SPOT_MAX_PRICE, spotParameters.getMaxPrice());
}
});
if (cloudPlatform == CloudPlatform.AZURE) {
if (diskEncryptionSetId != null) {
attributes.put(AzureInstanceTemplate.DISK_ENCRYPTION_SET_ID, diskEncryptionSetId);
attributes.put(AzureInstanceTemplate.MANAGED_DISK_ENCRYPTION_WITH_CUSTOM_KEY_ENABLED, true);
}
if (entitlementService.isAzureEncryptionAtHostEnabled(accountId)) {
attributes.put(AzureInstanceTemplate.ENCRYPTION_AT_HOST_ENABLED, true);
}
}
if (gcpKmsEncryptionKey != null && cloudPlatform == CloudPlatform.GCP) {
attributes.put(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_ID, gcpKmsEncryptionKey);
attributes.put(GcpInstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE, EncryptionType.CUSTOM);
attributes.put(GcpInstanceTemplate.KEY_ENCRYPTION_METHOD, KeyEncryptionMethod.KMS);
}
template.setAttributes(new Json(attributes));
return template;
}
use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.
the class InstanceMetaDataToCloudInstanceConverter method convert.
public CloudInstance convert(InstanceMetaData metaDataEntity) {
InstanceGroup group = metaDataEntity.getInstanceGroup();
Optional<StackAuthenticationView> stackAuthenticationView = instanceMetaDataService.getStackAuthenticationViewByInstanceMetaDataId(metaDataEntity.getId());
Template template = metaDataEntity.getInstanceGroup().getTemplate();
Optional<StackAuthentication> stackAuthentication = stackAuthenticationView.map(StackAuthenticationView::getStackAuthentication);
InstanceStatus status = getInstanceStatus(metaDataEntity);
String imageId = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackId -> imageService.getByStackId(stackId)).map(ImageEntity::getImageName).orElse(null);
InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEntity.getPrivateId(), status, imageId);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.map(StackAuthentication::getPublicKey).orElse(null), stackAuthentication.map(StackAuthentication::getPublicKeyId).orElse(null), stackAuthentication.map(StackAuthentication::getLoginUserName).orElse(null));
Map<String, Object> params = new HashMap<>();
params.put(SUBNET_ID, metaDataEntity.getSubnetId());
params.put(CloudInstance.INSTANCE_NAME, metaDataEntity.getInstanceName());
Stack stack = stackAuthenticationView.map(StackAuthenticationView::getStackId).map(stackService::getStackById).orElseThrow(NotFoundException::new);
Map<String, Object> cloudInstanceParameters = stackToCloudStackConverter.buildCloudInstanceParameters(stack.getEnvironmentCrn(), metaDataEntity);
params.putAll(cloudInstanceParameters);
return new CloudInstance(metaDataEntity.getInstanceId(), instanceTemplate, instanceAuthentication, metaDataEntity.getSubnetId(), stack.getAvailabilityZone(), params);
}
use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.
the class FreeIpaRecommendationServiceTest method createStack.
private Stack createStack(String instanceType) {
Stack stack = new Stack();
stack.setCloudPlatform("AWS");
stack.setRegion("eu-central-1");
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setGroupName("master");
Template template = new Template();
template.setInstanceType(instanceType);
instanceGroup.setTemplate(template);
stack.getInstanceGroups().add(instanceGroup);
return stack;
}
use of com.sequenceiq.freeipa.entity.Template in project cloudbreak by hortonworks.
the class DefaultInstanceGroupProviderTest method createDefaultTemplateTestVolumeEncryptionAddedWhenAzureAndNoDESAndEncryptionAtHostEnabled.
@Test
void createDefaultTemplateTestVolumeEncryptionAddedWhenAzureAndNoDESAndEncryptionAtHostEnabled() {
when(entitlementService.isAzureEncryptionAtHostEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
Template result = underTest.createDefaultTemplate(CloudPlatform.AZURE, ACCOUNT_ID, null, null, null);
assertThat(result).isNotNull();
Json attributes = result.getAttributes();
assertThat(attributes).isNotNull();
assertThat(attributes.<Object>getValue(AzureInstanceTemplate.ENCRYPTION_AT_HOST_ENABLED)).isEqualTo(Boolean.TRUE);
}
Aggregations