mirror of https://github.com/apache/jclouds.git
Merge pull request #167 from jsonking/695-1
Lots of new domain object code for VirtualMachine plus change Boolean to boolean
This commit is contained in:
commit
89802cf955
|
@ -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<HardwareConfiguration> {
|
||||
|
||||
@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<HardwareConfiguration> {
|
||||
|
||||
private Actions actions;
|
||||
private int processorCount;
|
||||
private Memory memory;
|
||||
|
||||
/**
|
||||
* @see HardwareConfiguration#getActions
|
||||
*/
|
||||
public Builder actions(Set<Action> 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<HardwareConfiguration> 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<String, String> 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<Action> 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;
|
||||
}
|
||||
}
|
|
@ -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<Memory> {
|
||||
|
||||
@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<Memory> {
|
||||
|
||||
@Override
|
||||
public Memory build() {
|
||||
return new Memory(value,unit);
|
||||
}
|
||||
|
||||
public Builder fromMemory(Memory in) {
|
||||
return fromResource(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromResource(ResourceCapacity<Memory> 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
|
||||
}
|
||||
}
|
|
@ -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<OperatingSystem> {
|
||||
|
||||
@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<OperatingSystem> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public OperatingSystem build() {
|
||||
return new OperatingSystem(href, type, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromResource(BaseResource<OperatingSystem> in) {
|
||||
return Builder.class.cast(super.fromResource(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Builder fromNamedResource(BaseNamedResource<OperatingSystem> 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<String, String> in) {
|
||||
return Builder.class.cast(super.fromAttributes(in));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public OperatingSystem(URI href, String type, String name) {
|
||||
super(href, type, name);
|
||||
}
|
||||
|
||||
protected OperatingSystem() {
|
||||
//For JAXB
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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<VirtualMachine> {
|
|||
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
|
||||
|
@ -97,14 +110,80 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
/**
|
||||
* @see VirtualMachine#getLayout()
|
||||
*/
|
||||
public Builder description(Layout layout) {
|
||||
public Builder layout(Layout layout) {
|
||||
this.layout = layout;
|
||||
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,15 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
.links(in.getLinks())
|
||||
.tasks(in.getTasks())
|
||||
.actions(in.getActions())
|
||||
.description(in.getDescription());
|
||||
.description(in.getDescription())
|
||||
.layout(in.getLayout())
|
||||
.status(in.getStatus())
|
||||
.poweredOn(in.isPoweredOn())
|
||||
.toolsStatus(in.getToolsStatus())
|
||||
.mediaStatus(in.getMediaStatus())
|
||||
.customizationPending(in.isCustomizationPending())
|
||||
.operatingSystem(in.getOperatingSystem())
|
||||
.hardwareConfiguration(in.getHardwareConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -181,13 +268,44 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
@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, 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");
|
||||
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 +335,50 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
return description;
|
||||
}
|
||||
|
||||
public VirtualMachineStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public Layout getLayout() {
|
||||
return layout;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -229,12 +387,21 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
|
||||
VirtualMachine that = (VirtualMachine) o;
|
||||
|
||||
if (customizationPending != that.customizationPending) return false;
|
||||
if (poweredOn != that.poweredOn) return false;
|
||||
if (!actions.equals(that.actions)) 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 (status != that.status) return false;
|
||||
if (!tasks.equals(that.tasks)) return false;
|
||||
if (toolsStatus != that.toolsStatus) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -247,12 +414,63 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
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 ? 1 : 0);
|
||||
result = 31 * result + (toolsStatus != null ? toolsStatus.hashCode() : 0);
|
||||
result = 31 * result + (mediaStatus != null ? mediaStatus.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;
|
||||
}
|
||||
|
||||
@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+
|
||||
", customizationPending="+customizationPending+", 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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<T extends ResourceCapacity<T>> {
|
||||
|
||||
public static <T extends ResourceCapacity<T>> Builder<T> builder() {
|
||||
return new Builder<T>();
|
||||
}
|
||||
|
||||
public Builder<T> toBuilder() {
|
||||
return new Builder<T>().fromResource(this);
|
||||
}
|
||||
|
||||
public static class Builder<T extends ResourceCapacity<T>> {
|
||||
|
||||
protected double value; //mandatory
|
||||
protected String unit; //optional
|
||||
|
||||
/**
|
||||
* @see ResourceCapacity#getValue
|
||||
*/
|
||||
public Builder<T> value(double value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResourceCapacity#getUnit
|
||||
*/
|
||||
public Builder<T> unit(String unit) {
|
||||
this.unit = unit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResourceCapacity<T> build() {
|
||||
return new ResourceCapacity<T>(value, unit);
|
||||
}
|
||||
|
||||
public Builder<T> fromResource(ResourceCapacity<T> 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;
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -139,5 +139,5 @@
|
|||
type="application/vnd.tmrk.cloud.operatingSystem"/>
|
||||
<ToolsStatus>NotRunning</ToolsStatus>
|
||||
<MediaStatus>Unmounted</MediaStatus>
|
||||
<CustomizationPending>false</CustomizationPending>
|
||||
<CustomizationPending>true</CustomizationPending>
|
||||
</VirtualMachine>
|
Loading…
Reference in New Issue