use of com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta in project cloudbreak by hortonworks.
the class TemplateDecoratorTest method testDecoratorWhenNoInstanceType.
@Test
public void testDecoratorWhenNoInstanceType() {
String vmType = "vmType";
String platform1 = "platform";
String volumeType = "volumeType";
String region = "region";
String availibilityZone = "availabilityZone";
String variant = "variant";
Credential cloudCredential = mock(Credential.class);
Template template = new Template();
template.setInstanceType("missingVmType");
template.setCloudPlatform(platform1);
template.setVolumeType(volumeType);
Platform platform = Platform.platform(platform1);
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(volumeType, 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(vmType, vmTypeMeta, true)));
cloudVmTypes.setCloudVmResponses(region1);
when(cloudParameterService.getDiskTypes()).thenReturn(platformDisk);
when(cloudParameterService.getVmTypesV2(eq(cloudCredential), eq(region), eq(variant), anyMap())).thenReturn(cloudVmTypes);
when(locationService.location(region, availibilityZone)).thenReturn(region);
Template actual = underTest.decorate(cloudCredential, template, region, availibilityZone, variant);
Assert.assertNull(actual.getVolumeCount());
Assert.assertNull(actual.getVolumeSize());
}
use of com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta in project cloudbreak by hortonworks.
the class AwsPlatformResources method readVmTypes.
private void readVmTypes() {
Map<String, VmType> vmTypeMap = new TreeMap<>();
String vm = getDefinition(awsVmParameterDefinitionPath, "vm");
String zoneVms = getDefinition(awsVmParameterDefinitionPath, "zone-vm");
try {
VmsSpecification oVms = JsonUtil.readValue(vm, VmsSpecification.class);
for (VmSpecification vmSpecification : oVms.getItems()) {
VmTypeMetaBuilder builder = VmTypeMetaBuilder.builder().withCpuAndMemory(vmSpecification.getMetaSpecification().getProperties().getCpu(), vmSpecification.getMetaSpecification().getProperties().getMemory()).withPrice(vmSpecification.getMetaSpecification().getProperties().getPrice());
for (ConfigSpecification configSpecification : vmSpecification.getMetaSpecification().getConfigSpecification()) {
addConfig(builder, configSpecification);
}
VmTypeMeta vmTypeMeta = builder.create();
vmTypeMap.put(vmSpecification.getValue(), VmType.vmTypeWithMeta(vmSpecification.getValue(), vmTypeMeta, vmSpecification.getExtended()));
}
ZoneVmSpecifications zoneVmSpecifications = JsonUtil.readValue(zoneVms, ZoneVmSpecifications.class);
for (ZoneVmSpecification zvs : zoneVmSpecifications.getItems()) {
Set<VmType> regionVmTypes = new HashSet<>();
for (String vmTypeString : zvs.getVmTypes()) {
VmType vmType = vmTypeMap.get(vmTypeString);
if (vmType != null) {
regionVmTypes.add(vmType);
}
}
vmTypes.put(region(zvs.getZone()), regionVmTypes);
VmType vmType = vmTypeMap.get(zvs.getDefaultVmType());
if (vmType != null) {
defaultVmTypes.put(region(zvs.getZone()), vmType);
}
}
} catch (IOException e) {
LOGGER.error("Cannot initialize platform parameters for aws", e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta in project cloudbreak by hortonworks.
the class TemplateDecoratorTest method testDecorator.
@Test
public void testDecorator() {
String vmType = "vmType";
String platform1 = "platform";
String volumeType = "volumeType";
String region = "region";
String availibilityZone = "availabilityZone";
String variant = "variant";
Credential cloudCredential = mock(Credential.class);
Template template = new Template();
template.setInstanceType(vmType);
template.setCloudPlatform(platform1);
template.setVolumeType(volumeType);
Platform platform = Platform.platform(platform1);
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(volumeType, 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(vmType, vmTypeMeta, true)));
cloudVmTypes.setCloudVmResponses(region1);
when(cloudParameterService.getDiskTypes()).thenReturn(platformDisk);
when(cloudParameterService.getVmTypesV2(eq(cloudCredential), eq(region), eq(variant), anyMap())).thenReturn(cloudVmTypes);
when(locationService.location(region, availibilityZone)).thenReturn(region);
Template actual = underTest.decorate(cloudCredential, template, region, availibilityZone, variant);
Assert.assertEquals(maximumNumber, actual.getVolumeCount().longValue());
Assert.assertEquals(maximumSize, actual.getVolumeSize().longValue());
}
use of com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta in project cloudbreak by hortonworks.
the class GcpPlatformResources method virtualMachines.
@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
Compute compute = GcpStackUtil.buildCompute(cloudCredential);
String projectId = GcpStackUtil.getProjectId(cloudCredential);
Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
try {
Set<VmType> types = new HashSet<>();
VmType defaultVmType = null;
CloudRegions regions = regions(cloudCredential, region, filters);
for (AvailabilityZone availabilityZone : regions.getCloudRegions().get(region)) {
MachineTypeList machineTypeList = compute.machineTypes().list(projectId, availabilityZone.value()).execute();
for (MachineType machineType : machineTypeList.getItems()) {
VmTypeMeta vmTypeMeta = VmTypeMetaBuilder.builder().withCpuAndMemory(machineType.getGuestCpus(), machineType.getMemoryMb().floatValue() / THOUSAND).withMagneticConfig(TEN, machineType.getMaximumPersistentDisksSizeGb().intValue(), 1, machineType.getMaximumPersistentDisksSizeGb().intValue()).withSsdConfig(TEN, machineType.getMaximumPersistentDisksSizeGb().intValue(), 1, machineType.getMaximumPersistentDisks()).withMaximumPersistentDisksSizeGb(machineType.getMaximumPersistentDisksSizeGb().toString()).create();
VmType vmType = VmType.vmTypeWithMeta(machineType.getName(), vmTypeMeta, true);
types.add(vmType);
if (machineType.getName().equals(gcpVmDefault)) {
defaultVmType = vmType;
}
}
cloudVmResponses.put(availabilityZone.value(), types);
defaultCloudVmResponses.put(availabilityZone.value(), defaultVmType);
}
return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
} catch (Exception e) {
return new CloudVmTypes(new HashMap<>(), new HashMap<>());
}
}
Aggregations