use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsSubnetRequestProviderTest method testProvideWhenOnlyTwoCidrProvided.
@Test
public void testProvideWhenOnlyTwoCidrProvided() {
AmazonEc2Client ec2Client = createEc2Client(List.of(createAZ(AZ_1), createAZ(AZ_2), createAZ(AZ_3), createAZ(AZ_4)));
List<NetworkSubnetRequest> publicSubnets = List.of(createSubnetRequest(CIDR_1), createSubnetRequest(CIDR_2));
List<SubnetRequest> actual = underTest.provide(ec2Client, publicSubnets, new ArrayList<>());
assertEquals(CIDR_1, actual.get(0).getPublicSubnetCidr());
assertEquals(AZ_1, actual.get(0).getAvailabilityZone());
assertEquals(CIDR_2, actual.get(1).getPublicSubnetCidr());
assertEquals(AZ_2, actual.get(1).getAvailabilityZone());
assertTrue(actual.size() == 2);
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsSubnetRequestProviderTest method testProvideWhenTwoAzAvailable.
@Test
public void testProvideWhenTwoAzAvailable() {
AmazonEc2Client ec2Client = createEc2Client(List.of(createAZ(AZ_1), createAZ(AZ_2)));
List<NetworkSubnetRequest> publicSubnets = List.of(createSubnetRequest(CIDR_4), createSubnetRequest(CIDR_5), createSubnetRequest(CIDR_6));
List<NetworkSubnetRequest> privateSubnets = List.of(createSubnetRequest(CIDR_1), createSubnetRequest(CIDR_2), createSubnetRequest(CIDR_3));
List<SubnetRequest> actual = underTest.provide(ec2Client, publicSubnets, privateSubnets);
assertEquals(CIDR_4, actual.get(0).getPublicSubnetCidr());
assertEquals(AZ_1, actual.get(0).getAvailabilityZone());
assertEquals(CIDR_5, actual.get(1).getPublicSubnetCidr());
assertEquals(AZ_2, actual.get(1).getAvailabilityZone());
assertEquals(CIDR_6, actual.get(2).getPublicSubnetCidr());
assertEquals(AZ_1, actual.get(2).getAvailabilityZone());
assertEquals(CIDR_1, actual.get(3).getPrivateSubnetCidr());
assertEquals(AZ_1, actual.get(3).getAvailabilityZone());
assertEquals(CIDR_2, actual.get(4).getPrivateSubnetCidr());
assertEquals(AZ_2, actual.get(4).getAvailabilityZone());
assertEquals(CIDR_3, actual.get(5).getPrivateSubnetCidr());
assertEquals(AZ_1, actual.get(5).getAvailabilityZone());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AwsSubnetRequestProviderTest method testProvideWhenFourAzAvailable.
@Test
public void testProvideWhenFourAzAvailable() {
AmazonEc2Client ec2Client = createEc2Client(List.of(createAZ(AZ_1), createAZ(AZ_2), createAZ(AZ_3), createAZ(AZ_4)));
List<NetworkSubnetRequest> publicSubnets = List.of(createSubnetRequest(CIDR_4), createSubnetRequest(CIDR_5), createSubnetRequest(CIDR_6));
List<NetworkSubnetRequest> privateSubnets = List.of(createSubnetRequest(CIDR_1), createSubnetRequest(CIDR_2), createSubnetRequest(CIDR_3));
List<SubnetRequest> actual = underTest.provide(ec2Client, publicSubnets, privateSubnets);
assertEquals(CIDR_4, actual.get(0).getPublicSubnetCidr());
assertEquals(AZ_1, actual.get(0).getAvailabilityZone());
assertEquals(CIDR_5, actual.get(1).getPublicSubnetCidr());
assertEquals(AZ_2, actual.get(1).getAvailabilityZone());
assertEquals(CIDR_6, actual.get(2).getPublicSubnetCidr());
assertEquals(AZ_3, actual.get(2).getAvailabilityZone());
assertEquals(CIDR_1, actual.get(3).getPrivateSubnetCidr());
assertEquals(AZ_1, actual.get(3).getAvailabilityZone());
assertEquals(CIDR_2, actual.get(4).getPrivateSubnetCidr());
assertEquals(AZ_2, actual.get(4).getAvailabilityZone());
assertEquals(CIDR_3, actual.get(5).getPrivateSubnetCidr());
assertEquals(AZ_3, actual.get(5).getAvailabilityZone());
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AzureNetworkConnectorTest 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;
}
use of com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest in project cloudbreak by hortonworks.
the class AzureNetworkConnectorTest method testCreateNetworkWithSubnetsShouldReturnTheNetworkNameAndSubnetName.
@Test
public void testCreateNetworkWithSubnetsShouldReturnTheNetworkNameAndSubnetName() {
String networkCidr = "0.0.0.0/16";
Set<NetworkSubnetRequest> subnets = new HashSet<>(Arrays.asList(createSubnetRequest(SUBNET_CIDR_0), createSubnetRequest(SUBNET_CIDR_1)));
Deployment templateDeployment = mock(Deployment.class);
ResourceGroup resourceGroup = mock(ResourceGroup.class);
Map<String, Map> outputs = createOutput();
ArrayList<SubnetRequest> subnetRequests = Lists.newArrayList(publicSubnetRequest("10.0.1.0/24", 0), publicSubnetRequest("10.0.1.0/24", 1));
NetworkCreationRequest networkCreationRequest = createNetworkRequest(networkCidr, subnets);
when(resourceGroup.name()).thenReturn(ENV_NAME);
when(azureSubnetRequestProvider.provide(anyString(), anyList(), anyList(), anyBoolean())).thenReturn(subnetRequests);
when(azureUtils.generateResourceGroupNameByNameAndId(anyString(), anyString())).thenReturn(ENV_NAME);
when(azureClientService.getClient(networkCreationRequest.getCloudCredential())).thenReturn(azureClient);
when(azureNetworkTemplateBuilder.build(networkCreationRequest, subnetRequests, resourceGroup.name())).thenReturn(TEMPLATE);
when(azureClient.createTemplateDeployment(ENV_NAME, STACK_NAME, TEMPLATE, PARAMETER)).thenReturn(templateDeployment);
when(azureClient.createResourceGroup(ENV_NAME, REGION.value(), Collections.emptyMap())).thenReturn(resourceGroup);
when(resourceGroup.name()).thenReturn(ENV_NAME);
when(templateDeployment.outputs()).thenReturn(outputs);
CreatedCloudNetwork actual = underTest.createNetworkWithSubnets(networkCreationRequest);
assertEquals(ENV_NAME, actual.getNetworkId());
assertTrue(actual.getSubnets().stream().anyMatch(cloudSubnet -> cloudSubnet.getSubnetId().equals(SUBNET_ID_0)));
assertTrue(actual.getSubnets().stream().anyMatch(cloudSubnet -> cloudSubnet.getSubnetId().equals(SUBNET_ID_1)));
assertTrue(actual.getSubnets().size() == 2);
}
Aggregations