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);
}
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());
}
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;
}
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());
}
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());
}
Aggregations