use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes in project cloudbreak by hortonworks.
the class AwsPlatformResources method virtualMachines.
@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
CloudRegions regions = regions(cloudCredential, region, filters);
Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
for (AvailabilityZone availabilityZone : regions.getCloudRegions().get(region)) {
cloudVmResponses.put(availabilityZone.value(), vmTypes.get(region));
defaultCloudVmResponses.put(availabilityZone.value(), defaultVmTypes.get(region));
}
return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes in project cloudbreak by hortonworks.
the class AzurePlatformResources method virtualMachines.
@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
AzureClient client = azureClientService.getClient(cloudCredential);
Set<VirtualMachineSize> vmTypes = client.getVmTypes(region.value());
Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
Set<VmType> types = new HashSet<>();
VmType defaultVmType = null;
for (VirtualMachineSize virtualMachineSize : vmTypes) {
float memoryInGB = virtualMachineSize.memoryInMB() / NO_MB_PER_GB;
VmTypeMetaBuilder builder = VmTypeMetaBuilder.builder().withCpuAndMemory(virtualMachineSize.numberOfCores(), memoryInGB);
for (VolumeParameterType volumeParameterType : values()) {
switch(volumeParameterType) {
case MAGNETIC:
builder.withMagneticConfig(volumeParameterConfig(MAGNETIC, virtualMachineSize));
break;
default:
break;
}
}
VmType vmType = VmType.vmTypeWithMeta(virtualMachineSize.name(), builder.create(), true);
types.add(vmType);
if (virtualMachineSize.name().equals(armVmDefault)) {
defaultVmType = vmType;
}
}
cloudVmResponses.put(region.value(), types);
defaultCloudVmResponses.put(region.value(), defaultVmType);
return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes in project cloudbreak by hortonworks.
the class OpenStackPlatformResourcesTest method testVirtualMachines.
@Test
public void testVirtualMachines() {
CloudCredential cloudCredential = new CloudCredential(0L, "name");
OSClient osClient = mock(OSClient.class);
String regionName = "region1";
Set<String> regionsFromOpenStack = Sets.newHashSet(regionName);
List<AvailabilityZone> availabilityZones = newArrayList(new AvailabilityZone("zone1"));
Flavor flavor8GB = flavor(8192);
when(openStackClient.createOSClient(cloudCredential)).thenReturn(osClient);
when(openStackClient.getRegion(cloudCredential)).thenReturn(regionsFromOpenStack);
when(openStackClient.getZones(osClient, regionName)).thenReturn(availabilityZones);
when(openStackClient.getFlavors(osClient)).thenReturn((List) Collections.singletonList(flavor8GB));
CloudVmTypes actual = underTest.virtualMachines(cloudCredential, null, null);
Assert.assertEquals(1, actual.getCloudVmResponses().get("zone1").size());
Assert.assertEquals(1, actual.getDefaultCloudVmResponses().size());
Assert.assertEquals("8.0", actual.getCloudVmResponses().get("zone1").iterator().next().getMetaData().getProperties().get("Memory"));
Assert.assertNotNull(actual.getDefaultCloudVmResponses().get(regionName));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes in project cloudbreak by hortonworks.
the class OpenStackPlatformResources method virtualMachines.
@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);
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.info("openstack virtual machine types: {}", cloudVmTypes);
return cloudVmTypes;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes in project cloudbreak by hortonworks.
the class TemplateDecoratorTest method testDecoratorWhenNoLocation.
@Test
public void testDecoratorWhenNoLocation() {
String region = "region";
String availibilityZone = "availabilityZone";
String variant = "variant";
String vmType = "vmType";
Template template = new Template();
Credential cloudCredential = mock(Credential.class);
CloudVmTypes cloudVmTypes = new CloudVmTypes(singletonMap(region, emptySet()), emptyMap());
when(cloudParameterService.getVmTypesV2(eq(cloudCredential), eq(region), eq(variant), anyMap())).thenReturn(cloudVmTypes);
when(locationService.location(region, availibilityZone)).thenReturn(null);
Template actual = underTest.decorate(cloudCredential, template, region, availibilityZone, variant);
Assert.assertNull(actual.getVolumeCount());
Assert.assertNull(actual.getVolumeSize());
}
Aggregations