mirror of https://github.com/apache/jclouds.git
Issue 695: Encapsulated Nics,Disks,Actions so externally deal with Sets, wrappers just internally for JAXB
This commit is contained in:
parent
2c12a26fe5
commit
5c09b1befe
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||||
|
|
||||||
|
@ -49,18 +51,17 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||||
|
|
||||||
public static class Builder extends BaseResource.Builder<HardwareConfiguration> {
|
public static class Builder extends BaseResource.Builder<HardwareConfiguration> {
|
||||||
|
|
||||||
private Actions actions = new Actions();
|
private Set<Action> actions = Sets.newLinkedHashSet();
|
||||||
private int processorCount;
|
private int processorCount;
|
||||||
private Memory memory;
|
private Memory memory;
|
||||||
private Disks disks = new Disks();
|
private Set<VirtualDisk> virtualDisks = Sets.newLinkedHashSet();
|
||||||
private Nics nics = new Nics();
|
private Set<VirtualNic> virtualNics = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HardwareConfiguration#getActions
|
* @see HardwareConfiguration#getActions
|
||||||
*/
|
*/
|
||||||
public Builder actions(Set<Action> actions) {
|
public Builder actions(Set<Action> actions) {
|
||||||
checkNotNull(actions,"actions");
|
this.actions = ImmutableSet.<Action> copyOf(checkNotNull(actions, "actions"));
|
||||||
for(Action action:actions) this.actions.setAction(action);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,24 +82,25 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HardwareConfiguration#getDisks
|
* @see HardwareConfiguration#getVirtualDisks
|
||||||
*/
|
*/
|
||||||
public Builder disks(Disks disks) {
|
public Builder disks(Set<VirtualDisk> virtualDisks) {
|
||||||
this.disks = checkNotNull(disks,"disks");;
|
this.virtualDisks = ImmutableSet.<VirtualDisk> copyOf(checkNotNull(virtualDisks, "virtualDisks"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see HardwareConfiguration#getDisks
|
* @see HardwareConfiguration#getVirtualNics
|
||||||
*/
|
*/
|
||||||
public Builder nics(Nics nics) {
|
public Builder nics(Set<VirtualNic> virtualNics) {
|
||||||
this.nics = checkNotNull(nics,"nics");;
|
this.virtualNics = ImmutableSet.<VirtualNic> copyOf(checkNotNull(virtualNics, "virtualNics"));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HardwareConfiguration build() {
|
public HardwareConfiguration build() {
|
||||||
return new HardwareConfiguration(actions, processorCount, memory, disks, nics);
|
return new HardwareConfiguration(actions, processorCount, memory, virtualDisks, virtualNics);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,8 +139,8 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||||
return fromResource(in).actions(in.getActions())
|
return fromResource(in).actions(in.getActions())
|
||||||
.processorCount(in.getProcessorCount())
|
.processorCount(in.getProcessorCount())
|
||||||
.memory(in.getMemory())
|
.memory(in.getMemory())
|
||||||
.disks(in.getDisks())
|
.disks(in.getVirtualDisks())
|
||||||
.nics(in.getNics());
|
.nics(in.getVirtualNics());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,17 +154,18 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||||
private Memory memory;
|
private Memory memory;
|
||||||
|
|
||||||
@XmlElement(name = "Disks", required = false)
|
@XmlElement(name = "Disks", required = false)
|
||||||
private Disks disks = new Disks();
|
private Disks virtualDisks = new Disks();
|
||||||
|
|
||||||
@XmlElement(name = "Nics", required = false)
|
@XmlElement(name = "Nics", required = false)
|
||||||
private Nics nics = new Nics();
|
private Nics virtualNics = new Nics();
|
||||||
|
|
||||||
|
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable Memory memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
|
||||||
|
for( Action action: checkNotNull(actions, "actions")) this.actions.setAction(action);
|
||||||
|
for( VirtualDisk disk: checkNotNull(virtualDisks, "virtualDisks")) this.virtualDisks.setVirtualDisk(disk);
|
||||||
|
for( VirtualNic virtualNic: checkNotNull(virtualNics, "virtualNics")) this.virtualNics.setVirtualNic(virtualNic);
|
||||||
|
|
||||||
public HardwareConfiguration(Actions actions, int processorCount, @Nullable Memory memory, Disks disks, Nics nics) {
|
|
||||||
this.actions = checkNotNull(actions, "actions");
|
|
||||||
this.processorCount = processorCount;
|
this.processorCount = processorCount;
|
||||||
this.memory = memory;
|
this.memory = memory;
|
||||||
this.disks = checkNotNull(disks, "disks");
|
|
||||||
this.nics = checkNotNull(nics, "nics");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HardwareConfiguration() {
|
protected HardwareConfiguration() {
|
||||||
|
@ -181,12 +184,12 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||||
return memory;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Disks getDisks() {
|
public Set<VirtualDisk> getVirtualDisks() {
|
||||||
return disks;
|
return Collections.unmodifiableSet(virtualDisks.getVirtualDisks());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Nics getNics() {
|
public Set<VirtualNic> getVirtualNics() {
|
||||||
return nics;
|
return Collections.unmodifiableSet(virtualNics.getVirtualNics());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -199,10 +202,10 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||||
|
|
||||||
if (processorCount != that.processorCount) return false;
|
if (processorCount != that.processorCount) return false;
|
||||||
if (!actions.equals(that.actions)) return false;
|
if (!actions.equals(that.actions)) return false;
|
||||||
if (!disks.equals(that.disks)) return false;
|
if (!virtualDisks.equals(that.virtualDisks)) return false;
|
||||||
if (memory != null ? !memory.equals(that.memory) : that.memory != null)
|
if (memory != null ? !memory.equals(that.memory) : that.memory != null)
|
||||||
return false;
|
return false;
|
||||||
if (!nics.equals(that.nics)) return false;
|
if (!virtualNics.equals(that.virtualNics)) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -213,14 +216,14 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
||||||
result = 31 * result + actions.hashCode();
|
result = 31 * result + actions.hashCode();
|
||||||
result = 31 * result + processorCount;
|
result = 31 * result + processorCount;
|
||||||
result = 31 * result + (memory != null ? memory.hashCode() : 0);
|
result = 31 * result + (memory != null ? memory.hashCode() : 0);
|
||||||
result = 31 * result + disks.hashCode();
|
result = 31 * result + virtualDisks.hashCode();
|
||||||
result = 31 * result + nics.hashCode();
|
result = 31 * result + virtualNics.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String string() {
|
public String string() {
|
||||||
return super.string()+", actions="+actions+", processorCount="+processorCount+
|
return super.string()+", actions="+actions+", processorCount="+processorCount+
|
||||||
", memory="+memory+", disks="+disks+", nics="+nics;
|
", memory="+memory+", disks="+ virtualDisks +", nics="+ virtualNics;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,10 @@ import org.jclouds.tmrk.enterprisecloud.domain.*;
|
||||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus;
|
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus;
|
||||||
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
|
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.AssertJUnit;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
import org.testng.collections.Sets;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -142,18 +142,16 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
|
||||||
assertEquals(1,hardwareConfiguration.getProcessorCount());
|
assertEquals(1,hardwareConfiguration.getProcessorCount());
|
||||||
Memory memory = Memory.builder().value(384).unit("MB").build();
|
Memory memory = Memory.builder().value(384).unit("MB").build();
|
||||||
assertEquals(memory,hardwareConfiguration.getMemory());
|
assertEquals(memory,hardwareConfiguration.getMemory());
|
||||||
assertDisks(hardwareConfiguration.getDisks());
|
assertDisks(hardwareConfiguration.getVirtualDisks());
|
||||||
assertNics(hardwareConfiguration.getNics().getVirtualNics());
|
assertNics(hardwareConfiguration.getVirtualNics());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertDisks(Disks disks) {
|
private void assertDisks(Set<VirtualDisk> disks) {
|
||||||
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
|
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
|
||||||
.size(Size.builder().value(10).unit("GB").build())
|
.size(Size.builder().value(10).unit("GB").build())
|
||||||
.build();
|
.build();
|
||||||
Disks expectedDisks = new Disks();
|
|
||||||
expectedDisks.setVirtualDisk(disk);
|
|
||||||
|
|
||||||
assertEquals(expectedDisks, disks);
|
assertEquals(ImmutableSet.of(disk), disks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue