Search in sources :

Example 51 with EnvironmentNetworkResponse

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

the class SubnetSelectorTest method testChooseSubnetPreferPublic.

@Test
public void testChooseSubnetPreferPublic() {
    EnvironmentNetworkResponse source = new EnvironmentNetworkResponse();
    source.setSubnetMetas(Map.of("key1", getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1), "key2", getPublicCloudSubnet(PUBLIC_ID_1, AZ_1)));
    // Loop to ensure we select the public subnet every time
    for (int i = 0; i < 10; i++) {
        Optional<CloudSubnet> subnet = underTest.chooseSubnetPreferPublic(null, source.getSubnetMetas(), AZ_1);
        assert subnet.isPresent();
        assertEquals(PUBLIC_ID_1, subnet.get().getId());
    }
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest)

Example 52 with EnvironmentNetworkResponse

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

the class SubnetSelectorTest method testChooseEndpointGatewaySubnetNoPublicEndpointSubnetsEndpointGatewayValidationEnabled.

@Test
public void testChooseEndpointGatewaySubnetNoPublicEndpointSubnetsEndpointGatewayValidationEnabled() {
    EnvironmentNetworkResponse source = setupResponse();
    source.setSubnetMetas(Map.of("key", getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1)));
    source.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
    source.setGatewayEndpointSubnetMetas(Map.of("private-key", getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1)));
    when(entitlementService.endpointGatewaySkipValidation(any())).thenReturn(false);
    Optional<CloudSubnet> subnet = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.chooseSubnetForEndpointGateway(source, PRIVATE_ID_1));
    assert subnet.isEmpty();
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest)

Example 53 with EnvironmentNetworkResponse

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

the class SubnetSelectorTest method testChooseEndpointGatewaySubnetNoPublicEndpointSubnetsEndpointGatewayValidationDisabled.

@Test
public void testChooseEndpointGatewaySubnetNoPublicEndpointSubnetsEndpointGatewayValidationDisabled() {
    EnvironmentNetworkResponse source = setupResponse();
    source.setSubnetMetas(Map.of("key", getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1)));
    source.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
    source.setGatewayEndpointSubnetMetas(Map.of("private-key", getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1)));
    when(entitlementService.endpointGatewaySkipValidation(any())).thenReturn(true);
    Optional<CloudSubnet> subnet = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.chooseSubnetForEndpointGateway(source, PRIVATE_ID_1));
    assert subnet.isPresent();
    assertEquals(PRIVATE_ID_1, subnet.get().getId());
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest)

Example 54 with EnvironmentNetworkResponse

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

the class NetworkV1ToNetworkV4ConverterTest method testConvertToStackRequestWhenAzurePresentedWithSubnet.

@Test
public void testConvertToStackRequestWhenAzurePresentedWithSubnet() {
    NetworkV1Request networkV1Request = azureNetworkV1Request();
    DetailedEnvironmentResponse environmentNetworkResponse = azureEnvironmentNetwork();
    NetworkV4Request networkV4Request = underTest.convertToNetworkV4Request(new ImmutablePair<>(networkV1Request, environmentNetworkResponse));
    assertEquals(networkV4Request.createAzure().getNetworkId(), VPC_ID);
    assertEquals(networkV4Request.createAzure().getResourceGroupName(), GROUP_NAME);
    assertEquals(networkV4Request.createAzure().getSubnetId(), SUBNET_ID);
}
Also used : DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request) Test(org.junit.jupiter.api.Test)

Example 55 with EnvironmentNetworkResponse

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

the class NetworkV1ToNetworkV4ConverterTest method testConvertToStackRequestWhenAwsPresentedWithSubnet.

@Test
public void testConvertToStackRequestWhenAwsPresentedWithSubnet() {
    NetworkV1Request networkV1Request = awsNetworkV1Request();
    DetailedEnvironmentResponse environmentNetworkResponse = awsEnvironmentNetwork();
    NetworkV4Request[] networkV4Request = new NetworkV4Request[1];
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        networkV4Request[0] = underTest.convertToNetworkV4Request(new ImmutablePair<>(networkV1Request, environmentNetworkResponse));
    });
    assertEquals(networkV4Request[0].createAws().getVpcId(), VPC_ID);
    assertEquals(networkV4Request[0].createAws().getSubnetId(), SUBNET_ID);
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request) 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