Search in sources :

Example 1 with SdxRecommendationResponse

use of com.sequenceiq.sdx.api.model.SdxRecommendationResponse in project cloudbreak by hortonworks.

the class SdxRecommendationServiceTest method testGetRecommendation.

@Test
public void testGetRecommendation() {
    when(cdpConfigService.getConfigForKey(any())).thenReturn(createStackRequest());
    when(environmentClientService.getVmTypesByCredential(anyString(), anyString(), anyString(), eq(CdpResourceType.DATALAKE), any())).thenReturn(createPlatformVmtypesResponse());
    SdxRecommendationResponse recommendation = underTest.getRecommendation("cred", LIGHT_DUTY, "7.2.14", "AWS", "ec-central-1", null);
    StackV4Request defaultTemplate = recommendation.getTemplate();
    assertNotNull(defaultTemplate);
    assertThat(defaultTemplate.getInstanceGroups()).hasSize(2).extracting(ig -> ig.getName(), ig -> ig.getTemplate().getInstanceType()).containsExactlyInAnyOrder(tuple("master", "large"), tuple("idbroker", "medium"));
    Map<String, List<com.sequenceiq.sdx.api.model.VmTypeResponse>> availableVmTypesByInstanceGroup = recommendation.getAvailableVmTypesByInstanceGroup();
    assertThat(availableVmTypesByInstanceGroup).containsOnlyKeys("master", "idbroker");
    assertThat(availableVmTypesByInstanceGroup.get("master")).extracting(vmType -> vmType.getValue()).containsExactlyInAnyOrder("large");
    assertThat(availableVmTypesByInstanceGroup.get("idbroker")).extracting(vmType -> vmType.getValue()).containsExactlyInAnyOrder("large", "medium", "mediumv2");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SdxDefaultTemplateResponse(com.sequenceiq.sdx.api.model.SdxDefaultTemplateResponse) HashMap(java.util.HashMap) PlatformVmtypesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformVmtypesResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) CUSTOM(com.sequenceiq.sdx.api.model.SdxClusterShape.CUSTOM) HashSet(java.util.HashSet) VmTypeConverter(com.sequenceiq.datalake.converter.VmTypeConverter) CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) CdpResourceType(com.sequenceiq.common.api.type.CdpResourceType) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) Spy(org.mockito.Spy) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) VirtualMachinesResponse(com.sequenceiq.environment.api.v1.platformresource.model.VirtualMachinesResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) InjectMocks(org.mockito.InjectMocks) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) SdxRecommendationResponse(com.sequenceiq.sdx.api.model.SdxRecommendationResponse) Assertions.tuple(org.assertj.core.api.Assertions.tuple) EnvironmentClientService(com.sequenceiq.datalake.service.EnvironmentClientService) Set(java.util.Set) CDPConfigService(com.sequenceiq.datalake.configuration.CDPConfigService) VmTypeMetaJson(com.sequenceiq.environment.api.v1.platformresource.model.VmTypeMetaJson) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) LIGHT_DUTY(com.sequenceiq.sdx.api.model.SdxClusterShape.LIGHT_DUTY) Mockito.never(org.mockito.Mockito.never) List(java.util.List) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) VmTypeResponse(com.sequenceiq.environment.api.v1.platformresource.model.VmTypeResponse) Assertions.assertDoesNotThrow(org.junit.jupiter.api.Assertions.assertDoesNotThrow) InstanceTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SdxRecommendationResponse(com.sequenceiq.sdx.api.model.SdxRecommendationResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with SdxRecommendationResponse

use of com.sequenceiq.sdx.api.model.SdxRecommendationResponse in project cloudbreak by hortonworks.

the class SdxRecommendationService method getRecommendation.

public SdxRecommendationResponse getRecommendation(String credentialCrn, SdxClusterShape clusterShape, String runtimeVersion, String cloudPlatform, String region, String availabilityZone) {
    try {
        StackV4Request defaultTemplate = getDefaultTemplate(clusterShape, runtimeVersion, cloudPlatform);
        List<VmTypeResponse> availableVmTypes = getAvailableVmTypes(credentialCrn, cloudPlatform, region, availabilityZone);
        Map<String, VmTypeResponse> defaultVmTypesByInstanceGroup = getDefaultVmTypesByInstanceGroup(availableVmTypes, defaultTemplate);
        Map<String, List<VmTypeResponse>> availableVmTypesByInstanceGroup = filterAvailableVmTypesBasedOnDefault(availableVmTypes, defaultVmTypesByInstanceGroup);
        LOGGER.debug("Return default template and available vm types for clusterShape: {}, " + "runtimeVersion: {}, cloudPlatform: {}, region: {}, availabilityZone: {}", clusterShape, runtimeVersion, cloudPlatform, region, availabilityZone);
        return new SdxRecommendationResponse(defaultTemplate, availableVmTypesByInstanceGroup);
    } catch (NotFoundException | BadRequestException e) {
        throw e;
    } catch (Exception e) {
        LOGGER.warn("Getting recommendation failed!", e);
        throw new RuntimeException("Getting recommendation failed: " + e.getMessage());
    }
}
Also used : NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) VmTypeResponse(com.sequenceiq.sdx.api.model.VmTypeResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxRecommendationResponse(com.sequenceiq.sdx.api.model.SdxRecommendationResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) List(java.util.List)

Aggregations

StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 SdxRecommendationResponse (com.sequenceiq.sdx.api.model.SdxRecommendationResponse)2 List (java.util.List)2 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)1 InstanceTemplateV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request)1 CdpResourceType (com.sequenceiq.common.api.type.CdpResourceType)1 CDPConfigService (com.sequenceiq.datalake.configuration.CDPConfigService)1 VmTypeConverter (com.sequenceiq.datalake.converter.VmTypeConverter)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 EnvironmentClientService (com.sequenceiq.datalake.service.EnvironmentClientService)1 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)1 CompactRegionResponse (com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 PlatformVmtypesResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformVmtypesResponse)1 VirtualMachinesResponse (com.sequenceiq.environment.api.v1.platformresource.model.VirtualMachinesResponse)1 VmTypeMetaJson (com.sequenceiq.environment.api.v1.platformresource.model.VmTypeMetaJson)1 VmTypeResponse (com.sequenceiq.environment.api.v1.platformresource.model.VmTypeResponse)1 SdxClusterShape (com.sequenceiq.sdx.api.model.SdxClusterShape)1