Search in sources :

Example 6 with NetworkSubnetRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest 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);
}
Also used : NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Test(org.junit.Test)

Example 7 with NetworkSubnetRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest 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());
}
Also used : NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Test(org.junit.Test)

Example 8 with NetworkSubnetRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest 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());
}
Also used : NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Test(org.junit.Test)

Example 9 with NetworkSubnetRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest 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);
}
Also used : Arrays(java.util.Arrays) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) NetworkResourcesCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkResourcesCreationRequest) Mockito.doThrow(org.mockito.Mockito.doThrow) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) BadRequestException(javax.ws.rs.BadRequestException) MediaType(okhttp3.MediaType) ResponseBody(okhttp3.ResponseBody) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Set(java.util.Set) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) AzureTransientDeploymentService(com.sequenceiq.cloudbreak.cloud.azure.template.AzureTransientDeploymentService) AzureClientService(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureNetworkView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureNetworkView) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) HashMap(java.util.HashMap) Response(retrofit2.Response) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) PUBLIC(com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PUBLIC) Lists(com.google.common.collect.Lists) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ExpectedException(org.junit.rules.ExpectedException) InjectMocks(org.mockito.InjectMocks) Deployment(com.microsoft.azure.management.resources.Deployment) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) CloudException(com.microsoft.azure.CloudException) AzureSubnetSelectorService(com.sequenceiq.cloudbreak.cloud.azure.subnet.selector.AzureSubnetSelectorService) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) Deployment(com.microsoft.azure.management.resources.Deployment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Map(java.util.Map) HashMap(java.util.HashMap) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with NetworkSubnetRequest

use of com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest 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;
}
Also used : NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) ArrayList(java.util.ArrayList)

Aggregations

NetworkSubnetRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest)12 SubnetRequest (com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest)9 Test (org.junit.Test)6 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)5 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)3 NetworkCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest)3 ArrayList (java.util.ArrayList)3 CreateStackRequest (com.amazonaws.services.cloudformation.model.CreateStackRequest)2 AmazonCloudFormationClient (com.sequenceiq.cloudbreak.cloud.aws.client.AmazonCloudFormationClient)2 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)2 CreatedSubnet (com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet)2 HashSet (java.util.HashSet)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)1 Lists (com.google.common.collect.Lists)1 CloudException (com.microsoft.azure.CloudException)1 Deployment (com.microsoft.azure.management.resources.Deployment)1 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 AzureClientService (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService)1