Search in sources :

Example 1 with CloudVmTypes

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);
}
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 CloudVmTypes

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);
}
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 CloudVmTypes

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));
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) OSClient(org.openstack4j.api.OSClient) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Flavor(org.openstack4j.model.compute.Flavor) Test(org.junit.Test)

Example 4 with CloudVmTypes

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;
}
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 5 with 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());
}
Also used : Credential(com.sequenceiq.cloudbreak.domain.Credential) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Template(com.sequenceiq.cloudbreak.domain.Template) Test(org.junit.Test)

Aggregations

CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)14 Set (java.util.Set)8 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)7 HashMap (java.util.HashMap)6 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)5 Test (org.junit.Test)5 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)4 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)4 HashSet (java.util.HashSet)4 Cacheable (org.springframework.cache.annotation.Cacheable)4 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)3 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)3 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)3 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)3 Credential (com.sequenceiq.cloudbreak.domain.Credential)3 Template (com.sequenceiq.cloudbreak.domain.Template)3 Map (java.util.Map)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Collections.emptyMap (java.util.Collections.emptyMap)2