Search in sources :

Example 1 with VmType

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);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) HashMap(java.util.HashMap) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with VmType

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) HashSet(java.util.HashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 3 with VmType

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) HashMap(java.util.HashMap) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 4 with VmType

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);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) VirtualMachinesResponse(com.sequenceiq.cloudbreak.api.model.VirtualMachinesResponse) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) PlatformVmtypesResponse(com.sequenceiq.cloudbreak.api.model.PlatformVmtypesResponse) VmTypeJson(com.sequenceiq.cloudbreak.api.model.VmTypeJson) HashSet(java.util.HashSet)

Example 5 with VmType

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);
    }
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)12 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)7 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)4 Cacheable (org.springframework.cache.annotation.Cacheable)4 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)3 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)3 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)3 VmTypeMetaBuilder (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder)3 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 IOException (java.io.IOException)2 Compute (com.google.api.services.compute.Compute)1 MachineType (com.google.api.services.compute.model.MachineType)1 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)1 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)1 PlatformVmtypesResponse (com.sequenceiq.cloudbreak.api.model.PlatformVmtypesResponse)1 VirtualMachinesResponse (com.sequenceiq.cloudbreak.api.model.VirtualMachinesResponse)1