Search in sources :

Example 41 with EnvironmentNetworkResponse

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

the class EnvironmentBaseNetworkConverterTest method testConvertToLegacyNetworkWithEndpointAccessGatewayNoPublicSubnets.

@Test
public void testConvertToLegacyNetworkWithEndpointAccessGatewayNoPublicSubnets() {
    CloudSubnet privateSubnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
    EnvironmentNetworkResponse source = setupResponse();
    source.setSubnetMetas(Map.of("key", privateSubnet));
    source.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
    source.setGatewayEndpointSubnetMetas(Map.of("private-key", privateSubnet));
    when(subnetSelector.chooseSubnet(any(), anyMap(), anyString(), any())).thenReturn(Optional.of(privateSubnet));
    when(subnetSelector.chooseSubnetForEndpointGateway(any(), anyString())).thenReturn(Optional.empty());
    Exception exception = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.convertToLegacyNetwork(source, AZ_1)));
    assertEquals("Could not find public subnet in availability zone: AZ-1", exception.getMessage());
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) BadRequestException(javax.ws.rs.BadRequestException) Test(org.junit.jupiter.api.Test) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest)

Example 42 with EnvironmentNetworkResponse

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

the class EnvironmentBaseNetworkConverterTest method testConvertToLegacyNetworkWhenSubnetNotFound.

@Test
public void testConvertToLegacyNetworkWhenSubnetNotFound() {
    EnvironmentNetworkResponse source = new EnvironmentNetworkResponse();
    source.setSubnetMetas(Map.of("key", getCloudSubnet("any")));
    when(subnetSelector.chooseSubnet(any(), anyMap(), anyString(), any())).thenReturn(Optional.empty());
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.convertToLegacyNetwork(source, EU_AZ)));
    assertEquals(badRequestException.getMessage(), "No subnet for the given availability zone: eu-west-1a");
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) BadRequestException(javax.ws.rs.BadRequestException) Test(org.junit.jupiter.api.Test) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest)

Example 43 with EnvironmentNetworkResponse

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

the class EnvironmentBaseNetworkConverterTest method testEndpointGatewayIsDisabledd.

@Test
public void testEndpointGatewayIsDisabledd() {
    CloudSubnet privateSubnet = getCloudSubnet(AZ_1);
    CloudSubnet publicSubnet = getPublicCloudSubnet(PUBLIC_ID_1, AZ_1);
    EnvironmentNetworkResponse source = setupResponse();
    source.setSubnetMetas(Map.of("key", privateSubnet));
    source.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.DISABLED);
    source.setGatewayEndpointSubnetMetas(Map.of("public-key", publicSubnet));
    when(subnetSelector.chooseSubnet(any(), anyMap(), anyString(), any())).thenReturn(Optional.of(privateSubnet));
    Network[] network = new Network[1];
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        network[0] = underTest.convertToLegacyNetwork(source, AZ_1);
    });
    assertNull(network[0].getAttributes().getValue(ENDPOINT_GATEWAY_SUBNET_ID));
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) 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 44 with EnvironmentNetworkResponse

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

the class GcpEnvironmentNetworkConverterTest method getNetworkIdForAttributeLegacyNetwork.

@Test
void getNetworkIdForAttributeLegacyNetwork() {
    EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
    EnvironmentNetworkGcpParams environmentNetworkGcpParams = mock(EnvironmentNetworkGcpParams.class);
    when(environmentNetworkResponse.getGcp()).thenReturn(environmentNetworkGcpParams);
    when(environmentNetworkGcpParams.getNetworkId()).thenReturn(GCP_NETWORK_ID);
    Map<String, Object> result = converter.getAttributesForLegacyNetwork(environmentNetworkResponse);
    assertEquals(GCP_NETWORK_ID, result.get("networkId"));
}
Also used : EnvironmentNetworkGcpParams(com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkGcpParams) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Test(org.junit.jupiter.api.Test)

Example 45 with EnvironmentNetworkResponse

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

the class GcpEnvironmentNetworkConverterTest method getNoPublicIpAttributeForLegacyNetwork.

@Test
void getNoPublicIpAttributeForLegacyNetwork() {
    EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
    EnvironmentNetworkGcpParams environmentNetworkGcpParams = mock(EnvironmentNetworkGcpParams.class);
    when(environmentNetworkResponse.getGcp()).thenReturn(environmentNetworkGcpParams);
    when(environmentNetworkGcpParams.getNoPublicIp()).thenReturn(true);
    Map<String, Object> result = converter.getAttributesForLegacyNetwork(environmentNetworkResponse);
    assertEquals(true, result.get("noPublicIp"));
}
Also used : EnvironmentNetworkGcpParams(com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkGcpParams) 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