Search in sources :

Example 1 with PlatformDisks

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

the class PlatformParameterV1Controller method getDisktypeByType.

@Override
public Collection<String> getDisktypeByType(String type) {
    PlatformDisks diskTypes = cloudParameterService.getDiskTypes();
    Collection<String> strings = conversionService.convert(diskTypes, PlatformDisksJson.class).getDiskTypes().get(type.toUpperCase());
    return strings == null ? new ArrayList<>() : strings;
}
Also used : PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)

Example 2 with PlatformDisks

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

the class TemplateDecorator method decorate.

public Template decorate(Credential credential, Template subject, String region, String availabilityZone, String variant) {
    PlatformDisks platformDisks = cloudParameterService.getDiskTypes();
    CloudVmTypes vmTypesV2 = cloudParameterService.getVmTypesV2(credential, region, variant, new HashMap<>());
    String locationString = locationService.location(region, availabilityZone);
    VolumeParameterConfig config;
    try {
        Platform platform = Platform.platform(subject.cloudPlatform());
        VmType vmType = vmTypesV2.getCloudVmResponses().getOrDefault(locationString, Collections.emptySet()).stream().filter(curr -> curr.value().equals(subject.getInstanceType())).findFirst().get();
        Map<String, VolumeParameterType> map = platformDisks.getDiskMappings().get(platform);
        VolumeParameterType volumeParameterType = map.get(subject.getVolumeType());
        config = vmType.getVolumeParameterbyVolumeParameterType(volumeParameterType);
    } catch (NoSuchElementException ignored) {
        LOGGER.info("No VolumeParameterConfig found, which might be normal for platforms like OpenStack");
        config = VolumeParameterConfig.EMPTY;
    }
    if (config.volumeParameterType() != null) {
        if (subject.getVolumeCount() == null) {
            subject.setVolumeCount(config.maximumNumber());
        }
        if (subject.getVolumeSize() == null) {
            subject.setVolumeSize(config.maximumSize());
        }
    }
    return subject;
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with PlatformDisks

use of com.sequenceiq.cloudbreak.cloud.model.PlatformDisks 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 4 with PlatformDisks

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

the class PlatformParameterV1Controller method getPlatforms.

@Override
public Map<String, Object> getPlatforms(Boolean extended) {
    PlatformVariants pv = cloudParameterService.getPlatformVariants();
    PlatformDisks diskTypes = cloudParameterService.getDiskTypes();
    PlatformRegions regions = cloudParameterService.getRegions();
    PlatformVirtualMachines vmtypes = new PlatformVirtualMachines();
    PlatformOrchestrators orchestrators = cloudParameterService.getOrchestrators();
    Map<Platform, PlatformParameters> platformParameters = cloudParameterService.getPlatformParameters();
    SpecialParameters specialParameters = cloudParameterService.getSpecialParameters();
    Map<String, Object> map = new HashMap<>();
    map.put("variants", conversionService.convert(pv, PlatformVariantsJson.class));
    map.put("disks", conversionService.convert(diskTypes, PlatformDisksJson.class));
    map.put("regions", conversionService.convert(regions, PlatformRegionsJson.class));
    map.put("virtualMachines", conversionService.convert(vmtypes, PlatformVirtualMachinesJson.class));
    map.put("orchestrators", conversionService.convert(orchestrators, PlatformOrchestratorsJson.class));
    map.put("tagspecifications", conversionService.convert(platformParameters, TagSpecificationsJson.class));
    Map<String, Boolean> globalParameters = conversionService.convert(specialParameters, Map.class);
    Map<String, Map<String, Boolean>> platformSpecificParameters = conversionService.convert(platformParameters, Map.class);
    SpecialParametersJson specialParametersJson = new SpecialParametersJson();
    specialParametersJson.setSpecialParameters(globalParameters);
    specialParametersJson.setPlatformSpecificSpecialParameters(platformSpecificParameters);
    map.put("specialParameters", specialParametersJson);
    return map;
}
Also used : PlatformRegions(com.sequenceiq.cloudbreak.cloud.model.PlatformRegions) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) HashMap(java.util.HashMap) PlatformRegionsJson(com.sequenceiq.cloudbreak.api.model.PlatformRegionsJson) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) PlatformVirtualMachines(com.sequenceiq.cloudbreak.cloud.model.PlatformVirtualMachines) PlatformVariantsJson(com.sequenceiq.cloudbreak.api.model.PlatformVariantsJson) SpecialParametersJson(com.sequenceiq.cloudbreak.api.model.SpecialParametersJson) SpecialParameters(com.sequenceiq.cloudbreak.api.model.SpecialParameters) PlatformOrchestratorsJson(com.sequenceiq.cloudbreak.api.model.PlatformOrchestratorsJson) TagSpecificationsJson(com.sequenceiq.cloudbreak.api.model.TagSpecificationsJson) PlatformDisksJson(com.sequenceiq.cloudbreak.api.model.PlatformDisksJson) PlatformVariants(com.sequenceiq.cloudbreak.cloud.model.PlatformVariants) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) PlatformOrchestrators(com.sequenceiq.cloudbreak.cloud.model.PlatformOrchestrators) PlatformVirtualMachinesJson(com.sequenceiq.cloudbreak.api.model.PlatformVirtualMachinesJson) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with PlatformDisks

use of com.sequenceiq.cloudbreak.cloud.model.PlatformDisks 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)

Aggregations

PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)7 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)6 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)4 Map (java.util.Map)4 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)3 Set (java.util.Set)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 DiskTypes (com.sequenceiq.cloudbreak.cloud.model.DiskTypes)2 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 Credential (com.sequenceiq.cloudbreak.domain.Credential)2 Template (com.sequenceiq.cloudbreak.domain.Template)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.emptySet (java.util.Collections.emptySet)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Matchers.anyMap (org.mockito.Matchers.anyMap)2 PlatformDisksJson (com.sequenceiq.cloudbreak.api.model.PlatformDisksJson)1 PlatformOrchestratorsJson (com.sequenceiq.cloudbreak.api.model.PlatformOrchestratorsJson)1