@Test public void testVirtualMachinesWhenTypesEmpty() { CloudCredential cloudCredential = new CloudCredential("crn", "name"); OSClient osClient = mock(OSClient.class); String regionName = "region1"; Set<String> regionsFromOpenStack = Sets.newHashSet(regionName); List<AvailabilityZone> availabilityZones = newArrayList(new AvailabilityZone("zone1")); when(openStackClient.createOSClient(cloudCredential)).thenReturn(osClient); when(openStackClient.getRegion(cloudCredential)).thenReturn(regionsFromOpenStack); when(openStackClient.getFlavors(osClient)).thenReturn(emptyList()); when(openStackAvailabilityZoneProvider.getAvailabilityZones(openStackClient, osClient, regionName, cloudCredential)) .thenReturn(availabilityZones); CloudVmTypes actual = underTest.virtualMachines(cloudCredential, null, null); verify(openStackClient, times(1)).getFlavors(osClient); Assert.assertEquals(0L, actual.getCloudVmResponses().get("zone1").size()); Assert.assertNull(actual.getDefaultCloudVmResponses().get(regionName)); }
@Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); Map<String, Set<VmType>> cloudVmResponses = new HashMap<>(); Map<String, VmType> defaultCloudVmResponses = new HashMap<>(); CloudRegions regions = regions(cloudCredential, region, filters, true); regions.getCloudRegions().forEach((cloudRegion, availabilityZones) -> { Set<VmType> types = collectVmTypes(osClient); convertVmSizeToGB(types); availabilityZones.forEach(availabilityZone -> cloudVmResponses.put(availabilityZone.value(), types)); defaultCloudVmResponses.put(cloudRegion.value(), types.isEmpty() ? null : (VmType) types.toArray()[0]); }); CloudVmTypes cloudVmTypes = new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses); LOGGER.debug("Openstack virtual machine types: {}", cloudVmTypes); return cloudVmTypes; }
OpenStackPlatformResources implements PlatformResources { @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); Map<String, Set<VmType>> cloudVmResponses = new HashMap<>(); Map<String, VmType> defaultCloudVmResponses = new HashMap<>(); CloudRegions regions = regions(cloudCredential, region, filters, true); regions.getCloudRegions().forEach((cloudRegion, availabilityZones) -> { Set<VmType> types = collectVmTypes(osClient); convertVmSizeToGB(types); availabilityZones.forEach(availabilityZone -> cloudVmResponses.put(availabilityZone.value(), types)); defaultCloudVmResponses.put(cloudRegion.value(), types.isEmpty() ? null : (VmType) types.toArray()[0]); }); CloudVmTypes cloudVmTypes = new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses); LOGGER.debug("Openstack virtual machine types: {}", cloudVmTypes); return cloudVmTypes; } }
OpenStackPlatformResources implements PlatformResources { @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); Map<String, Set<VmType>> cloudVmResponses = new HashMap<>(); Map<String, VmType> defaultCloudVmResponses = new HashMap<>(); CloudRegions regions = regions(cloudCredential, region, filters, true); regions.getCloudRegions().forEach((cloudRegion, availabilityZones) -> { Set<VmType> types = collectVmTypes(osClient); convertVmSizeToGB(types); availabilityZones.forEach(availabilityZone -> cloudVmResponses.put(availabilityZone.value(), types)); defaultCloudVmResponses.put(cloudRegion.value(), types.isEmpty() ? null : (VmType) types.toArray()[0]); }); CloudVmTypes cloudVmTypes = new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses); LOGGER.debug("Openstack virtual machine types: {}", cloudVmTypes); return cloudVmTypes; }  }
OpenStackPlatformResources implements PlatformResources { @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); Map<String, Set<VmType>> cloudVmResponses = new HashMap<>(); Map<String, VmType> defaultCloudVmResponses = new HashMap<>(); CloudRegions regions = regions(cloudCredential, region, filters, true); regions.getCloudRegions().forEach((cloudRegion, availabilityZones) -> { Set<VmType> types = collectVmTypes(osClient); convertVmSizeToGB(types); availabilityZones.forEach(availabilityZone -> cloudVmResponses.put(availabilityZone.value(), types)); defaultCloudVmResponses.put(cloudRegion.value(), types.isEmpty() ? null : (VmType) types.toArray()[0]); }); CloudVmTypes cloudVmTypes = new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses); LOGGER.debug("Openstack virtual machine types: {}", cloudVmTypes); return cloudVmTypes; }  @PostConstruct void init(); String resourceDefinition(String resource); @Override CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded); @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudAccessConfigs accessConfigs(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudEncryptionKeys encryptionKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudNoSqlTables noSqlTables(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudResourceGroups resourceGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters); }
OpenStackPlatformResources implements PlatformResources { @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); Map<String, Set<VmType>> cloudVmResponses = new HashMap<>(); Map<String, VmType> defaultCloudVmResponses = new HashMap<>(); CloudRegions regions = regions(cloudCredential, region, filters, true); regions.getCloudRegions().forEach((cloudRegion, availabilityZones) -> { Set<VmType> types = collectVmTypes(osClient); convertVmSizeToGB(types); availabilityZones.forEach(availabilityZone -> cloudVmResponses.put(availabilityZone.value(), types)); defaultCloudVmResponses.put(cloudRegion.value(), types.isEmpty() ? null : (VmType) types.toArray()[0]); }); CloudVmTypes cloudVmTypes = new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses); LOGGER.debug("Openstack virtual machine types: {}", cloudVmTypes); return cloudVmTypes; }  @PostConstruct void init(); String resourceDefinition(String resource); @Override CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override @Cacheable(cacheNames = "cloudResourceRegionCache", key = "{ #cloudCredential?.id, #availabilityZonesNeeded }") CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded); @Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudGateWays gateways(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudAccessConfigs accessConfigs(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudEncryptionKeys encryptionKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudNoSqlTables noSqlTables(CloudCredential cloudCredential, Region region, Map<String, String> filters); @Override CloudResourceGroups resourceGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters);  }