use of com.amazonaws.services.ec2.model.DescribeVolumesResult in project photon-model by vmware.
the class AWSRemoteCleanup method deleteStaleAwsVolumes.
@Test
public void deleteStaleAwsVolumes() {
AmazonEC2 usEastEc2Client = this.ec2Clients.get(US_EAST_1_TAG);
DescribeVolumesResult volumesResult = usEastEc2Client.describeVolumes();
List<Volume> volumeList = volumesResult.getVolumes();
for (Volume volume : volumeList) {
long volumeCreationTimeMicros = TimeUnit.MILLISECONDS.toMicros(volume.getCreateTime().getTime());
long timeDifference = Utils.getNowMicrosUtc() - volumeCreationTimeMicros;
if (timeDifference > TimeUnit.HOURS.toMicros(1) && volume.getState().equalsIgnoreCase("available")) {
this.host.log("Terminating stale volume: %s", volume.getVolumeId());
DeleteVolumeRequest deleteVolumeRequest = new DeleteVolumeRequest().withVolumeId(volume.getVolumeId());
usEastEc2Client.deleteVolume(deleteVolumeRequest);
}
}
}
use of com.amazonaws.services.ec2.model.DescribeVolumesResult in project photon-model by vmware.
the class TestAWSSetupUtils method getAwsDisksByIds.
/**
* Method to get Disk details directly from Amazon
*/
public static List<Volume> getAwsDisksByIds(AmazonEC2AsyncClient client, VerificationHost host, List<String> diskIds) throws Throwable {
try {
host.log("Getting disks with ids " + diskIds + " from the AWS endpoint using the EC2 client.");
DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withVolumeIds(diskIds);
DescribeVolumesResult describeVolumesResult = client.describeVolumes(describeVolumesRequest);
return describeVolumesResult.getVolumes();
} catch (Exception e) {
if (e instanceof AmazonEC2Exception && ((AmazonEC2Exception) e).getErrorCode().equalsIgnoreCase(AWS_INVALID_VOLUME_ID_ERROR_CODE)) {
return null;
}
}
return new ArrayList<>();
}
use of com.amazonaws.services.ec2.model.DescribeVolumesResult in project photon-model by vmware.
the class TestAWSProvisionTask method getVolume.
protected Volume getVolume(AmazonEC2AsyncClient client, Instance awsInstance, String deviceName) {
InstanceBlockDeviceMapping bootDiskMapping = awsInstance.getBlockDeviceMappings().stream().filter(blockDeviceMapping -> blockDeviceMapping.getDeviceName().equals(deviceName)).findAny().orElse(null);
// The ami used in this test is an ebs-backed AMI
assertNotNull("Device type should be ebs type", bootDiskMapping.getEbs());
String bootVolumeId = bootDiskMapping.getEbs().getVolumeId();
DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest().withVolumeIds(bootVolumeId);
DescribeVolumesResult describeVolumesResult = client.describeVolumes(describeVolumesRequest);
return describeVolumesResult.getVolumes().get(0);
}
Aggregations