Merge branch 'master' of git@github.com:jclouds/jclouds

* 'master' of git@github.com:jclouds/jclouds:
  added AWS Elastic IP Address clojure wrapper
  additional region-related fixes for clojure wrappers
  changed AvailabilityZone to String (from enum)
This commit is contained in:
Adrian Cole 2010-05-02 17:56:52 -07:00
commit 453148e56f
28 changed files with 226 additions and 150 deletions

View File

@ -24,7 +24,7 @@
(:use (clojure.contrib def core))
(:import org.jclouds.aws.domain.Region
org.jclouds.compute.domain.NodeMetadata
(org.jclouds.aws.ec2.domain Volume Snapshot AvailabilityZone)
(org.jclouds.aws.ec2.domain Volume Volume$Status Snapshot Snapshot$Status AvailabilityZone)
(org.jclouds.aws.ec2.options DescribeSnapshotsOptions DetachVolumeOptions CreateSnapshotOptions)))
(defn snapshot?
@ -46,16 +46,16 @@
.getContext .getProviderSpecificContext .getApi .getElasticBlockStoreServices))
(defn get-region
"Returns the first argument as the corresponding Region if it is a
keyword or already a Region instance. An optional second argument
is returned if the first cannot be coerced into a Region.
"Coerces the first parameter into a Region string; strings, keywords, and
NodeMetadata instances are acceptable arguments. An optional second argument
is returned if the first cannot be coerced into a region string.
Returns nil otherwise."
([v] (get-region v nil))
([v default-region]
(cond
(string? v) v
(keyword? v) (name v)
(instance? Region v) v
(instance? NodeMetadata v) (let [zone (.getLocationId v)]
(instance? NodeMetadata v) (let [zone (compute/location v)]
; no easier way to go from zone -> region?
(if (> (.indexOf zone "-") -1)
(subs zone 0 (-> zone count dec))
@ -119,7 +119,7 @@
"Returns a set of org.jclouds.aws.ec2.domain.Snapshot instances that match
the criteria provided. Options include:
:region - region string or keyword
:region - region string, keyword, or NodeMetadata
:owner - AWS account id (or \"amazon\" or \"self\")
:restorable-by - AWS account id
@ -172,9 +172,9 @@
[v]
(cond
(instance? AvailabilityZone v) v
(instance? NodeMetadata v) (AvailabilityZone/fromValue (.getLocationId #^NodeMetadata v))
(string? v) (AvailabilityZone/fromValue v)
(keyword? v) (AvailabilityZone/fromValue (name v))
(instance? NodeMetadata v) (compute/location #^NodeMetadata v)
(string? v) v
(keyword? v) (name v)
:else (throw (IllegalArgumentException.
(str "Can't obtain zone from argument of type " (class v))))))
@ -283,3 +283,36 @@
(.deleteVolumeInRegion (ebs-service)
(get-region region)
(as-string volume-id))))
(defn status
"Returns the status of the given entity; works for Volumes and Snapshots."
[k]
(.getStatus k))
(defn status-available?
[#^Volume v]
(= Volume$Status/AVAILABLE (status v)))
(defn status-creating?
[#^Volume v]
(= Volume$Status/CREATING (status v)))
(defn status-deleting?
[#^Volume v]
(= Volume$Status/DELETING (status v)))
(defn status-in-use?
[#^Volume v]
(= Volume$Status/IN_USE (status v)))
(defn status-completed?
[#^Snapshot s]
(= Snapshot$Status/COMPLETED (status s)))
(defn status-error?
[#^Snapshot s]
(= Snapshot$Status/ERROR (status s)))
(defn status-pending?
[#^Snapshot s]
(= Snapshot$Status/PENDING (status s)))

View File

@ -0,0 +1,91 @@
;;
;; Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
;;
;; ====================================================================
;; Licensed 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.
;; ====================================================================
;;
(ns
#^{:author "Chas Emerick, cemerick@snowtide.com"
:doc "A clojure binding for the jclouds AWS elastic IP address interface."}
org.jclouds.aws.elastic-ip
(:require (org.jclouds [compute :as compute])
[org.jclouds.aws.ebs :as ebs])
(:use (clojure.contrib def core))
(:import org.jclouds.compute.domain.NodeMetadata
(org.jclouds.aws.ec2.domain PublicIpInstanceIdPair)
java.net.InetAddress))
(defn #^org.jclouds.aws.ec2.services.ElasticIPAddressClient
eip-service
"Returns the synchronous ElasticIPAddressClient associated with
the specified compute service, or compute/*compute* as bound by with-compute-service."
[& [compute]]
(-> (or compute compute/*compute*)
.getContext .getProviderSpecificContext .getApi .getElasticIPAddressServices))
(defn- as-ip
"Coerces v to an InetAddress; accepts InetAddresses and strings."
[v]
(if (string? v)
(InetAddress/getByName v)
v))
(defn allocate
"Claims a new elastic IP address within the (optionally) specified region for your account.
Region may be a string, keyword, or a node from which the region
is inferred. Returns a corresponding InetAddress instance."
([] (allocate nil))
([region]
(.allocateAddressInRegion (eip-service) (ebs/get-region region))))
(defn associate
"Associates an elastic IP address with a node."
([#^NodeMetadata node public-ip]
(associate node public-ip (.getId node)))
([region public-ip instance-id]
(.associateAddressInRegion (eip-service)
(ebs/get-region region)
(as-ip public-ip)
instance-id)))
(defn addresses
"Returns a map of elastic IP addresses to maps with slots:
:region - the region (string/keyword/NodeMetadata) the IP address is allocated within
:node-id - the ID of the instance with which the IP address is associated (optional)
You may optionally specify which IP addresses you would like to query."
([] (addresses nil))
([region & public-ips]
(into {} (for [#^PublicIpInstanceIdPair pair (.describeAddressesInRegion (eip-service)
(ebs/get-region region)
(into-array InetAddress (map as-ip public-ips)))]
[(.getPublicIp pair) (merge {:region (.getRegion pair)}
(when (.getInstanceId pair) {:node-id (.getInstanceId pair)}))]))))
(defn dissociate
"Dissociates an elastic IP address from the node with which it is currently associated."
[region public-ip]
(.disassociateAddressInRegion (eip-service)
(ebs/get-region region)
(as-ip public-ip)))
(defn release
"Disclaims an elastic IP address from your account."
([public-ip] (release nil public-ip))
([region public-ip]
(.releaseAddressInRegion (eip-service)
(ebs/get-region region)
(as-ip public-ip))))

View File

@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Singleton;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.Binder;
import org.jclouds.rest.internal.GeneratedHttpRequest;
@ -41,10 +40,10 @@ public class IfNotNullBindAvailabilityZoneToFormParam implements Binder {
if (input != null) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
checkArgument(input instanceof AvailabilityZone,
checkArgument(input instanceof String,
"this binder is only valid for AvailabilityZone!");
((GeneratedHttpRequest<?>) request).addFormParam("Placement.AvailabilityZone",
((AvailabilityZone) input).value());
(String) input);
}
}

View File

@ -49,7 +49,6 @@ import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
import org.jclouds.aws.ec2.compute.strategy.EC2DestroyNodeStrategy;
import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy;
import org.jclouds.aws.ec2.config.EC2ContextModule;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.functions.RunningInstanceToStorageMappingUnix;
@ -257,11 +256,11 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule {
@Provides
@Singleton
Map<String, ? extends Location> provideLocations(Map<AvailabilityZone, String> availabilityZoneToRegionMap) {
Map<String, ? extends Location> provideLocations(Map<String, String> availabilityZoneToRegionMap) {
Map<String, Location> locations = Maps.newLinkedHashMap();
for (AvailabilityZone zone : availabilityZoneToRegionMap.keySet()) {
locations.put(zone.toString(), new LocationImpl(LocationScope.ZONE, zone.toString(), zone
.toString(), availabilityZoneToRegionMap.get(zone)));
for (String zone : availabilityZoneToRegionMap.keySet()) {
locations.put(zone, new LocationImpl(LocationScope.ZONE, zone, zone,
availabilityZoneToRegionMap.get(zone)));
}
for (String region : availabilityZoneToRegionMap.values()) {
locations.put(region, new LocationImpl(LocationScope.REGION, region,

View File

@ -102,7 +102,7 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
Set<InetAddress> publicAddresses = nullSafeSet(instance.getIpAddress());
Set<InetAddress> privateAddresses = nullSafeSet(instance.getPrivateIpAddress());
String locationId = instance.getAvailabilityZone().toString();
String locationId = instance.getAvailabilityZone();
Map<String, String> extra = getExtra(instance);

View File

@ -34,7 +34,6 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.compute.domain.EC2Size;
import org.jclouds.aws.ec2.compute.domain.PortsRegionTag;
@ -42,7 +41,6 @@ import org.jclouds.aws.ec2.compute.domain.RegionTag;
import org.jclouds.aws.ec2.compute.functions.CreateNewKeyPair;
import org.jclouds.aws.ec2.compute.functions.CreateSecurityGroupIfNeeded;
import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.RunningInstance;
@ -122,8 +120,7 @@ public class EC2RunNodesAndAddToSetStrategy implements RunNodesAndAddToSetStrate
EC2Size ec2Size = EC2Size.class.cast(template.getSize());
// parse the availability zone of the request
AvailabilityZone zone = template.getLocation().getScope() == LocationScope.ZONE ? AvailabilityZone
.fromValue(template.getLocation().getId())
String zone = template.getLocation().getScope() == LocationScope.ZONE ? template.getLocation().getId()
: null;
// if the location has a parent, it must be an availability zone.

View File

@ -27,9 +27,7 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.aws.ec2.domain.RunningInstance;
import org.jclouds.aws.ec2.predicates.InstanceStateRunning;
@ -132,9 +130,9 @@ public class EC2RestClientModule extends AbstractModule {
@Provides
@Singleton
Map<AvailabilityZone, String> provideAvailabilityZoneToRegions(
Map<String, String> provideAvailabilityZoneToRegions(
AvailabilityZoneAndRegionClient client, @EC2 Map<String, URI> regions) {
Map<AvailabilityZone, String> map = Maps.newHashMap();
Map<String, String> map = Maps.newHashMap();
for (String region : regions.keySet()) {
for (AvailabilityZoneInfo zoneInfo : client.describeAvailabilityZonesInRegion(region)) {
map.put(zoneInfo.getZone(), region);

View File

@ -18,9 +18,9 @@
*/
package org.jclouds.aws.ec2.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.inject.internal.ImmutableSet;
import com.google.common.base.CaseFormat;
import java.util.Set;
/**
*
@ -28,21 +28,21 @@ import com.google.common.base.CaseFormat;
*
* @author Adrian Cole
*/
public enum AvailabilityZone {
public class AvailabilityZone {
UNKNOWN, EU_WEST_1A, EU_WEST_1B, US_EAST_1A, US_EAST_1B, US_EAST_1C, US_EAST_1D, US_WEST_1A, US_WEST_1B, AP_SOUTHEAST_1A, AP_SOUTHEAST_1B;
public static final String EU_WEST_1A = "eu-west-1a";
public static final String EU_WEST_1B = "eu-west-1b";
public static final String US_EAST_1A = "us-east-1a";
public static final String US_EAST_1B = "us-east-1b";
public static final String US_EAST_1C = "us-east-1c";
public static final String US_EAST_1D = "us-east-1d";
public static final String US_WEST_1A = "us-west-1a";
public static final String US_WEST_1B = "us-west-1b";
public static final String AP_SOUTHEAST_1A = "ap-southeast-1a";
public static final String AP_SOUTHEAST_1B = "ap-southeast-1b";
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
}
public static final Set<String> zones = ImmutableSet.of(EU_WEST_1A, EU_WEST_1B,
US_EAST_1A, US_EAST_1B, US_EAST_1C, US_EAST_1D,
US_WEST_1A, US_WEST_1B, AP_SOUTHEAST_1A, AP_SOUTHEAST_1B);
@Override
public String toString() {
return value();
}
public static AvailabilityZone fromValue(String availablilityZone) {
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(
availablilityZone, "availablilityZone")));
}
}

View File

@ -51,32 +51,23 @@ public class AvailabilityZoneInfo implements Comparable<AvailabilityZoneInfo>{
}
}
private final String zoneName;
private final AvailabilityZone zone;
private final String zone;
private final State state;
private final String region;
private final Set<String> messages = Sets.newHashSet();
public AvailabilityZoneInfo(String zoneName, AvailabilityZone zone, State zoneState,
public AvailabilityZoneInfo(String zone, State zoneState,
String region, Iterable<String> messages) {
this.zoneName = checkNotNull(zoneName, "zoneName");
this.zone = checkNotNull(zone, "zone");
this.state = checkNotNull(zoneState, "zoneState");
this.region = checkNotNull(region, "region");
Iterables.addAll(this.messages, checkNotNull(messages, "messages"));
}
/**
* Name of the Availability Zone.
*/
public String getZoneName() {
return zoneName;
}
/**
* the Availability Zone.
*/
public AvailabilityZone getZone() {
public String getZone() {
return zone;
}
@ -109,7 +100,6 @@ public class AvailabilityZoneInfo implements Comparable<AvailabilityZoneInfo>{
result = prime * result + ((region == null) ? 0 : region.hashCode());
result = prime * result + ((state == null) ? 0 : state.hashCode());
result = prime * result + ((zone == null) ? 0 : zone.hashCode());
result = prime * result + ((zoneName == null) ? 0 : zoneName.hashCode());
return result;
}
@ -142,23 +132,18 @@ public class AvailabilityZoneInfo implements Comparable<AvailabilityZoneInfo>{
return false;
} else if (!zone.equals(other.zone))
return false;
if (zoneName == null) {
if (other.zoneName != null)
return false;
} else if (!zoneName.equals(other.zoneName))
return false;
return true;
}
@Override
public String toString() {
return "AvailabilityZoneInfo [messages=" + messages + ", region=" + region + ", state="
+ state + ", zone=" + zone + ", zoneName=" + zoneName + "]";
+ state + ", zone=" + zone + "]";
}
@Override
public int compareTo(AvailabilityZoneInfo that) {
return zoneName.compareTo(that.zoneName);
return zone.compareTo(that.zone);
}
}

View File

@ -132,7 +132,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
private final String keyName;
private final Date launchTime;
private final boolean monitoring;
private final AvailabilityZone availabilityZone;
private final String availabilityZone;
@Nullable
private final String platform;
@Nullable
@ -161,7 +161,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
String imageId, String instanceId, InstanceState instanceState,
String instanceType, @Nullable InetAddress ipAddress, @Nullable String kernelId,
@Nullable String keyName, Date launchTime, boolean monitoring,
AvailabilityZone availabilityZone, @Nullable String platform,
String availabilityZone, @Nullable String platform,
@Nullable String privateDnsName, @Nullable InetAddress privateIpAddress,
Set<String> productCodes, @Nullable String ramdiskId, @Nullable String reason,
@Nullable String subnetId, @Nullable String vpcId, RootDeviceType rootDeviceType,
@ -284,7 +284,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
/**
* The location where the instance launched.
*/
public AvailabilityZone getAvailabilityZone() {
public String getAvailabilityZone() {
return availabilityZone;
}

View File

@ -84,13 +84,13 @@ public class Volume implements Comparable<Volume> {
private final int size;
@Nullable
private final String snapshotId;
private final AvailabilityZone availabilityZone;
private final String availabilityZone;
private final Status status;
private final Date createTime;
private final Set<Attachment> attachments = Sets.newLinkedHashSet();
public Volume(String region, String id, int size, String snapshotId,
AvailabilityZone availabilityZone, Volume.Status status, Date createTime,
String availabilityZone, Volume.Status status, Date createTime,
Iterable<Attachment> attachments) {
this.region = checkNotNull(region, "region");
this.id = id;
@ -122,7 +122,7 @@ public class Volume implements Comparable<Volume> {
return snapshotId;
}
public AvailabilityZone getAvailabilityZone() {
public String getAvailabilityZone() {
return availabilityZone;
}

View File

@ -24,9 +24,7 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import com.google.common.base.Function;
@ -36,12 +34,12 @@ import com.google.common.base.Function;
*/
@Singleton
public class AvailabilityZoneToEndpoint implements Function<Object, URI> {
private final Map<AvailabilityZone, String> availabilityZoneToRegion;
private final Map<String, String> availabilityZoneToRegion;
private final Map<String, URI> regionToEndpoint;
@Inject
public AvailabilityZoneToEndpoint(@EC2 Map<String, URI> regionToEndpoint,
Map<AvailabilityZone, String> availabilityZoneToRegion) {
Map<String, String> availabilityZoneToRegion) {
this.regionToEndpoint = regionToEndpoint;
this.availabilityZoneToRegion = availabilityZoneToRegion;
}

View File

@ -18,9 +18,9 @@
*/
package org.jclouds.aws.ec2.options;
import java.util.Arrays;
import java.util.Set;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.options.internal.BaseEC2RequestOptions;
/**
@ -46,10 +46,8 @@ public class DescribeAvailabilityZonesOptions extends BaseEC2RequestOptions {
/**
* Availability Zone name.
*/
public DescribeAvailabilityZonesOptions zones(AvailabilityZone... zones) {
String[] zoneStrings = new String[zones.length];
for (int i = 0; i < zoneStrings.length; i++)
zoneStrings[i] = zones[i].value();
public DescribeAvailabilityZonesOptions zones(String... zones) {
String[] zoneStrings = Arrays.copyOf(zones, zones.length, String[].class);
indexFormValuesWithPrefix("ZoneName", zoneStrings);
return this;
}
@ -61,9 +59,9 @@ public class DescribeAvailabilityZonesOptions extends BaseEC2RequestOptions {
public static class Builder {
/**
* @see DescribeAvailabilityZonesOptions#zones(AvailabilityZone[] )
* @see DescribeAvailabilityZonesOptions#zones(String...)
*/
public static DescribeAvailabilityZonesOptions availabilityZones(AvailabilityZone... zones) {
public static DescribeAvailabilityZonesOptions availabilityZones(String... zones) {
DescribeAvailabilityZonesOptions options = new DescribeAvailabilityZonesOptions();
return options.zones(zones);
}

View File

@ -28,12 +28,10 @@ import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.binders.BindUserGroupsToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindUserIdsToIndexedFormParams;
import org.jclouds.aws.ec2.binders.BindVolumeIdsToIndexedFormParams;
import org.jclouds.aws.ec2.domain.Attachment;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Permission;
import org.jclouds.aws.ec2.domain.Snapshot;
import org.jclouds.aws.ec2.domain.Volume;
@ -79,7 +77,7 @@ public interface ElasticBlockStoreAsyncClient {
@FormParams(keys = ACTION, values = "CreateVolume")
@XMLResponseParser(CreateVolumeResponseHandler.class)
ListenableFuture<Volume> createVolumeFromSnapshotInAvailabilityZone(
@EndpointParam(parser = AvailabilityZoneToEndpoint.class) @FormParam("AvailabilityZone") AvailabilityZone availabilityZone,
@EndpointParam(parser = AvailabilityZoneToEndpoint.class) @FormParam("AvailabilityZone") String availabilityZone,
@FormParam("SnapshotId") String snapshotId);
/**
@ -90,7 +88,7 @@ public interface ElasticBlockStoreAsyncClient {
@FormParams(keys = ACTION, values = "CreateVolume")
@XMLResponseParser(CreateVolumeResponseHandler.class)
ListenableFuture<Volume> createVolumeFromSnapshotInAvailabilityZone(
@EndpointParam(parser = AvailabilityZoneToEndpoint.class) @FormParam("AvailabilityZone") AvailabilityZone availabilityZone,
@EndpointParam(parser = AvailabilityZoneToEndpoint.class) @FormParam("AvailabilityZone") String availabilityZone,
@FormParam("Size") int size, @FormParam("SnapshotId") String snapshotId);
/**
@ -101,7 +99,7 @@ public interface ElasticBlockStoreAsyncClient {
@FormParams(keys = ACTION, values = "CreateVolume")
@XMLResponseParser(CreateVolumeResponseHandler.class)
ListenableFuture<Volume> createVolumeInAvailabilityZone(
@EndpointParam(parser = AvailabilityZoneToEndpoint.class) @FormParam("AvailabilityZone") AvailabilityZone availabilityZone,
@EndpointParam(parser = AvailabilityZoneToEndpoint.class) @FormParam("AvailabilityZone") String availabilityZone,
@FormParam("Size") int size);
/**

View File

@ -23,9 +23,7 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.Attachment;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Permission;
import org.jclouds.aws.ec2.domain.Snapshot;
import org.jclouds.aws.ec2.domain.Volume;
@ -65,7 +63,7 @@ public interface ElasticBlockStoreClient {
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html"
* />
*/
Volume createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone availabilityZone,
Volume createVolumeFromSnapshotInAvailabilityZone(String availabilityZone,
String snapshotId);
/**
@ -95,7 +93,7 @@ public interface ElasticBlockStoreClient {
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html"
* />
*/
Volume createVolumeFromSnapshotInAvailabilityZone(AvailabilityZone availabilityZone,
Volume createVolumeFromSnapshotInAvailabilityZone(String availabilityZone,
int size, String snapshotId);
/**
@ -120,7 +118,7 @@ public interface ElasticBlockStoreClient {
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateVolume.html"
* />
*/
Volume createVolumeInAvailabilityZone(AvailabilityZone availabilityZone, int size);
Volume createVolumeInAvailabilityZone(String availabilityZone, int size);
/**
* Describes the specified Amazon EBS volumes that you own. If you do not specify one or more

View File

@ -88,7 +88,7 @@ public interface InstanceAsyncClient {
@XMLResponseParser(RunInstancesResponseHandler.class)
ListenableFuture<Reservation> runInstancesInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable String region,
@Nullable @BinderParam(IfNotNullBindAvailabilityZoneToFormParam.class) AvailabilityZone nullableAvailabilityZone,
@Nullable @BinderParam(IfNotNullBindAvailabilityZoneToFormParam.class) String nullableAvailabilityZone,
@FormParam("ImageId") String imageId, @FormParam("MinCount") int minCount,
@FormParam("MaxCount") int maxCount, RunInstancesOptions... options);

View File

@ -134,7 +134,7 @@ public interface InstanceClient {
* @see RunInstancesOptions
*/
Reservation runInstancesInRegion(@Nullable String region,
@Nullable AvailabilityZone nullableAvailabilityZone, String imageId, int minCount,
@Nullable String nullableAvailabilityZone, String imageId, int minCount,
int maxCount, RunInstancesOptions... options);
/**

View File

@ -70,10 +70,11 @@ public class EC2Utils {
return null;
}
public static AvailabilityZone findAvailabilityZoneInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
public static String findAvailabilityZoneInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof AvailabilityZone) {
return (AvailabilityZone) arg;
if (arg instanceof String) {
String zone = (String) arg;
if(AvailabilityZone.zones.contains(zone)) return zone;
}
}
return null;

View File

@ -28,12 +28,9 @@ import java.util.SortedSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.Attachment;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.InstanceState;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.Reservation;
import org.jclouds.aws.ec2.domain.RootDeviceType;
import org.jclouds.aws.ec2.domain.RunningInstance;
@ -81,7 +78,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
private String keyName;
private Date launchTime;
private boolean monitoring;
private AvailabilityZone availabilityZone;
private String availabilityZone;
private String platform;
private String privateDnsName;
private InetAddress privateIpAddress;
@ -153,7 +150,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
} else if (qName.equals("enabled")) {
monitoring = Boolean.parseBoolean(currentOrNull());
} else if (qName.equals("availabilityZone")) {
availabilityZone = AvailabilityZone.fromValue(currentOrNull());
availabilityZone = currentOrNull();
} else if (qName.equals("platform")) {
platform = currentOrNull();
} else if (qName.equals("privateDnsName")) {

View File

@ -27,10 +27,8 @@ import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2;
import org.jclouds.aws.ec2.domain.Attachment;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.Volume;
import org.jclouds.aws.ec2.util.EC2Utils;
import org.jclouds.date.DateService;
@ -56,12 +54,12 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerWithResult<Volu
@EC2
String defaultRegion;
@Inject
protected Map<AvailabilityZone, String> availabilityZoneToRegion;
protected Map<String, String> availabilityZoneToRegion;
private String id;
private int size;
private String snapshotId;
private AvailabilityZone availabilityZone;
private String availabilityZone;
private Volume.Status volumeStatus;
private Date createTime;
private Set<Attachment> attachments = Sets.newLinkedHashSet();
@ -96,13 +94,7 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerWithResult<Volu
} 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;
}
availabilityZone = currentText.toString().trim();
} else if (qName.equals("volumeId")) {
if (inAttachmentSet) {
volumeId = currentText.toString().trim();
@ -166,7 +158,7 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerWithResult<Volu
super.setContext(request);
region = EC2Utils.findRegionInArgsOrNull(request);
if (region == null) {
AvailabilityZone zone = EC2Utils.findAvailabilityZoneInArgsOrNull(request);
String zone = EC2Utils.findAvailabilityZoneInArgsOrNull(request);
if (zone != null) {
region = checkNotNull(availabilityZoneToRegion.get(zone), String.format(
"zone %s not in %s", zone, availabilityZoneToRegion));

View File

@ -22,8 +22,6 @@ import java.util.Set;
import javax.annotation.Resource;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo.State;
import org.jclouds.http.functions.ParseSax;
@ -41,11 +39,10 @@ public class DescribeAvailabilityZonesResponseHandler extends
private StringBuilder currentText = new StringBuilder();
private Set<AvailabilityZoneInfo> availablilityZones = Sets.newLinkedHashSet();
private AvailabilityZone zone;
private String zone;
@Resource
protected Logger logger = Logger.NULL;
private String region;
private String zoneName;
private State zoneState;
private boolean inMessageSet;
private Set<String> messages = Sets.newHashSet();
@ -62,13 +59,7 @@ public class DescribeAvailabilityZonesResponseHandler extends
public void endElement(String uri, String name, String qName) {
if (qName.equals("zoneName")) {
zoneName = currentText.toString().trim();
try {
zone = AvailabilityZone.fromValue(zoneName);
} catch (IllegalArgumentException e) {
logger.warn(e, "unsupported region: %s", zoneName);
zone = AvailabilityZone.UNKNOWN;
}
zone = currentText.toString().trim();
} else if (qName.equals("regionName")) {
try {
region = currentText.toString().trim();
@ -88,10 +79,9 @@ public class DescribeAvailabilityZonesResponseHandler extends
} else if (qName.equals("messageSet")) {
inMessageSet = false;
} else if (qName.equals("item") && !inMessageSet) {
availablilityZones.add(new AvailabilityZoneInfo(zoneName, zone, zoneState, region,
availablilityZones.add(new AvailabilityZoneInfo(zone, zoneState, region,
messages));
this.zone = null;
this.zoneName = null;
this.region = null;
this.zoneState = null;
this.messages = Sets.newHashSet();

View File

@ -34,7 +34,6 @@ import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2AsyncClient;
import org.jclouds.aws.ec2.EC2Client;
import org.jclouds.aws.ec2.EC2ContextFactory;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
@ -75,8 +74,8 @@ public class AvailabilityZoneAndRegionClientLiveTest {
assertNotNull(allResults);
assert allResults.size() >= 2 : allResults.size();
Iterator<AvailabilityZoneInfo> iterator = allResults.iterator();
AvailabilityZone id1 = iterator.next().getZone();
AvailabilityZone id2 = iterator.next().getZone();
String id1 = iterator.next().getZone();
String id2 = iterator.next().getZone();
SortedSet<AvailabilityZoneInfo> twoResults = Sets.newTreeSet(client
.describeAvailabilityZonesInRegion(region, availabilityZones(id1, id2)));
assertNotNull(twoResults);

View File

@ -108,8 +108,8 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
@SuppressWarnings("unused")
@Singleton
@Provides
Map<AvailabilityZone, String> provideAvailabilityZoneRegionMap() {
return ImmutableMap.<AvailabilityZone, String> of(AvailabilityZone.US_EAST_1A,
Map<String, String> provideAvailabilityZoneRegionMap() {
return ImmutableMap.<String, String> of(AvailabilityZone.US_EAST_1A,
Region.US_EAST_1);
}
};

View File

@ -25,7 +25,6 @@ import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.domain.AvailabilityZone;
import org.jclouds.aws.ec2.functions.ReturnVoidOnVolumeAvailable;
import org.jclouds.aws.ec2.options.CreateSnapshotOptions;
@ -57,7 +56,7 @@ public class ElasticBlockStoreAsyncClientTest extends
public void testCreateVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"createVolumeInAvailabilityZone", AvailabilityZone.class, int.class);
"createVolumeInAvailabilityZone", String.class, int.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest(
method, AvailabilityZone.US_EAST_1A, 20);
@ -77,7 +76,7 @@ public class ElasticBlockStoreAsyncClientTest extends
public void testCreateVolumeFromSnapShot() throws SecurityException, NoSuchMethodException,
IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"createVolumeFromSnapshotInAvailabilityZone", AvailabilityZone.class, String.class);
"createVolumeFromSnapshotInAvailabilityZone", String.class, String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest(
method, AvailabilityZone.US_EAST_1A, "snapshotId");
@ -97,7 +96,7 @@ public class ElasticBlockStoreAsyncClientTest extends
public void testCreateVolumeFromSnapShotWithSize() throws SecurityException,
NoSuchMethodException, IOException {
Method method = ElasticBlockStoreAsyncClient.class.getMethod(
"createVolumeFromSnapshotInAvailabilityZone", AvailabilityZone.class, int.class,
"createVolumeFromSnapshotInAvailabilityZone", String.class, int.class,
String.class);
GeneratedHttpRequest<ElasticBlockStoreAsyncClient> httpMethod = processor.createRequest(
method, AvailabilityZone.US_EAST_1A, 15, "snapshotId");

View File

@ -113,7 +113,7 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
public void testRunInstances() throws SecurityException, NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class,
AvailabilityZone.class, String.class, int.class, int.class, Array.newInstance(
String.class, String.class, int.class, int.class, Array.newInstance(
RunInstancesOptions.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null,
null, "ami-voo", 1, 1);
@ -134,7 +134,7 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
public void testRunInstancesOptions() throws SecurityException, NoSuchMethodException,
IOException {
Method method = InstanceAsyncClient.class.getMethod("runInstancesInRegion", String.class,
AvailabilityZone.class, String.class, int.class, int.class, Array.newInstance(
String.class, String.class, int.class, int.class, Array.newInstance(
RunInstancesOptions.class, 0).getClass());
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method,
Region.EU_WEST_1, AvailabilityZone.EU_WEST_1A, "ami-voo", 1, 5,

View File

@ -67,8 +67,8 @@ public class BaseEC2HandlerTest extends BaseHandlerTest {
@SuppressWarnings("unused")
@Singleton
@Provides
Map<AvailabilityZone, String> provideAvailabilityZoneRegionMap() {
return ImmutableMap.<AvailabilityZone, String> of(AvailabilityZone.US_EAST_1A,
Map<String, String> provideAvailabilityZoneRegionMap() {
return ImmutableMap.<String, String> of(AvailabilityZone.US_EAST_1A,
Region.US_EAST_1);
}
});

View File

@ -44,15 +44,19 @@ public class DescribeAvailabilityZonesResponseHandlerTest extends BaseHandlerTes
InputStream is = getClass().getResourceAsStream("/ec2/availabilityZones.xml");
Set<AvailabilityZoneInfo> expected = ImmutableSet.<AvailabilityZoneInfo> of(
new AvailabilityZoneInfo("us-east-1a", AvailabilityZone.US_EAST_1A,
AvailabilityZoneInfo.State.AVAILABLE, Region.US_EAST_1, ImmutableSet
.<String> of()), new AvailabilityZoneInfo("us-east-1b",
AvailabilityZone.US_EAST_1B, AvailabilityZoneInfo.State.AVAILABLE,
Region.US_EAST_1, ImmutableSet.<String> of()), new AvailabilityZoneInfo(
"us-east-1c", AvailabilityZone.US_EAST_1C,
AvailabilityZoneInfo.State.AVAILABLE, Region.US_EAST_1, ImmutableSet
.<String> of("our service is awesome")), new AvailabilityZoneInfo(
"us-east-1d", AvailabilityZone.US_EAST_1D,
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1A,
AvailabilityZoneInfo.State.AVAILABLE, Region.US_EAST_1, ImmutableSet
.<String> of()),
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1B,
AvailabilityZoneInfo.State.AVAILABLE,
Region.US_EAST_1, ImmutableSet.<String> of()),
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1C,
AvailabilityZoneInfo.State.AVAILABLE, Region.US_EAST_1, ImmutableSet
.<String> of("our service is awesome")),
new AvailabilityZoneInfo(AvailabilityZone.US_EAST_1D,
AvailabilityZoneInfo.State.UNKNOWN, Region.US_EAST_1, ImmutableSet
.<String> of()));
Set<AvailabilityZoneInfo> result = factory.create(

View File

@ -51,7 +51,7 @@ Here's an example of creating and running a small linux node with the tag webser
See http://code.google.com/p/jclouds for details."
(:use org.jclouds.core
clojure.contrib.logging)
(clojure.contrib logging core))
(:import java.io.File
java.util.Properties
[org.jclouds.domain Location]
@ -304,7 +304,7 @@ See http://code.google.com/p/jclouds for details."
(defn location
"Returns the compute node's location id"
[#^ComputeMetadata node]
(.getLocationId node))
(-?> node .getLocation .getId))
(define-accessors Template image size location options)
(define-accessors Image version os-family os-description architecture)