Search in sources :

Example 61 with EnvironmentNetworkResponse

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

the class NetworkV1ToNetworkV4ConverterTest method createEnvironmentNetworkResponseForGcp.

private EnvironmentNetworkResponse createEnvironmentNetworkResponseForGcp() {
    EnvironmentNetworkResponse environmentNetworkResponse = new EnvironmentNetworkResponse();
    environmentNetworkResponse.setSubnetIds(SUBNET_IDS);
    environmentNetworkResponse.setPreferedSubnetId(SUBNET_ID);
    environmentNetworkResponse.setGcp(createEnvironmentNetworkGcpParams());
    return environmentNetworkResponse;
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)

Example 62 with EnvironmentNetworkResponse

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

the class NetworkV1ToNetworkV4ConverterTest method testConvertToStackRequestWhenYarnPresented.

@Test
public void testConvertToStackRequestWhenYarnPresented() {
    NetworkV1Request networkV1Request = yarnNetworkV1Request();
    DetailedEnvironmentResponse environmentNetworkResponse = yarnEnvironmentNetwork();
    NetworkV4Request networkV4Request = underTest.convertToNetworkV4Request(new ImmutablePair<>(networkV1Request, environmentNetworkResponse));
    assertTrue(networkV4Request.createYarn().asMap().size() == 1);
}
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 63 with EnvironmentNetworkResponse

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

the class StackV4RequestToStackConverter method setNetworkIfApplicable.

private void setNetworkIfApplicable(StackV4Request source, Stack stack, DetailedEnvironmentResponse environment) {
    if (source.getNetwork() != null) {
        source.getNetwork().setCloudPlatform(source.getCloudPlatform());
        Network network = networkV4RequestToNetworkConverter.convert(source.getNetwork());
        EnvironmentNetworkResponse envNetwork = environment == null ? null : environment.getNetwork();
        if (envNetwork != null) {
            network.setNetworkCidrs(envNetwork.getNetworkCidrs());
            network.setOutboundInternetTraffic(envNetwork.getOutboundInternetTraffic());
        }
        stack.setNetwork(network);
    } else {
        EnvironmentNetworkConverter environmentNetworkConverter = environmentNetworkConverterMap.get(source.getCloudPlatform());
        String availabilityZone = source.getPlacement() != null ? source.getPlacement().getAvailabilityZone() : null;
        if (environmentNetworkConverter != null && environment != null) {
            Network network = environmentNetworkConverter.convertToLegacyNetwork(environment.getNetwork(), availabilityZone);
            stack.setNetwork(network);
        }
    }
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) EnvironmentNetworkConverter(com.sequenceiq.cloudbreak.converter.v4.environment.network.EnvironmentNetworkConverter)

Example 64 with EnvironmentNetworkResponse

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

the class StackV4RequestToStackConverter method setupEndpointGatewayNetwork.

private void setupEndpointGatewayNetwork(InstanceGroupNetworkV4Request instanceGroupNetworkV4Request, Stack stack, String instanceGroupName, DetailedEnvironmentResponse environment) {
    if (CloudPlatform.AWS.name().equals(stack.getCloudPlatform()) && instanceGroupNetworkV4Request != null && instanceGroupNetworkV4Request.getAws() != null) {
        EnvironmentNetworkResponse envNetwork = environment == null ? null : environment.getNetwork();
        if (envNetwork != null) {
            if (PublicEndpointAccessGateway.ENABLED.equals(envNetwork.getPublicEndpointAccessGateway())) {
                LOGGER.info("Found AWS stack with endpoint gatewy enabled. Selecting endpoint gateway subnet ids.");
                List<String> subnetIds = instanceGroupNetworkV4Request.getAws().getSubnetIds();
                LOGGER.debug("Endpoint gateway selection: Found instance group network subnet list of {} for instance group {}", subnetIds, instanceGroupName);
                List<String> allAvailabilityZones = envNetwork.getSubnetMetas().values().stream().filter(subnetMeta -> subnetIds.contains(subnetMeta.getId())).map(CloudSubnet::getAvailabilityZone).collect(Collectors.toList());
                LOGGER.debug("Endpoint gatway selection: Instance group network has availability zones {}", allAvailabilityZones);
                List<String> endpointGatewaySubnetIds = envNetwork.getGatewayEndpointSubnetMetas().values().stream().filter(subnetMeta -> allAvailabilityZones.contains(subnetMeta.getAvailabilityZone())).map(CloudSubnet::getId).collect(Collectors.toList());
                if (endpointGatewaySubnetIds.isEmpty()) {
                    String endpointGatewaySubnetId = getStackEndpointGatwaySubnetIdIfExists(stack);
                    LOGGER.info("Unable to find endpoint gateway subnet metas to match AZs {}. Falling back to subnet {}.", allAvailabilityZones, endpointGatewaySubnetId);
                    instanceGroupNetworkV4Request.getAws().setEndpointGatewaySubnetIds(List.of(endpointGatewaySubnetId));
                } else {
                    LOGGER.info("Selected endpoint gateway subnets {} for instance group {}", endpointGatewaySubnetIds, instanceGroupName);
                    instanceGroupNetworkV4Request.getAws().setEndpointGatewaySubnetIds(endpointGatewaySubnetIds);
                }
            }
        }
    }
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)

Example 65 with EnvironmentNetworkResponse

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

the class EndpointGatewayNetworkValidatorTest method validateWhenEndpointGatewaySubnetsAreInvalid.

@Test
public void validateWhenEndpointGatewaySubnetsAreInvalid() {
    EnvironmentNetworkResponse network = new EnvironmentNetworkResponse();
    network.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
    CloudSubnet publicSubnet = getPublicCloudSubnet(PUBLIC_ID_1, AZ_1);
    network.setGatewayEndpointSubnetMetas(Map.of(KEY, publicSubnet));
    when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1)));
    when(subnetSelector.chooseSubnetForEndpointGateway(any(), anyString())).thenReturn(Optional.empty());
    ValidationResult result = underTest.validate(new ImmutablePair<>(PRIVATE_ID_1, network));
    assert result.hasError();
    assertEquals(String.format(NO_USABLE_SUBNET_IN_ENDPOINT_GATEWAY, AZ_1), result.getErrors().get(0));
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.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