Search in sources :

Example 1 with VmTypeResponse

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;
}
Also used : VmTypeResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse) VolumeParameterConfigResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VolumeParameterConfigResponse) VmTypeMetaJson(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeMetaJson) ArrayList(java.util.ArrayList)

Example 2 with 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");
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) VmTypeResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse) FreeIpaRecommendationResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse) Test(org.junit.jupiter.api.Test)

Example 3 with VmTypeResponse

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));
}
Also used : VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) VmTypeResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse) VolumeParameterConfigResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VolumeParameterConfigResponse) VmTypeMetaJson(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeMetaJson) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 4 with VmTypeResponse

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);
}
Also used : Credential(com.sequenceiq.freeipa.dto.Credential) VmTypeResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse) FreeIpaRecommendationResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse)

Example 5 with VmTypeResponse

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());
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) Credential(com.sequenceiq.freeipa.dto.Credential) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) FreeIpaRecommendationResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse) Stack(com.sequenceiq.freeipa.entity.Stack) DefaultInstanceTypeProvider(com.sequenceiq.freeipa.service.stack.instance.DefaultInstanceTypeProvider) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) VmTypeResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse) Logger(org.slf4j.Logger) VmTypeMeta(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta) CloudParameterService(com.sequenceiq.cloudbreak.cloud.service.CloudParameterService) Set(java.util.Set) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) Optional(java.util.Optional) CredentialToExtendedCloudCredentialConverter(com.sequenceiq.freeipa.converter.cloud.CredentialToExtendedCloudCredentialConverter) Collections(java.util.Collections) VmTypeToVmTypeResponseConverter(com.sequenceiq.freeipa.converter.instance.VmTypeToVmTypeResponseConverter) CredentialService(com.sequenceiq.freeipa.service.CredentialService) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType)

Aggregations

VmTypeResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeResponse)5 FreeIpaRecommendationResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.FreeIpaRecommendationResponse)3 Credential (com.sequenceiq.freeipa.dto.Credential)3 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 VmTypeMetaJson (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VmTypeMetaJson)2 VolumeParameterConfigResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.create.VolumeParameterConfigResponse)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 Maps (com.google.common.collect.Maps)1 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)1 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)1 CloudParameterService (com.sequenceiq.cloudbreak.cloud.service.CloudParameterService)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 CdpResourceType (com.sequenceiq.common.api.type.CdpResourceType)1 CredentialToExtendedCloudCredentialConverter (com.sequenceiq.freeipa.converter.cloud.CredentialToExtendedCloudCredentialConverter)1 VmTypeToVmTypeResponseConverter (com.sequenceiq.freeipa.converter.instance.VmTypeToVmTypeResponseConverter)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 CredentialService (com.sequenceiq.freeipa.service.CredentialService)1 DefaultInstanceTypeProvider (com.sequenceiq.freeipa.service.stack.instance.DefaultInstanceTypeProvider)1