You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2019/01/18 15:16:47 UTC

[jclouds-labs] branch master updated: JCLOUD-96-JCLOUD-91-Fix NPE and Remove Nullable osImageKey From OsImage

This is an automated email from the ASF dual-hosted git repository.

nacx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds-labs.git


The following commit(s) were added to refs/heads/master by this push:
     new 686b608  JCLOUD-96-JCLOUD-91-Fix NPE and Remove Nullable osImageKey From OsImage
686b608 is described below

commit 686b608f08ba60be71c9b8bc48b027fbf429d5b5
Author: john.clarke <jo...@dimensiondata.com>
AuthorDate: Thu Jan 10 11:30:09 2019 +0000

    JCLOUD-96-JCLOUD-91-Fix NPE and Remove Nullable osImageKey From OsImage
---
 .../functions/ServerWithNatRuleToNodeMetadata.java | 12 +++++----
 .../dimensiondata/cloudcontrol/domain/OsImage.java |  2 --
 .../dimensiondata/cloudcontrol/domain/State.java   |  2 +-
 .../ServerWithNatRuleToNodeMetadataTest.java       | 31 ++++++++++++++++++++--
 4 files changed, 37 insertions(+), 10 deletions(-)

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 @@ class ServerWithNatRuleToNodeMetadata implements Function<ServerWithExternalIp,
 
    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 @@ class ServerWithNatRuleToNodeMetadata implements Function<ServerWithExternalIp,
       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 @@ package org.jclouds.dimensiondata.cloudcontrol.domain;
 
 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 @@ public abstract class OsImage extends BaseImage {
       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 @@ import static com.google.common.base.Preconditions.checkNotNull;
 
 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 @@ public class ServerWithNatRuleToNodeMetadataTest {
 
       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 @@ public class ServerWithNatRuleToNodeMetadataTest {
 
       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 @@ public class ServerWithNatRuleToNodeMetadataTest {
             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);