From b81317651d08294dc3429e0d15d852f4f491c70a Mon Sep 17 00:00:00 2001 From: Jason King Date: Wed, 16 Nov 2011 18:11:42 +0000 Subject: [PATCH 1/2] Issue 695: Domain objects for VirtualMachine --- .../domain/HardwareConfiguration.java | 187 ++++++++++++++ .../tmrk/enterprisecloud/domain/Memory.java | 87 +++++++ .../domain/OperatingSystem.java | 114 +++++++++ .../enterprisecloud/domain/ToolsStatus.java | 49 ++++ .../domain/VirtualMachine.java | 233 +++++++++++++++++- .../domain/internal/ResourceCapacity.java | 126 ++++++++++ .../xml/VirtualMachineJAXBParsingTest.java | 31 ++- .../src/test/resources/virtualMachine.xml | 2 +- 8 files changed, 822 insertions(+), 7 deletions(-) create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/HardwareConfiguration.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Memory.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/OperatingSystem.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/ToolsStatus.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/ResourceCapacity.java diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/HardwareConfiguration.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/HardwareConfiguration.java new file mode 100644 index 0000000000..a5f159c3f4 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/HardwareConfiguration.java @@ -0,0 +1,187 @@ +/** + * 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.tmrk.enterprisecloud.domain; + +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.net.URI; +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Jason King + */ +@XmlRootElement(name = "HardwareConfiguration") +public class HardwareConfiguration extends BaseResource { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return new Builder().fromHardwareConfiguration(this); + } + + public static class Builder extends BaseResource.Builder { + + private Actions actions; + private int processorCount; + private Memory memory; + + /** + * @see HardwareConfiguration#getActions + */ + public Builder actions(Set actions) { + this.actions = new Actions(); + for(Action action:actions) this.actions.setAction(action); + return this; + } + + /** + * @see HardwareConfiguration#getProcessorCount + */ + public Builder processorCount(int processorCount) { + this.processorCount = processorCount; + return this; + } + + /** + * @see HardwareConfiguration#getMemory + */ + public Builder memory(Memory memory) { + this.memory = memory; + return this; + } + + @Override + public HardwareConfiguration build() { + return new HardwareConfiguration(actions, processorCount, memory); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(BaseResource in) { + return Builder.class.cast(super.fromResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map attributes) { + return Builder.class.cast(super.fromAttributes(attributes)); + } + + public Builder fromHardwareConfiguration(HardwareConfiguration in) { + return fromResource(in).actions(in.getActions()) + .processorCount(in.getProcessorCount()); + } + } + + @XmlElement(name = "Actions", required = true) + private Actions actions; + + @XmlElement(name = "ProcessorCount", required = true) + private int processorCount; + + @XmlElement(name = "Memory", required = true) + private Memory memory; + + public HardwareConfiguration(@Nullable Actions actions, int processorCount, @Nullable Memory memory) { + this.actions = checkNotNull(actions, "actions"); + this.processorCount = processorCount; + this.memory = memory; + } + + protected HardwareConfiguration() { + //For JAXB + } + + public Set getActions() { + return Collections.unmodifiableSet(actions.getActions()); + } + + public int getProcessorCount() { + return processorCount; + } + + public Memory getMemory() { + return memory; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + HardwareConfiguration that = (HardwareConfiguration) o; + + if (processorCount != that.processorCount) return false; + if (actions != null ? !actions.equals(that.actions) : that.actions != null) + return false; + if (memory != null ? !memory.equals(that.memory) : that.memory != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (actions != null ? actions.hashCode() : 0); + result = 31 * result + processorCount; + result = 31 * result + (memory != null ? memory.hashCode() : 0); + return result; + } + + @Override + public String string() { + return super.string()+", actions="+actions+", processorCount="+processorCount+", memory="+memory; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Memory.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Memory.java new file mode 100644 index 0000000000..bb55d1645a --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Memory.java @@ -0,0 +1,87 @@ +/** + * 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.tmrk.enterprisecloud.domain; + +import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Jason King + */ +@XmlRootElement(name = "Memory") +public class Memory extends ResourceCapacity { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return new Builder().fromMemory(this); + } + + public static class Builder extends ResourceCapacity.Builder { + + @Override + public Memory build() { + return new Memory(value,unit); + } + + public Builder fromMemory(Memory in) { + return fromResource(in); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(ResourceCapacity in) { + return Builder.class.cast(super.fromResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder value(double value) { + return Builder.class.cast(super.value(value)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder unit(String unit) { + return Builder.class.cast(super.unit(unit)); + } + } + + public Memory(double value, String unit) { + super(value, unit); + } + + protected Memory() { + //For JAXB + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/OperatingSystem.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/OperatingSystem.java new file mode 100644 index 0000000000..856bac6f1e --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/OperatingSystem.java @@ -0,0 +1,114 @@ +/** + * 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.tmrk.enterprisecloud.domain; + +import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; + +import java.net.URI; +import java.util.Map; + +/** + * + * @author Jason King + * + */ +public class OperatingSystem extends BaseNamedResource { + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder toBuilder() { + return new Builder().fromNamedResource(this); + } + + public static class Builder extends BaseNamedResource.Builder { + + /** + * {@inheritDoc} + */ + @Override + public OperatingSystem build() { + return new OperatingSystem(href, type, name); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromResource(BaseResource in) { + return Builder.class.cast(super.fromResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromNamedResource(BaseNamedResource in) { + return Builder.class.cast(super.fromNamedResource(in)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder name(String name) { + return Builder.class.cast(super.name(name)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder href(URI href) { + return Builder.class.cast(super.href(href)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder type(String type) { + return Builder.class.cast(super.type(type)); + } + + /** + * {@inheritDoc} + */ + @Override + public Builder fromAttributes(Map in) { + return Builder.class.cast(super.fromAttributes(in)); + } + + } + + public OperatingSystem(URI href, String type, String name) { + super(href, type, name); + } + + protected OperatingSystem() { + //For JAXB + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/ToolsStatus.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/ToolsStatus.java new file mode 100644 index 0000000000..ebeda5ea72 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/ToolsStatus.java @@ -0,0 +1,49 @@ +/** + * 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.tmrk.enterprisecloud.domain; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; + +import static com.google.common.base.CaseFormat.LOWER_CAMEL; +import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; + +/** + * @author Jason King + */ +@XmlEnum +public enum ToolsStatus { + @XmlEnumValue("NotInstalled") + NOT_INSTALLED, + @XmlEnumValue("NotRunning") + NOT_RUNNING, + @XmlEnumValue("OutOfDate") + OUT_OF_DATE, + @XmlEnumValue("Current") + CURRENT; + + public String value() { + return UPPER_UNDERSCORE.to(LOWER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java index 6625415898..c992ffbb6c 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java @@ -18,16 +18,21 @@ */ package org.jclouds.tmrk.enterprisecloud.domain; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource; import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource; import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlRootElement; import java.net.URI; import java.util.Collections; import java.util.Map; import java.util.Set; +import static com.google.common.base.CaseFormat.LOWER_CAMEL; +import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; import static com.google.common.base.Preconditions.checkNotNull; /** @@ -56,7 +61,15 @@ public class VirtualMachine extends BaseNamedResource { private Actions actions; private Tasks tasks; private String description; + private VirtualMachineStatus status; + private Layout layout; + private Boolean poweredOn; + private ToolsStatus toolsStatus; + private VirtualMachineMediaStatus mediaStatus; + private Boolean customizationPending; + private OperatingSystem operatingSystem; + private HardwareConfiguration hardwareConfiguration; /** * @see VirtualMachine#getLinks @@ -102,9 +115,75 @@ public class VirtualMachine extends BaseNamedResource { return this; } + /** + * @see VirtualMachine#getToolsStatus() + */ + public Builder toolStatus(ToolsStatus toolsStatus) { + this.toolsStatus = toolsStatus; + return this; + } + + /** + * @see VirtualMachine#isCustomizationPending() + */ + public Builder customizationPending(Boolean customizationPending) { + this.customizationPending = customizationPending; + return this; + } + + /** + * @see VirtualMachine#getStatus() + */ + public Builder status(VirtualMachineStatus status) { + this.status = status; + return this; + } + + /** + * @see VirtualMachine#getToolsStatus() + */ + public Builder toolsStatus(ToolsStatus toolsStatus) { + this.toolsStatus = toolsStatus; + return this; + } + + /** + * @see VirtualMachine#getMediaStatus() + */ + public Builder mediaStatus(VirtualMachineMediaStatus mediaStatus) { + this.mediaStatus = mediaStatus; + return this; + } + + /** + * @see VirtualMachine#isPoweredOn() + */ + public Builder poweredOn(Boolean poweredOn) { + this.poweredOn = poweredOn; + return this; + } + + /** + * @see VirtualMachine#getOperatingSystem() + */ + public Builder operatingSystem(OperatingSystem operatingSystem) { + this.operatingSystem = operatingSystem; + return this; + } + + /** + * @see VirtualMachine#getHardwareConfiguration() + */ + public Builder hardwareConfiguration(HardwareConfiguration hardwareConfiguration) { + this.hardwareConfiguration = hardwareConfiguration; + return this; + } + @Override public VirtualMachine build() { - return new VirtualMachine(href, type, name, tasks, actions, links, description, layout); + return new VirtualMachine(href, type, name, tasks, actions, links, description, layout, + status, poweredOn, toolsStatus, mediaStatus, customizationPending, operatingSystem, + hardwareConfiguration); } public Builder fromVirtualMachine(VirtualMachine in) { @@ -112,7 +191,14 @@ public class VirtualMachine extends BaseNamedResource { .links(in.getLinks()) .tasks(in.getTasks()) .actions(in.getActions()) - .description(in.getDescription()); + .description(in.getDescription()) + .status(in.getStatus()) + .poweredOn(in.isPoweredOn()) + .toolsStatus(in.getToolsStatus()) + .mediaStatus(in.getMediaStatus()) + .customizationPending(in.isCustomizationPending()) + .operatingSystem(in.getOperatingSystem()) + .hardwareConfiguration(in.getHardwareConfiguration()); } /** @@ -181,13 +267,44 @@ public class VirtualMachine extends BaseNamedResource { @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) { + @XmlElement(name = "Status", required = false) + private VirtualMachineStatus status; + + @XmlElement(name = "PoweredOn", required = false) + private Boolean poweredOn; + + @XmlElement(name = "ToolsStatus", required = false) + private ToolsStatus toolsStatus; + + @XmlElement(name = "MediaStatus", required = false) + private VirtualMachineMediaStatus mediaStatus; + + @XmlElement(name = "CustomizationPending", required = false) + private Boolean customizationPending; + + @XmlElement(name = "OperatingSystem", required = false) + private OperatingSystem operatingSystem; + + @XmlElement(name = "HardwareConfiguration", required = false) + private HardwareConfiguration hardwareConfiguation; + + public VirtualMachine(URI href, String type, String name, Tasks tasks, Actions actions, Links links, String description, @Nullable Layout layout, + VirtualMachineStatus status, @Nullable Boolean poweredOn, @Nullable ToolsStatus toolsStatus, @Nullable VirtualMachineMediaStatus mediaStatus, @Nullable Boolean customizationPending, + @Nullable OperatingSystem operatingSystem, @Nullable HardwareConfiguration hardwareConfiguration ) { 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.status = checkNotNull(status, "status"); + this.layout = layout; + this.poweredOn = poweredOn; + this.toolsStatus = toolsStatus; + this.mediaStatus = mediaStatus; + this.customizationPending = customizationPending; + this.operatingSystem = operatingSystem; + this.hardwareConfiguation = hardwareConfiguration; } protected VirtualMachine() { @@ -217,10 +334,56 @@ public class VirtualMachine extends BaseNamedResource { return description; } + public VirtualMachineStatus getStatus() { + return status; + } + public Layout getLayout() { return layout; } + /** + * Is optional, so may return null + */ + public Boolean isPoweredOn() { + return poweredOn; + } + + /** + * Is optional, so may return null + */ + public ToolsStatus getToolsStatus() { + return toolsStatus; + } + + /** + * Is optional, so may return null + */ + public VirtualMachineMediaStatus getMediaStatus() { + return mediaStatus; + } + + /** + * Is optional, so may return null + */ + public HardwareConfiguration getHardwareConfiguration() { + return hardwareConfiguation; + } + + /** + * Is optional, so may return null + */ + public Boolean isCustomizationPending() { + return customizationPending; + } + + /** + * Is optional, so may return null + */ + public OperatingSystem getOperatingSystem() { + return operatingSystem; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -230,11 +393,22 @@ public class VirtualMachine extends BaseNamedResource { VirtualMachine that = (VirtualMachine) o; if (!actions.equals(that.actions)) return false; + if (customizationPending != null ? !customizationPending.equals(that.customizationPending) : that.customizationPending != null) + return false; if (!description.equals(that.description)) return false; + if (hardwareConfiguation != null ? !hardwareConfiguation.equals(that.hardwareConfiguation) : that.hardwareConfiguation != null) + return false; if (layout != null ? !layout.equals(that.layout) : that.layout != null) return false; if (!links.equals(that.links)) return false; + if (mediaStatus != that.mediaStatus) return false; + if (operatingSystem != null ? !operatingSystem.equals(that.operatingSystem) : that.operatingSystem != null) + return false; + if (poweredOn != null ? !poweredOn.equals(that.poweredOn) : that.poweredOn != null) + return false; + if (status != that.status) return false; if (!tasks.equals(that.tasks)) return false; + if (toolsStatus != that.toolsStatus) return false; return true; } @@ -247,12 +421,63 @@ public class VirtualMachine extends BaseNamedResource { result = 31 * result + actions.hashCode(); result = 31 * result + description.hashCode(); result = 31 * result + (layout != null ? layout.hashCode() : 0); + result = 31 * result + status.hashCode(); + result = 31 * result + (poweredOn != null ? poweredOn.hashCode() : 0); + result = 31 * result + (toolsStatus != null ? toolsStatus.hashCode() : 0); + result = 31 * result + (mediaStatus != null ? mediaStatus.hashCode() : 0); + result = 31 * result + (customizationPending != null ? customizationPending.hashCode() : 0); + result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0); + result = 31 * result + (hardwareConfiguation != null ? hardwareConfiguation.hashCode() : 0); return result; } @Override public String string() { - return super.string()+", links="+links+", tasks="+tasks+", actions="+actions+", description="+description+", layout="+layout; + return super.string()+", links="+links+", tasks="+tasks+", actions="+actions+", description="+description+", layout="+layout+ + ", status="+status+", poweredOn="+poweredOn+", toolsStatus="+toolsStatus+", mediaStatus="+mediaStatus+ + ", operatingSystem="+operatingSystem+", hardwareConfiguration="+hardwareConfiguation; + } + + @XmlEnum + public enum VirtualMachineStatus { + @XmlEnumValue("NotDeployed") + NOT_DEPLOYED, + @XmlEnumValue("Deployed") + DEPLOYED, + @XmlEnumValue("Orphaned") + ORPHANED, + @XmlEnumValue("TaskInProgress") + TASK_IN_PROGRESS, + @XmlEnumValue("CopyInProgress") + COPY_IN_PROGRESS; + + public String value() { + return UPPER_UNDERSCORE.to(LOWER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + + } + + @XmlEnum + public enum VirtualMachineMediaStatus { + @XmlEnumValue("Unmounted") + UNMOUNTED, + @XmlEnumValue("Mounted") + MOUNTED; + + public String value() { + return UPPER_UNDERSCORE.to(LOWER_CAMEL, name()); + } + + @Override + public String toString() { + return value(); + } + } } \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/ResourceCapacity.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/ResourceCapacity.java new file mode 100644 index 0000000000..a39fdf9de0 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/internal/ResourceCapacity.java @@ -0,0 +1,126 @@ +/** + * 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.tmrk.enterprisecloud.domain.internal; + +import org.jclouds.javax.annotation.Nullable; + +import javax.xml.bind.annotation.XmlElement; + +/** + * @author Jason King + */ +public class ResourceCapacity> { + + public static > Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromResource(this); + } + + public static class Builder> { + + protected double value; //mandatory + protected String unit; //optional + + /** + * @see ResourceCapacity#getValue + */ + public Builder value(double value) { + this.value = value; + return this; + } + + /** + * @see ResourceCapacity#getUnit + */ + public Builder unit(String unit) { + this.unit = unit; + return this; + } + + public ResourceCapacity build() { + return new ResourceCapacity(value, unit); + } + + public Builder fromResource(ResourceCapacity in) { + return value(in.getValue()).unit(in.getUnit()); + } + } + + @XmlElement(name = "Value") + protected double value; + + @XmlElement(name = "Unit") + protected String unit; + + public ResourceCapacity(double value, @Nullable String unit) { + this.value = value; + this.unit = unit; + } + + protected ResourceCapacity() { + //For JAXB + } + + public double getValue() { + return value; + } + + /** + * Optional. May be null + */ + public String getUnit() { + return unit; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ResourceCapacity that = (ResourceCapacity) o; + + if (Double.compare(that.value, value) != 0) return false; + if (unit != null ? !unit.equals(that.unit) : that.unit != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result; + long temp; + temp = value != +0.0d ? Double.doubleToLongBits(value) : 0L; + result = (int) (temp ^ (temp >>> 32)); + result = 31 * result + (unit != null ? unit.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return String.format("[%s]",string()); + } + + protected String string() { + return "value="+value+", unit="+unit; + } +} \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java index 8c698842d0..1f8ff371b3 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/xml/VirtualMachineJAXBParsingTest.java @@ -34,9 +34,10 @@ import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.BaseRestClientTest; import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.tmrk.enterprisecloud.domain.Layout; -import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine; +import org.jclouds.tmrk.enterprisecloud.domain.*; +import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus; import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient; +import org.testng.Assert; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -44,11 +45,14 @@ import org.testng.annotations.Test; import javax.inject.Named; import java.io.InputStream; import java.lang.reflect.Method; +import java.net.URI; import java.util.Set; 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.Assert.assertFalse; +import static org.testng.Assert.assertTrue; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNotNull; @@ -108,6 +112,13 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest { assertEquals(1,virtualMachine.getTasks().size()); assertLayout(virtualMachine.getLayout()); + assertEquals(VirtualMachineStatus.DEPLOYED, virtualMachine.getStatus()); + assertFalse(virtualMachine.isPoweredOn(),"virtual machine is not powered on"); + assertEquals(ToolsStatus.NOT_RUNNING, virtualMachine.getToolsStatus()); + assertEquals(VirtualMachine.VirtualMachineMediaStatus.UNMOUNTED, virtualMachine.getMediaStatus()); + assertTrue(virtualMachine.isCustomizationPending(),"virtual machine is pending customization"); + assertOperatingSystem(virtualMachine.getOperatingSystem()); + assertHardwareConfiguration(virtualMachine.getHardwareConfiguration()); } private void assertLayout(Layout layout) { @@ -115,4 +126,20 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest { assertEquals("test row", layout.getRow().getName()); assertEquals("test group",layout.getGroup().getName()); } + + private void assertOperatingSystem(OperatingSystem operatingSystem) throws Exception { + String href = "/cloudapi/ecloud/operatingsystems/rhel5_64guest/computepools/89"; + String name = "Red Hat Enterprise Linux 5 (64-bit)"; + String type = "application/vnd.tmrk.cloud.operatingSystem"; + OperatingSystem os = OperatingSystem.builder().href(new URI(href)).name(name).type(type).build(); + Assert.assertEquals(os, operatingSystem); + } + + private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) { + assertEquals(1,hardwareConfiguration.getActions().size()); + assertEquals(1,hardwareConfiguration.getProcessorCount()); + Memory memory = Memory.builder().value(384).unit("MB").build(); + assertEquals(memory,hardwareConfiguration.getMemory()); + } + } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/resources/virtualMachine.xml b/sandbox-providers/tmrk-enterprisecloud/src/test/resources/virtualMachine.xml index cee037e899..06b94283be 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/resources/virtualMachine.xml +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/resources/virtualMachine.xml @@ -139,5 +139,5 @@ type="application/vnd.tmrk.cloud.operatingSystem"/> NotRunning Unmounted - false + true \ No newline at end of file From f7c95790190e62ae23a22fcd9a8e4be277de7192 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 17 Nov 2011 11:40:17 +0000 Subject: [PATCH 2/2] Issue 695: Converted optional Boolean to boolean, fixed layout(), fromVirtualMachine() and toString() --- .../domain/VirtualMachine.java | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java index c992ffbb6c..d6b12fda70 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/VirtualMachine.java @@ -64,10 +64,10 @@ public class VirtualMachine extends BaseNamedResource { private VirtualMachineStatus status; private Layout layout; - private Boolean poweredOn; + private boolean poweredOn; private ToolsStatus toolsStatus; private VirtualMachineMediaStatus mediaStatus; - private Boolean customizationPending; + private boolean customizationPending; private OperatingSystem operatingSystem; private HardwareConfiguration hardwareConfiguration; @@ -110,7 +110,7 @@ public class VirtualMachine extends BaseNamedResource { /** * @see VirtualMachine#getLayout() */ - public Builder description(Layout layout) { + public Builder layout(Layout layout) { this.layout = layout; return this; } @@ -126,7 +126,7 @@ public class VirtualMachine extends BaseNamedResource { /** * @see VirtualMachine#isCustomizationPending() */ - public Builder customizationPending(Boolean customizationPending) { + public Builder customizationPending(boolean customizationPending) { this.customizationPending = customizationPending; return this; } @@ -158,7 +158,7 @@ public class VirtualMachine extends BaseNamedResource { /** * @see VirtualMachine#isPoweredOn() */ - public Builder poweredOn(Boolean poweredOn) { + public Builder poweredOn(boolean poweredOn) { this.poweredOn = poweredOn; return this; } @@ -192,6 +192,7 @@ public class VirtualMachine extends BaseNamedResource { .tasks(in.getTasks()) .actions(in.getActions()) .description(in.getDescription()) + .layout(in.getLayout()) .status(in.getStatus()) .poweredOn(in.isPoweredOn()) .toolsStatus(in.getToolsStatus()) @@ -271,7 +272,7 @@ public class VirtualMachine extends BaseNamedResource { private VirtualMachineStatus status; @XmlElement(name = "PoweredOn", required = false) - private Boolean poweredOn; + private boolean poweredOn; @XmlElement(name = "ToolsStatus", required = false) private ToolsStatus toolsStatus; @@ -280,7 +281,7 @@ public class VirtualMachine extends BaseNamedResource { private VirtualMachineMediaStatus mediaStatus; @XmlElement(name = "CustomizationPending", required = false) - private Boolean customizationPending; + private boolean customizationPending; @XmlElement(name = "OperatingSystem", required = false) private OperatingSystem operatingSystem; @@ -289,7 +290,7 @@ public class VirtualMachine extends BaseNamedResource { private HardwareConfiguration hardwareConfiguation; public VirtualMachine(URI href, String type, String name, Tasks tasks, Actions actions, Links links, String description, @Nullable Layout layout, - VirtualMachineStatus status, @Nullable Boolean poweredOn, @Nullable ToolsStatus toolsStatus, @Nullable VirtualMachineMediaStatus mediaStatus, @Nullable Boolean customizationPending, + VirtualMachineStatus status, boolean poweredOn, @Nullable ToolsStatus toolsStatus, @Nullable VirtualMachineMediaStatus mediaStatus, boolean customizationPending, @Nullable OperatingSystem operatingSystem, @Nullable HardwareConfiguration hardwareConfiguration ) { super(href, type, name); this.description = checkNotNull(description, "description"); @@ -342,10 +343,7 @@ public class VirtualMachine extends BaseNamedResource { return layout; } - /** - * Is optional, so may return null - */ - public Boolean isPoweredOn() { + public boolean isPoweredOn() { return poweredOn; } @@ -370,10 +368,7 @@ public class VirtualMachine extends BaseNamedResource { return hardwareConfiguation; } - /** - * Is optional, so may return null - */ - public Boolean isCustomizationPending() { + public boolean isCustomizationPending() { return customizationPending; } @@ -392,9 +387,9 @@ public class VirtualMachine extends BaseNamedResource { VirtualMachine that = (VirtualMachine) o; + if (customizationPending != that.customizationPending) return false; + if (poweredOn != that.poweredOn) return false; if (!actions.equals(that.actions)) return false; - if (customizationPending != null ? !customizationPending.equals(that.customizationPending) : that.customizationPending != null) - return false; if (!description.equals(that.description)) return false; if (hardwareConfiguation != null ? !hardwareConfiguation.equals(that.hardwareConfiguation) : that.hardwareConfiguation != null) return false; @@ -404,8 +399,6 @@ public class VirtualMachine extends BaseNamedResource { if (mediaStatus != that.mediaStatus) return false; if (operatingSystem != null ? !operatingSystem.equals(that.operatingSystem) : that.operatingSystem != null) return false; - if (poweredOn != null ? !poweredOn.equals(that.poweredOn) : that.poweredOn != null) - return false; if (status != that.status) return false; if (!tasks.equals(that.tasks)) return false; if (toolsStatus != that.toolsStatus) return false; @@ -422,10 +415,10 @@ public class VirtualMachine extends BaseNamedResource { result = 31 * result + description.hashCode(); result = 31 * result + (layout != null ? layout.hashCode() : 0); result = 31 * result + status.hashCode(); - result = 31 * result + (poweredOn != null ? poweredOn.hashCode() : 0); + result = 31 * result + (poweredOn ? 1 : 0); result = 31 * result + (toolsStatus != null ? toolsStatus.hashCode() : 0); result = 31 * result + (mediaStatus != null ? mediaStatus.hashCode() : 0); - result = 31 * result + (customizationPending != null ? customizationPending.hashCode() : 0); + result = 31 * result + (customizationPending ? 1 : 0); result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0); result = 31 * result + (hardwareConfiguation != null ? hardwareConfiguation.hashCode() : 0); return result; @@ -435,7 +428,7 @@ public class VirtualMachine extends BaseNamedResource { public String string() { return super.string()+", links="+links+", tasks="+tasks+", actions="+actions+", description="+description+", layout="+layout+ ", status="+status+", poweredOn="+poweredOn+", toolsStatus="+toolsStatus+", mediaStatus="+mediaStatus+ - ", operatingSystem="+operatingSystem+", hardwareConfiguration="+hardwareConfiguation; + ", customizationPending="+customizationPending+", operatingSystem="+operatingSystem+", hardwareConfiguration="+hardwareConfiguation; } @XmlEnum