JCLOUD-96-JCLOUD-91-Fix NPE and Remove Nullable osImageKey From OsImage
diff --git a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/ServerWithNatRuleToNodeMetadata.java b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/ServerWithNatRuleToNodeMetadata.java
index 6ffb9fe..403e4e4 100644
--- a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/ServerWithNatRuleToNodeMetadata.java
+++ b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/ServerWithNatRuleToNodeMetadata.java
@@ -48,10 +48,10 @@
private static final Map<State, NodeMetadata.Status> serverStateToNodeStatus = ImmutableMap.<State, NodeMetadata.Status>builder()
.put(State.PENDING_DELETE, NodeMetadata.Status.PENDING).put(State.PENDING_CHANGE, NodeMetadata.Status.PENDING)
- .put(State.FAILED_ADD, NodeMetadata.Status.ERROR).put(State.FAILED_CHANGE, NodeMetadata.Status.ERROR)
- .put(State.FAILED_DELETE, NodeMetadata.Status.ERROR).put(State.DELETED, NodeMetadata.Status.TERMINATED)
- .put(State.NORMAL, NodeMetadata.Status.RUNNING).put(State.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED)
- .build();
+ .put(State.PENDING_ADD, NodeMetadata.Status.PENDING).put(State.FAILED_ADD, NodeMetadata.Status.ERROR)
+ .put(State.FAILED_CHANGE, NodeMetadata.Status.ERROR).put(State.FAILED_DELETE, NodeMetadata.Status.ERROR)
+ .put(State.DELETED, NodeMetadata.Status.TERMINATED).put(State.NORMAL, NodeMetadata.Status.RUNNING)
+ .put(State.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED).build();
private final Supplier<Set<? extends Location>> locations;
private final GroupNamingConvention nodeNamingConvention;
@@ -80,7 +80,9 @@
builder.hardware(serverToHardware.apply(serverWithExternalIp.server()));
builder.imageId(server.sourceImageId());
builder.operatingSystem(operatingSystemToOperatingSystem.apply(server.guest().operatingSystem()));
- builder.status(serverStateToNodeStatus.get(server.state()));
+ builder.status(server.started() ?
+ serverStateToNodeStatus.get(server.state()) :
+ NodeMetadata.Status.SUSPENDED);
Set<String> privateAddresses = new HashSet<String>();
if (server.networkInfo() != null) {
diff --git a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/domain/OsImage.java b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/domain/OsImage.java
index a64c7a5..7b179e5 100644
--- a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/domain/OsImage.java
+++ b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/domain/OsImage.java
@@ -18,7 +18,6 @@
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
-import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import java.util.Date;
@@ -32,7 +31,6 @@
type = TYPE;
}
- @Nullable
public abstract String osImageKey();
@SerializedNames({ "id", "name", "description", "cluster", "guest", "datacenterId", "cpu", "memoryGb", "nic", "disk",
diff --git a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/domain/State.java b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/domain/State.java
index 9e7255c..e0dbe54 100644
--- a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/domain/State.java
+++ b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/domain/State.java
@@ -22,7 +22,7 @@
public enum State {
- NORMAL, FAILED_ADD, FAILED_CHANGE, FAILED_DELETE, PENDING_DELETE, DELETED, UNRECOGNIZED, PENDING_CHANGE, PENDING_CLEAN, REQUIRES_SUPPORT;
+ NORMAL, FAILED_ADD, FAILED_CHANGE, FAILED_DELETE, PENDING_DELETE, DELETED, UNRECOGNIZED, PENDING_CHANGE, PENDING_ADD, PENDING_CLEAN, REQUIRES_SUPPORT;
@Override
public String toString() {
diff --git a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/ServerWithNatRuleToNodeMetadataTest.java b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/ServerWithNatRuleToNodeMetadataTest.java
index 49fd60c..5f83775 100644
--- a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/ServerWithNatRuleToNodeMetadataTest.java
+++ b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/ServerWithNatRuleToNodeMetadataTest.java
@@ -106,7 +106,7 @@
server = Server.builder().id("serverId").name(serverName).datacenterId(datacenterId)
.networkInfo(NetworkInfo.create(networkDomainId, nic, new ArrayList<NIC>())).cpu(cpu).deployed(true)
- .state(State.NORMAL).sourceImageId("imageId").started(false).createTime(new Date()).memoryGb(1024)
+ .state(State.NORMAL).sourceImageId("imageId").started(true).createTime(new Date()).memoryGb(1024)
.guest(Guest.builder().osCustomization(false).operatingSystem(os).build()).build();
serverWithNatRuleToNodeMetadata = new ServerWithNatRuleToNodeMetadata(locations, conventionFactory,
@@ -140,7 +140,7 @@
server = Server.builder().id("serverId").name(serverName).datacenterId(datacenterId)
.networkInfo(NetworkInfo.create(networkDomainId, nic, new ArrayList<NIC>())).cpu(cpu).deployed(true)
- .state(State.DELETED).sourceImageId("imageId").started(false).createTime(new Date()).memoryGb(1024)
+ .state(State.DELETED).sourceImageId("imageId").started(true).createTime(new Date()).memoryGb(1024)
.guest(Guest.builder().osCustomization(false).operatingSystem(os).build()).build();
serverWithExternalIp = ServerWithExternalIp.create(server, null);
@@ -155,6 +155,33 @@
NodeMetadata.Status.TERMINATED, ImmutableSet.<String>of(), ImmutableSet.<String>of());
}
+ @Test(dependsOnMethods = "testApplyWithNullables")
+ public void testApplyServerStopped() {
+
+ server = Server.builder().id("serverId").name(serverName).datacenterId(datacenterId)
+ .networkInfo(NetworkInfo.create(networkDomainId, nic, new ArrayList<NIC>())).cpu(cpu).deployed(true)
+ .state(State.DELETED).sourceImageId("imageId").started(false).createTime(new Date()).memoryGb(1024)
+ .guest(Guest.builder().osCustomization(false).operatingSystem(os).build()).build();
+
+ serverWithExternalIp = ServerWithExternalIp.create(server, externalIp);
+
+ org.jclouds.compute.domain.OperatingSystem operatingSystem = org.jclouds.compute.domain.OperatingSystem.builder()
+ .description("Windows 10 x64").name("Win10x64").is64Bit(true).family(OsFamily.WINDOWS).build();
+
+ expect(image.getId()).andReturn("imageId");
+ expect(image.getOperatingSystem()).andReturn(operatingSystem);
+ expect(nic.privateIpv4()).andReturn("192.168.1.1").anyTimes();
+ expect(nodeNamingConvention.groupInUniqueNameOrNull(serverName)).andReturn("[" + serverName + "]").anyTimes();
+ expect(serverToHardware.apply(server)).andReturn(hardware);
+ expect(operatingSystemToOperatingSystem.apply(os)).andReturn(operatingSystem);
+
+ EasyMock.replay(nodeNamingConvention, serverImageApi, image, nic, serverToHardware, operatingSystemToOperatingSystem);
+
+ assertNodeMetadata(serverWithNatRuleToNodeMetadata.apply(serverWithExternalIp), operatingSystem,
+ serverWithExternalIp.server().sourceImageId(), NodeMetadata.Status.SUSPENDED,
+ ImmutableSet.of(nic.privateIpv4()), ImmutableSet.of(externalIp));
+ }
+
private void assertNodeMetadata(NodeMetadata result, org.jclouds.compute.domain.OperatingSystem os, String imageId,
NodeMetadata.Status status, ImmutableSet<String> privateIpAddresses, ImmutableSet<String> publicIpAddresses) {
assertNotNull(result);