Search in sources :

Example 1 with InstanceGroupAwsNetworkV1Parameters

use of com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters 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 InstanceGroupAwsNetworkV1Parameters

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

the class InstanceGroupNetworkParameterConverter method convert.

public InstanceGroupAwsNetworkV4Parameters convert(InstanceGroupAwsNetworkV1Parameters aws, EnvironmentNetworkResponse value, CloudPlatform cloudPlatform) {
    InstanceGroupAwsNetworkV4Parameters response = null;
    if (CloudPlatform.AWS == cloudPlatform) {
        InstanceGroupAwsNetworkV1Parameters params = aws == null ? new InstanceGroupAwsNetworkV1Parameters() : aws;
        response = convertToAwsNetworkParams(new ImmutablePair<>(params, value));
    }
    return response;
}
Also used : InstanceGroupAwsNetworkV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.instancegroup.network.aws.InstanceGroupAwsNetworkV4Parameters) InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 3 with InstanceGroupAwsNetworkV1Parameters

use of com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters 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 InstanceGroupAwsNetworkV1Parameters

use of com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters 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 InstanceGroupAwsNetworkV1Parameters

use of com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters 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

InstanceGroupAwsNetworkV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters)10 InstanceGroupNetworkV1Request (com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request)6 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)6 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)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 InstanceGroupAwsNetworkV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.instancegroup.network.aws.InstanceGroupAwsNetworkV4Parameters)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)1 YarnStackV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.YarnStackV4Parameters)1 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)1 PlacementSettingsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request)1 TagsV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request)1 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1