Search in sources :

Example 46 with AmazonEc2Client

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client 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 47 with AmazonEc2Client

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client 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 48 with AmazonEc2Client

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.

the class AwsSubnetRequestProviderTest method createEc2Client.

private AmazonEc2Client createEc2Client(List<AvailabilityZone> availabilityZones) {
    AmazonEc2Client ec2Client = Mockito.mock(AmazonEc2Client.class);
    DescribeAvailabilityZonesResult result = new DescribeAvailabilityZonesResult();
    result.setAvailabilityZones(availabilityZones);
    Mockito.when(ec2Client.describeAvailabilityZones()).thenReturn(result);
    return ec2Client;
}
Also used : AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)

Example 49 with AmazonEc2Client

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client 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 50 with AmazonEc2Client

use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client in project cloudbreak by hortonworks.

the class AwsTaggingServiceTest method tesTagRootVolumesForInstancesMoreThanSingleRequestLimit.

@Test
public void tesTagRootVolumesForInstancesMoreThanSingleRequestLimit() {
    int instanceCount = 1200;
    CloudResource instance = CloudResource.builder().type(ResourceType.AWS_INSTANCE).instanceId(INSTANCE_ID).name(INSTANCE_ID).status(CommonStatus.CREATED).build();
    Instance awsInstance = new Instance().withInstanceId(INSTANCE_ID).withBlockDeviceMappings(new InstanceBlockDeviceMapping().withDeviceName("/dev/sda1").withEbs(new EbsInstanceBlockDevice().withVolumeId(VOLUME_ID))).withRootDeviceName("/dev/sda1");
    List<CloudResource> instanceList = new ArrayList<>(instanceCount);
    List<Instance> awsInstances = new ArrayList<>(instanceCount);
    for (int i = 0; i < instanceCount; i++) {
        instanceList.add(instance);
        awsInstances.add(awsInstance);
    }
    DescribeInstancesResult describeResult = new DescribeInstancesResult().withReservations(new Reservation().withInstances(awsInstances));
    AmazonEc2Client ec2Client = mock(AmazonEc2Client.class);
    when(ec2Client.describeInstances(any())).thenReturn(describeResult);
    awsTaggingService.tagRootVolumes(authenticatedContext(), ec2Client, instanceList, Map.of());
    verify(ec2Client, times(2)).createTags(tagRequestCaptor.capture());
    List<CreateTagsRequest> requests = tagRequestCaptor.getAllValues();
    assertEquals(1000, requests.get(0).getResources().size());
    assertEquals(200, requests.get(1).getResources().size());
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) ArrayList(java.util.ArrayList) InstanceBlockDeviceMapping(com.amazonaws.services.ec2.model.InstanceBlockDeviceMapping) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Reservation(com.amazonaws.services.ec2.model.Reservation) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) EbsInstanceBlockDevice(com.amazonaws.services.ec2.model.EbsInstanceBlockDevice) Test(org.junit.Test)

Aggregations

AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)97 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)44 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)41 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)30 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)29 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)29 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)28 HashMap (java.util.HashMap)28 Group (com.sequenceiq.cloudbreak.cloud.model.Group)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)24 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)23 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)23 Network (com.sequenceiq.cloudbreak.cloud.model.Network)23 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)22 AmazonServiceException (com.amazonaws.AmazonServiceException)21 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)21 List (java.util.List)21 Vpc (com.amazonaws.services.ec2.model.Vpc)20 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)20