@Test public void testDecorator() { Template template = new Template(); template.setInstanceType(VM_TYPE); template.setCloudPlatform(PLATFORM_1); VolumeTemplate volumeTemplate = new VolumeTemplate(); volumeTemplate.setVolumeType(VOLUME_TYPE); template.setVolumeTemplates(Sets.newHashSet(volumeTemplate)); Platform platform = Platform.platform(PLATFORM_1); int minimumSize = 10; int maximumSize = 100; int minimumNumber = 1; int maximumNumber = 5; VolumeParameterConfig config = new VolumeParameterConfig(VolumeParameterType.MAGNETIC, minimumSize, maximumSize, minimumNumber, maximumNumber); VmTypeMeta vmTypeMeta = new VmTypeMeta(); vmTypeMeta.setMagneticConfig(config); Map<Platform, Map<String, VolumeParameterType>> diskMappings = newHashMap(); diskMappings.put(platform, singletonMap(VOLUME_TYPE, VolumeParameterType.MAGNETIC)); PlatformDisks platformDisk = new PlatformDisks(emptyMap(), emptyMap(), diskMappings, emptyMap()); CloudVmTypes cloudVmTypes = new CloudVmTypes(); Map<String, Set<VmType>> region1 = singletonMap(REGION, Collections.singleton(VmType.vmTypeWithMeta(VM_TYPE, vmTypeMeta, true))); cloudVmTypes.setCloudVmResponses(region1); when(cloudParameterService.getDiskTypes()).thenReturn(platformDisk); when(cloudParameterService.getVmTypesV2(eq(extendedCloudCredential), eq(REGION), eq(VARIANT), eq(CdpResourceType.DATAHUB), anyMap())).thenReturn(cloudVmTypes); when(locationService.location(REGION, AVAILABILITY_ZONE)).thenReturn(REGION); Template actual = underTest.decorate(cloudCredential, template, REGION, AVAILABILITY_ZONE, VARIANT, CdpResourceType.DATAHUB); VolumeTemplate next = actual.getVolumeTemplates().iterator().next(); assertEquals(maximumNumber, next.getVolumeCount().longValue()); assertEquals(maximumSize, next.getVolumeSize().longValue()); }
public Template decorate(Credential credential, Template template, String region, String availabilityZone, String variant, CdpResourceType cdpResourceType) { setRootVolumeSize(template); PlatformDisks platformDisks = cloudParameterService.getDiskTypes(); CloudVmTypes vmTypesV2 = cloudParameterService.getVmTypesV2( extendedCloudCredentialConverter.convert(credential), region, variant, cdpResourceType, new HashMap<>()); String locationString = locationService.location(region, availabilityZone); VolumeParameterConfig config; for (VolumeTemplate volumeTemplate : template.getVolumeTemplates()) { try { config = resolveVolumeParameterConfig(template, volumeTemplate, platformDisks, vmTypesV2, locationString); } catch (NoSuchElementException ignored) { LOGGER.debug("No VolumeParameterConfig found, which might be normal for platforms like OpenStack"); config = VolumeParameterConfig.EMPTY; } if (config.volumeParameterType() != null) { if (volumeTemplate.getVolumeCount() == null) { volumeTemplate.setVolumeCount(config.maximumNumber()); } if (volumeTemplate.getVolumeSize() == null) { volumeTemplate.setVolumeSize(config.maximumSize()); } } } return template; }
TemplateDecorator { public Template decorate(Credential credential, Template template, String region, String availabilityZone, String variant, CdpResourceType cdpResourceType) { setRootVolumeSize(template); PlatformDisks platformDisks = cloudParameterService.getDiskTypes(); CloudVmTypes vmTypesV2 = cloudParameterService.getVmTypesV2( extendedCloudCredentialConverter.convert(credential), region, variant, cdpResourceType, new HashMap<>()); String locationString = locationService.location(region, availabilityZone); VolumeParameterConfig config; for (VolumeTemplate volumeTemplate : template.getVolumeTemplates()) { try { config = resolveVolumeParameterConfig(template, volumeTemplate, platformDisks, vmTypesV2, locationString); } catch (NoSuchElementException ignored) { LOGGER.debug("No VolumeParameterConfig found, which might be normal for platforms like OpenStack"); config = VolumeParameterConfig.EMPTY; } if (config.volumeParameterType() != null) { if (volumeTemplate.getVolumeCount() == null) { volumeTemplate.setVolumeCount(config.maximumNumber()); } if (volumeTemplate.getVolumeSize() == null) { volumeTemplate.setVolumeSize(config.maximumSize()); } } } return template; } }
TemplateDecorator { public Template decorate(Credential credential, Template template, String region, String availabilityZone, String variant, CdpResourceType cdpResourceType) { setRootVolumeSize(template); PlatformDisks platformDisks = cloudParameterService.getDiskTypes(); CloudVmTypes vmTypesV2 = cloudParameterService.getVmTypesV2( extendedCloudCredentialConverter.convert(credential), region, variant, cdpResourceType, new HashMap<>()); String locationString = locationService.location(region, availabilityZone); VolumeParameterConfig config; for (VolumeTemplate volumeTemplate : template.getVolumeTemplates()) { try { config = resolveVolumeParameterConfig(template, volumeTemplate, platformDisks, vmTypesV2, locationString); } catch (NoSuchElementException ignored) { LOGGER.debug("No VolumeParameterConfig found, which might be normal for platforms like OpenStack"); config = VolumeParameterConfig.EMPTY; } if (config.volumeParameterType() != null) { if (volumeTemplate.getVolumeCount() == null) { volumeTemplate.setVolumeCount(config.maximumNumber()); } if (volumeTemplate.getVolumeSize() == null) { volumeTemplate.setVolumeSize(config.maximumSize()); } } } return template; }  }
TemplateDecorator { public Template decorate(Credential credential, Template template, String region, String availabilityZone, String variant, CdpResourceType cdpResourceType) { setRootVolumeSize(template); PlatformDisks platformDisks = cloudParameterService.getDiskTypes(); CloudVmTypes vmTypesV2 = cloudParameterService.getVmTypesV2( extendedCloudCredentialConverter.convert(credential), region, variant, cdpResourceType, new HashMap<>()); String locationString = locationService.location(region, availabilityZone); VolumeParameterConfig config; for (VolumeTemplate volumeTemplate : template.getVolumeTemplates()) { try { config = resolveVolumeParameterConfig(template, volumeTemplate, platformDisks, vmTypesV2, locationString); } catch (NoSuchElementException ignored) { LOGGER.debug("No VolumeParameterConfig found, which might be normal for platforms like OpenStack"); config = VolumeParameterConfig.EMPTY; } if (config.volumeParameterType() != null) { if (volumeTemplate.getVolumeCount() == null) { volumeTemplate.setVolumeCount(config.maximumNumber()); } if (volumeTemplate.getVolumeSize() == null) { volumeTemplate.setVolumeSize(config.maximumSize()); } } } return template; }  Template decorate(Credential credential, Template template, String region, String availabilityZone, String variant, CdpResourceType cdpResourceType); }
TemplateDecorator { public Template decorate(Credential credential, Template template, String region, String availabilityZone, String variant, CdpResourceType cdpResourceType) { setRootVolumeSize(template); PlatformDisks platformDisks = cloudParameterService.getDiskTypes(); CloudVmTypes vmTypesV2 = cloudParameterService.getVmTypesV2( extendedCloudCredentialConverter.convert(credential), region, variant, cdpResourceType, new HashMap<>()); String locationString = locationService.location(region, availabilityZone); VolumeParameterConfig config; for (VolumeTemplate volumeTemplate : template.getVolumeTemplates()) { try { config = resolveVolumeParameterConfig(template, volumeTemplate, platformDisks, vmTypesV2, locationString); } catch (NoSuchElementException ignored) { LOGGER.debug("No VolumeParameterConfig found, which might be normal for platforms like OpenStack"); config = VolumeParameterConfig.EMPTY; } if (config.volumeParameterType() != null) { if (volumeTemplate.getVolumeCount() == null) { volumeTemplate.setVolumeCount(config.maximumNumber()); } if (volumeTemplate.getVolumeSize() == null) { volumeTemplate.setVolumeSize(config.maximumSize()); } } } return template; }  Template decorate(Credential credential, Template template, String region, String availabilityZone, String variant, CdpResourceType cdpResourceType);  }