public DescribeVolumesResult unmarshall(StaxUnmarshallerContext context) throws Exception {
    DescribeVolumesResult describeVolumesResult = new DescribeVolumesResult();
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) targetDepth += 1;

    while (true) {
      XMLEvent xmlEvent = context.nextEvent();
      if (xmlEvent.isEndDocument()) return describeVolumesResult;

      if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
        if (context.testExpression("volumeSet/item", targetDepth)) {
          describeVolumesResult
              .getVolumes()
              .add(VolumeStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
      } else if (xmlEvent.isEndElement()) {
        if (context.getCurrentDepth() < originalDepth) {
          return describeVolumesResult;
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Describe a set of specific EBS volumes.
   *
   * @param volumeIds the volume ids
   * @return the volumes
   */
  public List<Volume> describeVolumes(String... volumeIds) {
    if (volumeIds == null || volumeIds.length == 0) {
      LOGGER.info("Getting all EBS volumes.");
    } else {
      LOGGER.info(String.format("Getting EBS volumes for %d ids.", volumeIds.length));
    }

    AmazonEC2 ec2Client = ec2Client();
    DescribeVolumesRequest request = new DescribeVolumesRequest();
    if (volumeIds != null) {
      request.setVolumeIds(Arrays.asList(volumeIds));
    }
    DescribeVolumesResult result = ec2Client.describeVolumes(request);
    List<Volume> volumes = result.getVolumes();

    LOGGER.info(String.format("Got %d EBS volumes.", volumes.size()));
    return volumes;
  }