Search in sources :

Example 6 with InstanceGroupAwsNetworkV1Parameters

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

the class DistroXV1RequestToStackV4RequestConverterTest method testGetNetworkWhenHasOneSubnetIdInInstanceGroupsNetworkAws.

@Test
public void testGetNetworkWhenHasOneSubnetIdInInstanceGroupsNetworkAws() {
    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();
    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 7 with InstanceGroupAwsNetworkV1Parameters

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

the class DistroXV1RequestToStackV4RequestConverterTest method testGetNetworkWhenHasDiffSubnetIdInInstanceGroupsNetworkAws.

@Test
public void testGetNetworkWhenHasDiffSubnetIdInInstanceGroupsNetworkAws() {
    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("subnet2"));
    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("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)

Example 8 with InstanceGroupAwsNetworkV1Parameters

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

the class InstanceGroupNetworkParameterConverter method convertToAwsNetworkParams.

private InstanceGroupAwsNetworkV4Parameters convertToAwsNetworkParams(Pair<InstanceGroupAwsNetworkV1Parameters, EnvironmentNetworkResponse> source) {
    InstanceGroupAwsNetworkV1Parameters key = source.getKey();
    InstanceGroupAwsNetworkV4Parameters response = new InstanceGroupAwsNetworkV4Parameters();
    if (key != null) {
        List<String> subnetIds = key.getSubnetIds();
        if (subnetIdsDefined(subnetIds)) {
            response.setSubnetIds(subnetIds);
        } else if (source.getValue() != null) {
            response.setSubnetIds(List.of(source.getValue().getPreferedSubnetId()));
        }
        List<String> endpointGatewaySubnetIds = key.getEndpointGatewaySubnetIds();
        if (subnetIdsDefined(endpointGatewaySubnetIds)) {
            response.setEndpointGatewaySubnetIds(endpointGatewaySubnetIds);
        } else if (source.getValue() != null) {
            response.setEndpointGatewaySubnetIds(List.copyOf(source.getValue().getEndpointGatewaySubnetIds()));
        }
    }
    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)

Example 9 with InstanceGroupAwsNetworkV1Parameters

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

the class InstanceGroupV1ToInstanceGroupV4Converter method hasAwsSubnets.

private boolean hasAwsSubnets(InstanceGroupV1Request instanceGroupV1Request) {
    boolean instanceGroupRequestHasSubnet = false;
    InstanceGroupAwsNetworkV1Parameters aws = instanceGroupV1Request.getNetwork().getAws();
    if (aws != null) {
        instanceGroupRequestHasSubnet = isNotEmptyOrNull(aws.getSubnetIds());
    }
    return instanceGroupRequestHasSubnet;
}
Also used : InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters)

Example 10 with InstanceGroupAwsNetworkV1Parameters

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

the class DistroXV1RequestToStackV4RequestConverter method getNetwork.

NetworkV4Request getNetwork(NetworkV1Request networkRequest, DetailedEnvironmentResponse environment, Set<InstanceGroupV1Request> instanceGroupRequests) {
    Set<String> subnetIds = new HashSet<>();
    if (instanceGroupRequests != null) {
        subnetIds.addAll(instanceGroupRequests.stream().map(ig -> Optional.ofNullable(ig.getNetwork()).map(InstanceGroupNetworkV1Base::getAws).map(InstanceGroupAwsNetworkV1Parameters::getSubnetIds).orElseGet(ArrayList::new)).flatMap(Collection::stream).collect(Collectors.toSet()));
    }
    if (subnetIds.size() == 1) {
        String subnetId = subnetIds.stream().findFirst().get();
        LOGGER.info("Update the global subnet id to {}, because it is configured in instance group level as the new way", subnetId);
        if (networkRequest == null) {
            networkRequest = new NetworkV1Request();
        }
        if (networkRequest.getAws() == null) {
            networkRequest.setAws(new AwsNetworkV1Parameters());
        }
        networkRequest.getAws().setSubnetId(subnetId);
    } else {
        LOGGER.info("Use the legacy way to configure the global network.");
    }
    NetworkV4Request network = getIfNotNull(new ImmutablePair<>(networkRequest, environment), networkConverter::convertToNetworkV4Request);
    validateSubnetIds(network, environment);
    return network;
}
Also used : PlacementSettingsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.environment.placement.PlacementSettingsV4Request) InstanceGroupNetworkV1Base(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Base) InstanceGroupAwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters) NullUtil.getIfNotNull(com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) TelemetryConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.TelemetryConverter) LoggerFactory(org.slf4j.LoggerFactory) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) TagsV1Request(com.sequenceiq.distrox.api.v1.distrox.model.tags.TagsV1Request) ArrayList(java.util.ArrayList) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) HashSet(java.util.HashSet) Inject(javax.inject.Inject) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) AwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) TelemetryResponse(com.sequenceiq.common.api.telemetry.response.TelemetryResponse) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) TagsV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.tags.TagsV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) YarnStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.YarnStackV4Parameters) Component(org.springframework.stereotype.Component) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) SdxClientService(com.sequenceiq.cloudbreak.service.datalake.SdxClientService) Optional(java.util.Optional) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) ArrayList(java.util.ArrayList) Collection(java.util.Collection) InstanceGroupNetworkV1Base(com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Base) NetworkV1Request(com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request) 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)

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