From dbb7e5fb5d96e587880392fd6178ef4e080a793a Mon Sep 17 00:00:00 2001 From: Matt Stephenson Date: Tue, 27 Dec 2011 17:23:45 -0600 Subject: [PATCH 1/3] Add vcpus to the flavor entity. --- .../jclouds/openstack/nova/domain/Flavor.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java index 2916be9c37..499856b20b 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java @@ -32,7 +32,7 @@ public class Flavor extends Resource { @Override public String toString() { - return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + "]"; + return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]"; } public Flavor(int id, String name) { @@ -44,6 +44,7 @@ public class Flavor extends Resource { private String name; private Integer disk; private Integer ram; + private Integer vcpus; public Integer getDisk() { return disk; @@ -77,6 +78,14 @@ public class Flavor extends Resource { this.ram = value; } + public Integer getVcpus() { + return vcpus; + } + + public void setVcpus(Integer value) { + this.vcpus = value; + } + @Override public int hashCode() { final int prime = 31; @@ -85,6 +94,7 @@ public class Flavor extends Resource { result = prime * result + id; result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((ram == null) ? 0 : ram.hashCode()); + result = prime * result + ((vcpus == null) ? 0 : vcpus.hashCode()); return result; } @@ -114,6 +124,11 @@ public class Flavor extends Resource { return false; } else if (!ram.equals(other.ram)) return false; + if (vcpus == null) { + if (other.vcpus != null) + return false; + } else if (!vcpus.equals(other.vcpus)) + return false; return true; } From 481f7a4b2f23534e699310f2100ef28729ee703d Mon Sep 17 00:00:00 2001 From: Matt Stephenson Date: Wed, 28 Dec 2011 10:45:34 -0600 Subject: [PATCH 2/3] Refactor Flavor class so that it is immutable --- .../jclouds/openstack/nova/domain/Flavor.java | 54 ++++++++----------- .../openstack/nova/domain/Resource.java | 6 ++- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java index 499856b20b..f0491e19c8 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Flavor.java @@ -27,65 +27,49 @@ package org.jclouds.openstack.nova.domain; */ public class Flavor extends Resource { - public Flavor() { + private final int id; + private final String name; + private final Integer disk; + private final Integer ram; + private final Integer vcpus; + + //Required because of how Gson is being used to do wire marshalling with the Server class + private Flavor(){ + id=0; + name=null; + disk=null; + ram=null; + vcpus=null; } - @Override - public String toString() { - return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]"; - } - - public Flavor(int id, String name) { + public Flavor(int id, String name, Integer disk, Integer ram, Integer vcpus) { this.id = id; this.name = name; + this.disk = disk; + this.ram = ram; + this.vcpus = vcpus; } - private int id; - private String name; - private Integer disk; - private Integer ram; - private Integer vcpus; - public Integer getDisk() { return disk; } - public void setDisk(Integer value) { - this.disk = value; - } - public int getId() { return id; } - public void setId(int value) { - this.id = value; - } - public String getName() { return name; } - public void setName(String value) { - this.name = value; - } - public Integer getRam() { return ram; } - public void setRam(Integer value) { - this.ram = value; - } - public Integer getVcpus() { return vcpus; } - public void setVcpus(Integer value) { - this.vcpus = value; - } - @Override public int hashCode() { final int prime = 31; @@ -132,4 +116,8 @@ public class Flavor extends Resource { return true; } + @Override + public String toString() { + return "Flavor [disk=" + disk + ", id=" + id + ", name=" + name + ", ram=" + ram + ", vcpus=" + vcpus +"]"; + } } diff --git a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java index 156730b851..8dea23f058 100644 --- a/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java +++ b/apis/nova/src/main/java/org/jclouds/openstack/nova/domain/Resource.java @@ -67,7 +67,11 @@ public class Resource { }; } - private final ConcurrentSkipListMap orderedSelfReferences = new ConcurrentSkipListMap(); + private final ConcurrentSkipListMap orderedSelfReferences; + + public Resource(){ + orderedSelfReferences = new ConcurrentSkipListMap(); + } private void populateOrderedSelfReferences() { for (Map linkProperties : links) { From f50ef6ecfc9cd73b3616b60255922569bbce3b82 Mon Sep 17 00:00:00 2001 From: Matt Stephenson Date: Wed, 28 Dec 2011 10:46:10 -0600 Subject: [PATCH 3/3] Add tests for Virtual CPU attribute in Flavor json --- .../nova/compute/functions/FlavorToHardwareTest.java | 2 +- .../functions/ParseFlavorFromJsonResponseTest.java | 1 + .../ParseFlavorListFromJsonResponseTest.java | 12 +++++++----- .../src/test/resources/test_get_flavor_details.json | 1 + .../src/test/resources/test_list_flavors_detail.json | 2 ++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/compute/functions/FlavorToHardwareTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/compute/functions/FlavorToHardwareTest.java index c42ad4eece..616487a072 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/compute/functions/FlavorToHardwareTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/compute/functions/FlavorToHardwareTest.java @@ -44,7 +44,7 @@ public class FlavorToHardwareTest { public void test() throws UnknownHostException, URISyntaxException { Hardware flavor = convertFlavor(); Hardware tempFlavor = new HardwareBuilder().ids("1").name("256 MB Server") - .processors(ImmutableList.of(new Processor(1.0, 1.0))) + .processors(ImmutableList.of(new Processor(2.0, 2.0))) .ram(256) .volumes(ImmutableList.of( new VolumeBuilder().type(Volume.Type.LOCAL).size(10.0f).durable(true).bootDevice(true).build())) diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorFromJsonResponseTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorFromJsonResponseTest.java index a6b2c727a7..c1128e31cc 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorFromJsonResponseTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorFromJsonResponseTest.java @@ -55,6 +55,7 @@ public class ParseFlavorFromJsonResponseTest { assertEquals(response.getName(), "256 MB Server"); assertEquals(response.getDisk().intValue(), 10); assertEquals(response.getRam().intValue(), 256); + assertEquals(response.getVcpus().intValue(), 2); } public static Flavor parseFlavor() { diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorListFromJsonResponseTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorListFromJsonResponseTest.java index bc90d310b5..a3edb25bf2 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorListFromJsonResponseTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/functions/ParseFlavorListFromJsonResponseTest.java @@ -50,7 +50,7 @@ public class ParseFlavorListFromJsonResponseTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/test_list_flavors.json"); - List expects = ImmutableList.of(new Flavor(1, "256 MB Server"), new Flavor(2, "512 MB Server")); + List expects = ImmutableList.of(new Flavor(1, "256 MB Server", null, null, null), new Flavor(2, "512 MB Server", null, null, null)); UnwrapOnlyJsonValue> parser = i.getInstance(Key .get(new TypeLiteral>>() { @@ -69,13 +69,15 @@ public class ParseFlavorListFromJsonResponseTest { List response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))); assertEquals(response.get(0).getId(), 1); assertEquals(response.get(0).getName(), "256 MB Server"); - assertEquals(response.get(0).getDisk(), new Integer(10)); - assertEquals(response.get(0).getRam(), new Integer(256)); + assertEquals(response.get(0).getDisk(), Integer.valueOf(10)); + assertEquals(response.get(0).getRam(), Integer.valueOf(256)); + assertEquals(response.get(0).getVcpus(), Integer.valueOf(2)); assertEquals(response.get(1).getId(), 2); assertEquals(response.get(1).getName(), "512 MB Server"); - assertEquals(response.get(1).getDisk(), new Integer(20)); - assertEquals(response.get(1).getRam(), new Integer(512)); + assertEquals(response.get(1).getDisk(), Integer.valueOf(20)); + assertEquals(response.get(1).getRam(), Integer.valueOf(512)); + assertEquals(response.get(1).getVcpus(), Integer.valueOf(5)); } diff --git a/apis/nova/src/test/resources/test_get_flavor_details.json b/apis/nova/src/test/resources/test_get_flavor_details.json index bd3266c04e..ed1b29cf20 100644 --- a/apis/nova/src/test/resources/test_get_flavor_details.json +++ b/apis/nova/src/test/resources/test_get_flavor_details.json @@ -4,6 +4,7 @@ "name" : "256 MB Server", "ram" : 256, "disk" : 10, + "vcpus" : 2, "links": [ { "rel" : "self", diff --git a/apis/nova/src/test/resources/test_list_flavors_detail.json b/apis/nova/src/test/resources/test_list_flavors_detail.json index c8939ee520..867a5960f4 100644 --- a/apis/nova/src/test/resources/test_list_flavors_detail.json +++ b/apis/nova/src/test/resources/test_list_flavors_detail.json @@ -5,6 +5,7 @@ "name" : "256 MB Server", "ram" : 256, "disk" : 10, + "vcpus" : 2, "links": [ { "rel" : "self", @@ -27,6 +28,7 @@ "name" : "512 MB Server", "ram" : 512, "disk" : 20, + "vcpus" : 5, "links": [ { "rel" : "self",