use of com.sequenceiq.cloudbreak.cloud.model.VmType 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.VmType 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.VmType 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.VmType in project cloudbreak by hortonworks.
the class CloudVmTypesToPlatformVmTypesResponseConverter method convert.
@Override
public PlatformVmtypesResponse convert(CloudVmTypes source) {
Map<String, VirtualMachinesResponse> result = new HashMap<>();
for (Entry<String, Set<VmType>> entry : source.getCloudVmResponses().entrySet()) {
Set<VmTypeJson> vmTypeJsons = new HashSet<>();
for (VmType vmType : entry.getValue()) {
vmTypeJsons.add(getConversionService().convert(vmType, VmTypeJson.class));
}
VmTypeJson defaultVmType = getConversionService().convert(source.getDefaultCloudVmResponses().get(entry.getKey()), VmTypeJson.class);
VirtualMachinesResponse virtualMachinesResponse = new VirtualMachinesResponse();
virtualMachinesResponse.setDefaultVirtualMachine(defaultVmType);
virtualMachinesResponse.setVirtualMachines(vmTypeJsons);
result.put(entry.getKey(), virtualMachinesResponse);
}
return new PlatformVmtypesResponse(result);
}
use of com.sequenceiq.cloudbreak.cloud.model.VmType in project cloudbreak by hortonworks.
the class TemplateValidator method validateTemplateRequest.
public void validateTemplateRequest(Credential credential, Template value, String region, String availabilityZone, String variant) {
CloudVmTypes cloudVmTypes = cloudParameterService.getVmTypesV2(credential, region, variant, new HashMap<>());
if (StringUtils.isEmpty(value.getInstanceType())) {
validateCustomInstanceType(value);
} else {
VmType vmType = null;
VolumeParameterType volumeParameterType = null;
Platform platform = Platform.platform(value.cloudPlatform());
Map<String, Set<VmType>> machines = cloudVmTypes.getCloudVmResponses();
String locationString = locationService.location(region, availabilityZone);
if (machines.containsKey(locationString) && !machines.get(locationString).isEmpty()) {
for (VmType type : machines.get(locationString)) {
if (type.value().equals(value.getInstanceType())) {
vmType = type;
break;
}
}
if (vmType == null) {
throw new BadRequestException(String.format("The '%s' instance type isn't supported by '%s' platform", value.getInstanceType(), platform.value()));
}
}
Map<Platform, Map<String, VolumeParameterType>> disks = diskMappings.get();
if (disks.containsKey(platform) && !disks.get(platform).isEmpty()) {
Map<String, VolumeParameterType> map = disks.get(platform);
volumeParameterType = map.get(value.getVolumeType());
if (volumeParameterType == null) {
throw new BadRequestException(String.format("The '%s' volume type isn't supported by '%s' platform", value.getVolumeType(), platform.value()));
}
}
validateVolume(value, vmType, platform, volumeParameterType);
}
}
Aggregations