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