Search in sources :

Example 1 with InstanceGroupNetworkV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request in project cloudbreak by hortonworks.

the class DistroXTestDtoBase method withPreferredSubnetsForInstanceNetworkIfMultiAzEnabledOrJustFirst.

public DistroXTestDtoBase<T> withPreferredSubnetsForInstanceNetworkIfMultiAzEnabledOrJustFirst() {
    if (StringUtils.isEmpty(getRequest().getEnvironmentName())) {
        throw new TestFailException("Cannot fetch the preferred subnet without env name, please add it");
    }
    try {
        EnvironmentClient envClient = getTestContext().getMicroserviceClient(EnvironmentClient.class);
        DetailedEnvironmentResponse envResponse = envClient.getDefaultClient().environmentV1Endpoint().getByName(getRequest().getEnvironmentName());
        InstanceGroupNetworkV1Request instanceGroupNetworkV1Request = new InstanceGroupNetworkV1Request();
        InstanceGroupAwsNetworkV1Parameters awsNetworkV1Parameters = new InstanceGroupAwsNetworkV1Parameters();
        if ("AWS_NATIVE".equals(getRequest().getVariant())) {
            awsNetworkV1Parameters.setSubnetIds(new ArrayList<>(envResponse.getNetwork().getPreferedSubnetIds()));
        } else {
            envResponse.getNetwork().getPreferedSubnetIds().stream().filter(s -> !s.equals(envResponse.getNetwork().getPreferedSubnetId())).findFirst().ifPresent(s -> awsNetworkV1Parameters.setSubnetIds(List.of(s)));
        }
        instanceGroupNetworkV1Request.setAws(awsNetworkV1Parameters);
        getRequest().getInstanceGroups().forEach(s -> s.setNetwork(instanceGroupNetworkV1Request));
    } catch (Exception e) {
        String message = "Cannot fetch preferred subnets from " + getRequest().getEnvironmentName();
        throw new TestFailException(message, e);
    }
    return this;
}
Also used : InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) EnvironmentClient(com.sequenceiq.it.cloudbreak.EnvironmentClient) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupNetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 2 with InstanceGroupNetworkV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request 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 3 with InstanceGroupNetworkV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request in project cloudbreak by hortonworks.

the class InstanceGroupV1ToInstanceGroupV4Converter method getInstanceGroupNetworkV1RequestByProvider.

private InstanceGroupNetworkV1Request getInstanceGroupNetworkV1RequestByProvider(NetworkV4Request distroxNetwork, DetailedEnvironmentResponse environment) {
    InstanceGroupNetworkV1Request request = null;
    switch(environment.getCloudPlatform()) {
        case "AWS":
            if (distroxNetwork.getAws() != null) {
                request = new InstanceGroupNetworkV1Request();
                InstanceGroupAwsNetworkV1Parameters aws = new InstanceGroupAwsNetworkV1Parameters();
                aws.setSubnetIds(getSubnetIds(distroxNetwork.getAws().getSubnetId()));
                request.setAws(aws);
            }
            break;
        case "AZURE":
            if (distroxNetwork.getAzure() != null) {
                request = new InstanceGroupNetworkV1Request();
                InstanceGroupAzureNetworkV1Parameters azure = new InstanceGroupAzureNetworkV1Parameters();
                azure.setSubnetIds(getSubnetIds(distroxNetwork.getAzure().getSubnetId()));
                request.setAzure(azure);
            }
            break;
        case "MOCK":
            if (distroxNetwork.getMock() != null) {
                request = new InstanceGroupNetworkV1Request();
                InstanceGroupMockNetworkV1Parameters mock = new InstanceGroupMockNetworkV1Parameters();
                mock.setSubnetIds(getSubnetIds(distroxNetwork.getMock().getSubnetId()));
                request.setMock(mock);
            }
            break;
        case "GCP":
            if (distroxNetwork.getGcp() != null) {
                request = new InstanceGroupNetworkV1Request();
                InstanceGroupGcpNetworkV1Parameters gcp = new InstanceGroupGcpNetworkV1Parameters();
                gcp.setSubnetIds(getSubnetIds(distroxNetwork.getGcp().getSubnetId()));
                request.setGcp(gcp);
            }
            break;
        default:
    }
    return request;
}
Also used : InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) InstanceGroupGcpNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.gcp.InstanceGroupGcpNetworkV1Parameters) InstanceGroupAzureNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.azure.InstanceGroupAzureNetworkV1Parameters) InstanceGroupNetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request) InstanceGroupMockNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.mock.InstanceGroupMockNetworkV1Parameters)

Example 4 with InstanceGroupNetworkV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method testGetNetworkWhenHasSameSubnetIdInInstanceGroupsNetworkAws.

@Test
public void testGetNetworkWhenHasSameSubnetIdInInstanceGroupsNetworkAws() {
    NetworkV1Request networkRequest = new NetworkV1Request();
    AwsNetworkV1Parameters aws = new AwsNetworkV1Parameters();
    aws.setSubnetId("sub1");
    networkRequest.setAws(aws);
    Set<InstanceGroupV1Request> instanceGroups = new HashSet<>();
    InstanceGroupV1Request ig1 = new InstanceGroupV1Request();
    InstanceGroupNetworkV1Request network = new InstanceGroupNetworkV1Request();
    InstanceGroupAwsNetworkV1Parameters awsNetworkV1Parameters = new InstanceGroupAwsNetworkV1Parameters();
    awsNetworkV1Parameters.setSubnetIds(List.of("subnet1"));
    network.setAws(awsNetworkV1Parameters);
    ig1.setNetwork(network);
    InstanceGroupV1Request ig2 = new InstanceGroupV1Request();
    InstanceGroupNetworkV1Request network1 = new InstanceGroupNetworkV1Request();
    InstanceGroupAwsNetworkV1Parameters awsNetworkV1Parameters1 = new InstanceGroupAwsNetworkV1Parameters();
    awsNetworkV1Parameters1.setSubnetIds(List.of("subnet1"));
    network1.setAws(awsNetworkV1Parameters1);
    ig2.setNetwork(network1);
    instanceGroups.add(ig1);
    instanceGroups.add(ig2);
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setCloudPlatform("ANY");
    NetworkV4Request networkV4Request = new NetworkV4Request();
    ArgumentCaptor<Pair<NetworkV1Request, DetailedEnvironmentResponse>> networkConverterCaptor = ArgumentCaptor.forClass(Pair.class);
    when(networkConverter.convertToNetworkV4Request(any())).thenReturn(networkV4Request);
    NetworkV4Request actual = underTest.getNetwork(networkRequest, environment, instanceGroups);
    verify(networkConverter).convertToNetworkV4Request(networkConverterCaptor.capture());
    Assertions.assertEquals(networkV4Request, actual);
    Pair<NetworkV1Request, DetailedEnvironmentResponse> captured = networkConverterCaptor.getValue();
    Assertions.assertEquals("subnet1", captured.getKey().getAws().getSubnetId());
}
Also used : InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupNetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) InstanceGroupNetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request) InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) AwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters) HashSet(java.util.HashSet) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with InstanceGroupNetworkV1Request

use of com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method testGetNetworkWhenSubnetIdsIsNullInInstanceGroupsNetworkAws.

@Test
public void testGetNetworkWhenSubnetIdsIsNullInInstanceGroupsNetworkAws() {
    NetworkV1Request networkRequest = new NetworkV1Request();
    AwsNetworkV1Parameters aws = new AwsNetworkV1Parameters();
    aws.setSubnetId("sub1");
    networkRequest.setAws(aws);
    Set<InstanceGroupV1Request> instanceGroups = new HashSet<>();
    InstanceGroupV1Request ig1 = new InstanceGroupV1Request();
    InstanceGroupNetworkV1Request network = new InstanceGroupNetworkV1Request();
    network.setAws(new InstanceGroupAwsNetworkV1Parameters());
    ig1.setNetwork(network);
    InstanceGroupV1Request ig2 = new InstanceGroupV1Request();
    InstanceGroupNetworkV1Request network1 = new InstanceGroupNetworkV1Request();
    network1.setAws(new InstanceGroupAwsNetworkV1Parameters());
    ig2.setNetwork(network1);
    instanceGroups.add(ig1);
    instanceGroups.add(ig2);
    DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
    environment.setCloudPlatform("ANY");
    NetworkV4Request networkV4Request = new NetworkV4Request();
    ArgumentCaptor<Pair<NetworkV1Request, DetailedEnvironmentResponse>> networkConverterCaptor = ArgumentCaptor.forClass(Pair.class);
    when(networkConverter.convertToNetworkV4Request(any())).thenReturn(networkV4Request);
    NetworkV4Request actual = underTest.getNetwork(networkRequest, environment, instanceGroups);
    verify(networkConverter).convertToNetworkV4Request(networkConverterCaptor.capture());
    Assertions.assertEquals(networkV4Request, actual);
    Pair<NetworkV1Request, DetailedEnvironmentResponse> captured = networkConverterCaptor.getValue();
    Assertions.assertEquals("sub1", captured.getKey().getAws().getSubnetId());
}
Also used : InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupNetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) InstanceGroupNetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request) InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) AwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters) HashSet(java.util.HashSet) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

InstanceGroupNetworkV1Request (com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request)10 InstanceGroupAwsNetworkV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters)7 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)7 NetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)5 InstanceGroupV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request)5 NetworkV1Request (com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request)5 AwsNetworkV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters)5 HashSet (java.util.HashSet)5 Pair (org.apache.commons.lang3.tuple.Pair)5 Test (org.junit.jupiter.api.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 InstanceGroupNetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.network.InstanceGroupNetworkV4Request)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 InstanceGroupAzureNetworkV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.network.azure.InstanceGroupAzureNetworkV1Parameters)1 InstanceGroupGcpNetworkV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.network.gcp.InstanceGroupGcpNetworkV1Parameters)1 InstanceGroupMockNetworkV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.network.mock.InstanceGroupMockNetworkV1Parameters)1 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)1 EnvironmentClient (com.sequenceiq.it.cloudbreak.EnvironmentClient)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 LinkedList (java.util.LinkedList)1