Search in sources :

Example 36 with EnvironmentNetworkResponse

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

the class EnvironmentValidatorTest method createEnvironment.

private DetailedEnvironmentResponse createEnvironment(String cloudplatform, Map<String, CloudSubnet> subnetMetas) {
    DetailedEnvironmentResponse env = new DetailedEnvironmentResponse();
    env.setCloudPlatform(cloudplatform);
    EnvironmentNetworkResponse network = createNetwork(subnetMetas);
    env.setNetwork(network);
    return env;
}
Also used : DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)

Example 37 with EnvironmentNetworkResponse

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

the class StackV4RequestToStackConverterTest method setupForEndpointGateway.

private StackV4Request setupForEndpointGateway(boolean enabled) {
    initMocks();
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
    StackV4Request request = getRequest("stack-datalake-with-instancegroups.json");
    EnvironmentNetworkResponse networkResponse = new EnvironmentNetworkResponse();
    networkResponse.setPublicEndpointAccessGateway(enabled ? PublicEndpointAccessGateway.ENABLED : PublicEndpointAccessGateway.DISABLED);
    DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
    environmentResponse.setCredential(credentialResponse);
    environmentResponse.setCloudPlatform("AWS");
    environmentResponse.setTunnel(Tunnel.DIRECT);
    environmentResponse.setTags(new TagResponse());
    environmentResponse.setNetwork(networkResponse);
    when(environmentClientService.getByName(anyString())).thenReturn(environmentResponse);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    given(credentialClientService.getByCrn(anyString())).willReturn(credential);
    given(credentialClientService.getByName(anyString())).willReturn(credential);
    given(providerParameterCalculator.get(request)).willReturn(getMappable());
    given(clusterV4RequestToClusterConverter.convert(any(ClusterV4Request.class))).willReturn(new Cluster());
    given(telemetryConverter.convert(null, StackType.DATALAKE)).willReturn(new Telemetry());
    given(loadBalancerConfigService.getKnoxGatewayGroups(any(Stack.class))).willReturn(Set.of("master"));
    return request;
}
Also used : ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse) 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) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Telemetry(com.sequenceiq.common.api.telemetry.model.Telemetry) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 38 with EnvironmentNetworkResponse

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

the class AzureEnvironmentNetworkConverterTest method testConvertToLegacyNetworkWithPublicEndpointAccessGatewayEnabled.

@Test
void testConvertToLegacyNetworkWithPublicEndpointAccessGatewayEnabled() {
    EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
    EnvironmentNetworkAzureParams azure = mock(EnvironmentNetworkAzureParams.class);
    CloudSubnet cloudSubnet = mock(CloudSubnet.class);
    when(environmentNetworkResponse.getPublicEndpointAccessGateway()).thenReturn(PublicEndpointAccessGateway.ENABLED);
    when(subnetSelector.chooseSubnet(any(), any(), any(), any())).thenReturn(Optional.of(cloudSubnet));
    when(cloudSubnet.getId()).thenReturn("my_cloud_subnet");
    when(environmentNetworkResponse.getAzure()).thenReturn(azure);
    when(azure.getNetworkId()).thenReturn("my_network_id");
    when(azure.getResourceGroupName()).thenReturn("my_resource_group");
    when(azure.getNoPublicIp()).thenReturn(true);
    Network result = converter.convertToLegacyNetwork(environmentNetworkResponse, "my-az");
    assertEquals(CloudPlatform.AZURE.toString(), result.getAttributes().getMap().get(CLOUD_PLATFORM).toString());
    assertFalse(result.getAttributes().getMap().containsKey(ENDPOINT_GATEWAY_SUBNET_ID));
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) EnvironmentNetworkAzureParams(com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkAzureParams) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 39 with EnvironmentNetworkResponse

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

the class EnvironmentBaseNetworkConverterTest method testConvertToLegacyNetworkWhenSubnetFound.

@Test
public void testConvertToLegacyNetworkWhenSubnetFound() {
    CloudSubnet subnet = getCloudSubnet(EU_AZ);
    Map<String, CloudSubnet> metas = Map.of("key", subnet);
    EnvironmentNetworkResponse source = setupResponse();
    source.setSubnetMetas(metas);
    when(subnetSelector.chooseSubnet(any(), eq(metas), eq(EU_AZ), eq(SelectionFallbackStrategy.ALLOW_FALLBACK))).thenReturn(Optional.of(subnet));
    Network[] network = new Network[1];
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        network[0] = underTest.convertToLegacyNetwork(source, EU_AZ);
    });
    assertEquals(network[0].getAttributes().getValue("subnetId"), "eu-west-1");
    assertTrue(network[0].getNetworkCidrs().containsAll(NETWORK_CIDRS));
    assertEquals(source.getOutboundInternetTraffic(), network[0].getOutboundInternetTraffic());
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest)

Example 40 with EnvironmentNetworkResponse

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

the class EnvironmentBaseNetworkConverterTest method testConvertToLegacyNetworkWithEndpointAccessGateway.

@Test
public void testConvertToLegacyNetworkWithEndpointAccessGateway() {
    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.ENABLED);
    source.setGatewayEndpointSubnetMetas(Map.of("public-key", publicSubnet));
    when(subnetSelector.chooseSubnet(any(), eq(source.getSubnetMetas()), eq(AZ_1), eq(SelectionFallbackStrategy.ALLOW_FALLBACK))).thenReturn(Optional.of(privateSubnet));
    when(subnetSelector.chooseSubnetForEndpointGateway(eq(source), eq(privateSubnet.getId()))).thenReturn(Optional.of(publicSubnet));
    Network[] network = new Network[1];
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        network[0] = underTest.convertToLegacyNetwork(source, AZ_1);
    });
    assertEquals(PUBLIC_ID_1, 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)

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