Issue 29: added parsers for Volumes

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2530 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-28 21:16:05 +00:00
parent 01a867d9a1
commit c5d67c7cb3
10 changed files with 730 additions and 47 deletions

View File

@ -0,0 +1,290 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import java.util.Set;
import javax.annotation.Nullable;
import com.google.common.base.CaseFormat;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
*
* @see <a href=
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html"
* />
* @author Adrian Cole
*/
public class Volume implements Comparable<Volume> {
public static enum Status {
CREATING, AVAILABLE, IN_USE, DELETING;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
}
@Override
public String toString() {
return value();
}
public static Status fromValue(String status) {
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(
status, "status")));
}
}
public static class Attachment {
public static enum Status {
ATTACHING, ATTACHED, DETACHING, DETACHED;
public String value() {
return name().toLowerCase();
}
@Override
public String toString() {
return value();
}
public static Status fromValue(String status) {
return valueOf(checkNotNull(status, "status").toUpperCase());
}
}
private final String volumeId;
private final String instanceId;
private final String device;
private final Status status;
private final Date attachTime;
public Attachment(String volumeId, String instanceId, String device, Status status,
Date attachTime) {
this.volumeId = volumeId;
this.instanceId = instanceId;
this.device = device;
this.status = status;
this.attachTime = attachTime;
}
public String getVolumeId() {
return volumeId;
}
public String getInstanceId() {
return instanceId;
}
public String getDevice() {
return device;
}
public Status getStatus() {
return status;
}
public Date getAttachTime() {
return attachTime;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((attachTime == null) ? 0 : attachTime.hashCode());
result = prime * result + ((device == null) ? 0 : device.hashCode());
result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((volumeId == null) ? 0 : volumeId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Attachment other = (Attachment) obj;
if (attachTime == null) {
if (other.attachTime != null)
return false;
} else if (!attachTime.equals(other.attachTime))
return false;
if (device == null) {
if (other.device != null)
return false;
} else if (!device.equals(other.device))
return false;
if (instanceId == null) {
if (other.instanceId != null)
return false;
} else if (!instanceId.equals(other.instanceId))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
if (volumeId == null) {
if (other.volumeId != null)
return false;
} else if (!volumeId.equals(other.volumeId))
return false;
return true;
}
@Override
public String toString() {
return "Attachment [attachTime=" + attachTime + ", device=" + device + ", instanceId="
+ instanceId + ", status=" + status + ", volumeId=" + volumeId + "]";
}
}
private final String id;
private final int size;
@Nullable
private final String snapshotId;
private final AvailabilityZone availabilityZone;
private final Status status;
private final Date createTime;
private final Set<Attachment> attachments = Sets.newLinkedHashSet();
public Volume(String id, int size, String snapshotId, AvailabilityZone availabilityZone,
org.jclouds.aws.ec2.domain.Volume.Status status, Date createTime,
Iterable<Attachment> attachments) {
this.id = id;
this.size = size;
this.snapshotId = snapshotId;
this.availabilityZone = availabilityZone;
this.status = status;
this.createTime = createTime;
Iterables.addAll(this.attachments, attachments);
}
public String getId() {
return id;
}
public int getSize() {
return size;
}
public String getSnapshotId() {
return snapshotId;
}
public AvailabilityZone getAvailabilityZone() {
return availabilityZone;
}
public Status getStatus() {
return status;
}
public Date getCreateTime() {
return createTime;
}
public Set<Attachment> getAttachments() {
return attachments;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((attachments == null) ? 0 : attachments.hashCode());
result = prime * result + ((availabilityZone == null) ? 0 : availabilityZone.hashCode());
result = prime * result + ((createTime == null) ? 0 : createTime.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + size;
result = prime * result + ((snapshotId == null) ? 0 : snapshotId.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Volume other = (Volume) obj;
if (attachments == null) {
if (other.attachments != null)
return false;
} else if (!attachments.equals(other.attachments))
return false;
if (availabilityZone == null) {
if (other.availabilityZone != null)
return false;
} else if (!availabilityZone.equals(other.availabilityZone))
return false;
if (createTime == null) {
if (other.createTime != null)
return false;
} else if (!createTime.equals(other.createTime))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (size != other.size)
return false;
if (snapshotId == null) {
if (other.snapshotId != null)
return false;
} else if (!snapshotId.equals(other.snapshotId))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
return true;
}
@Override
public int compareTo(Volume that) {
return id.compareTo(that.id);
}
@Override
public String toString() {
return "Volume [attachments=" + attachments + ", availabilityZone=" + availabilityZone
+ ", createTime=" + createTime + ", id=" + id + ", size=" + size + ", snapshotId="
+ snapshotId + ", status=" + status + "]";
}
}

View File

@ -26,6 +26,7 @@ package org.jclouds.aws.ec2.services;
import static org.jclouds.aws.ec2.reference.EC2Parameters.ACTION; import static org.jclouds.aws.ec2.reference.EC2Parameters.ACTION;
import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION; import static org.jclouds.aws.ec2.reference.EC2Parameters.VERSION;
import java.util.Set;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
@ -36,14 +37,18 @@ import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.binders.BindVolumeIdsToIndexedFormParams; import org.jclouds.aws.ec2.binders.BindVolumeIdsToIndexedFormParams;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Region;
import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.filters.FormSigner;
import org.jclouds.aws.ec2.functions.RegionToEndpoint; import org.jclouds.aws.ec2.functions.RegionToEndpoint;
import org.jclouds.aws.ec2.xml.CreateVolumeResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.FormParams; import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
/** /**
* Provides access to EC2 Elastic Block Store services via their REST API. * Provides access to EC2 Elastic Block Store services via their REST API.
@ -61,10 +66,11 @@ public interface ElasticBlockStoreAsyncClient {
*/ */
@POST @POST
@Path("/") @Path("/")
@Endpoint(EC2.class) // TODO: remove @Endpoint(EC2.class)
// TODO: remove
@FormParams(keys = ACTION, values = "CreateVolume") @FormParams(keys = ACTION, values = "CreateVolume")
// @XMLResponseParser(VolumeResponseHandler.class) @XMLResponseParser(CreateVolumeResponseHandler.class)
Future<String> createVolumeFromSnapshotInAvailabilityZone( Future<Volume> createVolumeFromSnapshotInAvailabilityZone(
@FormParam("AvailabilityZone") AvailabilityZone availabilityZone, @FormParam("AvailabilityZone") AvailabilityZone availabilityZone,
@FormParam("SnapshotId") String snapshotId); @FormParam("SnapshotId") String snapshotId);
@ -73,10 +79,11 @@ public interface ElasticBlockStoreAsyncClient {
*/ */
@POST @POST
@Path("/") @Path("/")
@Endpoint(EC2.class) // TODO: remove @Endpoint(EC2.class)
// TODO: remove
@FormParams(keys = ACTION, values = "CreateVolume") @FormParams(keys = ACTION, values = "CreateVolume")
// @XMLResponseParser(VolumeResponseHandler.class) @XMLResponseParser(CreateVolumeResponseHandler.class)
Future<String> createVolumeInAvailabilityZone( Future<Volume> createVolumeInAvailabilityZone(
@FormParam("AvailabilityZone") AvailabilityZone availabilityZone, @FormParam("AvailabilityZone") AvailabilityZone availabilityZone,
@FormParam("Size") int size); @FormParam("Size") int size);
@ -86,8 +93,8 @@ public interface ElasticBlockStoreAsyncClient {
@POST @POST
@Path("/") @Path("/")
@FormParams(keys = ACTION, values = "DescribeVolumes") @FormParams(keys = ACTION, values = "DescribeVolumes")
// @XMLResponseParser(DescribeVolumesResponseHandler.class) @XMLResponseParser(DescribeVolumesResponseHandler.class)
Future<String> describeVolumesInRegion( Future<? extends Set<Volume>> describeVolumesInRegion(
@EndpointParam(parser = RegionToEndpoint.class) Region region, @EndpointParam(parser = RegionToEndpoint.class) Region region,
@BinderParam(BindVolumeIdsToIndexedFormParams.class) String... volumeIds); @BinderParam(BindVolumeIdsToIndexedFormParams.class) String... volumeIds);

View File

@ -23,10 +23,12 @@
*/ */
package org.jclouds.aws.ec2.services; package org.jclouds.aws.ec2.services;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Region;
import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
/** /**
@ -60,7 +62,7 @@ public interface ElasticBlockStoreClient {
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html" * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html"
* /> * />
*/ */
String createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone availabilityZone, Volume createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone availabilityZone,
String snapshotId); String snapshotId);
/** /**
@ -85,7 +87,7 @@ public interface ElasticBlockStoreClient {
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html" * "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html"
* /> * />
*/ */
String createVolumeInAvailabilityZone(AvailabilityZone availabilityZone, int size); Volume createVolumeInAvailabilityZone(AvailabilityZone availabilityZone, int size);
/** /**
* Describes the specified Amazon EBS volumes that you own. If you do not specify one or more * Describes the specified Amazon EBS volumes that you own. If you do not specify one or more
@ -103,7 +105,7 @@ public interface ElasticBlockStoreClient {
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeVolumes.html" * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeVolumes.html"
* /> * />
*/ */
String describeVolumesInRegion(Region region, String... volumeIds); Set<Volume> describeVolumesInRegion(Region region, String... volumeIds);
/** /**
* Deletes an Amazon EBS volume that you own. For more information about Amazon EBS, go to the * Deletes an Amazon EBS volume that you own. For more information about Amazon EBS, go to the

View File

@ -0,0 +1,150 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.xml;
import java.util.Date;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.aws.ec2.domain.Volume.Attachment;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
/**
*
* @author Adrian Cole
*/
public class CreateVolumeResponseHandler extends ParseSax.HandlerWithResult<Volume> {
private StringBuilder currentText = new StringBuilder();
@Resource
protected Logger logger = Logger.NULL;
@Inject
protected DateService dateService;
private String id;
private int size;
private String snapshotId;
private AvailabilityZone availabilityZone;
private Volume.Status volumeStatus;
private Date createTime;
private Set<Attachment> attachments = Sets.newLinkedHashSet();
private String volumeId;
private String instanceId;
private String device;
private Volume.Attachment.Status attachmentStatus;
private Date attachTime;
private boolean inAttachmentSet;
public Volume getResult() {
return newVolume();
}
public void startElement(String uri, String name, String qName, Attributes attrs) {
if (qName.equals("attachmentSet")) {
inAttachmentSet = true;
}
}
public void endElement(String uri, String name, String qName) {
if (qName.equals("volumeId")) {
if (inAttachmentSet) {
volumeId = currentText.toString().trim();
} else {
id = currentText.toString().trim();
}
} else if (qName.equals("size")) {
size = Integer.parseInt(currentText.toString().trim());
} else if (qName.equals("availabilityZone")) {
String availabilityZoneName = currentText.toString().trim();
try {
availabilityZone = AvailabilityZone.fromValue(availabilityZoneName);
} catch (IllegalArgumentException e) {
logger.warn(e, "unsupported availability zone: %s", availabilityZoneName);
availabilityZone = AvailabilityZone.UNKNOWN;
}
} else if (qName.equals("volumeId")) {
if (inAttachmentSet) {
volumeId = currentText.toString().trim();
} else {
id = currentText.toString().trim();
}
} else if (qName.equals("status")) {
if (inAttachmentSet) {
attachmentStatus = Volume.Attachment.Status.fromValue(currentText.toString().trim());
} else {
volumeStatus = Volume.Status.fromValue(currentText.toString().trim());
}
} else if (qName.equals("createTime")) {
createTime = dateService.iso8601DateParse(currentText.toString().trim());
} else if (qName.equals("attachmentSet")) {
inAttachmentSet = false;
} else if (qName.equals("instanceId")) {
instanceId = currentText.toString().trim();
} else if (qName.equals("device")) {
device = currentText.toString().trim();
} else if (qName.equals("attachTime")) {
attachTime = dateService.iso8601DateParse(currentText.toString().trim());
} else if (qName.equals("item")) {
if (inAttachmentSet) {
attachments.add(new Attachment(volumeId, instanceId, device, attachmentStatus,
attachTime));
volumeId = null;
instanceId = null;
device = null;
attachmentStatus = null;
attachTime = null;
}
}
currentText = new StringBuilder();
}
private Volume newVolume() {
Volume volume = new Volume(id, size, snapshotId, availabilityZone, volumeStatus, createTime,
attachments);
id = null;
size = 0;
snapshotId = null;
availabilityZone = null;
volumeStatus = null;
createTime = null;
attachments = Sets.newLinkedHashSet();
return volume;
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,78 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class DescribeVolumesResponseHandler extends ParseSax.HandlerWithResult<Set<Volume>> {
private Set<Volume> volumes = Sets.newLinkedHashSet();
private final CreateVolumeResponseHandler volumeHandler;
private boolean inAttachmentSet;
@Inject
public DescribeVolumesResponseHandler(CreateVolumeResponseHandler volumeHandler) {
this.volumeHandler = volumeHandler;
}
public Set<Volume> getResult() {
return volumes;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equals("attachmentSet")) {
inAttachmentSet = true;
}
volumeHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
volumeHandler.endElement(uri, localName, qName);
if (qName.equals("attachmentSet")) {
inAttachmentSet = false;
} else if (qName.equals("item") && !inAttachmentSet) {
this.volumes.add(volumeHandler.getResult());
}
}
public void characters(char ch[], int start, int length) {
volumeHandler.characters(ch, start, length);
}
}

View File

@ -37,9 +37,11 @@ import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Region;
import org.jclouds.aws.ec2.filters.FormSigner; import org.jclouds.aws.ec2.filters.FormSigner;
import org.jclouds.aws.ec2.xml.CreateVolumeResponseHandler;
import org.jclouds.aws.ec2.xml.DescribeVolumesResponseHandler;
import org.jclouds.aws.reference.AWSConstants; import org.jclouds.aws.reference.AWSConstants;
import org.jclouds.date.TimeStamp; import org.jclouds.date.TimeStamp;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnVoidIf2xx; import org.jclouds.http.functions.ReturnVoidIf2xx;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
@ -75,8 +77,8 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20"); "Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&Size=20");
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(httpMethod);
@ -95,8 +97,8 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId"); "Version=2009-11-30&Action=CreateVolume&AvailabilityZone=us-east-1a&SnapshotId=snapshotId");
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, CreateVolumeResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(httpMethod);
@ -131,10 +133,8 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
"Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n"); "Content-Length: 41\nContent-Type: application/x-www-form-urlencoded\nHost: ec2.amazonaws.com\n");
assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeVolumes"); assertPayloadEquals(httpMethod, "Version=2009-11-30&Action=DescribeVolumes");
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
// assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
// assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(httpMethod);
@ -153,10 +153,8 @@ public class ElasticBlockStoreAsyncClientTest extends RestClientTest<ElasticBloc
assertPayloadEquals(httpMethod, assertPayloadEquals(httpMethod,
"Version=2009-11-30&Action=DescribeVolumes&VolumeId.1=1&VolumeId.2=2"); "Version=2009-11-30&Action=DescribeVolumes&VolumeId.1=1&VolumeId.2=2");
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
// assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
// assertSaxResponseParserClassEquals(method, DescribeVolumesResponseHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(httpMethod);

View File

@ -24,13 +24,17 @@
package org.jclouds.aws.ec2.services; package org.jclouds.aws.ec2.services;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.util.SortedSet;
import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.EC2ContextFactory; import org.jclouds.aws.ec2.EC2ContextFactory;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Region; import org.jclouds.aws.ec2.domain.Region;
import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
@ -38,6 +42,7 @@ import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/** /**
* Tests behavior of {@code ElasticBlockStoreClient} * Tests behavior of {@code ElasticBlockStoreClient}
@ -49,6 +54,7 @@ public class ElasticBlockStoreClientLiveTest {
private ElasticBlockStoreClient client; private ElasticBlockStoreClient client;
private RestContext<EC2AsyncClient, EC2Client> context; private RestContext<EC2AsyncClient, EC2Client> context;
private String volumeId;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
@ -63,32 +69,44 @@ public class ElasticBlockStoreClientLiveTest {
void testDescribeVolumes() { void testDescribeVolumes() {
for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1, for (Region region : ImmutableSet.of(Region.DEFAULT, Region.EU_WEST_1, Region.US_EAST_1,
Region.US_WEST_1)) { Region.US_WEST_1)) {
System.out.println(client.describeVolumesInRegion(region)); SortedSet<Volume> allResults = Sets.newTreeSet(client.describeVolumesInRegion(region));
// SortedSet<Volume> allResults = Sets.newTreeSet(client.describeVolumesInRegion(region)); assertNotNull(allResults);
// assertNotNull(allResults); if (allResults.size() >= 1) {
// if (allResults.size() >= 1) { Volume volume = allResults.last();
// Volume volume = allResults.last(); SortedSet<Volume> result = Sets.newTreeSet(client.describeVolumesInRegion(region,
// SortedSet<Volume> result = Sets.newTreeSet(client.describeVolumesInRegion(region, volume.getId()));
// volume.getKeyName())); assertNotNull(result);
// assertNotNull(result); Volume compare = result.last();
// Volume compare = result.last(); assertEquals(compare, volume);
// assertEquals(compare, volume); }
// }
} }
} }
@Test(enabled = false)// pending functionality to delete @Test
void testCreateVolumeInAvailabilityZone() { void testCreateVolumeInAvailabilityZone() {
String result = client.createVolumeInAvailabilityZone(AvailabilityZone.US_EAST_1A, 1); Volume expected = client.createVolumeInAvailabilityZone(AvailabilityZone.US_EAST_1B, 1);
assertNotNull(expected);
System.out.println(expected);
assertEquals(expected.getAvailabilityZone(), AvailabilityZone.US_EAST_1B);
this.volumeId = expected.getId();
SortedSet<Volume> result = Sets.newTreeSet(client.describeVolumesInRegion(Region.DEFAULT,
expected.getId()));
assertNotNull(result); assertNotNull(result);
System.out.println(result); assertEquals(result.size(), 1);
// Volume volume = result.iterator().next();
// SortedSet<Volume> result = Sets.newTreeSet(client.describeVolumesInRegion( assertEquals(volume.getId(), expected.getId());
// Region.DEFAULT, result.getId())); }
// assertNotNull(result);
// assertEquals(result.size(), 1); @Test(dependsOnMethods = "testCreateVolumeInAvailabilityZone")
// Volume volume = result.iterator().next(); void testDeleteInRegion() {
// assertEquals(volume, result); client.deleteVolumeInRegion(Region.DEFAULT, volumeId);
SortedSet<Volume> result = Sets.newTreeSet(client.describeVolumesInRegion(Region.DEFAULT,
volumeId));
assertEquals(result.size(), 1);
Volume volume = result.iterator().next();
assertEquals(volume.getStatus(), Volume.Status.DELETING);
} }
@Test @Test

View File

@ -0,0 +1,58 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.aws.ec2.domain.Volume.Attachment;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code CreateVolumeResponseHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.CreateVolumeResponseHandlerTest")
public class CreateVolumeResponseHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() {
DateService dateService = injector.getInstance(DateService.class);
InputStream is = getClass().getResourceAsStream("/ec2/created_volume.xml");
Volume expected = new Volume("vol-2a21e543", 1, null, AvailabilityZone.US_EAST_1A,
Volume.Status.CREATING, dateService.iso8601DateParse("2009-12-28T05:42:53.000Z"),
Sets.<Attachment>newLinkedHashSet());
Volume result = factory.create(injector.getInstance(CreateVolumeResponseHandler.class))
.parse(is);
assertEquals(result, expected);
}
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.aws.ec2.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Set;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.aws.ec2.domain.Volume.Attachment;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.BaseHandlerTest;
import org.testng.annotations.Test;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code DescribeVolumesResponseHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ec2.DescribeVolumesResponseHandlerTest")
public class DescribeVolumesResponseHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() {
DateService dateService = injector.getInstance(DateService.class);
InputStream is = getClass().getResourceAsStream("/ec2/describe_volumes.xml");
Set<Volume> expected = Sets.newLinkedHashSet();
expected.add(new Volume("vol-2a21e543", 1, null, AvailabilityZone.US_EAST_1A,
Volume.Status.AVAILABLE, dateService.iso8601DateParse("2009-12-28T05:42:53.000Z"),
Sets.<Attachment> newLinkedHashSet()));
expected.add(new Volume("vol-4282672b", 800, null, AvailabilityZone.US_EAST_1A,
Volume.Status.IN_USE, dateService.iso8601DateParse("2008-05-07T11:51:50.000Z"), Sets
.<Attachment> newHashSet(new Attachment("vol-4282672b", "i-6058a509",
"/dev/sdh", Volume.Attachment.Status.ATTACHED, dateService
.iso8601DateParse("2008-05-07T12:51:50.000Z")))));
Set<Volume> result = factory.create(
injector.getInstance(DescribeVolumesResponseHandler.class)).parse(is);
assertEquals(result, expected);
}
}

View File

@ -5,11 +5,28 @@
<item> <item>
<volumeId>vol-2a21e543</volumeId> <volumeId>vol-2a21e543</volumeId>
<size>1</size> <size>1</size>
<snapshotId/> <snapshotId />
<availabilityZone>us-east-1a</availabilityZone> <availabilityZone>us-east-1a</availabilityZone>
<status>available</status> <status>available</status>
<createTime>2009-12-28T05:42:53.000Z</createTime> <createTime>2009-12-28T05:42:53.000Z</createTime>
<attachmentSet/> <attachmentSet />
</item>
<item>
<volumeId>vol-4282672b</volumeId>
<size>800</size>
<snapshotId />
<availabilityZone>us-east-1a</availabilityZone>
<status>in-use</status>
<createTime>2008-05-07T11:51:50.000Z</createTime>
<attachmentSet>
<item>
<volumeId>vol-4282672b</volumeId>
<instanceId>i-6058a509</instanceId>
<device>/dev/sdh</device>
<status>attached</status>
<attachTime>2008-05-07T12:51:50.000Z</attachTime>
</item>
</attachmentSet>
</item> </item>
</volumeSet> </volumeSet>
</DescribeVolumesResponse> </DescribeVolumesResponse>