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());
}
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());
}
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;
}
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;
}
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;
}
Aggregations