Search in sources :

Example 31 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse 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 32 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class ProvisionerServiceTest method getEnvironmentResponse.

private DetailedEnvironmentResponse getEnvironmentResponse() {
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    detailedEnvironmentResponse.setName("env");
    detailedEnvironmentResponse.setEnvironmentStatus(EnvironmentStatus.AVAILABLE);
    CompactRegionResponse compactRegionResponse = new CompactRegionResponse();
    compactRegionResponse.setNames(Lists.newArrayList("eu-west-1"));
    compactRegionResponse.setDisplayNames(Map.of("eu-west-1", "ireland"));
    detailedEnvironmentResponse.setRegions(compactRegionResponse);
    detailedEnvironmentResponse.setCrn(CrnTestUtil.getEnvironmentCrnBuilder().setResource(UUID.randomUUID().toString()).setAccountId(UUID.randomUUID().toString()).build().toString());
    EnvironmentNetworkResponse network = new EnvironmentNetworkResponse();
    network.setCrn(CrnTestUtil.getNetworkCrnBuilder().setResource(UUID.randomUUID().toString()).setAccountId(UUID.randomUUID().toString()).build().toString());
    EnvironmentNetworkAwsParams environmentNetworkAwsParams = new EnvironmentNetworkAwsParams();
    environmentNetworkAwsParams.setVpcId("vpc");
    network.setAws(environmentNetworkAwsParams);
    network.setSubnetIds(Sets.newHashSet("subnet"));
    CloudSubnet cloudSubnet = new CloudSubnet();
    cloudSubnet.setId("subnet");
    cloudSubnet.setName("subnet");
    cloudSubnet.setAvailabilityZone("eu-west-1a");
    Map<String, CloudSubnet> cloudSubnetMap = Map.of("subnet", cloudSubnet);
    network.setSubnetMetas(cloudSubnetMap);
    detailedEnvironmentResponse.setNetwork(network);
    EnvironmentAuthenticationResponse authentication = new EnvironmentAuthenticationResponse();
    authentication.setPublicKey("ssh-public-key");
    detailedEnvironmentResponse.setAuthentication(authentication);
    return detailedEnvironmentResponse;
}
Also used : CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) EnvironmentNetworkAwsParams(com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkAwsParams) EnvironmentAuthenticationResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentAuthenticationResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 33 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class MultiAzDecoratorTest method decorateStackRequestWithMultiAzShouldPickMultipleSubnetsButOneSubnetPerAzForGatewayGroupWhenClusterShapeIsHA.

@Test
void decorateStackRequestWithMultiAzShouldPickMultipleSubnetsButOneSubnetPerAzForGatewayGroupWhenClusterShapeIsHA() {
    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-1a", "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 -> InstanceGroupType.GATEWAY.equals(ig.getType()) ? ig.getNetwork().getAws().getSubnetIds().size() == 1 : 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 34 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class NetworkDtoToResponseConverterTest method testConvertWithMockParams.

@Test
void testConvertWithMockParams() {
    NetworkDto network = createNetworkDto().withMock(createMockParams()).build();
    ProvidedSubnetIds providedSubnetIds = new ProvidedSubnetIds(PREFERRED_SUBNET_ID, Set.of(PREFERRED_SUBNET_ID));
    when(subnetIdProvider.subnets(network, TUNNEL, network.getCloudPlatform(), true)).thenReturn(providedSubnetIds);
    EnvironmentNetworkResponse actual = underTest.convert(network, TUNNEL, true);
    assertCommonFields(network, actual);
    assertEquals(network.getMock().getVpcId(), actual.getMock().getVpcId());
    assertEquals(network.getMock().getInternetGatewayId(), actual.getMock().getInternetGatewayId());
    assertNull(actual.getAws());
    assertNull(actual.getYarn());
    assertNull(actual.getAzure());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ProvidedSubnetIds(com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Test(org.junit.jupiter.api.Test)

Example 35 with EnvironmentNetworkResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse in project cloudbreak by hortonworks.

the class NetworkDtoToResponseConverterTest method testConvertWithAzureParams.

@Test
void testConvertWithAzureParams() {
    NetworkDto network = createNetworkDto().withAzure(createAzureParams()).build();
    ProvidedSubnetIds providedSubnetIds = new ProvidedSubnetIds(PREFERRED_SUBNET_ID, Set.of(PREFERRED_SUBNET_ID));
    when(subnetIdProvider.subnets(network, TUNNEL, network.getCloudPlatform(), true)).thenReturn(providedSubnetIds);
    EnvironmentNetworkResponse actual = underTest.convert(network, TUNNEL, true);
    assertCommonFields(network, actual);
    assertEquals(network.getAzure().isNoPublicIp(), actual.getAzure().getNoPublicIp());
    assertEquals(network.getAzure().getNetworkId(), actual.getAzure().getNetworkId());
    assertEquals(network.getAzure().getResourceGroupName(), actual.getAzure().getResourceGroupName());
    assertNull(actual.getAws());
    assertNull(actual.getYarn());
    assertNull(actual.getMock());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ProvidedSubnetIds(com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Test(org.junit.jupiter.api.Test)

Aggregations

EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)70 Test (org.junit.jupiter.api.Test)40 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)27 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)24 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)22 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)8 NetworkV1Request (com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request)8 NetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)7 Test (org.junit.Test)7 EnvironmentNetworkGcpParams (com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkGcpParams)6 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)5 Network (com.sequenceiq.cloudbreak.domain.Network)5 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)5 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)3 SubnetType (com.sequenceiq.cloudbreak.cloud.model.network.SubnetType)3 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)3 Tunnel (com.sequenceiq.common.api.type.Tunnel)3 EnvironmentNetworkAwsParams (com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkAwsParams)3