Search in sources :

Example 6 with NotFoundException

use of com.netflix.simianarmy.NotFoundException in project SimianArmy by Netflix.

the class AWSClient method listAttachedVolumes.

@Override
public List<String> listAttachedVolumes(String instanceId, boolean includeRoot) {
    Validate.notEmpty(instanceId);
    LOGGER.info(String.format("Listing volumes attached to instance %s in region %s.", instanceId, region));
    try {
        List<String> volumeIds = new ArrayList<String>();
        for (Instance instance : describeInstances(instanceId)) {
            String rootDeviceName = instance.getRootDeviceName();
            for (InstanceBlockDeviceMapping ibdm : instance.getBlockDeviceMappings()) {
                EbsInstanceBlockDevice ebs = ibdm.getEbs();
                if (ebs == null) {
                    continue;
                }
                String volumeId = ebs.getVolumeId();
                if (Strings.isNullOrEmpty(volumeId)) {
                    continue;
                }
                if (!includeRoot && rootDeviceName != null && rootDeviceName.equals(ibdm.getDeviceName())) {
                    continue;
                }
                volumeIds.add(volumeId);
            }
        }
        return volumeIds;
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidInstanceID.NotFound")) {
            throw new NotFoundException("AWS instance " + instanceId + " not found", e);
        }
        throw e;
    }
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) AmazonServiceException(com.amazonaws.AmazonServiceException) NotFoundException(com.netflix.simianarmy.NotFoundException)

Aggregations

NotFoundException (com.netflix.simianarmy.NotFoundException)6 AmazonServiceException (com.amazonaws.AmazonServiceException)4 Instance (com.amazonaws.services.ec2.model.Instance)1 AmazonRoute53Client (com.amazonaws.services.route53.AmazonRoute53Client)1 FeatureNotEnabledException (com.netflix.simianarmy.FeatureNotEnabledException)1 InstanceGroupNotFoundException (com.netflix.simianarmy.InstanceGroupNotFoundException)1 Event (com.netflix.simianarmy.MonkeyRecorder.Event)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1