use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class TestAWSClientManagement method testAWSClientManagementArnRefresh.
/**
* This test requires a minimum of 15 minutes waiting to ensure the ARN credentials refresh
* occurs.
*/
@Ignore
@Test
public void testAWSClientManagementArnRefresh() throws Throwable {
this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
this.host.setTimeoutSeconds(1200);
// Getting a reference to client managers in the test
AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
ec2ClientManager.cleanUpArnCache();
assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
this.creds = new AuthCredentialsServiceState();
this.creds.customProperties = new HashMap<>();
this.creds.customProperties.put(ARN_KEY, this.arn);
this.creds.customProperties.put(EXTERNAL_ID_KEY, this.externalId);
TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
waitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
waitContext.complete();
});
waitContext.await();
this.clientCacheCount = ec2ClientManager.getCacheCount();
host.log(Level.INFO, "Waiting 16 minutes for the current set of credentials to expire.");
Thread.sleep(TimeUnit.MINUTES.toMillis(16));
host.log(Level.INFO, "Retrieving the ec2 client with a refreshed set of credentials.");
// Requesting the EC2 client will generate a new client as the original client's credentials
// are now expired.
AmazonEC2AsyncClient oldClient = this.client;
TestContext nextContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
nextContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
this.clientCacheCount++;
nextContext.complete();
});
nextContext.await();
assertNotEquals(oldClient, this.client);
assertEquals(this.clientCacheCount, ec2ClientManager.getCacheCount());
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class TestAWSClientManagement method testAWSClientManagementArn.
@Test
public void testAWSClientManagementArn() throws Throwable {
this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
this.host.setTimeoutSeconds(60);
// Getting a reference to client managers in the test
AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
ec2ClientManager.cleanUpArnCache();
assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
this.creds = new AuthCredentialsServiceState();
this.creds.customProperties = new HashMap<>();
this.creds.customProperties.put(ARN_KEY, this.arn);
this.creds.customProperties.put(EXTERNAL_ID_KEY, this.externalId);
TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
waitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
waitContext.complete();
});
waitContext.await();
Assert.assertNotNull(this.client);
this.clientCacheCount = ec2ClientManager.getCacheCount();
// Requesting another AWS client with the same set of credentials will not
// create a new entry in the cache
AmazonEC2AsyncClient oldClient = this.client;
TestContext nextContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
nextContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
nextContext.complete();
});
nextContext.await();
Assert.assertNotNull(this.client);
Assert.assertEquals(oldClient, this.client);
assertEquals(this.clientCacheCount, ec2ClientManager.getCacheCount());
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class TestAWSClientManagement method testAWSClientManagementArnDr.
@Test
public void testAWSClientManagementArnDr() throws Throwable {
this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
this.host.setTimeoutSeconds(60);
// Getting a reference to client managers in the test
AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
ec2ClientManager.cleanUpArnCache();
assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
this.creds = new AuthCredentialsServiceState();
this.creds.customProperties = new HashMap<>();
this.creds.customProperties.put(ARN_KEY, this.arn);
this.creds.customProperties.put(EXTERNAL_ID_KEY, this.externalId);
TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
waitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
waitContext.complete();
});
waitContext.await();
Assert.assertNotNull(this.client);
this.clientCacheCount = ec2ClientManager.getCacheCount();
// Requesting another AWS client with the same set of credentials will not
// create a new entry in the cache
AmazonEC2AsyncClient oldClient = this.client;
TestContext nextContext = new TestContext(1, Duration.ofSeconds(30L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
nextContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.client = ec2Client;
nextContext.complete();
});
nextContext.await();
Assert.assertNotNull(this.client);
Assert.assertEquals(oldClient, this.client);
assertEquals(this.clientCacheCount, ec2ClientManager.getCacheCount());
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class AWSUtils method tagResourcesWithName.
/**
* Synchronous Tagging of one or many AWS resources with the provided name.
*/
public static void tagResourcesWithName(AmazonEC2AsyncClient client, String name, String... resourceIds) {
Tag awsNameTag = new Tag().withKey(AWS_TAG_NAME).withValue(name);
tagResources(client, Collections.singletonList(awsNameTag), resourceIds);
}
use of com.amazonaws.services.ec2.AmazonEC2AsyncClient in project photon-model by vmware.
the class TestAWSProvisionTask method assertEbsDiskConfiguration.
protected void assertEbsDiskConfiguration(AmazonEC2AsyncClient client, Instance awsInstance, DiskState diskState) {
assertNotNull("Additional Disk should contain atleast one custom property", diskState.customProperties);
assertTrue("deviceName is missing from the custom properties", diskState.customProperties.containsKey(DEVICE_NAME));
Volume volume = getVolume(client, awsInstance, diskState.customProperties.get(DEVICE_NAME));
assertEquals("Additional disk capacity in diskstate is not matching the volume size in aws", diskState.capacityMBytes, volume.getSize() * 1024);
assertNotNull("Disk creation time cannot be empty", diskState.creationTimeMicros);
assertEquals("Additional disk type in diskstate is not same as the type of the volume in aws", diskState.customProperties.get(VOLUME_TYPE), volume.getVolumeType());
// assert encryption status
assertEquals("Additional disk encryption status is not matching the " + "actual encryption status of the disk on aws", diskState.encrypted, volume.getEncrypted());
if (diskState.customProperties.containsKey(DISK_IOPS)) {
int requestedIops = Integer.parseInt(diskState.customProperties.get(DISK_IOPS));
int MAX_SUPPORTED_IOPS = (int) (diskState.capacityMBytes / 1024) * 50;
int provisionedIops = Math.min(requestedIops, MAX_SUPPORTED_IOPS);
assertEquals("Disk speeds are not matching", provisionedIops, volume.getIops().intValue());
}
assertEquals("Additional disk attach status is not matching", DiskService.DiskStatus.ATTACHED, diskState.status);
}
Aggregations