Search in sources :

Example 1 with NetworkV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request in project cloudbreak by hortonworks.

the class NetworkToNetworkV4RequestConverterTest method testConvertWhenSubnetCidrIsNotNullThenResultShouldContainSubnetCidr.

@Test
void testConvertWhenSubnetCidrIsNotNullThenResultShouldContainSubnetCidr() {
    Network input = new Network();
    input.setSubnetCIDR("someCidr");
    NetworkV4Request result = underTest.convert(input);
    assertNotNull(result);
    assertEquals(input.getSubnetCIDR(), result.getSubnetCIDR());
}
Also used : Network(com.sequenceiq.cloudbreak.domain.Network) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request) Test(org.junit.jupiter.api.Test)

Example 2 with NetworkV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverter method convert.

public StackV4Request convert(DistroXV1Request source) {
    DetailedEnvironmentResponse environment = Optional.ofNullable(environmentClientService.getByName(source.getEnvironmentName())).orElseThrow(() -> new BadRequestException("No environment name provided hence unable to obtain some important data"));
    StackV4Request request = new StackV4Request();
    SdxClusterResponse sdxClusterResponse = getSdxClusterResponse(environment);
    request.setName(source.getName());
    request.setType(StackType.WORKLOAD);
    request.setCloudPlatform(getCloudPlatform(environment));
    request.setEnvironmentCrn(environment.getCrn());
    request.setAuthentication(getIfNotNull(environment.getAuthentication(), authenticationConverter::convert));
    request.setImage(getIfNotNull(source.getImage(), imageConverter::convert));
    request.setCluster(getIfNotNull(source, environment, clusterConverter::convert));
    NetworkV4Request network = getNetwork(source.getNetwork(), environment, source.getInstanceGroups());
    request.setNetwork(network);
    request.setInstanceGroups(getIfNotNull(source.getInstanceGroups(), igs -> instanceGroupConverter.convertTo(network, igs, environment)));
    request.setAws(getIfNotNull(source.getAws(), stackParameterConverter::convert));
    request.setAzure(getIfNotNull(source.getAzure(), stackParameterConverter::convert));
    request.setGcp(getIfNotNull(source.getGcp(), stackParameterConverter::convert));
    request.setYarn(getYarnProperties(source, environment));
    request.setInputs(source.getInputs());
    request.setTags(getIfNotNull(source.getTags(), this::getTags));
    request.setPlacement(preparePlacement(environment));
    request.setSharedService(sdxConverter.getSharedService(sdxClusterResponse));
    request.setCustomDomain(null);
    request.setTimeToLive(source.getTimeToLive());
    request.setTelemetry(getTelemetryRequest(environment, sdxClusterResponse));
    request.setGatewayPort(source.getGatewayPort());
    request.setExternalDatabase(getIfNotNull(source.getExternalDatabase(), databaseRequestConverter::convert));
    request.setEnableLoadBalancer(source.isEnableLoadBalancer());
    request.setVariant(source.getVariant());
    checkMultipleGatewayNodes(source);
    return request;
}
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) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) NetworkV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)

Example 3 with NetworkV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request in project cloudbreak by hortonworks.

the class InstanceGroupV1ToInstanceGroupV4Converter method convert.

private InstanceGroupV4Request convert(NetworkV4Request network, InstanceGroupV1Request source, DetailedEnvironmentResponse environment) {
    InstanceGroupV4Request response = new InstanceGroupV4Request();
    response.setNodeCount(source.getNodeCount());
    response.setType(source.getType());
    response.setCloudPlatform(source.getCloudPlatform());
    response.setName(source.getName());
    response.setTemplate(getIfNotNull(source.getTemplate(), environment, instanceTemplateConverter::convert));
    response.setRecoveryMode(source.getRecoveryMode());
    response.setScalabilityOption(source.getScalabilityOption());
    response.setSecurityGroup(createSecurityGroupFromEnvironment(source.getType(), environment));
    response.setRecipeNames(source.getRecipeNames());
    response.setMinimumNodeCount(source.getMinimumNodeCount());
    response.setAws(getIfNotNull(source.getAws(), instanceGroupParameterConverter::convert));
    response.setAzure(getIfNotNull(source.getAzure(), instanceGroupParameterConverter::convert));
    response.setGcp(getIfNotNull(source.getGcp(), instanceGroupParameterConverter::convert));
    response.setYarn(getIfNotNull(source.getYarn(), instanceGroupParameterConverter::convert));
    response.setNetwork(getInstanceGroupNetworkV4Request(network, source, environment));
    return response;
}
Also used : InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)

Example 4 with NetworkV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request 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 NetworkV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request 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

NetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.network.NetworkV4Request)35 Test (org.junit.jupiter.api.Test)21 NetworkV1Request (com.sequenceiq.distrox.api.v1.distrox.model.network.NetworkV1Request)19 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)17 InstanceGroupV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request)10 AwsNetworkV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters)8 InstanceGroupAwsNetworkV1Parameters (com.sequenceiq.distrox.api.v1.distrox.model.network.aws.InstanceGroupAwsNetworkV1Parameters)8 HashSet (java.util.HashSet)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 InstanceGroupNetworkV1Request (com.sequenceiq.distrox.api.v1.distrox.model.network.InstanceGroupNetworkV1Request)6 Pair (org.apache.commons.lang3.tuple.Pair)6 InstanceGroupNetworkV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.network.InstanceGroupNetworkV4Request)5 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)5 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)4 Test (org.junit.Test)4 AwsNetworkV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.network.AwsNetworkV4Parameters)3 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)3 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)3 StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)2 AzureNetworkV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.network.AzureNetworkV4Parameters)2