Search in sources :

Example 51 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class MultiAzDecoratorTest method decorateStackRequestWithMultiAzShouldPickMultipleSubnetsWhenClusterShapeIsHA.

@Test
void decorateStackRequestWithMultiAzShouldPickMultipleSubnetsWhenClusterShapeIsHA() {
    StackV4Request stackV4Request = new StackV4Request();
    stackV4Request.setInstanceGroups(List.of(getInstanceGroupV4Request(InstanceGroupType.GATEWAY), getInstanceGroupV4Request(InstanceGroupType.CORE)));
    Set<String> subnetIds = Set.of(PREFERRED_SUBNET_ID, PREFERRED_SUBNET_ID2);
    EnvironmentNetworkResponse network = new EnvironmentNetworkResponse();
    network.setPreferedSubnetId(PREFERRED_SUBNET_ID);
    network.setPreferedSubnetIds(subnetIds);
    network.setSubnetIds(subnetIds);
    network.setSubnetMetas(Map.of(PREFERRED_SUBNET_ID, new CloudSubnet("id1", PREFERRED_SUBNET_ID, "eu-central-1a", "10.0.0.0/24", false, true, true, SubnetType.PUBLIC), PREFERRED_SUBNET_ID2, new CloudSubnet("id1", PREFERRED_SUBNET_ID2, "eu-central-1b", "10.0.1.0/24", false, true, true, SubnetType.PUBLIC)));
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setNetwork(network);
    environment.setTunnel(Tunnel.DIRECT);
    underTest.decorateStackRequestWithMultiAz(stackV4Request, environment, SdxClusterShape.MEDIUM_DUTY_HA);
    Assertions.assertTrue(stackV4Request.getInstanceGroups().stream().allMatch(ig -> ig.getNetwork().getAws().getSubnetIds().containsAll(subnetIds)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) SdxClusterShape(com.sequenceiq.sdx.api.model.SdxClusterShape) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Set(java.util.Set) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Test(org.junit.jupiter.api.Test) List(java.util.List) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SubnetType(com.sequenceiq.cloudbreak.cloud.model.network.SubnetType) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Assertions(org.junit.jupiter.api.Assertions) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) Tunnel(com.sequenceiq.common.api.type.Tunnel) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 52 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class SdxRecommendationServiceTest method validateVmTypeOverrideWhenDefaultVmTypeIsMissingFromAvailableVmTypes.

@Test
public void validateVmTypeOverrideWhenDefaultVmTypeIsMissingFromAvailableVmTypes() {
    StackV4Request defaultTemplate = createStackRequest();
    defaultTemplate.getInstanceGroups().get(0).getTemplate().setInstanceType("unknown");
    when(cdpConfigService.getConfigForKey(any())).thenReturn(defaultTemplate);
    when(environmentClientService.getVmTypesByCredential(anyString(), anyString(), anyString(), eq(CdpResourceType.DATALAKE), any())).thenReturn(createPlatformVmtypesResponse());
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> underTest.validateVmTypeOverride(createEnvironment("AWS"), createSdxCluster(createStackRequest(), LIGHT_DUTY)));
    assertEquals("Missing vm type for default template instance group: master - unknown", badRequestException.getMessage());
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 53 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class SdxRecommendationServiceTest method createStackRequest.

private StackV4Request createStackRequest() {
    StackV4Request defaultTemplate = new StackV4Request();
    defaultTemplate.getInstanceGroups().add(createInstanceGroup("master", "large"));
    defaultTemplate.getInstanceGroups().add(createInstanceGroup("idbroker", "medium"));
    return defaultTemplate;
}
Also used : StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)

Example 54 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request in project cloudbreak by hortonworks.

the class SdxRecommendationServiceTest method testGetDefaultTemplate.

@Test
public void testGetDefaultTemplate() {
    StackV4Request defaultTemplate = createStackRequest();
    when(cdpConfigService.getConfigForKey(any())).thenReturn(defaultTemplate);
    SdxDefaultTemplateResponse response = underTest.getDefaultTemplateResponse(LIGHT_DUTY, "7.2.14", "AWS");
    assertEquals(defaultTemplate, response.getTemplate());
}
Also used : SdxDefaultTemplateResponse(com.sequenceiq.sdx.api.model.SdxDefaultTemplateResponse) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) Test(org.junit.jupiter.api.Test)

Example 55 with StackV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request 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)

Aggregations

StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)105 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)66 Test (org.junit.jupiter.api.Test)58 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)52 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)36 Test (org.junit.Test)36 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)34 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)33 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)32 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)31 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)17 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)14 Map (java.util.Map)13 Set (java.util.Set)13 Optional (java.util.Optional)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)11 HashMap (java.util.HashMap)11 List (java.util.List)11