use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse in project cloudbreak by hortonworks.
the class VmTypeToVmTypeResponseConverter method convert.
public VmTypeResponse convert(VmType source) {
VmTypeResponse vmTypeResponse = new VmTypeResponse();
List<VolumeParameterConfigResponse> configs = new ArrayList<>();
convertVolumeConfig(configs, source.getMetaData().getAutoAttachedConfig());
convertVolumeConfig(configs, source.getMetaData().getEphemeralConfig());
convertVolumeConfig(configs, source.getMetaData().getMagneticConfig());
convertVolumeConfig(configs, source.getMetaData().getSsdConfig());
convertVolumeConfig(configs, source.getMetaData().getSt1Config());
VmTypeMetaJson vmTypeMetaJson = new VmTypeMetaJson();
vmTypeMetaJson.setProperties(source.getMetaData().getProperties());
vmTypeMetaJson.setConfigs(configs);
vmTypeResponse.setVmTypeMetaJson(vmTypeMetaJson);
vmTypeResponse.setValue(source.value());
return vmTypeResponse;
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse in project cloudbreak by hortonworks.
the class FreeIpaRecommendationServiceTest method testGetRecommendation.
@Test
public void testGetRecommendation() {
when(credentialService.getCredentialByCredCrn(anyString())).thenReturn(new Credential("AWS", "", "", "", ""));
when(cloudParameterService.getVmTypesV2(any(), eq("eu-central-1"), eq("AWS"), eq(CdpResourceType.DEFAULT), any())).thenReturn(initCloudVmTypes());
when(defaultInstanceTypeProvider.getForPlatform(eq("AWS"))).thenReturn("medium");
FreeIpaRecommendationResponse recommendation = underTest.getRecommendation("cred", "eu-central-1", null);
assertEquals("medium", recommendation.getDefaultInstanceType());
Set<VmTypeResponse> vmTypes = recommendation.getVmTypes();
assertEquals(2, vmTypes.size());
assertThat(vmTypes.stream().map(VmTypeResponse::getValue).collect(Collectors.toSet())).containsExactly("large", "medium");
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse in project cloudbreak by hortonworks.
the class VmTypeToVmTypeResponseConverterTest method testConvert.
@Test
public void testConvert() {
VmTypeMeta vmTypeMeta = VmTypeMeta.VmTypeMetaBuilder.builder().withAutoAttachedConfig(1, 2, 3, 4).withEphemeralConfig(2, 3, 4, 5).withMagneticConfig(3, 4, 5, 6).withSsdConfig(4, 5, 6, 7).withSt1Config(5, 6, 7, 8).withCpuAndMemory(100, 32).withPrice(100.0).withMaximumPersistentDisksSizeGb(5000L).withVolumeEncryptionSupport(false).withProperty("custom", "value").create();
VmType vmType = VmType.vmTypeWithMeta("large", vmTypeMeta, false);
VmTypeResponse vmTypeResponse = underTest.convert(vmType);
assertEquals("large", vmTypeResponse.getValue());
VmTypeMetaJson vmTypeMetaJson = vmTypeResponse.getVmTypeMetaJson();
Map<String, Object> properties = vmTypeMetaJson.getProperties();
assertThat(properties.entrySet()).extracting(Map.Entry::getKey, Map.Entry::getValue).containsOnly(tuple("Cpu", 100), tuple("Memory", 32), tuple("Price", "100.0"), tuple("maximumPersistentDisksSizeGb", 5000L), tuple("EncryptionSupported", false), tuple("custom", "value"));
List<VolumeParameterConfigResponse> configs = vmTypeMetaJson.getConfigs();
assertThat(configs).hasSize(5);
assertThat(configs).extracting(VolumeParameterConfigResponse::getVolumeParameterType, VolumeParameterConfigResponse::getMinimumSize, VolumeParameterConfigResponse::getMaximumSize, VolumeParameterConfigResponse::getMinimumNumber, VolumeParameterConfigResponse::getMaximumNumber).containsOnly(tuple("AUTO_ATTACHED", 1, 2, 3, 4), tuple("EPHEMERAL", 2, 3, 4, 5), tuple("MAGNETIC", 3, 4, 5, 6), tuple("SSD", 4, 5, 6, 7), tuple("ST1", 5, 6, 7, 8));
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse in project cloudbreak by hortonworks.
the class FreeIpaRecommendationService method getRecommendation.
public FreeIpaRecommendationResponse getRecommendation(String credentialCrn, String region, String availabilityZone) {
Credential credential = credentialService.getCredentialByCredCrn(credentialCrn);
String defaultInstanceType = defaultInstanceTypeProvider.getForPlatform(credential.getCloudPlatform());
Set<VmTypeResponse> availableVmTypes = getAvailableVmTypes(region, availabilityZone, credential, defaultInstanceType);
return new FreeIpaRecommendationResponse(availableVmTypes, defaultInstanceType);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse in project cloudbreak by hortonworks.
the class FreeIpaRecommendationService method getAvailableVmTypes.
private Set<VmTypeResponse> getAvailableVmTypes(String region, String availabilityZone, Credential credential, String defaultInstanceType) {
CloudVmTypes vmTypes = cloudParameterService.getVmTypesV2(extendedCloudCredentialConverter.convert(credential), region, credential.getCloudPlatform(), CdpResourceType.DEFAULT, Maps.newHashMap());
Set<VmType> availableVmTypes = Collections.emptySet();
if (vmTypes.getCloudVmResponses() != null && StringUtils.isNotBlank(availabilityZone) && vmTypes.getDefaultCloudVmResponses().containsKey(availabilityZone)) {
availableVmTypes = vmTypes.getCloudVmResponses().get(availabilityZone);
} else if (vmTypes.getCloudVmResponses() != null && !vmTypes.getCloudVmResponses().isEmpty()) {
availableVmTypes = vmTypes.getCloudVmResponses().values().iterator().next();
}
Optional<VmType> defaultVmType = availableVmTypes.stream().filter(vmType -> defaultInstanceType.equals(vmType.value())).findAny();
return availableVmTypes.stream().filter(vmType -> filterVmTypeLargerThanDefault(vmType, defaultVmType)).map(vmType -> vmTypeConverter.convert(vmType)).collect(Collectors.toSet());
}
Aggregations