@Test void shouldNotSetVolumeEncryptionWhenAwsAndNotEntitled() { InstanceTemplateRequest source = new InstanceTemplateRequest(); source.setInstanceType(INSTANCE_TYPE); when(entitlementService.freeIpaDlEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, ACCOUNT_ID)).thenReturn(false); Template result = underTest.convert(source, CLOUD_PLATFORM, ACCOUNT_ID); Json attributes = result.getAttributes(); assertThat(attributes).isNotNull(); assertThat(attributes.<Object>getValue(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED)).isNull(); assertThat(attributes.<Object>getValue(InstanceTemplate.VOLUME_ENCRYPTION_KEY_TYPE)).isNull(); }
public Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId) { Template template = new Template(); 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 && entitlementService.freeIpaDlEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)) { attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE); attributes.put(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, entitlementService.fastEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)); 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()); } } ); template.setAttributes(new Json(attributes)); return template; }
InstanceTemplateRequestToTemplateConverter { public Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId) { Template template = new Template(); 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 && entitlementService.freeIpaDlEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)) { attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE); attributes.put(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, entitlementService.fastEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)); 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()); } } ); template.setAttributes(new Json(attributes)); return template; } }
InstanceTemplateRequestToTemplateConverter { public Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId) { Template template = new Template(); 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 && entitlementService.freeIpaDlEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)) { attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE); attributes.put(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, entitlementService.fastEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)); 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()); } } ); template.setAttributes(new Json(attributes)); return template; }  }
InstanceTemplateRequestToTemplateConverter { public Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId) { Template template = new Template(); 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 && entitlementService.freeIpaDlEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)) { attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE); attributes.put(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, entitlementService.fastEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)); 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()); } } ); template.setAttributes(new Json(attributes)); return template; }  Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId); }
InstanceTemplateRequestToTemplateConverter { public Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId) { Template template = new Template(); 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 && entitlementService.freeIpaDlEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)) { attributes.put(AwsInstanceTemplate.EBS_ENCRYPTION_ENABLED, Boolean.TRUE); attributes.put(AwsInstanceTemplate.FAST_EBS_ENCRYPTION_ENABLED, entitlementService.fastEbsEncryptionEnabled(INTERNAL_ACTOR_CRN, accountId)); 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()); } } ); template.setAttributes(new Json(attributes)); return template; }  Template convert(InstanceTemplateRequest source, CloudPlatform cloudPlatform, String accountId);  }