Removed sharedIP. Renamed id to ref in tests.

This commit is contained in:
vicglarson 2011-04-14 17:32:15 +04:00 committed by Dmitri Babaev
parent 8d2d3e8088
commit 39c642964a
13 changed files with 799 additions and 978 deletions

View File

@ -18,49 +18,22 @@
*/ */
package org.jclouds.openstack.nova; package org.jclouds.openstack.nova;
import java.net.URI; import com.google.common.util.concurrent.ListenableFuture;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.ExecutionException;
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.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.openstack.nova.domain.Addresses;
import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.RebootType;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.options.CreateServerOptions;
import org.jclouds.openstack.nova.options.CreateSharedIpGroupOptions;
import org.jclouds.openstack.nova.options.ListOptions;
import org.jclouds.openstack.nova.options.RebuildServerOptions;
import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.openstack.filters.AddTimestampQuery; import org.jclouds.openstack.filters.AddTimestampQuery;
import org.jclouds.openstack.filters.AuthenticateRequest; import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.rest.annotations.BinderParam; import org.jclouds.openstack.nova.domain.*;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.openstack.nova.options.CreateServerOptions;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.openstack.nova.options.ListOptions;
import org.jclouds.rest.annotations.MapBinder; import org.jclouds.openstack.nova.options.RebuildServerOptions;
import org.jclouds.rest.annotations.Payload; import org.jclouds.rest.annotations.*;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture; import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Set;
import java.util.concurrent.ExecutionException;
/** /**
* Provides asynchronous access to OpenStack Nova via their REST API. * Provides asynchronous access to OpenStack Nova via their REST API.
@ -69,12 +42,12 @@ import com.google.common.util.concurrent.ListenableFuture;
* during processing will be wrapped in an {@link ExecutionException} as documented in * during processing will be wrapped in an {@link ExecutionException} as documented in
* {@link ListenableFuture#get()}. * {@link ListenableFuture#get()}.
* *
* @author Adrian Cole
* @see NovaClient * @see NovaClient
* @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" /> * @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" />
* @author Adrian Cole
*/ */
@SkipEncoding({ '/', '=' }) @SkipEncoding({'/', '='})
@RequestFilters({ AuthenticateRequest.class, AddTimestampQuery.class }) @RequestFilters({AuthenticateRequest.class, AddTimestampQuery.class})
@Endpoint(ServerManagement.class) @Endpoint(ServerManagement.class)
public interface NovaAsyncClient { public interface NovaAsyncClient {
@ -254,7 +227,7 @@ public interface NovaAsyncClient {
@PayloadParam("serverId") int serverId); @PayloadParam("serverId") int serverId);
/** /**
* @see NovaClient#listAddresses * @see NovaClient#getAddresses(int)
*/ */
@GET @GET
@Unwrap @Unwrap
@ -264,7 +237,7 @@ public interface NovaAsyncClient {
ListenableFuture<Addresses> getAddresses(@PathParam("id") int serverId); ListenableFuture<Addresses> getAddresses(@PathParam("id") int serverId);
/** /**
* @see NovaClient#listPublicAddresses * @see NovaClient#listPublicAddresses(int)
*/ */
@GET @GET
@Unwrap @Unwrap

View File

@ -18,27 +18,18 @@
*/ */
package org.jclouds.openstack.nova; package org.jclouds.openstack.nova;
import java.net.URI;
import java.net.URL;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.PathParam;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.openstack.nova.domain.Addresses; import org.jclouds.openstack.nova.domain.*;
import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.RebootType;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.options.CreateServerOptions; import org.jclouds.openstack.nova.options.CreateServerOptions;
import org.jclouds.openstack.nova.options.CreateSharedIpGroupOptions;
import org.jclouds.openstack.nova.options.ListOptions; import org.jclouds.openstack.nova.options.ListOptions;
import org.jclouds.openstack.nova.options.RebuildServerOptions; import org.jclouds.openstack.nova.options.RebuildServerOptions;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import javax.ws.rs.PathParam;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/** /**
* Provides access to OpenStack Nova via their REST API. * Provides access to OpenStack Nova via their REST API.
@ -47,17 +38,16 @@ import java.util.concurrent.Future;
* during processing will be wrapped in an {@link ExecutionException} as documented in * during processing will be wrapped in an {@link ExecutionException} as documented in
* {@link Future#get()}. * {@link Future#get()}.
* *
* @author Adrian Cole
* @see NovaAsyncClient * @see NovaAsyncClient
* @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" /> * @see <a href="http://wiki.openstack.org/OpenStackAPI_1-1" />
* @author Adrian Cole
*/ */
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface NovaClient { public interface NovaClient {
/** /**
*
* List all servers (IDs and names only) * List all servers (IDs and names only)
* * <p/>
* This operation provides a list of servers associated with your identity. Servers that have been * This operation provides a list of servers associated with your identity. Servers that have been
* deleted are not included in this list. * deleted are not included in this list.
* <p/> * <p/>
@ -67,7 +57,6 @@ public interface NovaClient {
Set<Server> listServers(ListOptions... options); Set<Server> listServers(ListOptions... options);
/** /**
*
* This operation returns details of the specified server. * This operation returns details of the specified server.
* *
* @return null, if the server is not found * @return null, if the server is not found
@ -76,7 +65,6 @@ public interface NovaClient {
Server getServer(@PathParam("id") int id); Server getServer(@PathParam("id") int id);
/** /**
*
* This operation deletes a cloud server instance from the system. * This operation deletes a cloud server instance from the system.
* <p/> * <p/>
* Note: When a server is deleted, all images created from that server are also removed. * Note: When a server is deleted, all images created from that server are also removed.
@ -95,8 +83,7 @@ public interface NovaClient {
* <p/> * <p/>
* ACTIVE - HARD_REBOOT - ACTIVE (hard reboot) * ACTIVE - HARD_REBOOT - ACTIVE (hard reboot)
* *
* @param rebootType * @param rebootType With a soft reboot, the operating system is signaled to restart, which allows for a
* With a soft reboot, the operating system is signaled to restart, which allows for a
* graceful shutdown of all processes. A hard reboot is the equivalent of power cycling * graceful shutdown of all processes. A hard reboot is the equivalent of power cycling
* the server. * the server.
*/ */
@ -151,8 +138,7 @@ public interface NovaClient {
* generated for you and returned in the response object. For security reasons, it will not be * generated for you and returned in the response object. For security reasons, it will not be
* returned in subsequent GET calls against a given server ID. * returned in subsequent GET calls against a given server ID.
* *
* @param options * @param options - used to specify extra files, metadata, or ip parameters during server creation.
* - used to specify extra files, metadata, or ip parameters during server creation.
*/ */
Server createServer(String name, String imageRef, String flavorRef, CreateServerOptions... options); Server createServer(String name, String imageRef, String flavorRef, CreateServerOptions... options);
@ -167,8 +153,7 @@ public interface NovaClient {
* ACTIVE - REBUILD - ERROR (on error) * ACTIVE - REBUILD - ERROR (on error)
* <p/> * <p/>
* *
* @param options * @param options - imageId is an optional argument. If it is not specified, the server is rebuilt
* - imageId is an optional argument. If it is not specified, the server is rebuilt
* with the original imageId. * with the original imageId.
*/ */
void rebuildServer(int id, RebuildServerOptions... options); void rebuildServer(int id, RebuildServerOptions... options);
@ -177,7 +162,6 @@ public interface NovaClient {
* This operation allows you to change the administrative password. * This operation allows you to change the administrative password.
* <p/> * <p/>
* Status Transition: ACTIVE - PASSWORD - ACTIVE * Status Transition: ACTIVE - PASSWORD - ACTIVE
*
*/ */
void changeAdminPass(int id, String adminPass); void changeAdminPass(int id, String adminPass);
@ -186,21 +170,18 @@ public interface NovaClient {
* the server in the OpenStack Nova system and does not change the server host name itself. * the server in the OpenStack Nova system and does not change the server host name itself.
* <p/> * <p/>
* Status Transition: ACTIVE - PASSWORD - ACTIVE * Status Transition: ACTIVE - PASSWORD - ACTIVE
*
*/ */
void renameServer(int id, String newName); void renameServer(int id, String newName);
/** /**
*
* List available flavors (IDs and names only) * List available flavors (IDs and names only)
* * <p/>
* in order to retrieve all details, pass the option {@link ListOptions#withDetails() * in order to retrieve all details, pass the option {@link ListOptions#withDetails()
* withDetails()} * withDetails()}
*/ */
Set<Flavor> listFlavors(ListOptions... options); Set<Flavor> listFlavors(ListOptions... options);
/** /**
*
* This operation returns details of the specified flavor. * This operation returns details of the specified flavor.
* *
* @return null, if the flavor is not found * @return null, if the flavor is not found
@ -209,26 +190,22 @@ public interface NovaClient {
Flavor getFlavor(int id); Flavor getFlavor(int id);
/** /**
*
* List available images (IDs and names only) * List available images (IDs and names only)
* * <p/>
* in order to retrieve all details, pass the option {@link ListOptions#withDetails() * in order to retrieve all details, pass the option {@link ListOptions#withDetails()
* withDetails()} * withDetails()}
*/ */
Set<Image> listImages(ListOptions... options); Set<Image> listImages(ListOptions... options);
/** /**
*
* This operation returns details of the specified image. * This operation returns details of the specified image.
* *
* @return null, if the image is not found * @return null, if the image is not found
*
* @see Image * @see Image
*/ */
Image getImage(int id); Image getImage(int id);
/** /**
*
* This operation deletes an image from the system. * This operation deletes an image from the system.
* <p/> * <p/>
* Note: Images are immediately removed. Currently, there are no state transitions to track the * Note: Images are immediately removed. Currently, there are no state transitions to track the
@ -240,12 +217,11 @@ public interface NovaClient {
boolean deleteImage(int id); boolean deleteImage(int id);
/** /**
*
* This operation creates a new image for the given server ID. Once complete, a new image will be * This operation creates a new image for the given server ID. Once complete, a new image will be
* available that can be used to rebuild or create servers. Specifying the same image name as an * available that can be used to rebuild or create servers. Specifying the same image name as an
* existing custom image replaces the image. The image creation status can be queried by * existing custom image replaces the image. The image creation status can be queried by
* performing a GET on /images/id and examining the status and progress attributes. * performing a GET on /images/id and examining the status and progress attributes.
* * <p/>
* Status Transition: * Status Transition:
* <p/> * <p/>
* QUEUED - PREPARING - SAVING - ACTIVE * QUEUED - PREPARING - SAVING - ACTIVE
@ -255,29 +231,28 @@ public interface NovaClient {
* Note: At present, image creation is an asynchronous operation, so coordinating the creation * Note: At present, image creation is an asynchronous operation, so coordinating the creation
* with data quiescence, etc. is currently not possible. * with data quiescence, etc. is currently not possible.
* *
* @throws ResourceNotFoundException * @throws ResourceNotFoundException if the server is not found
* if the server is not found
* @see Image * @see Image
*/ */
Image createImageFromServer(String imageName, int serverId); Image createImageFromServer(String imageName, int serverId);
/** /**
* List all server addresses * List all server addresses
* * <p/>
* returns empty set if the server doesn't exist * returns empty set if the server doesn't exist
*/ */
Addresses getAddresses(int serverId); Addresses getAddresses(int serverId);
/** /**
* List all public server addresses * List all public server addresses
* * <p/>
* returns empty set if the server doesn't exist * returns empty set if the server doesn't exist
*/ */
Set<String> listPublicAddresses(int serverId); Set<String> listPublicAddresses(int serverId);
/** /**
* List all private server addresses * List all private server addresses
* * <p/>
* returns empty set if the server doesn't exist * returns empty set if the server doesn't exist
*/ */
Set<String> listPrivateAddresses(int serverId); Set<String> listPrivateAddresses(int serverId);

View File

@ -18,28 +18,22 @@
*/ */
package org.jclouds.openstack.nova.options; package org.jclouds.openstack.nova.options;
import static com.google.common.base.Preconditions.checkArgument; import com.google.common.collect.ImmutableMap;
import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.Lists;
import static com.google.common.base.Preconditions.checkState; import com.google.common.collect.Maps;
import java.net.URI;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.jclouds.encryption.internal.Base64; import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.nova.domain.Addresses; import org.jclouds.openstack.nova.domain.Addresses;
import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap; import java.util.List;
import com.google.common.collect.Lists; import java.util.Map;
import com.google.common.collect.Maps; import java.util.Map.Entry;
import static com.google.common.base.Preconditions.*;
/** /**
*
* @author Adrian Cole * @author Adrian Cole
*
*/ */
public class CreateServerOptions extends BindToJsonPayload { public class CreateServerOptions extends BindToJsonPayload {
@ -75,7 +69,6 @@ public class CreateServerOptions extends BindToJsonPayload {
final String flavorRef; final String flavorRef;
Map<String, String> metadata; Map<String, String> metadata;
List<File> personality; List<File> personality;
Integer sharedIpGroupId;
Addresses addresses; Addresses addresses;
private ServerRequest(String name, String imageRef, String flavorRef) { private ServerRequest(String name, String imageRef, String flavorRef) {
@ -88,7 +81,6 @@ public class CreateServerOptions extends BindToJsonPayload {
private Map<String, String> metadata = Maps.newHashMap(); private Map<String, String> metadata = Maps.newHashMap();
private List<File> files = Lists.newArrayList(); private List<File> files = Lists.newArrayList();
private Integer sharedIpGroupId;
private String publicIp; private String publicIp;
@Override @Override
@ -101,8 +93,6 @@ public class CreateServerOptions extends BindToJsonPayload {
server.metadata = metadata; server.metadata = metadata;
if (files.size() > 0) if (files.size() > 0)
server.personality = files; server.personality = files;
if (sharedIpGroupId != null)
server.sharedIpGroupId = this.sharedIpGroupId;
if (publicIp != null) { if (publicIp != null) {
server.addresses = new Addresses(); server.addresses = new Addresses();
server.addresses.getPublicAddresses().add(publicIp); server.addresses.getPublicAddresses().add(publicIp);
@ -132,29 +122,6 @@ public class CreateServerOptions extends BindToJsonPayload {
return this; return this;
} }
/**
* A shared IP group is a collection of servers that can share IPs with other members of the
* group. Any server in a group can share one or more public IPs with any other server in the
* group. With the exception of the first server in a shared IP group, servers must be launched
* into shared IP groups. A server may only be a member of one shared IP group.
*
* <p/>
* Servers in the same shared IP group can share public IPs for various high availability and
* load balancing configurations. To launch an HA server, include the optional sharedIpGroupId
* element and the server will be launched into that shared IP group.
* <p />
*
* Note: sharedIpGroupId is an optional parameter and for optimal performance, should ONLY be
* specified when intending to share IPs between servers.
*
* @see #withSharedIp(String)
*/
public CreateServerOptions withSharedIpGroup(int id) {
checkArgument(id > 0, "id must be positive or zero. was: " + id);
this.sharedIpGroupId = id;
return this;
}
/** /**
* Custom cloud server metadata can also be supplied at launch time. This metadata is stored in * Custom cloud server metadata can also be supplied at launch time. This metadata is stored in
* the API system where it is retrievable by querying the API for server status. The maximum size * the API system where it is retrievable by querying the API for server status. The maximum size
@ -181,46 +148,17 @@ public class CreateServerOptions extends BindToJsonPayload {
return this; return this;
} }
/**
* Public IP addresses can be shared across multiple servers for use in various high availability
* scenarios. When an IP address is shared to another server, the cloud network restrictions are
* modified to allow each server to listen to and respond on that IP address (you may optionally
* specify that the target server network configuration be modified). Shared IP addresses can be
* used with many standard heartbeat facilities (e.g. keepalived) that monitor for failure and
* manage IP failover.
*
* <p/>
* If you intend to use a shared IP on the server being created and have no need for a separate
* public IP address, you may launch the server into a shared IP group and specify an IP address
* from that shared IP group to be used as its public IP. You can accomplish this by specifying
* the public shared IP address in your request. This is optional and is only valid if
* sharedIpGroupId is also supplied.
*/
public CreateServerOptions withSharedIp(String publicIp) {
checkState(sharedIpGroupId != null,
"sharedIp is invalid unless a shared ip group is specified.");
this.publicIp = checkNotNull(publicIp, "ip");
return this;
}
public static class Builder { public static class Builder {
/** /**
* @see CreateServerOptions#withFile(String,byte []) * @see CreateServerOptions#withFile(String, byte[])
*/ */
public static CreateServerOptions withFile(String path, byte[] contents) { public static CreateServerOptions withFile(String path, byte[] contents) {
CreateServerOptions options = new CreateServerOptions(); CreateServerOptions options = new CreateServerOptions();
return options.withFile(path, contents); return options.withFile(path, contents);
} }
/**
* @see CreateServerOptions#withSharedIpGroup(int)
*/
public static CreateServerOptions withSharedIpGroup(int id) {
CreateServerOptions options = new CreateServerOptions();
return options.withSharedIpGroup(id);
}
/** /**
* @see CreateServerOptions#withMetadata(Map<String, String>) * @see CreateServerOptions#withMetadata(Map<String, String>)
*/ */
@ -229,13 +167,5 @@ public class CreateServerOptions extends BindToJsonPayload {
return options.withMetadata(metadata); return options.withMetadata(metadata);
} }
/**
* @see CreateServerOptions#withSharedIp(String)
*/
public static CreateServerOptions withSharedIp(String publicIp) {
CreateServerOptions options = new CreateServerOptions();
return options.withSharedIp(publicIp);
}
} }
} }

View File

@ -1,87 +0,0 @@
/**
*
* Copyright (C) 2011 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.openstack.nova.options;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.annotation.Nullable;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
/**
*
*
* @author Adrian Cole
*
*/
public class CreateSharedIpGroupOptions extends BindToJsonPayload {
Integer serverId;
@SuppressWarnings("unused")
private static class SharedIpGroupRequest {
final String name;
Integer server;
private SharedIpGroupRequest(String name, @Nullable Integer serverId) {
this.name = name;
this.server = serverId;
}
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
SharedIpGroupRequest createRequest = new SharedIpGroupRequest(checkNotNull(postParams
.get("name")), serverId);
return super.bindToRequest(request, ImmutableMap.of("sharedIpGroup", createRequest));
}
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
throw new IllegalStateException("CreateSharedIpGroup is a POST operation");
}
/**
*
* @param id
* of the server to include with this request.
*/
public CreateSharedIpGroupOptions withServer(int id) {
checkArgument(id > 0, "server id must be a positive number");
this.serverId = id;
return this;
}
public static class Builder {
/**
* @see CreateSharedIpGroupOptions#withServer(int)
*/
public static CreateSharedIpGroupOptions withServer(int id) {
CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
return options.withServer(id);
}
}
}

View File

@ -24,7 +24,6 @@ import com.google.inject.TypeLiteral;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnFalseOn404;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.UnwrapOnlyJsonValue; import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse; import org.jclouds.openstack.OpenStackAuthAsyncClient.AuthenticationResponse;
@ -34,14 +33,15 @@ import org.jclouds.openstack.filters.AuthenticateRequest;
import org.jclouds.openstack.nova.config.NovaRestClientModule; import org.jclouds.openstack.nova.config.NovaRestClientModule;
import org.jclouds.openstack.nova.domain.RebootType; import org.jclouds.openstack.nova.domain.RebootType;
import org.jclouds.openstack.nova.options.CreateServerOptions; import org.jclouds.openstack.nova.options.CreateServerOptions;
import org.jclouds.openstack.nova.options.CreateSharedIpGroupOptions;
import org.jclouds.openstack.nova.options.ListOptions; import org.jclouds.openstack.nova.options.ListOptions;
import org.jclouds.openstack.nova.options.RebuildServerOptions; import org.jclouds.openstack.nova.options.RebuildServerOptions;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.*; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -49,14 +49,13 @@ import javax.ws.rs.core.MediaType;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI; import java.net.URI;
import java.net.UnknownHostException;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
import static org.jclouds.Constants.PROPERTY_API_VERSION; import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.*; import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.openstack.nova.options.CreateSharedIpGroupOptions.Builder.withServer; import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withMetadata;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.changesSince; import static org.jclouds.openstack.nova.options.ListOptions.Builder.changesSince;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails; import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
import static org.jclouds.openstack.nova.options.RebuildServerOptions.Builder.withImage; import static org.jclouds.openstack.nova.options.RebuildServerOptions.Builder.withImage;
@ -82,7 +81,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers?format=json HTTP/1.1"); assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n"); assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1}}", assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1}}",
"application/json", false); "application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
@ -104,7 +103,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
assertNonPayloadHeadersEqual(request, "Accept: application/json\n"); assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals( assertPayloadEquals(
request, request,
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}", "{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
"application/json", false); "application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
@ -125,7 +124,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers?format=json HTTP/1.1"); assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/json\n"); assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
assertPayloadEquals(request, assertPayloadEquals(request,
"{\"server\":{\"name\":\"ralphie\",\"imageId\":2,\"flavorId\":1,\"metadata\":{\"foo\":\"bar\"}}}", "{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1,\"metadata\":{\"foo\":\"bar\"}}}",
"application/json", false); "application/json", false);
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class); assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
@ -507,7 +506,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers/3/action?format=json HTTP/1.1"); assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers/3/action?format=json HTTP/1.1");
assertNonPayloadHeadersEqual(request, ""); assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, "{\"rebuild\":{\"imageId\":2}}", MediaType.APPLICATION_JSON, false); assertPayloadEquals(request, "{\"rebuild\":{\"imageRef\":2}}", MediaType.APPLICATION_JSON, false);
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);

View File

@ -51,6 +51,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile; import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails; import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
import static org.testng.Assert.*; import static org.testng.Assert.*;
@ -73,11 +74,20 @@ public class NovaClientLiveTest {
protected String endpoint; protected String endpoint;
protected String apiversion; protected String apiversion;
private void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {
if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}"))
properties.setProperty(propertyName, System.getProperty(propertyName));
}
protected Properties setupProperties() throws IOException {
Properties overrides = new Properties();
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".credential");
overridePropertyFromSystemProperty(overrides, "test.initializer");
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
return overrides;
}
protected void setupCredentials(Properties properties) { protected void setupCredentials(Properties properties) {
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
@ -96,19 +106,6 @@ public class NovaClientLiveTest {
properties.setProperty(provider + ".apiversion", apiversion); properties.setProperty(provider + ".apiversion", apiversion);
} }
protected Properties setupProperties() throws IOException {
Properties overrides = new Properties();
overrides.load(this.getClass().getResourceAsStream("/test.properties"));
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".credential");
overridePropertyFromSystemProperty(overrides, "test.initializer");
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
return overrides;
}
@BeforeGroups(groups = {"live"}) @BeforeGroups(groups = {"live"})
public void setupClient() throws IOException { public void setupClient() throws IOException {
@ -268,7 +265,7 @@ public class NovaClientLiveTest {
@Test(enabled = true) @Test(enabled = true)
public void testCreateServer() throws Exception { public void testCreateServer() throws Exception {
String imageRef = "14362"; String imageRef = "3";
String flavorRef = "1"; String flavorRef = "1";
String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt(); String serverName = serverPrefix + "createserver" + new SecureRandom().nextInt();
Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt", Server server = client.createServer(serverName, imageRef, flavorRef, withFile("/etc/jclouds.txt",

View File

@ -0,0 +1,20 @@
package org.jclouds.openstack.nova;
import java.util.Properties;
/**
* Created by IntelliJ IDEA.
* User: VGalkin
* Date: 4/14/11
* Time: 4:32 PM
* To change this template use File | Settings | File Templates.
*/
public class PropertyHelper {
public static void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {
if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}"))
properties.setProperty(propertyName, System.getProperty(propertyName));
}
}

View File

@ -1,18 +1,16 @@
package org.jclouds.openstack.nova; package org.jclouds.openstack.nova;
import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.RunNodesException; import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
@ -21,7 +19,7 @@ import static org.jclouds.Constants.PROPERTY_ENDPOINT;
public class _NovaClient { public class _NovaClient {
static public void main(String[] args) { static public void main(String[] args) {
//curl -v -H "X-Auth-User:admin" -H "X-Auth-Key: d744752f-20d3-4d75-979f-f62f16033b07" http://172.18.34.40:8774/v1.0/ //curl -v -H "X-Auth-User:admin" -H "X-Auth-Key: d744752f-20d3-4d75-979f-f62f16033b07" http://172.18.34.40:8774/v1.0/
//curl -v -H "X-Auth-Token: c97b10659008d5a9ce91462f8c6a5c2c80439762" http://172.18.34.40:8774/v1.0/images/detail?format=json //curl -v -H "X-Auth-Token: 00cf93fd62df48f9fdc35fa16a7662447e48c513" http://dragon004.hw.griddynamics.net:8774/v1.1/images/detail?format=json
String identity = "admin"; String identity = "admin";
String credential = "d744752f-20d3-4d75-979f-f62f16033b07"; String credential = "d744752f-20d3-4d75-979f-f62f16033b07";
@ -42,7 +40,7 @@ public class _NovaClient {
TemplateOptions options = new TemplateOptions(); TemplateOptions options = new TemplateOptions();
//options.authorizePublicKey(""); //options.authorizePublicKey("");
Template template = cs.templateBuilder().imageId("13").options(options).build(); Template template = cs.templateBuilder().imageId("3").options(options).build();
try { try {
Set<? extends NodeMetadata> metedata = cs.runNodesWithTag("test", 1, template); Set<? extends NodeMetadata> metedata = cs.runNodesWithTag("test", 1, template);
System.out.println(metedata); System.out.println(metedata);

View File

@ -74,6 +74,7 @@ import static org.jclouds.compute.options.TemplateOptions.Builder.overrideCreden
import static org.jclouds.compute.predicates.NodePredicates.*; import static org.jclouds.compute.predicates.NodePredicates.*;
import static org.jclouds.compute.predicates.NodePredicates.all; import static org.jclouds.compute.predicates.NodePredicates.all;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.openstack.nova.PropertyHelper.overridePropertyFromSystemProperty;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
@ -108,11 +109,6 @@ public class NovaComputeServiceLiveTest {
} }
private void overridePropertyFromSystemProperty(final Properties properties, String propertyName) {
if ((System.getProperty(propertyName) != null) && !System.getProperty(propertyName).equals("${" + propertyName + "}"))
properties.setProperty(propertyName, System.getProperty(propertyName));
}
protected void setupCredentials(Properties properties) { protected void setupCredentials(Properties properties) {
identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); identity = checkNotNull(properties.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider credential = checkNotNull(properties.getProperty("test." + provider + ".credential"), "test." + provider
@ -131,13 +127,10 @@ public class NovaComputeServiceLiveTest {
} }
protected Properties setupProperties() { protected Properties setupProperties() throws IOException {
Properties overrides = new Properties(); Properties overrides = new Properties();
try {
overrides.load(this.getClass().getResourceAsStream("/test.properties")); overrides.load(this.getClass().getResourceAsStream("/test.properties"));
} catch (IOException e) {
throw new RuntimeException("Can't load properties");
}
overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint"); overridePropertyFromSystemProperty(overrides, "test." + provider + ".endpoint");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion"); overridePropertyFromSystemProperty(overrides, "test." + provider + ".apiversion");
overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity"); overridePropertyFromSystemProperty(overrides, "test." + provider + ".identity");

View File

@ -0,0 +1,150 @@
/**
*
* 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.openstack.nova.functions;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.io.Payloads;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.domain.Server;
import org.jclouds.openstack.nova.handlers.ParseNovaErrorFromHttpResponse;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
/**
* Tests behavior of {@code ParseServerListFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class ParseFaultFromJsonResponseTest {
Injector i = Guice.createInjector(new GsonModule());
@Test
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_list_servers.json");
UnwrapOnlyJsonValue<List<Server>> parser = i.getInstance(Key
.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Server>>>() {
}));
//List<Server> response = parser.apply(new HttpResponse(413, "Over limit", Payloads.newInputStreamPayload(is)));
new ParseNovaErrorFromHttpResponse().handleError(createHttpCommand(), new HttpResponse(413, "Over limit", Payloads.newInputStreamPayload(is)));
//assertEquals(response, expects);
}
@Test
public void testHandler() {
//InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
//
//
// NovaErrorHandler handler = Guice.createInjector(new GsonModule()).getInstance(GoGridErrorHandler.class);
//
// HttpCommand command = createHttpCommand();
// handler.handleError(command, new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
//
// Exception createdException = command.getException();
//
// assertNotNull(createdException, "There should've been an exception generated");
// String message = createdException.getMessage();
// assertTrue(message.contains("No object found that matches your input criteria."),
// "Didn't find the expected error cause in the exception message");
// assertTrue(message.contains("IllegalArgumentException"),
// "Didn't find the expected error code in the exception message");
//
// // make sure the InputStream is closed
// try {
// is.available();
// throw new TestException("Stream wasn't closed by the GoGridErrorHandler when it should've");
// } catch (IOException e) {
// // this is the excepted output
// }
}
HttpCommand createHttpCommand() {
return new HttpCommand() {
private Exception exception;
@Override
public int incrementRedirectCount() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public int getRedirectCount() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public boolean isReplayable() {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public int incrementFailureCount() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public int getFailureCount() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public HttpRequest getCurrentRequest() {
try {
return new HttpRequest("method", new URI("http://endpoint"));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
@Override
public void setCurrentRequest(HttpRequest request) {
//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void setException(Exception exception) {
this.exception = exception;
}
@Override
public Exception getException() {
return exception;
}
};
}
}

View File

@ -18,22 +18,18 @@
*/ */
package org.jclouds.openstack.nova.options; package org.jclouds.openstack.nova.options;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile; import com.google.common.collect.ImmutableMap;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withSharedIp; import com.google.inject.Guice;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withSharedIpGroup; import com.google.inject.Injector;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.json.config.GsonModule; import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import javax.ws.rs.HttpMethod;
import com.google.inject.Guice; import java.net.URI;
import com.google.inject.Injector;
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
import static org.testng.Assert.assertEquals;
/** /**
* Tests behavior of {@code ParseFlavorFromJsonResponse} * Tests behavior of {@code ParseFlavorFromJsonResponse}
@ -49,13 +45,13 @@ public class CreateServerOptionsTest {
public void testAddPayloadToRequestMapOfStringStringHttpRequest() { public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
CreateServerOptions options = new CreateServerOptions(); CreateServerOptions options = new CreateServerOptions();
HttpRequest request = buildRequest(options); HttpRequest request = buildRequest(options);
assertEquals("{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2}}", request.getPayload().getRawContent()); assertEquals("{\"server\":{\"name\":\"foo\",\"imageRef\":1,\"flavorRef\":2}}", request.getPayload().getRawContent());
} }
private HttpRequest buildRequest(CreateServerOptions options) { private HttpRequest buildRequest(CreateServerOptions options) {
injector.injectMembers(options); injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, ImmutableMap.of("name", "foo", "imageId", "1", "flavorId", "2")); options.bindToRequest(request, ImmutableMap.of("name", "foo", "imageRef", "1", "flavorRef", "2"));
return request; return request;
} }
@ -75,66 +71,13 @@ public class CreateServerOptionsTest {
} }
private void assertFile(HttpRequest request) { private void assertFile(HttpRequest request) {
assertEquals( assertEquals(request.getPayload().getRawContent(),
"{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"personality\":[{\"path\":\"/tmp/rhubarb\",\"contents\":\"Zm9v\"}]}}", "{\"server\":{\"name\":\"foo\",\"imageRef\":1,\"flavorRef\":2,\"personality\":[{\"path\":\"/tmp/rhubarb\",\"contents\":\"Zm9v\"}]}}");
request.getPayload().getRawContent());
}
@Test
public void testWithSharedIpGroup() {
CreateServerOptions options = new CreateServerOptions();
options.withSharedIpGroup(3);
HttpRequest request = buildRequest(options);
assertSharedIpGroup(request);
}
@Test
public void testWithSharedIpGroupStatic() {
CreateServerOptions options = withSharedIpGroup(3);
HttpRequest request = buildRequest(options);
assertSharedIpGroup(request);
}
private void assertSharedIpGroup(HttpRequest request) {
assertEquals("{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"sharedIpGroupId\":3}}", request
.getPayload().getRawContent());
} }
@Test @Test
public void testWithMetadata() { public void testWithMetadata() {
} }
@Test
public void testWithSharedIp() {
CreateServerOptions options = new CreateServerOptions();
options.withSharedIpGroup(3).withSharedIp("127.0.0.1");
HttpRequest request = buildRequest(options);
assertSharedIp(request);
}
@Test
public void testWithSharedIpStatic() {
CreateServerOptions options = withSharedIpGroup(3).withSharedIp("127.0.0.1");
HttpRequest request = buildRequest(options);
assertSharedIp(request);
}
private void assertSharedIp(HttpRequest request) {
assertEquals(
"{\"server\":{\"name\":\"foo\",\"imageId\":1,\"flavorId\":2,\"sharedIpGroupId\":3,\"addresses\":{\"public\":[\"127.0.0.1\"]}}}",
request.getPayload().getRawContent());
}
@Test(expectedExceptions = IllegalStateException.class)
public void testWithSharedIpNoGroup() {
CreateServerOptions options = new CreateServerOptions();
options.withSharedIp("127.0.0.1");
buildRequest(options);
}
@Test(expectedExceptions = IllegalStateException.class)
public void testWithSharedIpNoGroupStatic() {
CreateServerOptions options = withSharedIp("127.0.0.1");
buildRequest(options);
}
} }

View File

@ -1,79 +0,0 @@
/**
*
* Copyright (C) 2011 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.openstack.nova.options;
import static org.jclouds.openstack.nova.options.CreateSharedIpGroupOptions.Builder.withServer;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import javax.ws.rs.HttpMethod;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseFlavorFromJsonResponse}
*
* @author Adrian Cole
*/
@Test(groups = "unit")
public class CreateSharedIpGroupOptionsTest {
Injector injector = Guice.createInjector(new GsonModule());
@Test
public void testAddPayloadToRequestMapOfStringStringHttpRequest() {
CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
HttpRequest request = buildRequest(options);
assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\"}}", request.getPayload().getRawContent());
}
private HttpRequest buildRequest(CreateSharedIpGroupOptions options) {
injector.injectMembers(options);
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"));
options.bindToRequest(request, ImmutableMap.of("name", "foo"));
return request;
}
@Test
public void testWithServer() {
CreateSharedIpGroupOptions options = new CreateSharedIpGroupOptions();
options.withServer(3);
HttpRequest request = buildRequest(options);
assertSharedIpGroup(request);
}
@Test
public void testWithServerStatic() {
CreateSharedIpGroupOptions options = withServer(3);
HttpRequest request = buildRequest(options);
assertSharedIpGroup(request);
}
private void assertSharedIpGroup(HttpRequest request) {
assertEquals("{\"sharedIpGroup\":{\"name\":\"foo\",\"server\":3}}", request.getPayload().getRawContent());
}
}

View File

@ -0,0 +1,9 @@
{
"overLimit" : {
"code" : 413,
"message" : "OverLimit Retry...",
"details" : "Error Details...",
"retryAt" : "2010-08-01T00:00:00Z"
}
}