Search in sources :

Example 1 with EnvironmentNetworkResponse

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

the class GcpEnvironmentNetworkConverter method getAttributesForLegacyNetwork.

@Override
Map<String, Object> getAttributesForLegacyNetwork(EnvironmentNetworkResponse source) {
    EnvironmentNetworkGcpParams gcp = source.getGcp();
    Map<String, Object> result = new HashMap<>();
    if (!Strings.isNullOrEmpty(gcp.getNetworkId())) {
        result.put("networkId", gcp.getNetworkId());
    }
    if (gcp.getNoFirewallRules() != null) {
        result.put("noFirewallRules", gcp.getNoFirewallRules());
    }
    if (gcp.getNoPublicIp() != null) {
        result.put("noPublicIp", gcp.getNoPublicIp());
    }
    if (!Strings.isNullOrEmpty(gcp.getSharedProjectId())) {
        result.put("sharedProjectId", gcp.getSharedProjectId());
    }
    return result;
}
Also used : EnvironmentNetworkGcpParams(com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkGcpParams) HashMap(java.util.HashMap)

Example 2 with EnvironmentNetworkResponse

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

the class EndpointGatewayNetworkValidator method validate.

@Override
public ValidationResult validate(Pair<String, EnvironmentNetworkResponse> subject) {
    String baseSubnetId = subject.getLeft();
    EnvironmentNetworkResponse network = subject.getRight();
    ValidationResultBuilder resultBuilder = ValidationResult.builder();
    if (network == null) {
        LOGGER.debug("No network provided; public endpoint access gateway is disabled.");
    } else {
        if (PublicEndpointAccessGateway.ENABLED.equals(network.getPublicEndpointAccessGateway())) {
            if (Strings.isNullOrEmpty(baseSubnetId)) {
                resultBuilder.error(NO_BASE_SUBNET);
            } else {
                Optional<CloudSubnet> baseSubnet = subnetSelector.findSubnetById(network.getSubnetMetas(), baseSubnetId);
                if (baseSubnet.isEmpty()) {
                    resultBuilder.error(String.format(NO_BASE_SUBNET_META, baseSubnetId));
                } else {
                    String error;
                    if (!MapUtils.isEmpty(network.getGatewayEndpointSubnetMetas())) {
                        LOGGER.debug("Attempting to validate endpoint gateway subnet using provided endpoint subnets.");
                        error = NO_USABLE_SUBNET_IN_ENDPOINT_GATEWAY;
                    } else {
                        LOGGER.debug("Attempting to validate endpoint gateway subnet using cluster subnets.");
                        error = NO_USABLE_SUBNET_IN_CLUSTER;
                    }
                    Optional<CloudSubnet> endpointGatewaySubnet = subnetSelector.chooseSubnetForEndpointGateway(network, baseSubnetId);
                    resultBuilder.ifError(endpointGatewaySubnet::isEmpty, String.format(error, baseSubnet.get().getAvailabilityZone()));
                }
            }
        }
    }
    return resultBuilder.build();
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 3 with EnvironmentNetworkResponse

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

the class AwsEnvironmentNetworkConverterTest method getAttributesForLegacyNetwork.

@Test
void getAttributesForLegacyNetwork() {
    EnvironmentNetworkResponse source = mock(EnvironmentNetworkResponse.class);
    EnvironmentNetworkAwsParams aws = mock(EnvironmentNetworkAwsParams.class);
    when(source.getAws()).thenReturn(aws);
    when(aws.getVpcId()).thenReturn("my_vpc_id");
    Map<String, Object> result = converter.getAttributesForLegacyNetwork(source);
    assertEquals("my_vpc_id", result.get("vpcId"));
}
Also used : EnvironmentNetworkAwsParams(com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkAwsParams) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Test(org.junit.jupiter.api.Test)

Example 4 with EnvironmentNetworkResponse

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

the class AzureEnvironmentNetworkConverterTest method testGetAttributesForLegacyNetwork.

@Test
void testGetAttributesForLegacyNetwork() {
    EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
    EnvironmentNetworkAzureParams azure = mock(EnvironmentNetworkAzureParams.class);
    when(environmentNetworkResponse.getAzure()).thenReturn(azure);
    when(azure.getNetworkId()).thenReturn("my_network_id");
    when(azure.getResourceGroupName()).thenReturn("my_resource_group");
    when(azure.getNoPublicIp()).thenReturn(true);
    Map<String, Object> result = converter.getAttributesForLegacyNetwork(environmentNetworkResponse);
    assertEquals("my_network_id", result.get("networkId"));
    assertEquals("my_resource_group", result.get("resourceGroupName"));
    assertEquals(true, result.get("noPublicIp"));
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) EnvironmentNetworkAzureParams(com.sequenceiq.environment.api.v1.environment.model.EnvironmentNetworkAzureParams) Test(org.junit.jupiter.api.Test)

Example 5 with EnvironmentNetworkResponse

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

the class EnvironmentBaseNetworkConverterTest method setupResponse.

private EnvironmentNetworkResponse setupResponse() {
    EnvironmentNetworkResponse source = new EnvironmentNetworkResponse();
    source.setNetworkCidrs(NETWORK_CIDRS);
    source.setOutboundInternetTraffic(OutboundInternetTraffic.DISABLED);
    return source;
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)

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