Search in sources :

Example 1 with VmTypeMetaBuilder

use of com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder 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 2 with VmTypeMetaBuilder

use of com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder 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);
    }
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) VmSpecification(com.sequenceiq.cloudbreak.cloud.model.VmSpecification) ZoneVmSpecification(com.sequenceiq.cloudbreak.cloud.model.ZoneVmSpecification) IOException(java.io.IOException) TreeMap(java.util.TreeMap) VmsSpecification(com.sequenceiq.cloudbreak.cloud.model.VmsSpecification) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) ConfigSpecification(com.sequenceiq.cloudbreak.cloud.model.ConfigSpecification) ZoneVmSpecifications(com.sequenceiq.cloudbreak.cloud.model.ZoneVmSpecifications) ZoneVmSpecification(com.sequenceiq.cloudbreak.cloud.model.ZoneVmSpecification) HashSet(java.util.HashSet)

Example 3 with VmTypeMetaBuilder

use of com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method collectVmTypes.

private Set<VmType> collectVmTypes(OSClient<?> osClient) {
    Set<VmType> types = new HashSet<>();
    for (Flavor flavor : openStackClient.getFlavors(osClient)) {
        VmTypeMetaBuilder builder = VmTypeMetaBuilder.builder().withCpuAndMemory(flavor.getVcpus(), flavor.getRam());
        for (VolumeParameterType volumeParameterType : values()) {
            switch(volumeParameterType) {
                case MAGNETIC:
                    builder.withMagneticConfig(volumeParameterConfig(MAGNETIC));
                    break;
                case SSD:
                    builder.withSsdConfig(null);
                    break;
                case EPHEMERAL:
                    builder.withEphemeralConfig(null);
                    break;
                case ST1:
                    builder.withSt1Config(null);
                    break;
                case AUTO_ATTACHED:
                    builder.withAutoAttachedConfig(null);
                    break;
                default:
                    break;
            }
        }
        VmType vmType = VmType.vmTypeWithMeta(flavor.getName(), builder.create(), true);
        types.add(vmType);
    }
    LOGGER.info("openstack collect vm types result: {}", types);
    return types;
}
Also used : VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) Flavor(org.openstack4j.model.compute.Flavor) HashSet(java.util.HashSet)

Aggregations

VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 VmTypeMetaBuilder (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder)3 HashSet (java.util.HashSet)3 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)2 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)1 ConfigSpecification (com.sequenceiq.cloudbreak.cloud.model.ConfigSpecification)1 VmSpecification (com.sequenceiq.cloudbreak.cloud.model.VmSpecification)1 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)1 VmsSpecification (com.sequenceiq.cloudbreak.cloud.model.VmsSpecification)1 ZoneVmSpecification (com.sequenceiq.cloudbreak.cloud.model.ZoneVmSpecification)1 ZoneVmSpecifications (com.sequenceiq.cloudbreak.cloud.model.ZoneVmSpecifications)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Flavor (org.openstack4j.model.compute.Flavor)1 Cacheable (org.springframework.cache.annotation.Cacheable)1