Updated Branches: refs/heads/master ea532121e -> 3c027b515
Enables retrieving the database instance hostname https://issues.apache.org/jira/browse/JCLOUDS-118 Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/commit/0548cf6e Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/tree/0548cf6e Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/diff/0548cf6e Branch: refs/heads/master Commit: 0548cf6e21d82a57fc64b34d19f95aefdfbea617 Parents: ea53212 Author: zack-shoylev <[email protected]> Authored: Thu Jun 6 21:56:51 2013 -0500 Committer: Matt Stephenson <[email protected]> Committed: Tue Jun 18 15:00:39 2013 -0700 ---------------------------------------------------------------------- .../openstack/reddwarf/v1/domain/Instance.java | 38 ++++++++++++++++---- .../reddwarf/v1/features/InstanceApi.java | 14 +++++--- .../v1/features/InstanceApiExpectTest.java | 34 +----------------- .../v1/features/InstanceApiLiveTest.java | 2 ++ .../src/test/resources/instance_get.json | 1 + .../instance_noname_create_request.json | 8 ----- 6 files changed, 45 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/0548cf6e/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/domain/Instance.java ---------------------------------------------------------------------- diff --git a/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/domain/Instance.java b/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/domain/Instance.java index bf386d7..431a36a 100644 --- a/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/domain/Instance.java +++ b/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/domain/Instance.java @@ -20,6 +20,8 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.beans.ConstructorProperties; import java.util.List; + +import org.jclouds.openstack.reddwarf.v1.features.InstanceApi; import org.jclouds.openstack.reddwarf.v1.internal.Volume; import org.jclouds.openstack.v2_0.domain.Link; import com.google.common.base.Objects; @@ -39,18 +41,20 @@ public class Instance implements Comparable<Instance>{ private final Volume volume; private final Status status; private final List<Link> links; + private final String hostname; @ConstructorProperties({ - "id", "name", "flavor", "volume", "status", "links" + "id", "name", "flavor", "volume", "status", "links", "hostname" }) - protected Instance(String id, String name, Flavor flavor, Volume volume, Status status, List<Link> links) { + protected Instance(String id, String name, Flavor flavor, Volume volume, Status status, List<Link> links, String hostname) { this.id = checkNotNull(id, "id required"); - this.name = name; + this.name = checkNotNull(name, "name required"); this.flavor = checkNotNull(flavor, "flavor required"); this.volume = checkNotNull(volume, "volume required"); checkArgument(volume.getSize() > 0, "Size must be greater than 0"); this.status = checkNotNull(status, "status required"); this.links = checkNotNull(links, "links required"); + this.hostname = hostname; // Hostname is sometimes null. See Instance#getHostname() for details } /** @@ -99,6 +103,14 @@ public class Instance implements Comparable<Instance>{ public List<Link> getLinks() { return this.links; } + + /** + * @return the hostname of this instance. The hostname is null unless this Instance was obtained with {@link InstanceApi#get(String)} + * @see Instance.Builder#hostname(String) + */ + public String getHostname() { + return this.hostname; + } /** * Lists possible Instance status @@ -155,7 +167,7 @@ public class Instance implements Comparable<Instance>{ @Override public int hashCode() { - return Objects.hashCode(id, name, volume.getSize(), flavor, status, links); + return Objects.hashCode(id, name, volume.getSize(), flavor, status, links, hostname); } @Override @@ -168,7 +180,7 @@ public class Instance implements Comparable<Instance>{ protected ToStringHelper string() { return Objects.toStringHelper(this) - .add("id", id).add("name", name).add("flavor", flavor).add("volume size", volume.getSize()).add("links", links); + .add("id", id).add("name", name).add("flavor", flavor).add("volume size", volume.getSize()).add("links", links).add("hostname", hostname); } @Override @@ -191,6 +203,7 @@ public class Instance implements Comparable<Instance>{ protected Flavor flavor; protected Status status; protected ImmutableList<Link> links; + protected String hostname; /** * @param id The id of this instance @@ -251,13 +264,23 @@ public class Instance implements Comparable<Instance>{ this.links = links; return this; } + + /** + * @param name The hostname of this instance + * @return The builder object + * @see Instance#getHostname() + */ + public Builder hostname(String hostname) { + this.hostname = hostname; + return this; + } /** * * @return A new Instance object */ public Instance build() { - return new Instance(id, name, flavor, new Volume(size), status, links); + return new Instance(id, name, flavor, new Volume(size), status, links, hostname); } public Builder fromInstance(Instance in) { @@ -267,7 +290,8 @@ public class Instance implements Comparable<Instance>{ .flavor(in.getFlavor()) .size(in.getSize()) .status(in.getStatus()) - .links(links); + .links(links) + .hostname(hostname); } } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/0548cf6e/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApi.java ---------------------------------------------------------------------- diff --git a/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApi.java b/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApi.java index 17a9990..c2dd1ed 100644 --- a/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApi.java +++ b/openstack-reddwarf/src/main/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApi.java @@ -59,9 +59,14 @@ import com.google.common.collect.FluentIterable; public interface InstanceApi { /** - * Same as {@link #create(String, int, String)} but name is left empty + * Same as {@link #create(String, int, String)} but accept an integer Flavor ID + * + * @param flavor The flavor ID + * @param volumeSize The size in GB of the instance volume + * @param name The name of the instance + * @return The instance created. * - * @see org.jclouds.openstack.reddwarf.v1.domain.Instance#create(String, int) + * @see InstanceApi#create(String, int, String) */ @Named("instance:create") @POST @@ -69,13 +74,14 @@ public interface InstanceApi { @SelectJson("instance") @Consumes(MediaType.APPLICATION_JSON) @MapBinder(BindCreateInstanceToJson.class) - Instance create(@PayloadParam("flavorRef") String flavor, @PayloadParam("size") int volumeSize); + Instance create(@PayloadParam("flavorRef") int flavor, @PayloadParam("size") int volumeSize, @PayloadParam("name") String name); /** * Create a database instance by flavor type and volume size * - * @param flavor The flavor URL or flavor id + * @param flavor The flavor URL or flavor id as string * @param volumeSize The size in GB of the instance volume + * @param name The name of the instance * @return The instance created. */ @Named("instance:create") http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/0548cf6e/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiExpectTest.java ---------------------------------------------------------------------- diff --git a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiExpectTest.java b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiExpectTest.java index 98db6ad..549331a 100644 --- a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiExpectTest.java +++ b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiExpectTest.java @@ -53,23 +53,6 @@ public class InstanceApiExpectTest extends BaseRedDwarfApiExpectTest { assertEquals(instance.getName(), "json_rack_instance"); } - public void testCreateInstanceWithNoName() { - URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances"); - InstanceApi api = requestsSendResponses( - keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, - authenticatedGET().endpoint(endpoint) // bad naming convention, you should not be able to change the method to POST - .method("POST") - .payload(payloadFromResourceWithContentType("/instance_noname_create_request.json", MediaType.APPLICATION_JSON)) - .build(), - HttpResponse.builder().statusCode(200).payload(payloadFromResource("/instance_create.json")).build() // response - ).getInstanceApiForZone("RegionOne"); - - Instance instance = api.create("1", 2); - assertEquals(instance.getSize(),2); - assertEquals(instance.getName(), "json_rack_instance"); - } - @Test(expectedExceptions = ResourceNotFoundException.class) public void testCreateInstanceFail() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances"); @@ -86,22 +69,6 @@ public class InstanceApiExpectTest extends BaseRedDwarfApiExpectTest { api.create("1", 2, "json_rack_instance"); } - @Test(expectedExceptions = ResourceNotFoundException.class) - public void testCreateInstanceWithNoNameFail() { - URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances"); - InstanceApi api = requestsSendResponses( - keystoneAuthWithUsernameAndPasswordAndTenantName, - responseWithKeystoneAccess, - authenticatedGET().endpoint(endpoint) // bad naming convention, you should not be able to change the method to POST - .method("POST") - .payload(payloadFromResourceWithContentType("/instance_noname_create_request.json", MediaType.APPLICATION_JSON)) - .build(), - HttpResponse.builder().statusCode(404).payload(payloadFromResource("/instance_create.json")).build() // response - ).getInstanceApiForZone("RegionOne"); - - api.create("1", 2); - } - public void testDeleteInstance() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances/098653ba-218b-47ce-936a-e0b749101f81"); InstanceApi api = requestsSendResponses( @@ -167,6 +134,7 @@ public class InstanceApiExpectTest extends BaseRedDwarfApiExpectTest { assertEquals(instance.getName(), "json_rack_instance"); assertEquals(instance.getId(), "44b277eb-39be-4921-be31-3d61b43651d7"); assertEquals(instance.getLinks().size(), 2); + assertEquals(instance.getHostname(), "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com"); } public void testGetInstanceFail() { http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/0548cf6e/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiLiveTest.java ---------------------------------------------------------------------- diff --git a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiLiveTest.java b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiLiveTest.java index d763a6d..9d05956 100644 --- a/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiLiveTest.java +++ b/openstack-reddwarf/src/test/java/org/jclouds/openstack/reddwarf/v1/features/InstanceApiLiveTest.java @@ -94,6 +94,8 @@ public class InstanceApiLiveTest extends BaseRedDwarfApiLiveTest { InstanceApi instanceApi = api.getInstanceApiForZone(zone); for (Instance instance : instanceApi.list()) { Instance instanceFromGet = instanceApi.get(instance.getId()); + assertNotNull(instanceFromGet.getHostname()); + assertNull(instance.getHostname()); assertEquals(instanceFromGet.getId(), instance.getId()); assertEquals(instanceFromGet.getName(), instance.getName()); assertEquals(instanceFromGet.getStatus(), instance.getStatus()); http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/0548cf6e/openstack-reddwarf/src/test/resources/instance_get.json ---------------------------------------------------------------------- diff --git a/openstack-reddwarf/src/test/resources/instance_get.json b/openstack-reddwarf/src/test/resources/instance_get.json index f7b59f1..baf8708 100644 --- a/openstack-reddwarf/src/test/resources/instance_get.json +++ b/openstack-reddwarf/src/test/resources/instance_get.json @@ -14,6 +14,7 @@ } ] }, + "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com", "id": "44b277eb-39be-4921-be31-3d61b43651d7", "links": [ { http://git-wip-us.apache.org/repos/asf/incubator-jclouds-labs-openstack/blob/0548cf6e/openstack-reddwarf/src/test/resources/instance_noname_create_request.json ---------------------------------------------------------------------- diff --git a/openstack-reddwarf/src/test/resources/instance_noname_create_request.json b/openstack-reddwarf/src/test/resources/instance_noname_create_request.json deleted file mode 100644 index f248f1d..0000000 --- a/openstack-reddwarf/src/test/resources/instance_noname_create_request.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "instance":{ - "volume":{ - "size":2 - }, - "flavorRef":"1" - } -}
