Search in sources :

Example 16 with EnvironmentNetworkResponse

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

the class NetworkDtoToResponseConverterTest method testConvertWithLoadBalancerEnabled.

@Test
void testConvertWithLoadBalancerEnabled() {
    NetworkDto network = createNetworkDto().withAws(createAwsParams()).withLoadBalancerCreation(LoadBalancerCreation.ENABLED).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);
    assertEquals(network.getAws().getVpcId(), actual.getAws().getVpcId());
    assertEquals(LoadBalancerCreation.ENABLED, actual.getLoadBalancerCreation());
    assertNull(actual.getAzure());
    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)

Example 17 with EnvironmentNetworkResponse

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

the class InstanceGroupNetworkV1ToInstanceGroupNetworkV4Converter method convertToInstanceGroupNetworkV4Request.

public InstanceGroupNetworkV4Request convertToInstanceGroupNetworkV4Request(Pair<InstanceGroupNetworkV1Request, DetailedEnvironmentResponse> network) {
    DetailedEnvironmentResponse value = network.getValue();
    EnvironmentNetworkResponse environmentNetworkResponse = null;
    if (value == null) {
        environmentNetworkResponse = new EnvironmentNetworkResponse();
    } else {
        environmentNetworkResponse = value.getNetwork();
    }
    InstanceGroupNetworkV1Request key = network.getKey();
    if (key == null) {
        key = new InstanceGroupNetworkV1Request();
    }
    InstanceGroupNetworkV4Request request = new InstanceGroupNetworkV4Request();
    if (value != null) {
        CloudPlatform cloudPlatform = CloudPlatform.valueOf(value.getCloudPlatform());
        request.setCloudPlatform(cloudPlatform);
        request.setAws(instanceGroupNetworkParameterConverter.convert(key.getAws(), environmentNetworkResponse, cloudPlatform));
        request.setAzure(instanceGroupNetworkParameterConverter.convert(key.getAzure(), environmentNetworkResponse, cloudPlatform));
        request.setGcp(instanceGroupNetworkParameterConverter.convert(key.getGcp(), environmentNetworkResponse, cloudPlatform));
        request.setYarn(instanceGroupNetworkParameterConverter.convert(key.getYarn(), environmentNetworkResponse, cloudPlatform));
        request.setMock(instanceGroupNetworkParameterConverter.convert(key.getMock(), environmentNetworkResponse, cloudPlatform));
    }
    return request;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) InstanceGroupNetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.network.InstanceGroupNetworkV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) InstanceGroupNetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request)

Example 18 with EnvironmentNetworkResponse

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

the class NetworkV1ToNetworkV4Converter method convertToMockNetworkParams.

private MockNetworkV4Parameters convertToMockNetworkParams(Pair<MockNetworkV1Parameters, EnvironmentNetworkResponse> source) {
    EnvironmentNetworkResponse value = source.getValue();
    MockNetworkV1Parameters key = source.getKey();
    MockNetworkV4Parameters params = new MockNetworkV4Parameters();
    if (key != null) {
        String subnetId = key.getSubnetId();
        if (value != null) {
            evaluateIfTrueDoOtherwise(subnetId, StringUtils::isNotEmpty, params::setSubnetId, s -> params.setSubnetId(value.getPreferedSubnetId()));
        }
        params.setInternetGatewayId(key.getInternetGatewayId());
        params.setVpcId(key.getVpcId());
    }
    return params;
}
Also used : MockNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.mock.MockNetworkV1Parameters) StringUtils(org.apache.commons.lang3.StringUtils) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) MockNetworkV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.network.MockNetworkV4Parameters)

Example 19 with EnvironmentNetworkResponse

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

the class NetworkV1ToNetworkV4Converter method convertToGcpStackRequest.

private GcpNetworkV4Parameters convertToGcpStackRequest(Pair<GcpNetworkV1Parameters, EnvironmentNetworkResponse> source) {
    EnvironmentNetworkResponse value = source.getValue();
    GcpNetworkV1Parameters key = source.getKey();
    GcpNetworkV4Parameters response = new GcpNetworkV4Parameters();
    if (key != null) {
        response.setNetworkId(value.getGcp().getNetworkId());
        response.setNoFirewallRules(value.getGcp().getNoFirewallRules());
        response.setNoPublicIp(value.getGcp().getNoPublicIp());
        response.setSharedProjectId(value.getGcp().getSharedProjectId());
        String subnetId = key.getSubnetId();
        if (!Strings.isNullOrEmpty(subnetId)) {
            response.setSubnetId(subnetId);
        } else {
            response.setSubnetId(getFirstSubnetIdFromEnvironment(value));
        }
    }
    return response;
}
Also used : GcpNetworkV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.network.GcpNetworkV4Parameters) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) GcpNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.gcp.GcpNetworkV1Parameters)

Example 20 with EnvironmentNetworkResponse

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

the class NetworkV1ToNetworkV4Converter method convertToAwsStackRequest.

private AwsNetworkV4Parameters convertToAwsStackRequest(Pair<AwsNetworkV1Parameters, EnvironmentNetworkResponse> source) {
    EnvironmentNetworkResponse value = source.getValue();
    AwsNetworkV1Parameters key = source.getKey();
    AwsNetworkV4Parameters response = new AwsNetworkV4Parameters();
    if (key != null) {
        response.setVpcId(value.getAws().getVpcId());
        String subnetId = key.getSubnetId();
        if (!Strings.isNullOrEmpty(subnetId)) {
            response.setSubnetId(key.getSubnetId());
        } else if (value != null) {
            response.setSubnetId(value.getPreferedSubnetId());
        }
        if (PublicEndpointAccessGateway.ENABLED.equals(value.getPublicEndpointAccessGateway())) {
            ValidationResult validationResult = endpointGatewayNetworkValidator.validate(new ImmutablePair<>(response.getSubnetId(), value));
            if (validationResult.getState() == ValidationResult.State.ERROR || validationResult.hasError()) {
                throw new BadRequestException("Endpoint gateway subnet validation failed: " + validationResult.getFormattedErrors());
            }
            Optional<CloudSubnet> endpointGatewaySubnet = subnetSelector.chooseSubnetForEndpointGateway(value, response.getSubnetId());
            if (endpointGatewaySubnet.isPresent()) {
                response.setEndpointGatewaySubnetId(endpointGatewaySubnet.get().getId());
            }
        }
    }
    return response;
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) AwsNetworkV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.network.AwsNetworkV4Parameters)

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