use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsSubnetRequestProvider method provide.
public List<SubnetRequest> provide(AmazonEc2Client ec2Client, List<NetworkSubnetRequest> publicSubnets, List<NetworkSubnetRequest> privateSubnets) {
List<String> az = getAvailabilityZones(ec2Client);
List<SubnetRequest> subnets = new ArrayList<>();
int index = 0;
for (int i = 0; i < publicSubnets.size(); i++) {
SubnetRequest subnetRequest = new SubnetRequest();
NetworkSubnetRequest networkSubnetRequest = publicSubnets.get(i);
subnetRequest.setPublicSubnetCidr(networkSubnetRequest.getCidr());
subnetRequest.setType(networkSubnetRequest.getType());
subnetRequest.setAvailabilityZone(az.get(i % az.size()));
subnetRequest.setSubnetGroup(i % publicSubnets.size());
subnetRequest.setIndex(index++);
subnets.add(subnetRequest);
}
for (int i = 0; i < privateSubnets.size(); i++) {
SubnetRequest subnetRequest = new SubnetRequest();
NetworkSubnetRequest networkSubnetRequest = privateSubnets.get(i);
subnetRequest.setPrivateSubnetCidr(networkSubnetRequest.getCidr());
subnetRequest.setType(networkSubnetRequest.getType());
subnetRequest.setAvailabilityZone(az.get(i % az.size()));
// we will create 3 public subnet for nat gateways so we need to loadbalance between the public subnets
subnetRequest.setSubnetGroup(i % publicSubnets.size());
subnetRequest.setIndex(index++);
subnets.add(subnetRequest);
}
return subnets;
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsNetworkCfTemplateProviderTest method testProvideWhenPrivateSubnetsButNoVpcEndpointsConfigured.
@Test
public void testProvideWhenPrivateSubnetsButNoVpcEndpointsConfigured() throws IOException, TemplateException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode expectedJson = objectMapper.readTree(new File("src/test/resources/json/aws-cf-network-privatesubnet-novpcendpoints.json"));
when(freeMarkerTemplateUtils.processTemplateIntoString(any(), any())).thenCallRealMethod();
ReflectionTestUtils.setField(underTest, "gatewayServices", List.of());
ReflectionTestUtils.setField(underTest, "interfaceServices", List.of());
NetworkCreationRequest networkCreationRequest = createNetworkRequest(true, PrivateEndpointType.USE_VPC_ENDPOINT);
List<SubnetRequest> subnetRequestList = createPrivateAndPublicSubnetRequestList();
String actual = underTest.provide(networkCreationRequest, subnetRequestList);
JsonNode json = objectMapper.readTree(actual);
assertEquals(expectedJson, json);
verify(freeMarkerTemplateUtils).processTemplateIntoString(any(Template.class), anyMap());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsNetworkCfTemplateProviderTest method testProvideShouldThrowExceptionWhenTemplateProcessHasFailed.
@Test
public void testProvideShouldThrowExceptionWhenTemplateProcessHasFailed() throws IOException, TemplateException {
when(freeMarkerTemplateUtils.processTemplateIntoString(any(Template.class), anyMap())).thenThrow(TemplateException.class);
NetworkCreationRequest networkCreationRequest = createNetworkRequest(false, PrivateEndpointType.NONE);
List<SubnetRequest> subnetRequestList = createPublicSubnetRequestList();
Assertions.assertThrows(CloudConnectorException.class, () -> underTest.provide(networkCreationRequest, subnetRequestList));
verify(freeMarkerTemplateUtils).processTemplateIntoString(any(Template.class), anyMap());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method createSubnetRequestList.
private List<SubnetRequest> createSubnetRequestList() {
SubnetRequest subnetRequest1 = new SubnetRequest();
subnetRequest1.setPublicSubnetCidr("2.2.2.2/24");
subnetRequest1.setPrivateSubnetCidr("2.2.2.2/24");
subnetRequest1.setAvailabilityZone("az1");
SubnetRequest subnetRequest2 = new SubnetRequest();
subnetRequest2.setPublicSubnetCidr("2.2.2.2/24");
subnetRequest2.setPrivateSubnetCidr("2.2.2.2/24");
subnetRequest2.setAvailabilityZone("az2");
SubnetRequest subnetRequest3 = new SubnetRequest();
subnetRequest3.setPublicSubnetCidr("2.2.2.2/24");
subnetRequest3.setPrivateSubnetCidr("2.2.2.2/24");
subnetRequest3.setAvailabilityZone("az3");
return List.of(subnetRequest1, subnetRequest2, subnetRequest3);
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsCreatedSubnetProvider method provide.
Set<CreatedSubnet> provide(Map<String, String> output, List<SubnetRequest> subnetRequests, boolean privateSubnetEnabled) {
Set<CreatedSubnet> subnets = new HashSet<>();
for (SubnetRequest subnetRequest : subnetRequests) {
CreatedSubnet createdPublicSubnet = new CreatedSubnet();
createdPublicSubnet.setSubnetId(getValue(output, "id" + subnetRequest.getIndex()));
createdPublicSubnet.setAvailabilityZone(subnetRequest.getAvailabilityZone());
if (!Strings.isNullOrEmpty(subnetRequest.getPrivateSubnetCidr()) && privateSubnetEnabled) {
createdPublicSubnet.setCidr(subnetRequest.getPrivateSubnetCidr());
createdPublicSubnet.setPublicSubnet(false);
createdPublicSubnet.setMapPublicIpOnLaunch(false);
createdPublicSubnet.setIgwAvailable(false);
} else {
createdPublicSubnet.setCidr(subnetRequest.getPublicSubnetCidr());
createdPublicSubnet.setPublicSubnet(true);
createdPublicSubnet.setMapPublicIpOnLaunch(true);
createdPublicSubnet.setIgwAvailable(true);
}
createdPublicSubnet.setType(subnetRequest.getType());
subnets.add(createdPublicSubnet);
}
return subnets;
}
Aggregations