From 4be5c0520657c9d1b96d7585d6ef002ff9e19496 Mon Sep 17 00:00:00 2001 From: Jason King Date: Mon, 14 Nov 2011 17:38:09 +0000 Subject: [PATCH] Issue 695: Added Row,Group and Layout plus parse them from xml --- .../trmk/enterprisecloud/domain/Group.java | 34 ++++++++ .../trmk/enterprisecloud/domain/Layout.java | 84 +++++++++++++++++++ .../trmk/enterprisecloud/domain/Row.java | 33 ++++++++ .../domain/VirtualMachine.java | 36 ++++++-- .../xml/VirtualMachineJAXBParsingTest.java | 10 +++ 5 files changed, 189 insertions(+), 8 deletions(-) create mode 100644 sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Group.java create mode 100644 sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Layout.java create mode 100644 sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Row.java diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Group.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Group.java new file mode 100644 index 0000000000..5692ac0148 --- /dev/null +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Group.java @@ -0,0 +1,34 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.trmk.enterprisecloud.domain; + +import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Jason King + */ +@XmlRootElement(name = "Group") +public class Group extends BaseNamedResource{ + + public Group() { + //For JAXB + } +} diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Layout.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Layout.java new file mode 100644 index 0000000000..e8c9baeea9 --- /dev/null +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Layout.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.trmk.enterprisecloud.domain; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Layout is a logical aggregation of virtual machines and physical devices defined by the organization. + * Layout is an environment concept but visible from both the environment and the compute pool. + * From the environment, all rows, groups, virtual machines, and physical devices are visible. + * From the compute pool, only a subset is visible. + * To appear in a compute pool layout, virtual machines in the rows and groups must be allocated from the compute pool. + * As physical devices are not allocated from the compute pool, they do not appear on compute pool layouts. + * @author Jason King + */ +@XmlRootElement(name = "Layout") +public class Layout { + @XmlElement(name = "Group") + private Group group; + + @XmlElement(name = "Row") + private Row row; + + public Layout(Group group, Row row) { + this.group = group; + this.row = row; + } + + public Layout() { + //For JAXB + } + + public Group getGroup() { + return group; + } + + public Row getRow() { + return row; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Layout layout = (Layout) o; + + if (group != null ? !group.equals(layout.group) : layout.group != null) + return false; + if (row != null ? !row.equals(layout.row) : layout.row != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = group != null ? group.hashCode() : 0; + result = 31 * result + (row != null ? row.hashCode() : 0); + return result; + } + + public String toString() { + return "[group="+group+", row="+row+"]"; + } + +} diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Row.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Row.java new file mode 100644 index 0000000000..a7d439fc08 --- /dev/null +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/Row.java @@ -0,0 +1,33 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.trmk.enterprisecloud.domain; + +import org.jclouds.trmk.enterprisecloud.domain.internal.BaseNamedResource; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Jason King + */ +@XmlRootElement(name = "Row") +public class Row extends BaseNamedResource{ + public Row() { + //For JAXB + } +} diff --git a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java index e38a98e3a1..1f76551e9b 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java +++ b/sandbox-providers/trmk-enterprisecloud/src/main/java/org/jclouds/trmk/enterprisecloud/domain/VirtualMachine.java @@ -56,9 +56,10 @@ public class VirtualMachine extends BaseNamedResource { private Actions actions; private Tasks tasks; private String description; + private Layout layout; /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getLinks + * @see VirtualMachine#getLinks */ public Builder links(Set links) { this.links = new Links(); @@ -67,7 +68,7 @@ public class VirtualMachine extends BaseNamedResource { } /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getActions + * @see VirtualMachine#getActions */ public Builder actions(Set actions) { this.actions = new Actions(); @@ -76,7 +77,7 @@ public class VirtualMachine extends BaseNamedResource { } /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getTasks + * @see VirtualMachine#getTasks */ public Builder tasks(Set tasks) { this.tasks = new Tasks(); @@ -86,16 +87,24 @@ public class VirtualMachine extends BaseNamedResource { /** - * @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getDescription + * @see VirtualMachine#getDescription */ public Builder description(String description) { this.description = description; return this; } + /** + * @see VirtualMachine#getLayout() + */ + public Builder description(Layout layout) { + this.layout = layout; + return this; + } + @Override public VirtualMachine build() { - return new VirtualMachine(href, type, name, tasks, actions, links, description); + return new VirtualMachine(href, type, name, tasks, actions, links, description, layout); } public Builder fromVirtualMachine(VirtualMachine in) { @@ -169,12 +178,16 @@ public class VirtualMachine extends BaseNamedResource { @XmlElement(name = "Description", required = true) private String description; - public VirtualMachine(URI href, String type, String name, Tasks tasks, Actions actions, Links links, String description) { + @XmlElement(name = "Layout", required = false) + private Layout layout; + + public VirtualMachine(URI href, String type, String name, Tasks tasks, Actions actions, Links links, String description, Layout layout) { super(href, type, name); this.description = checkNotNull(description, "description"); this.links = checkNotNull(links, "links"); this.tasks = checkNotNull(tasks, "tasks"); this.actions = checkNotNull(actions, "actions"); + this.layout = layout; } protected VirtualMachine() { @@ -204,6 +217,10 @@ public class VirtualMachine extends BaseNamedResource { return description; } + public Layout getLayout() { + return layout; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -214,6 +231,8 @@ public class VirtualMachine extends BaseNamedResource { if (!actions.equals(that.actions)) return false; if (!description.equals(that.description)) return false; + if (layout != null ? !layout.equals(that.layout) : that.layout != null) + return false; if (!links.equals(that.links)) return false; if (!tasks.equals(that.tasks)) return false; @@ -227,12 +246,13 @@ public class VirtualMachine extends BaseNamedResource { result = 31 * result + tasks.hashCode(); result = 31 * result + actions.hashCode(); result = 31 * result + description.hashCode(); + result = 31 * result + (layout != null ? layout.hashCode() : 0); return result; } - @Override + @Override public String string() { - return super.string()+", links="+links+", tasks="+tasks+", actions="+actions+", description="+description; + return super.string()+", links="+links+", tasks="+tasks+", actions="+actions+", description="+description+", layout="+layout; } } \ No newline at end of file diff --git a/sandbox-providers/trmk-enterprisecloud/src/test/java/org/jclouds/trmk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java b/sandbox-providers/trmk-enterprisecloud/src/test/java/org/jclouds/trmk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java index 28ffca70e8..b0f6ea9fb6 100644 --- a/sandbox-providers/trmk-enterprisecloud/src/test/java/org/jclouds/trmk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java +++ b/sandbox-providers/trmk-enterprisecloud/src/test/java/org/jclouds/trmk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java @@ -34,6 +34,7 @@ import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.BaseRestClientTest; import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.trmk.enterprisecloud.domain.Layout; import org.jclouds.trmk.enterprisecloud.domain.VirtualMachine; import org.jclouds.trmk.enterprisecloud.features.VirtualMachineAsyncClient; import org.testng.annotations.BeforeClass; @@ -49,6 +50,7 @@ import static org.jclouds.io.Payloads.newInputStreamPayload; import static org.jclouds.rest.RestContextFactory.contextSpec; import static org.jclouds.rest.RestContextFactory.createContextBuilder; import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; /** * Tests behavior of JAXB parsing for VirtualMachines @@ -104,5 +106,13 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest { assertEquals(6,virtualMachine.getLinks().size()); assertEquals(11,virtualMachine.getActions().size()); assertEquals(1,virtualMachine.getTasks().size()); + + assertLayout(virtualMachine.getLayout()); + } + + private void assertLayout(Layout layout) { + assertNotNull(layout); + assertEquals("test row",layout.getRow().getName()); + assertEquals("test group",layout.getGroup().getName()); } }