use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes 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;
}
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());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes 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());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes in project cloudbreak by hortonworks.
the class PlatformParameterV2Controller method getVmTypesByCredentialId.
@Override
public PlatformVmtypesResponse getVmTypesByCredentialId(PlatformResourceRequestJson resourceRequestJson) {
resourceRequestJson = prepareAccountAndOwner(resourceRequestJson, authenticatedUserService.getCbUser());
PlatformResourceRequest convert = conversionService.convert(resourceRequestJson, PlatformResourceRequest.class);
fieldIsNotEmpty(resourceRequestJson.getRegion(), "region");
CloudVmTypes cloudVmTypes = cloudParameterService.getVmTypesV2(convert.getCredential(), convert.getRegion(), convert.getPlatformVariant(), convert.getFilters());
return conversionService.convert(cloudVmTypes, PlatformVmtypesResponse.class);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes 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());
}
Aggregations