use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsNetworkCfTemplateProviderTest method testProvideWhenPrivateSubnetCreationEnabled.
@ParameterizedTest
@MethodSource("privateSubnetArguments")
public void testProvideWhenPrivateSubnetCreationEnabled(String expectedTemplate, List<String> gatewayServices, List<String> interfaceServices, DescribeVpcEndpointServicesResult describeVpcEndpointServicesResult) throws IOException, TemplateException {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode expectedJson = objectMapper.readTree(new File(expectedTemplate));
when(freeMarkerTemplateUtils.processTemplateIntoString(any(), any())).thenCallRealMethod();
AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
when(awsClient.createEc2Client(any(), anyString())).thenReturn(ec2Client);
when(ec2Client.describeVpcEndpointServices()).thenReturn(describeVpcEndpointServicesResult);
NetworkCreationRequest networkCreationRequest = createNetworkRequest(true, PrivateEndpointType.USE_VPC_ENDPOINT);
List<SubnetRequest> subnetRequestList = createPrivateAndPublicSubnetRequestList();
ReflectionTestUtils.setField(underTest, "gatewayServices", gatewayServices);
ReflectionTestUtils.setField(underTest, "interfaceServices", interfaceServices);
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 createPrivateAndPublicSubnetRequestList.
private static List<SubnetRequest> createPrivateAndPublicSubnetRequestList() {
SubnetRequest subnetRequest1 = new SubnetRequest();
subnetRequest1.setPublicSubnetCidr("2.2.2.2/24");
subnetRequest1.setIndex(0);
subnetRequest1.setSubnetGroup(0);
subnetRequest1.setAvailabilityZone("az1");
SubnetRequest subnetRequest2 = new SubnetRequest();
subnetRequest2.setPublicSubnetCidr("2.2.2.2/24");
subnetRequest2.setIndex(1);
subnetRequest2.setSubnetGroup(1);
subnetRequest2.setAvailabilityZone("az2");
SubnetRequest subnetRequest3 = new SubnetRequest();
subnetRequest3.setPrivateSubnetCidr("2.2.2.2/24");
subnetRequest3.setIndex(2);
subnetRequest3.setSubnetGroup(2);
subnetRequest3.setAvailabilityZone("az1");
SubnetRequest subnetRequest4 = new SubnetRequest();
subnetRequest4.setPrivateSubnetCidr("2.2.2.2/24");
subnetRequest4.setIndex(3);
subnetRequest4.setSubnetGroup(3);
subnetRequest4.setAvailabilityZone("az2");
return List.of(subnetRequest1, subnetRequest2, subnetRequest3, subnetRequest4);
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testCreateNetworkWithSubnetsShouldReturnTheNetworkAndSubnets.
@Test
public void testCreateNetworkWithSubnetsShouldReturnTheNetworkAndSubnets() {
String networkCidr = "0.0.0.0/16";
Set<NetworkSubnetRequest> subnets = Set.of(new NetworkSubnetRequest("1.1.1.1/8", PUBLIC), new NetworkSubnetRequest("1.1.1.2/8", PUBLIC));
AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
Map<String, String> output = createOutput();
NetworkCreationRequest networkCreationRequest = createNetworkRequest(networkCidr, subnets);
List<SubnetRequest> subnetRequestList = createSubnetRequestList();
Set<CreatedSubnet> createdSubnets = Set.of(new CreatedSubnet(), new CreatedSubnet(), new CreatedSubnet());
when(awsClient.createEc2Client(any(), any())).thenReturn(ec2Client);
when(awsSubnetRequestProvider.provide(ec2Client, new ArrayList<>(subnets), new ArrayList<>(subnets))).thenReturn(subnetRequestList);
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()))).thenReturn(cfClient);
when(cfClient.waiters()).thenReturn(cfWaiters);
when(cfWaiters.stackCreateComplete()).thenReturn(creationWaiter);
when(cfStackUtil.getOutputs(NETWORK_ID, cfClient)).thenReturn(output);
when(awsCreatedSubnetProvider.provide(output, subnetRequestList, true)).thenReturn(createdSubnets);
CreatedCloudNetwork actual = underTest.createNetworkWithSubnets(networkCreationRequest);
verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
verify(creationWaiter, times(1)).run(any());
verify(cfStackUtil).getOutputs(NETWORK_ID, cfClient);
verify(awsTaggingService, never()).prepareCloudformationTags(any(), any());
verify(cfClient, never()).createStack(any(CreateStackRequest.class));
assertEquals(VPC_ID, actual.getNetworkId());
assertEquals(NUMBER_OF_SUBNETS, actual.getSubnets().size());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testCreateNewNetworkWithSubnetsShouldCreateTheNetworkAndSubnets.
@Test
public void testCreateNewNetworkWithSubnetsShouldCreateTheNetworkAndSubnets() {
String networkCidr = "0.0.0.0/16";
Set<NetworkSubnetRequest> subnets = Set.of(new NetworkSubnetRequest("1.1.1.1/8", PUBLIC), new NetworkSubnetRequest("1.1.1.2/8", PUBLIC));
AmazonServiceException amazonServiceException = new AmazonServiceException("does not exist");
amazonServiceException.setStatusCode(400);
AmazonCloudFormationClient cfClient = mock(AmazonCloudFormationClient.class);
when(cfClient.describeStacks(any(DescribeStacksRequest.class))).thenThrow(amazonServiceException);
AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
Map<String, String> output = createOutput();
NetworkCreationRequest networkCreationRequest = createNetworkRequest(networkCidr, subnets);
List<SubnetRequest> subnetRequestList = createSubnetRequestList();
Set<CreatedSubnet> createdSubnets = Set.of(new CreatedSubnet(), new CreatedSubnet(), new CreatedSubnet());
when(awsClient.createEc2Client(any(), any())).thenReturn(ec2Client);
when(awsSubnetRequestProvider.provide(ec2Client, new ArrayList<>(subnets), new ArrayList<>(subnets))).thenReturn(subnetRequestList);
when(awsClient.createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()))).thenReturn(cfClient);
when(cfClient.waiters()).thenReturn(cfWaiters);
when(cfWaiters.stackCreateComplete()).thenReturn(creationWaiter);
when(cfStackUtil.getOutputs(NETWORK_ID, cfClient)).thenReturn(output);
when(awsCreatedSubnetProvider.provide(output, subnetRequestList, true)).thenReturn(createdSubnets);
CreatedCloudNetwork actual = underTest.createNetworkWithSubnets(networkCreationRequest);
verify(awsClient).createCloudFormationClient(any(AwsCredentialView.class), eq(REGION.value()));
verify(awsNetworkCfTemplateProvider).provide(networkCreationRequest, subnetRequestList);
verify(creationWaiter, times(1)).run(any());
verify(awsTaggingService).prepareCloudformationTags(any(), any());
verify(cfClient).createStack(any(CreateStackRequest.class));
verify(cfStackUtil).getOutputs(NETWORK_ID, cfClient);
assertEquals(VPC_ID, actual.getNetworkId());
assertEquals(NUMBER_OF_SUBNETS, actual.getSubnets().size());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsCreatedSubnetProviderTest method publicSubnetRequest.
public SubnetRequest publicSubnetRequest(String cidr, int index) {
SubnetRequest subnetRequest = new SubnetRequest();
subnetRequest.setIndex(index);
subnetRequest.setPublicSubnetCidr(cidr);
subnetRequest.setSubnetGroup(index % 3);
subnetRequest.setAvailabilityZone("az");
return subnetRequest;
}
Aggregations