Issue 695: Added Row,Group and Layout plus parse them from xml

This commit is contained in:
Jason King 2011-11-14 17:38:09 +00:00
parent d33893d2c5
commit 4be5c05206
5 changed files with 189 additions and 8 deletions

View File

@ -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<Group>{
public Group() {
//For JAXB
}
}

View File

@ -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+"]";
}
}

View File

@ -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<Row>{
public Row() {
//For JAXB
}
}

View File

@ -56,9 +56,10 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
private Actions actions; private Actions actions;
private Tasks tasks; private Tasks tasks;
private String description; private String description;
private Layout layout;
/** /**
* @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getLinks * @see VirtualMachine#getLinks
*/ */
public Builder links(Set<Link> links) { public Builder links(Set<Link> links) {
this.links = new Links(); this.links = new Links();
@ -67,7 +68,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
} }
/** /**
* @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getActions * @see VirtualMachine#getActions
*/ */
public Builder actions(Set<Action> actions) { public Builder actions(Set<Action> actions) {
this.actions = new Actions(); this.actions = new Actions();
@ -76,7 +77,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
} }
/** /**
* @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getTasks * @see VirtualMachine#getTasks
*/ */
public Builder tasks(Set<Task> tasks) { public Builder tasks(Set<Task> tasks) {
this.tasks = new Tasks(); this.tasks = new Tasks();
@ -86,16 +87,24 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
/** /**
* @see org.jclouds.trmk.enterprisecloud.domain.VirtualMachine#getDescription * @see VirtualMachine#getDescription
*/ */
public Builder description(String description) { public Builder description(String description) {
this.description = description; this.description = description;
return this; return this;
} }
/**
* @see VirtualMachine#getLayout()
*/
public Builder description(Layout layout) {
this.layout = layout;
return this;
}
@Override @Override
public VirtualMachine build() { 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) { public Builder fromVirtualMachine(VirtualMachine in) {
@ -169,12 +178,16 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
@XmlElement(name = "Description", required = true) @XmlElement(name = "Description", required = true)
private String description; 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); super(href, type, name);
this.description = checkNotNull(description, "description"); this.description = checkNotNull(description, "description");
this.links = checkNotNull(links, "links"); this.links = checkNotNull(links, "links");
this.tasks = checkNotNull(tasks, "tasks"); this.tasks = checkNotNull(tasks, "tasks");
this.actions = checkNotNull(actions, "actions"); this.actions = checkNotNull(actions, "actions");
this.layout = layout;
} }
protected VirtualMachine() { protected VirtualMachine() {
@ -204,6 +217,10 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
return description; return description;
} }
public Layout getLayout() {
return layout;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -214,6 +231,8 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
if (!actions.equals(that.actions)) return false; if (!actions.equals(that.actions)) return false;
if (!description.equals(that.description)) 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 (!links.equals(that.links)) return false;
if (!tasks.equals(that.tasks)) return false; if (!tasks.equals(that.tasks)) return false;
@ -227,12 +246,13 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
result = 31 * result + tasks.hashCode(); result = 31 * result + tasks.hashCode();
result = 31 * result + actions.hashCode(); result = 31 * result + actions.hashCode();
result = 31 * result + description.hashCode(); result = 31 * result + description.hashCode();
result = 31 * result + (layout != null ? layout.hashCode() : 0);
return result; return result;
} }
@Override @Override
public String string() { 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;
} }
} }

View File

@ -34,6 +34,7 @@ import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.BaseRestClientTest; import org.jclouds.rest.BaseRestClientTest;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor; 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.domain.VirtualMachine;
import org.jclouds.trmk.enterprisecloud.features.VirtualMachineAsyncClient; import org.jclouds.trmk.enterprisecloud.features.VirtualMachineAsyncClient;
import org.testng.annotations.BeforeClass; 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.contextSpec;
import static org.jclouds.rest.RestContextFactory.createContextBuilder; import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
/** /**
* Tests behavior of JAXB parsing for VirtualMachines * Tests behavior of JAXB parsing for VirtualMachines
@ -104,5 +106,13 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
assertEquals(6,virtualMachine.getLinks().size()); assertEquals(6,virtualMachine.getLinks().size());
assertEquals(11,virtualMachine.getActions().size()); assertEquals(11,virtualMachine.getActions().size());
assertEquals(1,virtualMachine.getTasks().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());
} }
} }