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