Issue 230: completed ibmdev api from a coding and unit test perspective

This commit is contained in:
Adrian Cole 2010-06-07 17:32:47 -07:00
parent f624dbe3f8
commit f4e030d10f
39 changed files with 3331 additions and 17 deletions

View File

@ -23,29 +23,51 @@
*/
package org.jclouds.ibmdev;
import java.util.Date;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.ibmdev.binders.BindImageVisibilityToJsonPayload;
import org.jclouds.ibmdev.binders.BindExpirationTimeToJsonPayload;
import org.jclouds.ibmdev.binders.SaveInstanceBinder;
import org.jclouds.ibmdev.domain.Address;
import org.jclouds.ibmdev.domain.Image;
import org.jclouds.ibmdev.domain.Instance;
import org.jclouds.ibmdev.domain.Key;
import org.jclouds.ibmdev.domain.Location;
import org.jclouds.ibmdev.domain.Volume;
import org.jclouds.ibmdev.functions.ParseAddressFromJson;
import org.jclouds.ibmdev.functions.ParseAddressesFromJson;
import org.jclouds.ibmdev.functions.ParseExpirationTimeFromJson;
import org.jclouds.ibmdev.functions.ParseImageFromJson;
import org.jclouds.ibmdev.functions.ParseImagesFromJson;
import org.jclouds.ibmdev.functions.ParseInstanceFromJson;
import org.jclouds.ibmdev.functions.ParseInstancesFromJson;
import org.jclouds.ibmdev.functions.ParseKeyFromJson;
import org.jclouds.ibmdev.functions.ParseKeysFromJson;
import org.jclouds.ibmdev.functions.ParseVolumeFromJson;
import org.jclouds.ibmdev.functions.ParseVolumesFromJson;
import org.jclouds.ibmdev.options.CreateInstanceOptions;
import org.jclouds.ibmdev.options.RestartInstanceOptions;
import org.jclouds.ibmdev.xml.LocationHandler;
import org.jclouds.ibmdev.xml.LocationsHandler;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.MapPayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
@ -96,8 +118,19 @@ public interface IBMDeveloperCloudAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/images/{imageId}")
@ResponseParser(ParseImageFromJson.class)
@MapBinder(BindToJsonPayload.class)
ListenableFuture<Image> setImageVisibility(@PathParam("imageId") long id,
@BinderParam(BindImageVisibilityToJsonPayload.class) Image.Visibility visibility);
@MapPayloadParam("visibility") Image.Visibility visibility);
/**
* @see IBMDeveloperCloudClient#listInstancesFromRequest(long)
*/
@GET
@Path("/requests/{requestId}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@ResponseParser(ParseInstancesFromJson.class)
ListenableFuture<Set<? extends Instance>> listInstancesFromRequest(
@PathParam("requestId") long requestId);
/**
* @see IBMDeveloperCloudClient#listInstances()
@ -116,6 +149,47 @@ public interface IBMDeveloperCloudAsyncClient {
@ResponseParser(ParseInstanceFromJson.class)
ListenableFuture<Instance> getInstance(@PathParam("instanceId") long id);
/**
* @see IBMDeveloperCloudClient#extendReservationForInstance(long,Date)
*/
@PUT
@Path("/instances/{instanceId}")
@ResponseParser(ParseExpirationTimeFromJson.class)
ListenableFuture<Date> extendReservationForInstance(@PathParam("instanceId") long id,
@BinderParam(BindExpirationTimeToJsonPayload.class) Date expirationTime);
/**
* @see IBMDeveloperCloudClient#restartInstance
*/
@PUT
@Path("/instances/{instanceId}")
@MapBinder(RestartInstanceOptions.class)
ListenableFuture<Void> restartInstance(@PathParam("instanceId") long id,
RestartInstanceOptions... options);
/**
* @see IBMDeveloperCloudClient#saveInstanceToImage
*/
@PUT
@Path("/instances/{instanceId}")
@MapBinder(SaveInstanceBinder.class)
@ResponseParser(ParseImageFromJson.class)
ListenableFuture<Image> saveInstanceToImage(@PathParam("instanceId") long id,
@MapPayloadParam("name") String toImageName,
@MapPayloadParam("description") String toImageDescription);
/**
* @see IBMDeveloperCloudClient#createInstanceInLocation
*/
@POST
@Path("/instances")
@MapBinder(CreateInstanceOptions.class)
@ResponseParser(ParseInstanceFromJson.class)
ListenableFuture<Instance> createInstanceInLocation(
@MapPayloadParam("location") String location, @MapPayloadParam("name") String name,
@MapPayloadParam("imageID") String imageID,
@MapPayloadParam("instanceType") String instanceType, CreateInstanceOptions... options);
/**
* @see IBMDeveloperCloudClient#deleteInstance
*/
@ -124,4 +198,144 @@ public interface IBMDeveloperCloudAsyncClient {
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteInstance(@PathParam("instanceId") long id);
/**
* @see IBMDeveloperCloudClient#listKeys()
*/
@GET
@Path("/keys")
@ResponseParser(ParseKeysFromJson.class)
ListenableFuture<Set<? extends Key>> listKeys();
/**
* @see IBMDeveloperCloudClient#generateKeyPair(String)
*/
@POST
@Path("/keys")
@MapBinder(BindToJsonPayload.class)
@ResponseParser(ParseKeyFromJson.class)
ListenableFuture<Key> generateKeyPair(@MapPayloadParam("name") String name);
/**
* @see IBMDeveloperCloudClient#addPublicKey(String, String)
*/
@POST
@Path("/keys")
@MapBinder(BindToJsonPayload.class)
ListenableFuture<Void> addPublicKey(@MapPayloadParam("name") String name,
@MapPayloadParam("publicKey") String publicKey);
/**
* @see IBMDeveloperCloudClient#updatePublicKey(String, String)
*/
@PUT
@Path("/keys/{keyName}")
@MapBinder(BindToJsonPayload.class)
ListenableFuture<Void> updatePublicKey(@PathParam("keyName") String name,
@MapPayloadParam("publicKey") String publicKey);
/**
* @see IBMDeveloperCloudClient#setDefaultStatusOfKey(String, boolean)
*/
@PUT
@Path("/keys/{keyName}")
@MapBinder(BindToJsonPayload.class)
ListenableFuture<Void> setDefaultStatusOfKey(@PathParam("keyName") String name,
@MapPayloadParam("default") boolean isDefault);
/**
* @see IBMDeveloperCloudClient#getKey(String)
*/
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/keys/{keyName}")
@ResponseParser(ParseKeyFromJson.class)
ListenableFuture<Key> getKey(@PathParam("keyName") String name);
/**
* @see IBMDeveloperCloudClient#deleteKey
*/
@DELETE
@Path("/keys/{keyName}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteKey(@PathParam("keyName") String name);
/**
* @see IBMDeveloperCloudClient#listVolumes()
*/
@GET
@Path("/storage")
@ResponseParser(ParseVolumesFromJson.class)
ListenableFuture<Set<? extends Volume>> listVolumes();
/**
* @see IBMDeveloperCloudClient#createVolumeInLocation
*/
@POST
@Path("/storage")
@MapBinder(BindToJsonPayload.class)
@ResponseParser(ParseVolumeFromJson.class)
ListenableFuture<Volume> createVolumeInLocation(@MapPayloadParam("location") String location,
@MapPayloadParam("name") String name, @MapPayloadParam("format") String format,
@MapPayloadParam("size") String size);
/**
* @see IBMDeveloperCloudClient#getVolume(long)
*/
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/storage/{volumeId}")
@ResponseParser(ParseVolumeFromJson.class)
ListenableFuture<Volume> getVolume(@PathParam("volumeId") long id);
/**
* @see IBMDeveloperCloudClient#deleteVolume
*/
@DELETE
@Path("/storage/{volumeId}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> deleteVolume(@PathParam("volumeId") long id);
/**
* @see IBMDeveloperCloudClient#listLocations()
*/
@GET
@Path("/locations")
@Consumes(MediaType.TEXT_XML)
@XMLResponseParser(LocationsHandler.class)
ListenableFuture<Set<? extends Location>> listLocations();
/**
* @see IBMDeveloperCloudClient#getLocation(long)
*/
@GET
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/locations/{locationId}")
@Consumes(MediaType.TEXT_XML)
@XMLResponseParser(LocationHandler.class)
ListenableFuture<Location> getLocation(@PathParam("locationId") long id);
/**
* @see IBMDeveloperCloudClient#listAddresses()
*/
@GET
@Path("/addresses")
@ResponseParser(ParseAddressesFromJson.class)
ListenableFuture<Set<? extends Address>> listAddresses();
/**
* @see IBMDeveloperCloudClient#allocateAddressInLocation(long)
*/
@POST
@Path("/addresses")
@MapBinder(BindToJsonPayload.class)
@ResponseParser(ParseAddressFromJson.class)
ListenableFuture<Address> allocateAddressInLocation(@MapPayloadParam("location") long locationId);
/**
* @see IBMDeveloperCloudClient#releaseAddress(long)
*/
@DELETE
@Path("/addresses/{addressId}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
ListenableFuture<Void> releaseAddress(@PathParam("addressId") long id);
}

View File

@ -41,13 +41,21 @@
*/
package org.jclouds.ibmdev;
import java.util.Date;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.ibmdev.domain.Address;
import org.jclouds.ibmdev.domain.Image;
import org.jclouds.ibmdev.domain.Instance;
import org.jclouds.ibmdev.domain.Key;
import org.jclouds.ibmdev.domain.Location;
import org.jclouds.ibmdev.domain.Volume;
import org.jclouds.ibmdev.options.CreateInstanceOptions;
import org.jclouds.ibmdev.options.RestartInstanceOptions;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ResourceNotFoundException;
/**
* Provides synchronous access to IBMDeveloperCloud.
@ -85,7 +93,7 @@ public interface IBMDeveloperCloudClient {
void deleteImage(long id);
/**
* If set to {@link Image.Visibility#PUBLIC}, makes the Image identified by the supplied Image ID
* If set to {@code Image.Visibility#PUBLIC}, makes the Image identified by the supplied Image ID
* publicly available for all users to create Instances of.
*
* @return modified image or null, if image was not found.
@ -106,6 +114,15 @@ public interface IBMDeveloperCloudClient {
*/
Set<? extends Instance> listInstances();
/**
*
* @return the list of Instances that the authenticated user manages that were created as part of
* the request specified by {@code requestId}, or null if the request was not found
* @throws AuthorizationException
* code 401 if the currently authenticated user is not authorized to view this request
*/
Set<? extends Instance> listInstancesFromRequest(long requestId);
/**
* Returns the Instance that the authenticated user manages with the specified {@code id}
*
@ -116,6 +133,99 @@ public interface IBMDeveloperCloudClient {
*/
Instance getInstance(long id);
/**
* Requests a new Instance to be created.
*
* @param location
* The id of the Location where this instance will be created
* @param name
* The alias to use to reference this instance
* @param imageID
* The ID of the image to create this instance from
* @param instanceType
* The instance type to use for this instance {SMALL, MEDIUM, LARGE}
* @param options
* overrides default public key, mounts a volume, or attaches a static ip
* @throws AuthorizationException
* code 401 if the authenticated user is not authorized to create instances
* <p/>
* code 402 if payment is required before more instances may be created
* @throws IllegalStateException
* code 409 if there are not enough resources in the cloud to fulfill this request
* <p/>
* code 412 One or more of the supplied parameters are invalid for this request
*/
Instance createInstanceInLocation(String location, String name, String imageID,
String instanceType, CreateInstanceOptions... options);
/**
* Sets the expiration time of the instance to the value specified
*
* @throws ResourceNotFoundException
* code 404 The instance specified by {@code name} was not found
* @throws AuthorizationException
* code 401 if the user is not authorized to extend the expiration time of this
* instance
* <p/>
* code 402 if payment is required before more instances may be created
* @throws IllegalStateException
* <p>
* code 406 The provided expiration date is not valid code 409 if there are not enough
* resources in the cloud to fulfill this request
* <p/>
* code 412 The instance is in an invalid state to perform this operation
*/
Date extendReservationForInstance(long id, Date expirationTime);
/**
* Restart the instance
*
* @param id
* the instance to restart
* @param options
* allows you to specify a new public key for login
* @throws ResourceNotFoundException
* code 404 The instance specified by {@code name} was not found
* @throws AuthorizationException
* code 401 if the user is not authorized to extend the expiration time of this
* instance
* <p/>
* code 402 if payment is required before more instances may be created
* @throws IllegalStateException
* <p>
* code 406 The provided expiration date is not valid code 409 if there are not enough
* resources in the cloud to fulfill this request
* <p/>
* code 412 The instance is in an invalid state to perform this operation
*/
void restartInstance(long id, RestartInstanceOptions... options);
/**
* Saves an instance to a private image
*
* @param id
* the instance to save
* @param toImageName
* The name to associate with the captured image.
* @param toImageDescription
* The description to associate with the capture image.
* @return a private image
* @throws ResourceNotFoundException
* code 404 The instance specified by {@code name} was not found
* @throws AuthorizationException
* code 401 if the user is not authorized to extend the expiration time of this
* instance
* <p/>
* code 402 if payment is required before more instances may be created
* @throws IllegalStateException
* <p>
* code 406 The provided expiration date is not valid code 409 if there are not enough
* resources in the cloud to fulfill this request
* <p/>
* code 412 The instance is in an invalid state to perform this operation
*/
Image saveInstanceToImage(long id, String toImageName, String toImageDescription);
/**
* Deletes the Instance that the authenticated user manages with the specified {@code id}
*
@ -125,4 +235,186 @@ public interface IBMDeveloperCloudClient {
* code 412 if the instance is in an invalid state to perform this operation
*/
void deleteInstance(long id);
/**
*
* @return the set of Public Keys stored for the authenticated user.
*/
Set<? extends Key> listKeys();
/**
* Returns the key with the specified key name from the set of Public Keys stored for the
* authenticated user.
*
* @return null if key is not found
*/
Key getKey(String name);
/**
* Used to generate a new SSH Key Pair for the authenticated user.
*
* @param name
* The name to used to identify this key pair.
* @return private key
*
* @throws IllegalStateException
* code 409 A key with the specified {@code name} already exists
*
*/
Key generateKeyPair(String name);
/**
* Used to generate a new SSH Key Pair for the authenticated user.
*
* @param name
* The name to used to identify this key pair.
* @param publicKey
* The RSA SSH Key to add
*
* @throws IllegalStateException
* code 409 A key with the specified {@code name} already exists
* <p/>
* code 412 The supplied public key is invalid
*/
void addPublicKey(String name, String publicKey);
/**
* Used to update the Public Key specified by the supplied key name stored for the authenticated
* user.
*
* @param name
* The name to used to identify this key pair.
* @param publicKey
* The public key to store
* @throws ResourceNotFoundException
* code 404 The key specified by {@code name} was not found
* @throws IllegalStateException
* code 412 The supplied public key is invalid
*/
void updatePublicKey(String name, String publicKey);
/**
* Used to set the Public Key specified by the supplied key name as the default key.
*
* @param name
* The name to used to identify this key pair.
* @param isDefault
* A boolean representing the default state of this key
* @throws ResourceNotFoundException
* code 404 The key specified by {@code name} was not found
*/
void setDefaultStatusOfKey(String name, boolean isDefault);
/**
* Deletes Key identified by the supplied key name.
*
* @throws AuthorizationException
* code 401 if the user is not authorized to perform this action
*/
void deleteKey(String name);
/**
*
* @return the set of storage volumes for the authenticated user.
* @throws AuthorizationException
* code 401 if the currently authenticated user is not authorized to view this
* information
*/
Set<? extends Volume> listVolumes();
/**
* Creates a new storage volume for the authenticated user.
*
* @param location
* The id of the Location where the storage volume will be created
* @param name
* The desired name of the newly created storage volume
* @param format
* The filesystem format for the new storage volume. Valid format is: EXT3
* @param size
* The size of the new storage volume. Valid values may include SMALL, MEDIUM, and
* LARGE. Actual values may depend on the location used and may be discov- ered via the
* location service
* @throws AuthorizationException
* code 401 if the currently authenticated user is not authorized to create a volume
* <p/>
* code 402 if payment is required before more storage volumes may be created
* @throws IllegalStateException
* code 409 ifhere are not enough resources in the cloud to fulfill this request
* <p/>
* code 412 One or more of the supplied parameters are invalid for this request
*/
Volume createVolumeInLocation(String location, String name, String format, String size);
/**
* Used to retrieve the specified storage volume for the authenticated user.
*
* @return null if volume is not found
* @throws AuthorizationException
* code 401 if the currently authenticated user is not authorized to view this storage
* volume
*/
Volume getVolume(long id);
/**
* Remove the specified storage volume for the authenticated user.
*
* @throws AuthorizationException
* code 401 if the currently authenticated user is not authorized to remove this
* storage volume
* @throws IllegalStateException
* code 412 if the storage volume is not in the correct state to be deleted
*/
void deleteVolume(long id);
/**
*
* @return the list of Locations (Data Centers) that the user is entitled to and their
* capabilities
*/
Set<? extends Location> listLocations();
/**
* Returns the Location identified by the supplied Location ID
*
* @return null if location is not found
*
* @throws AuthorizationException
* code 401 if the user is not authorized
*/
Location getLocation(long id);
/**
*
* @return the set of static IP addresses for the authenticated user.
* @throws AuthorizationException
* code 401 if the currently authenticated user is not authorized to view this
* information
*/
Set<? extends Address> listAddresses();
/**
* Allocates a new static IP addresses for the authenticated user.
*
* @param locationId
* the id of the Location where this address will be allocated
* @throws AuthorizationException
* code 401 if the currently authenticated user is not authorized to remove this IP
* address
* <p/>
* code 402 if payment is required before more addresses may be allocated
* @throws IllegalStateException
* code 409 ifhere are not enough resources in the cloud to fulfill this request
*/
Address allocateAddressInLocation(long locationId);
/**
* Used to release the specified static IP addresses for the authenticated user.
*
* @throws AuthorizationException
* code 401 if the user is not authorized to release this address
* @throws IllegalStateException
* code 412 address is in an invalid state to perform this operation
*/
void releaseAddress(long id);
}

View File

@ -0,0 +1,48 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.binders;
import static com.google.common.base.Preconditions.checkArgument;
import java.util.Date;
import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
/**
*
* @author Adrian Cole
*
*/
public class BindExpirationTimeToJsonPayload extends BindToJsonPayload {
@Override
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
throw new IllegalStateException("Change Admin Pass is a PUT operation");
}
@Override
public void bindToRequest(HttpRequest request, Object toBind) {
checkArgument(toBind instanceof Date, "this binder is only valid for Date!");
super.bindToRequest(request, ImmutableMap.of("expirationTime", toBind));
}
}

View File

@ -3,14 +3,14 @@
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the ;License;);
* 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
* 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,
* 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.
@ -18,26 +18,23 @@
*/
package org.jclouds.ibmdev.binders;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToStringPayload;
import com.google.common.collect.ImmutableSet;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
*
*
* @author Adrian Cole
*
*/
public class BindImageVisibilityToJsonPayload extends BindToStringPayload {
public class SaveInstanceBinder extends BindToJsonPayload {
@Override
public void bindToRequest(HttpRequest request, Object payload) {
request.getHeaders().replaceValues(HttpHeaders.CONTENT_TYPE,
ImmutableSet.of(MediaType.APPLICATION_JSON));
super.bindToRequest(request, String.format("{\"visibility\":\"%s\"}", payload));
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
postParams.put("state", "save");
bindToRequest(request,(Object) postParams);
}
}
}

View File

@ -0,0 +1,135 @@
/**
*
* Copyright (C) 2009 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
*
* 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.ibmdev.domain;
import javax.annotation.Nullable;
/**
*
* The current state of a Address
*
* @author Adrian Cole
*/
public class Address {
private int state;
private int location;
private String ip;
private long id;
@Nullable
private Long instanceId;
public Address(int state, int location, String ip, long id, Long instanceId) {
this.state = state;
this.location = location;
this.ip = ip;
this.id = id;
this.instanceId = instanceId;
}
public Address() {
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public int getLocation() {
return location;
}
public void setLocation(int location) {
this.location = location;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Long getInstanceId() {
return instanceId;
}
public void setInstanceId(Long instanceId) {
this.instanceId = instanceId;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode());
result = prime * result + ((ip == null) ? 0 : ip.hashCode());
result = prime * result + location;
result = prime * result + state;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Address other = (Address) obj;
if (id != other.id)
return false;
if (instanceId == null) {
if (other.instanceId != null)
return false;
} else if (!instanceId.equals(other.instanceId))
return false;
if (ip == null) {
if (other.ip != null)
return false;
} else if (!ip.equals(other.ip))
return false;
if (location != other.location)
return false;
if (state != other.state)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + id + ", ip=" + ip + ", location=" + location + ", state=" + state
+ ", instanceId=" + instanceId + "]";
}
}

View File

@ -0,0 +1,148 @@
/**
*
* Copyright (C) 2009 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
*
* 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.ibmdev.domain;
import java.util.Date;
import java.util.Set;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName;
/**
*
* The current state of a public or private key.
*
* @author Adrian Cole
*/
public class Key {
@SerializedName("default")
private boolean isDefault;
private Set<Long> instanceIds = Sets.newLinkedHashSet();
private String keyMaterial;
@SerializedName("keyName")
private String name;
private Date lastModifiedTime;
public Key(boolean isDefault, Iterable<Long> instanceIds, String keyMaterial, String name,
Date lastModifiedTime) {
this.isDefault = isDefault;
Iterables.addAll(this.instanceIds, instanceIds);
this.keyMaterial = keyMaterial;
this.name = name;
this.lastModifiedTime = lastModifiedTime;
}
public Key() {
}
public boolean isDefault() {
return isDefault;
}
public void setDefault(boolean isDefault) {
this.isDefault = isDefault;
}
public String getKeyMaterial() {
return keyMaterial;
}
public void setKeyMaterial(String keyMaterial) {
this.keyMaterial = keyMaterial;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getLastModifiedTime() {
return lastModifiedTime;
}
public void setLastModifiedTime(Date lastModifiedTime) {
this.lastModifiedTime = lastModifiedTime;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((instanceIds == null) ? 0 : instanceIds.hashCode());
result = prime * result + (isDefault ? 1231 : 1237);
result = prime * result + ((keyMaterial == null) ? 0 : keyMaterial.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((lastModifiedTime == null) ? 0 : lastModifiedTime.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;
Key other = (Key) obj;
if (instanceIds == null) {
if (other.instanceIds != null)
return false;
} else if (!instanceIds.equals(other.instanceIds))
return false;
if (isDefault != other.isDefault)
return false;
if (keyMaterial == null) {
if (other.keyMaterial != null)
return false;
} else if (!keyMaterial.equals(other.keyMaterial))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (lastModifiedTime == null) {
if (other.lastModifiedTime != null)
return false;
} else if (!lastModifiedTime.equals(other.lastModifiedTime))
return false;
return true;
}
@Override
public String toString() {
return "Key [isDefault=" + isDefault + ", instanceIds=" + instanceIds + ", name=" + name
+ ", keyMaterial=" + keyMaterial + ", lastModifiedTime=" + lastModifiedTime + "]";
}
public Set<Long> getInstanceIds() {
return instanceIds;
}
public void setInstanceIds(Set<Long> instanceIds) {
this.instanceIds = instanceIds;
}
}

View File

@ -0,0 +1,120 @@
/**
*
* Copyright (C) 2009 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
*
* 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.ibmdev.domain;
import java.util.Map;
import com.google.common.collect.Maps;
/**
*
* The current state of a location (datacenter)
*
* @author Adrian Cole
*/
public class Location {
private final int id;
private final String name;
private final String description;
private final String location;
private final Map<String, Map<String, String>> capabilities = Maps.newLinkedHashMap();
public Location(int id, String name, String description, String location,
Map<String, Map<String, String>> capabilities) {
this.id = id;
this.name = name;
this.description = description;
this.location = location;
this.capabilities.putAll(capabilities);
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public String getLocation() {
return location;
}
public Map<String, Map<String, String>> getCapabilities() {
return capabilities;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((capabilities == null) ? 0 : capabilities.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + id;
result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.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;
Location other = (Location) obj;
if (capabilities == null) {
if (other.capabilities != null)
return false;
} else if (!capabilities.equals(other.capabilities))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (id != other.id)
return false;
if (location == null) {
if (other.location != null)
return false;
} else if (!location.equals(other.location))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return "Location [id=" + id + ", name=" + name + ", description=" + description
+ ", location=" + location + ", capabilities=" + capabilities + "]";
}
}

View File

@ -0,0 +1,219 @@
/**
*
* Copyright (C) 2009 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
*
* 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.ibmdev.domain;
import java.util.Date;
import java.util.Set;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
*
* The current state of a Volume
*
* @author Adrian Cole
*/
public class Volume {
private Long instanceId;
private int state;
private int size;
private String owner;
private Date createdTime;
private int location;
private Set<String> productCodes = Sets.newLinkedHashSet();
private String format;
private String name;
private long id;
public Volume(Long instanceId, int state, int size, String owner, Date createdTime,
int location, Iterable<String> productCodes, String format, String name, long id) {
this.instanceId = instanceId;
this.state = state;
this.size = size;
this.owner = owner;
this.createdTime = createdTime;
this.location = location;
Iterables.addAll(this.productCodes, productCodes);
this.format = format;
this.name = name;
this.id = id;
}
public Volume() {
}
public Long getInstanceId() {
return instanceId;
}
public void setInstanceId(Long instanceId) {
this.instanceId = instanceId;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public Date getCreatedTime() {
return createdTime;
}
public void setCreatedTime(Date createdTime) {
this.createdTime = createdTime;
}
public int getLocation() {
return location;
}
public void setLocation(int location) {
this.location = location;
}
public Set<String> getProductCodes() {
return productCodes;
}
public void setProductCodes(Set<String> productCodes) {
this.productCodes = productCodes;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((createdTime == null) ? 0 : createdTime.hashCode());
result = prime * result + ((format == null) ? 0 : format.hashCode());
result = prime * result + (int) (id ^ (id >>> 32));
result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode());
result = prime * result + location;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
result = prime * result + ((productCodes == null) ? 0 : productCodes.hashCode());
result = prime * result + size;
result = prime * result + state;
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 (createdTime == null) {
if (other.createdTime != null)
return false;
} else if (!createdTime.equals(other.createdTime))
return false;
if (format == null) {
if (other.format != null)
return false;
} else if (!format.equals(other.format))
return false;
if (id != other.id)
return false;
if (instanceId == null) {
if (other.instanceId != null)
return false;
} else if (!instanceId.equals(other.instanceId))
return false;
if (location != other.location)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (owner == null) {
if (other.owner != null)
return false;
} else if (!owner.equals(other.owner))
return false;
if (productCodes == null) {
if (other.productCodes != null)
return false;
} else if (!productCodes.equals(other.productCodes))
return false;
if (size != other.size)
return false;
if (state != other.state)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", size=" + size + ", state=" + state
+ ", instanceId=" + instanceId + ", location=" + location + ", format=" + format
+ ", owner=" + owner + ", createdTime=" + createdTime + ", productCodes="
+ productCodes + "]";
}
}

View File

@ -0,0 +1,74 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
/**
*
* 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.ibmdev.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.ibmdev.domain.Address;
import com.google.gson.Gson;
/**
* @author Adrian Cole
*/
@Singleton
public class ParseAddressFromJson extends ParseJson<Address> {
@Inject
public ParseAddressFromJson(Gson gson) {
super(gson);
}
@Override
protected Address apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), Address.class);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,80 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
/**
*
* 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.ibmdev.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.ibmdev.domain.Address;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
/**
* @author Adrian Cole
*/
@Singleton
public class ParseAddressesFromJson extends ParseJson<Set<? extends Address>> {
@Inject
public ParseAddressesFromJson(Gson gson) {
super(gson);
}
private static class AddressListResponse {
Set<Address> addresses = Sets.newLinkedHashSet();
}
@Override
protected Set<? extends Address> apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), AddressListResponse.class).addresses;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,55 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.functions.ParseJson;
import com.google.gson.Gson;
/**
* @author Adrian Cole
*/
@Singleton
public class ParseExpirationTimeFromJson extends ParseJson<Date> {
@Inject
public ParseExpirationTimeFromJson(Gson gson) {
super(gson);
}
private static class ExpirationTimeResponse {
Date expirationTime;
}
@Override
protected Date apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), ExpirationTimeResponse.class).expirationTime;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,74 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
/**
*
* 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.ibmdev.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.ibmdev.domain.Key;
import com.google.gson.Gson;
/**
* @author Adrian Cole
*/
@Singleton
public class ParseKeyFromJson extends ParseJson<Key> {
@Inject
public ParseKeyFromJson(Gson gson) {
super(gson);
}
@Override
protected Key apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), Key.class);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,80 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
/**
*
* 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.ibmdev.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.ibmdev.domain.Key;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
/**
* @author Adrian Cole
*/
@Singleton
public class ParseKeysFromJson extends ParseJson<Set<? extends Key>> {
@Inject
public ParseKeysFromJson(Gson gson) {
super(gson);
}
private static class KeyListResponse {
Set<Key> keys = Sets.newLinkedHashSet();
}
@Override
protected Set<? extends Key> apply(InputStream stream) {
try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), KeyListResponse.class).keys;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,58 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.ibmdev.domain.Volume;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
/**
* @author Adrian Cole
*/
@Singleton
public class ParseVolumeFromJson extends ParseJson<Volume> {
@Inject
public ParseVolumeFromJson(Gson gson) {
super(gson);
}
private static final Set<String> emptyString = ImmutableSet.of("");
@Override
protected Volume apply(InputStream stream) {
try {
Volume returnVal = gson.fromJson(new InputStreamReader(stream, "UTF-8"), Volume.class);
if (emptyString.equals(returnVal.getProductCodes()))
returnVal.getProductCodes().clear();
return returnVal;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.ibmdev.domain.Volume;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
/**
* @author Adrian Cole
*/
@Singleton
public class ParseVolumesFromJson extends ParseJson<Set<? extends Volume>> {
@Inject
public ParseVolumesFromJson(Gson gson) {
super(gson);
}
private static class VolumeListResponse {
Set<Volume> volumes = Sets.newLinkedHashSet();
}
private static final Set<String> emptyString = ImmutableSet.of("");
@Override
protected Set<? extends Volume> apply(InputStream stream) {
try {
Set<Volume> list = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
VolumeListResponse.class).volumes;
for (Volume volume : list)
if (emptyString.equals(volume.getProductCodes()))
volume.getProductCodes().clear();
return list;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
}
}
}

View File

@ -56,9 +56,12 @@ public class IBMDeveloperCloudErrorHandler implements HttpErrorHandler {
.getRequestLine(), response.getStatusLine());
switch (response.getStatusCode()) {
case 401:
case 402:
case 403:
exception = new AuthorizationException(message, exception);
break;
case 406:
case 409:
case 412:
exception = new IllegalStateException(message, exception);
break;

View File

@ -0,0 +1,125 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.options;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.Maps;
/**
*
*
* @author Adrian Cole
*
*/
public class CreateInstanceOptions extends BindToJsonPayload {
Long volumeID;
Long ip;
String publicKey = "DEFAULT";
Map<String, String> configurationData = Maps.newLinkedHashMap();
@Override
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
Map<String, Object> postData = Maps.newLinkedHashMap();
postData.putAll(postParams);
postData.put("publicKey", publicKey);
if (volumeID != null)
postData.put("volumeID", volumeID);
if (configurationData.size() > 0)
postData.put("configurationData", configurationData);
if (ip != null)
postData.put("ip", ip);
super.bindToRequest(request, postData);
}
@Override
public void bindToRequest(HttpRequest request, Object toBind) {
throw new IllegalStateException("CreateInstance is a POST operation");
}
/**
*
* @param id
* The ID of a storage volume to associate with this instance
* @param mountPoint
* The mount point in which to mount the attached storage volume
*/
public CreateInstanceOptions mountVolume(long id, String mountPoint) {
checkArgument(id > 0, "volume id must be a positive number");
checkNotNull(mountPoint, "mountPoint");
this.volumeID = id;
configurationData.put(String.format("oss.storage.id.%d.mnt", id), mountPoint);
return this;
}
/**
*
* @param publicKeyName
* The public key to use for accessing the created instancee
*/
public CreateInstanceOptions authorizePublicKey(String publicKeyName) {
checkNotNull(publicKeyName, "publicKeyName");
this.publicKey = publicKeyName;
return this;
}
/**
*
* @param id
* The ID of a static IP address to associate with this instance
*/
public CreateInstanceOptions attachIp(long id) {
checkArgument(id > 0, "ip id must be a positive number");
this.ip = id;
return this;
}
public static class Builder {
/**
* @see CreateInstanceOptions#mountVolume(long, String )
*/
public static CreateInstanceOptions mountVolume(long id, String mountPoint) {
CreateInstanceOptions options = new CreateInstanceOptions();
return options.mountVolume(id, mountPoint);
}
/**
* @see CreateInstanceOptions#attachIp(long )
*/
public static CreateInstanceOptions attachIp(long id) {
CreateInstanceOptions options = new CreateInstanceOptions();
return options.attachIp(id);
}
/**
* @see CreateInstanceOptions#authorizePublicKey(String )
*/
public static CreateInstanceOptions authorizePublicKey(String publicKeyName) {
CreateInstanceOptions options = new CreateInstanceOptions();
return options.authorizePublicKey(publicKeyName);
}
}
}

View File

@ -0,0 +1,75 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.options;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.Maps;
/**
*
*
* @author Adrian Cole
*
*/
public class RestartInstanceOptions extends BindToJsonPayload {
String keyName;
@Override
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
Map<String, Object> postData = Maps.newLinkedHashMap();
postData.putAll(postParams);
postData.put("state", "restart");
if (keyName != null)
postData.put("keyName", keyName);
super.bindToRequest(request, postData);
}
@Override
public void bindToRequest(HttpRequest request, Object toBind) {
throw new IllegalStateException("RestartInstance is a PUT operation");
}
/**
*
* @param keyName
* The name of the SSH Public Key to add to the instance during restart.
*/
public RestartInstanceOptions authorizePublicKey(String keyName) {
checkNotNull(keyName, "keyName");
this.keyName = keyName;
return this;
}
public static class Builder {
/**
* @see RestartInstanceOptions#authorizePublicKey(String )
*/
public static RestartInstanceOptions authorizePublicKey(String keyName) {
RestartInstanceOptions options = new RestartInstanceOptions();
return options.authorizePublicKey(keyName);
}
}
}

View File

@ -50,4 +50,8 @@ public interface IBMDeveloperCloudConstants {
public static final String PROPERTY_IBMDEVELOPERCLOUD_ENDPOINT = "jclouds.ibmdevelopercloud.endpoint";
public static final String PROPERTY_IBMDEVELOPERCLOUD_USER = "jclouds.ibmdevelopercloud.user";
public static final String PROPERTY_IBMDEVELOPERCLOUD_PASSWORD = "jclouds.ibmdevelopercloud.password";
public static final String CAPABILITY_CAPACITY = "oss.storage.capacity";
public static final String CAPABILITY_FORMAT = "oss.storage.format";
public static final String CAPABILITY_I386 = "oss.instance.spec.i386";
public static final String CAPABILITY_x86_64 = "oss.instance.spec.x86_64";
}

View File

@ -0,0 +1,99 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.xml;
import java.util.Map;
import javax.annotation.Resource;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ibmdev.domain.Location;
import org.jclouds.logging.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Maps;
/**
* @author Adrian Cole
*/
public class LocationHandler extends ParseSax.HandlerWithResult<Location> {
private StringBuilder currentText = new StringBuilder();
private int id;
private String name;
private String description;
private String location;
private Map<String, Map<String, String>> capabilities = Maps.newLinkedHashMap();
private String capabilityName;
private String capabilityKey;
@Resource
protected Logger logger = Logger.NULL;
private Location loc;
public Location getResult() {
return loc;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equalsIgnoreCase("Capability")) {
capabilityName = attributes.getValue(attributes.getIndex("id"));
capabilities.put(capabilityName, Maps.<String, String> newLinkedHashMap());
} else if (qName.equalsIgnoreCase("Entry")) {
capabilityKey = attributes.getValue(attributes.getIndex("key"));
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("ID")) {
id = Integer.parseInt(currentText.toString().trim());
} else if (qName.equalsIgnoreCase("Name")) {
name = currentText.toString().trim();
} else if (qName.equalsIgnoreCase("Description")) {
description = currentText.toString().trim();
if (description.equals(""))
description = null;
} else if (qName.equalsIgnoreCase("Value")) {
capabilities.get(capabilityName).put(capabilityKey, currentText.toString().trim());
} else if (qName.equalsIgnoreCase("Location")) {
if (currentText.toString().trim().equals("")) {
this.loc = new Location(id, name, description, location, capabilities);
id = 0;
name = null;
description = null;
location = null;
capabilities = Maps.newLinkedHashMap();
capabilityKey = null;
capabilityName = null;
} else {
location = currentText.toString().trim();
}
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,69 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.xml;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ibmdev.domain.Location;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class LocationsHandler extends ParseSax.HandlerWithResult<Set<? extends Location>> {
private StringBuilder currentText = new StringBuilder();
private Set<Location> tasks = Sets.newLinkedHashSet();
private final LocationHandler locationHandler;
@Inject
public LocationsHandler(LocationHandler locationHandler) {
this.locationHandler = locationHandler;
}
public Set<? extends Location> getResult() {
return tasks;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
locationHandler.startElement(uri, localName, qName, attributes);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
locationHandler.endElement(uri, localName, qName);
if (qName.equals("Location") && currentText.toString().trim().equals("")) {
this.tasks.add(locationHandler.getResult());
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
locationHandler.characters(ch, start, length);
currentText.append(ch, start, length);
}
}

View File

@ -27,15 +27,28 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Date;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.ibmdev.config.IBMDeveloperCloudRestClientModule;
import org.jclouds.ibmdev.domain.Image;
import org.jclouds.ibmdev.functions.ParseAddressFromJson;
import org.jclouds.ibmdev.functions.ParseAddressesFromJson;
import org.jclouds.ibmdev.functions.ParseExpirationTimeFromJson;
import org.jclouds.ibmdev.functions.ParseImageFromJson;
import org.jclouds.ibmdev.functions.ParseImagesFromJson;
import org.jclouds.ibmdev.functions.ParseInstanceFromJson;
import org.jclouds.ibmdev.functions.ParseInstancesFromJson;
import org.jclouds.ibmdev.functions.ParseKeyFromJson;
import org.jclouds.ibmdev.functions.ParseKeysFromJson;
import org.jclouds.ibmdev.functions.ParseVolumeFromJson;
import org.jclouds.ibmdev.functions.ParseVolumesFromJson;
import org.jclouds.ibmdev.options.CreateInstanceOptions;
import org.jclouds.ibmdev.options.RestartInstanceOptions;
import org.jclouds.ibmdev.xml.LocationHandler;
import org.jclouds.ibmdev.xml.LocationsHandler;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
@ -161,6 +174,26 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
}
public void testListInstancesFromRequest() throws SecurityException, NoSuchMethodException,
IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listInstancesFromRequest",
long.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1l);
assertRequestLineEquals(httpRequest,
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/requests/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseInstancesFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGetInstance() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getInstance", long.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
@ -179,6 +212,83 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
}
public void testExtendReservationForInstance() throws SecurityException, NoSuchMethodException,
IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("extendReservationForInstance",
long.class, Date.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1, new Date(123215235l));
assertRequestLineEquals(httpRequest,
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 28\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"expirationTime\":123215235}");
assertResponseParserClassEquals(method, httpRequest, ParseExpirationTimeFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testRestartInstance() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("restartInstance", long.class,
RestartInstanceOptions[].class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1);
assertRequestLineEquals(httpRequest,
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 19\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"state\":\"restart\"}");
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testRestartInstanceNewKey() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("restartInstance", long.class,
RestartInstanceOptions[].class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1, new RestartInstanceOptions().authorizePublicKey("keyName"));
assertRequestLineEquals(httpRequest,
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 39\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"state\":\"restart\",\"keyName\":\"keyName\"}");
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testSaveInstanceToImage() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("saveInstanceToImage", long.class,
String.class,String.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1, "imageName", "imageDescription");
assertRequestLineEquals(httpRequest,
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances/1 HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 68\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"description\":\"imageDescription\",\"name\":\"imageName\",\"state\":\"save\"}");
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testDeleteInstance() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("deleteInstance", long.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
@ -197,6 +307,358 @@ public class IBMDeveloperCloudAsyncClientTest extends RestClientTest<IBMDevelope
}
public void testListKeys() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listKeys");
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseKeysFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testGetKey() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getKey", String.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "1");
assertRequestLineEquals(httpRequest,
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testGenerateKeyPair() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("generateKeyPair", String.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "key");
assertRequestLineEquals(httpRequest,
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 14\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"name\":\"key\"}");
assertResponseParserClassEquals(method, httpRequest, ParseKeyFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testAddPublicKey() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("addPublicKey", String.class,
String.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "key", "publicbits");
assertRequestLineEquals(httpRequest,
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 39\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"publicKey\":\"publicbits\",\"name\":\"key\"}");
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testUpdatePublicKey() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("updatePublicKey", String.class,
String.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "key", "publicbits");
assertRequestLineEquals(httpRequest,
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/key HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 26\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"publicKey\":\"publicbits\"}");
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testSetDefaultStatusOfKey() throws SecurityException, NoSuchMethodException,
IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("setDefaultStatusOfKey",
String.class, boolean.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "key", true);
assertRequestLineEquals(httpRequest,
"PUT https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/key HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 18\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"default\":\"true\"}");
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testDeleteKey() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("deleteKey", String.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "1");
assertRequestLineEquals(httpRequest,
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/keys/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testListVolumes() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listVolumes");
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseVolumesFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testGetVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getVolume", long.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1);
assertRequestLineEquals(httpRequest,
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseVolumeFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testCreateVolumeInLocation() throws SecurityException, NoSuchMethodException,
IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createVolumeInLocation",
String.class, String.class, String.class, String.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "location", "name", "format", "size");
assertRequestLineEquals(httpRequest,
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 69\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest,
"{\"location\":\"location\",\"name\":\"name\",\"format\":\"format\",\"size\":\"size\"}");
assertResponseParserClassEquals(method, httpRequest, ParseVolumeFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testCreateInstanceInLocation() throws SecurityException, NoSuchMethodException,
IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createInstanceInLocation",
String.class, String.class, String.class, String.class,
CreateInstanceOptions[].class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "location", "name", "imageID", "instanceType");
assertRequestLineEquals(httpRequest,
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 109\nContent-Type: application/json\n");
assertPayloadEquals(
httpRequest,
"{\"instanceType\":\"instanceType\",\"imageID\":\"imageID\",\"location\":\"location\",\"name\":\"name\",\"publicKey\":\"DEFAULT\"}");
assertResponseParserClassEquals(method, httpRequest, ParseInstanceFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testCreateInstanceInLocationWithOptions() throws SecurityException,
NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("createInstanceInLocation",
String.class, String.class, String.class, String.class,
CreateInstanceOptions[].class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, "location", "name", "imageID", "instanceType", new CreateInstanceOptions()
.attachIp(1l).authorizePublicKey("MOO").mountVolume(2l, "/mnt"));
assertRequestLineEquals(httpRequest,
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/instances HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 177\nContent-Type: application/json\n");
assertPayloadEquals(
httpRequest,
"{\"instanceType\":\"instanceType\",\"imageID\":\"imageID\",\"location\":\"location\",\"name\":\"name\",\"publicKey\":\"MOO\",\"volumeID\":2,\"configurationData\":{\"oss.storage.id.2.mnt\":\"/mnt\"},\"ip\":1}");
assertResponseParserClassEquals(method, httpRequest, ParseInstanceFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testDeleteVolume() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("deleteVolume", long.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1);
assertRequestLineEquals(httpRequest,
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/storage/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testListLocations() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listLocations");
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/locations HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: text/xml\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
assertSaxResponseParserClassEquals(method, LocationsHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testGetLocation() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("getLocation", long.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1);
assertRequestLineEquals(httpRequest,
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/locations/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: text/xml\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseSax.class);
assertSaxResponseParserClassEquals(method, LocationHandler.class);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testListAddresses() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("listAddresses");
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor
.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, ParseAddressesFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testAllocateAddressInLocation() throws SecurityException, NoSuchMethodException,
IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("allocateAddressInLocation",
long.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1);
assertRequestLineEquals(httpRequest,
"POST https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses HTTP/1.1");
assertHeadersEqual(httpRequest,
"Accept: application/json\nContent-Length: 16\nContent-Type: application/json\n");
assertPayloadEquals(httpRequest, "{\"location\":\"1\"}");
assertResponseParserClassEquals(method, httpRequest, ParseAddressFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
checkFilters(httpRequest);
}
public void testReleaseAddress() throws SecurityException, NoSuchMethodException, IOException {
Method method = IBMDeveloperCloudAsyncClient.class.getMethod("releaseAddress", long.class);
GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest = processor.createRequest(
method, 1);
assertRequestLineEquals(httpRequest,
"DELETE https://www-180.ibm.com/cloud/enterprise/beta/api/rest/20090403/addresses/1 HTTP/1.1");
assertHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null);
assertResponseParserClassEquals(method, httpRequest, CloseContentAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
checkFilters(httpRequest);
}
@Override
protected void checkFilters(GeneratedHttpRequest<IBMDeveloperCloudAsyncClient> httpRequest) {
assertEquals(httpRequest.getFilters().size(), 1);

View File

@ -26,11 +26,16 @@ package org.jclouds.ibmdev;
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.assertNull;
import java.util.Set;
import org.jclouds.ibmdev.domain.Address;
import org.jclouds.ibmdev.domain.Image;
import org.jclouds.ibmdev.domain.Instance;
import org.jclouds.ibmdev.domain.Key;
import org.jclouds.ibmdev.domain.Location;
import org.jclouds.ibmdev.domain.Volume;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -78,6 +83,12 @@ public class IBMDeveloperCloudClientLiveTest {
assertNotNull(response);
}
@Test
public void testListInstancesFromRequestReturnsNull() throws Exception {
Set<? extends Instance> response = connection.listInstancesFromRequest(Long.MAX_VALUE);
assertNull(response);
}
@Test
public void testGetInstance() throws Exception {
Set<? extends Instance> response = connection.listInstances();
@ -87,4 +98,59 @@ public class IBMDeveloperCloudClientLiveTest {
assertEquals(connection.getInstance(instance.getId()).getId(), instance.getId());
}
}
@Test
public void testListKeys() throws Exception {
Set<? extends Key> response = connection.listKeys();
assertNotNull(response);
}
@Test
public void testGetKey() throws Exception {
Set<? extends Key> response = connection.listKeys();
assertNotNull(response);
if (response.size() > 0) {
Key key = Iterables.get(response, 0);
assertEquals(connection.getKey(key.getName()).getName(), key.getName());
}
}
@Test
public void testListVolumes() throws Exception {
Set<? extends Volume> response = connection.listVolumes();
assertNotNull(response);
}
@Test
public void testGetVolume() throws Exception {
Set<? extends Volume> response = connection.listVolumes();
assertNotNull(response);
if (response.size() > 0) {
Volume image = Iterables.get(response, 0);
assertEquals(connection.getVolume(image.getId()).getId(), image.getId());
}
}
@Test
public void testListLocations() throws Exception {
Set<? extends Location> response = connection.listLocations();
assertNotNull(response);
}
@Test
public void testGetLocation() throws Exception {
Set<? extends Location> response = connection.listLocations();
assertNotNull(response);
if (response.size() > 0) {
Location image = Iterables.get(response, 0);
assertEquals(connection.getLocation(image.getId()).getId(), image.getId());
}
}
@Test
public void testListAddresss() throws Exception {
Set<? extends Address> response = connection.listAddresses();
assertNotNull(response);
}
}

View File

@ -0,0 +1,64 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.domain.Address;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseAddressFromJson}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "ibmdev.ParseAddressFromJsonTest")
public class ParseAddressFromJsonTest {
private ParseAddressFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
handler = injector.getInstance(ParseAddressFromJson.class);
}
public void test() {
Address address = new Address(2, 1, "129.33.196.243", 1217l, 1l);
Address compare = handler.apply(new HttpResponse(ParseAddressFromJsonTest.class
.getResourceAsStream("/address.json")));
assertEquals(compare, address);
}
}

View File

@ -0,0 +1,64 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import java.io.IOException;
import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.domain.Address;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseAddresssFromJson}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "ibmdev.ParseAddressesFromJsonTest")
public class ParseAddressesFromJsonTest {
private ParseAddressesFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
handler = injector.getInstance(ParseAddressesFromJson.class);
}
public void test() {
Address address1 = new Address(2, 1, "129.33.196.243", 1217l, 1l);
Address address2 = new Address(3, 2, "129.33.196.244", 1218l, null);
Set<? extends Address> compare = handler.apply(new HttpResponse(
ParseAddressesFromJsonTest.class.getResourceAsStream("/addresses.json")));
assert (compare.contains(address1));
assert (compare.contains(address2));
}
}

View File

@ -0,0 +1,63 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Date;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.util.Utils;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseExpirationTimeFromJson}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "ibmdev.ParseExpirationTimeFromJsonTest")
public class ParseExpirationTimeFromJsonTest {
private ParseExpirationTimeFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
handler = injector.getInstance(ParseExpirationTimeFromJson.class);
}
public void test() {
Date compare = handler.apply(new HttpResponse(Utils
.toInputStream("{ \"expirationTime\":1249876800000 }")));
assertEquals(compare, new Date(1249876800000l));
}
}

View File

@ -0,0 +1,67 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Date;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.domain.Key;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseKeyFromJson}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "ibmdev.ParseKeyFromJsonTest")
public class ParseKeyFromJsonTest {
private ParseKeyFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
handler = injector.getInstance(ParseKeyFromJson.class);
}
public void test() {
Key key = new Key(true, ImmutableSet.<Long> of(1l),
"AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+...", "DEFAULT", new Date(1260428507510l));
Key compare = handler.apply(new HttpResponse(ParseKeyFromJsonTest.class
.getResourceAsStream("/key.json")));
assertEquals(compare, key);
}
}

View File

@ -0,0 +1,69 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import java.io.IOException;
import java.util.Date;
import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.domain.Key;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseKeysFromJson}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "ibmdev.ParseKeysFromJsonTest")
public class ParseKeysFromJsonTest {
private ParseKeysFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
handler = injector.getInstance(ParseKeysFromJson.class);
}
public void test() {
Key key1 = new Key(true, ImmutableSet.<Long> of(1l),
"AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+...", "DEFAULT", new Date(1260428507510l));
Key key2 = new Key(false, ImmutableSet.<Long> of(), "AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+",
"BEAR", new Date(1260428507511l));
Set<? extends Key> compare = handler.apply(new HttpResponse(ParseKeysFromJsonTest.class
.getResourceAsStream("/keys.json")));
assert (compare.contains(key1));
assert (compare.contains(key2));
}
}

View File

@ -0,0 +1,68 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Date;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.domain.Volume;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseVolumeFromJson}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "ibmdev.ParseVolumeFromJsonTest")
public class ParseVolumeFromJsonTest {
private ParseVolumeFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
handler = injector.getInstance(ParseVolumeFromJson.class);
}
public void test() {
Volume volume = new Volume(2l, 5, 50, "aadelucc@us.ibm.com", new Date(1260469075119l), 1,
ImmutableSet.<String> of(), "ext3", "New Storage", 67l);
Volume compare = handler.apply(new HttpResponse(ParseVolumeFromJsonTest.class
.getResourceAsStream("/volume.json")));
assertEquals(compare, volume);
}
}

View File

@ -0,0 +1,70 @@
/**
*
* 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.
* ====================================================================
*/
package org.jclouds.ibmdev.functions;
import java.io.IOException;
import java.util.Date;
import java.util.Set;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.ibmdev.domain.Volume;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseVolumesFromJson}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "ibmdev.ParseVolumesFromJsonTest")
public class ParseVolumesFromJsonTest {
private ParseVolumesFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(LongDateAdapter.class);
super.configure();
}
});
handler = injector.getInstance(ParseVolumesFromJson.class);
}
public void test() {
Volume volume1 = new Volume(2l, 5, 50, "aadelucc@us.ibm.com", new Date(1260469075119l), 1,
ImmutableSet.<String> of(), "ext3", "New Storage", 67l);
Volume volume2 = new Volume(null, 6, 51, "aadelucc@us.ibm.com", new Date(1260469075120l), 2,
ImmutableSet.<String> of("abrad"), "ext3", "New Storage1", 68l);
Set<? extends Volume> compare = handler.apply(new HttpResponse(ParseVolumesFromJsonTest.class
.getResourceAsStream("/volumes.json")));
assert (compare.contains(volume1));
assert (compare.contains(volume2));
}
}

View File

@ -0,0 +1,60 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Map;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.ibmdev.domain.Location;
import org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
* Tests behavior of {@code LocationHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ibmdev.LocationHandlerTest")
public class LocationHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/location.xml");
Location result = factory.create(injector.getInstance(LocationHandler.class)).parse(is);
Map<String, Map<String, String>> capabilites = ImmutableMap.<String, Map<String, String>> of(
IBMDeveloperCloudConstants.CAPABILITY_CAPACITY, ImmutableMap.<String, String> of(
"SMALL", "50", "MEDIUM", "100", "LARGE", "200"),
IBMDeveloperCloudConstants.CAPABILITY_FORMAT, ImmutableMap.<String, String> of(
"EXT3", "ext3"), IBMDeveloperCloudConstants.CAPABILITY_I386,
ImmutableMap.<String, String> of("SMALL", "SMALL", "MEDIUM", "MEDIUM", "LARGE",
"LARGE"), IBMDeveloperCloudConstants.CAPABILITY_x86_64, ImmutableMap
.<String, String> of(
));
Location expects = new Location(1, "US North East: Poughkeepsie, NY", null, "POK",
capabilites);
assertEquals(result, expects);
}
}

View File

@ -0,0 +1,102 @@
/**
*
* Copyright (C) 2009 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.
* ====================================================================
*/
package org.jclouds.ibmdev.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.util.Map;
import java.util.Set;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.ibmdev.domain.Location;
import org.jclouds.ibmdev.reference.IBMDeveloperCloudConstants;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* Tests behavior of {@code LocationsHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "ibmdev.LocationsHandlerTest")
public class LocationsHandlerTest extends BaseHandlerTest {
public void testLocation() {
InputStream is = getClass().getResourceAsStream("/location.xml");
Set<? extends Location> result = factory.create(injector.getInstance(LocationsHandler.class))
.parse(is);
Map<String, Map<String, String>> capabilites = ImmutableMap.<String, Map<String, String>> of(
IBMDeveloperCloudConstants.CAPABILITY_CAPACITY, ImmutableMap.<String, String> of(
"SMALL", "50", "MEDIUM", "100", "LARGE", "200"),
IBMDeveloperCloudConstants.CAPABILITY_FORMAT, ImmutableMap.<String, String> of(
"EXT3", "ext3"), IBMDeveloperCloudConstants.CAPABILITY_I386,
ImmutableMap.<String, String> of("SMALL", "SMALL", "MEDIUM", "MEDIUM", "LARGE",
"LARGE"), IBMDeveloperCloudConstants.CAPABILITY_x86_64, ImmutableMap
.<String, String> of(
));
Location location1 = new Location(1, "US North East: Poughkeepsie, NY", null, "POK",
capabilites);
assertEquals(result, ImmutableSet.of(location1));
}
@Test(enabled = false)
public void testAllLocations() {
InputStream is = getClass().getResourceAsStream("/locations.xml");
Set<? extends Location> result = factory.create(injector.getInstance(LocationsHandler.class))
.parse(is);
Map<String, Map<String, String>> capabilites = ImmutableMap.<String, Map<String, String>> of(
IBMDeveloperCloudConstants.CAPABILITY_CAPACITY, ImmutableMap.<String, String> of(
"SMALL", "50", "MEDIUM", "100", "LARGE", "200"),
IBMDeveloperCloudConstants.CAPABILITY_FORMAT, ImmutableMap.<String, String> of(
"EXT3", "ext3"), IBMDeveloperCloudConstants.CAPABILITY_I386,
ImmutableMap.<String, String> of("SMALL", "SMALL", "MEDIUM", "MEDIUM", "LARGE",
"LARGE"), IBMDeveloperCloudConstants.CAPABILITY_x86_64, ImmutableMap
.<String, String> of(
));
Location location1 = new Location(1, "US North East: Poughkeepsie, NY", null, "POK",
capabilites);
capabilites = ImmutableMap.<String, Map<String, String>> of(
IBMDeveloperCloudConstants.CAPABILITY_CAPACITY, ImmutableMap.<String, String> of(
"SMALL", "50", "MEDIUM", "100", "LARGE", "200"),
IBMDeveloperCloudConstants.CAPABILITY_FORMAT, ImmutableMap.<String, String> of(
"EXT3", "ext3"), IBMDeveloperCloudConstants.CAPABILITY_I386,
ImmutableMap.<String, String> of("SMALL", "SMALL", "MEDIUM", "MEDIUM", "LARGE",
"LARGE"), IBMDeveloperCloudConstants.CAPABILITY_x86_64, ImmutableMap
.<String, String> of(
));
Location location2 = new Location(1, "US North East: Poughkeepsie, NY", null, "POK",
capabilites);
assertEquals(result, ImmutableSet.of(location1, location2));
}
}

View File

@ -0,0 +1,7 @@
{
"state":2,
"location":"1",
"ip": "129.33.196.243",
"id":"1217",
"instanceId":"1"
}

View File

@ -0,0 +1,16 @@
{"addresses": [
{
"state":2,
"location":"1",
"ip": "129.33.196.243",
"id":"1217",
"instanceId":"1"
},
{
"state":3,
"location":"2",
"ip": "129.33.196.244",
"id":"1218"
}
]
}

View File

@ -0,0 +1,7 @@
{
"default":true,
"instanceIds":["1"],
"keyMaterial":"AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+...",
"keyName":"DEFAULT",
"lastModifiedTime":1260428507510
}

View File

@ -0,0 +1,18 @@
{
"keys":[
{
"default":true,
"instanceIds":["1"],
"keyMaterial":"AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+...",
"keyName":"DEFAULT",
"lastModifiedTime":1260428507510
},
{
"default":false,
"instanceIds":[],
"keyMaterial":"AAAB3NzaC1yc2EAAAADAQABAAABAQCqBw7a+",
"keyName":"BEAR",
"lastModifiedTime":1260428507511
}
]
}

View File

@ -0,0 +1,39 @@
<ns2:DescribeLocationResponse
xmlns:ns2="http://www.ibm.com/xmlns/b2b/cloud/api/2009-04-03">
<Location>
<ID>1</ID>
<Name>US North East: Poughkeepsie, NY</Name>
<Description></Description>
<Location>POK</Location>
<Capabilities>
<Capability id="oss.storage.capacity">
<Entry key="SMALL">
<Value>50</Value>
</Entry>
<Entry key="MEDIUM">
<Value>100</Value>
</Entry>
<Entry key="LARGE">
<Value>200</Value>
</Entry>
</Capability>
<Capability id="oss.storage.format">
<Entry key="EXT3">
<Value>ext3</Value>
</Entry>
</Capability>
<Capability id="oss.instance.spec.i386">
<Entry key="SMALL">
<Value>SMALL</Value>
</Entry>
<Entry key="MEDIUM">
<Value>MEDIUM</Value>
</Entry>
<Entry key="LARGE">
<Value>LARGE</Value>
</Entry>
</Capability>
<Capability id="oss.instance.spec.x86_64" />
</Capabilities>
</Location>
</ns2:DescribeLocationResponse>

View File

@ -0,0 +1,12 @@
{
"instanceId":"2",
"state":5,
"size":"50",
"owner":"aadelucc@us.ibm.com",
"createdTime":1260469075119,
"location":"1",
"productCodes":[],
"format":"ext3",
"name":"New Storage",
"id":"67"
}

View File

@ -0,0 +1,26 @@
{"volumes": [
{
"instanceId":"2",
"state":5,
"size":"50",
"owner":"aadelucc@us.ibm.com",
"createdTime":1260469075119,
"location":"1",
"productCodes":[],
"format":"ext3",
"name":"New Storage",
"id":"67"
},
{
"state":6,
"size":"51",
"owner":"aadelucc@us.ibm.com",
"createdTime":1260469075120,
"location":"2",
"productCodes":["abrad"],
"format":"ext3",
"name":"New Storage1",
"id":"68"
}
]}