Search in sources :

Example 1 with VmTypeMeta

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());
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) Credential(com.sequenceiq.cloudbreak.domain.Credential) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) Template(com.sequenceiq.cloudbreak.domain.Template) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Matchers.anyMap(org.mockito.Matchers.anyMap) Test(org.junit.Test)

Example 2 with VmTypeMeta

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

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());
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) Credential(com.sequenceiq.cloudbreak.domain.Credential) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) Template(com.sequenceiq.cloudbreak.domain.Template) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Matchers.anyMap(org.mockito.Matchers.anyMap) Test(org.junit.Test)

Example 4 with VmTypeMeta

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<>());
    }
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) MachineType(com.google.api.services.compute.model.MachineType) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) IOException(java.io.IOException) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Compute(com.google.api.services.compute.Compute) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) MachineTypeList(com.google.api.services.compute.model.MachineTypeList) HashSet(java.util.HashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Set (java.util.Set)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)2 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)2 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)2 Credential (com.sequenceiq.cloudbreak.domain.Credential)2 Template (com.sequenceiq.cloudbreak.domain.Template)2 IOException (java.io.IOException)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.emptySet (java.util.Collections.emptySet)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Test (org.junit.Test)2 Matchers.anyMap (org.mockito.Matchers.anyMap)2 Compute (com.google.api.services.compute.Compute)1 MachineType (com.google.api.services.compute.model.MachineType)1