Repository: jclouds-labs
Updated Branches:
  refs/heads/2.0.x dab07d44e -> bf34887e3


Refactor DimensionDataCloudControlResponseUtils waitFor* methods so that they 
are injectable.


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/bf34887e
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/bf34887e
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/bf34887e

Branch: refs/heads/2.0.x
Commit: bf34887e348bd8b0a0510ae9895a68f647757aab
Parents: dab07d4
Author: Trevor Flanagan <[email protected]>
Authored: Thu Dec 14 17:17:16 2017 +0000
Committer: Ignasi Barrera <[email protected]>
Committed: Mon Dec 18 14:19:58 2017 +0100

----------------------------------------------------------------------
 .../DimensionDataCloudControlApiMetadata.java   |  11 +-
 .../compute/functions/CleanupServer.java        |  23 +-
 ...CloudControlComputeServiceContextModule.java | 252 +++++++++++++++++++
 .../config/DimensionDataProperties.java         |  26 ++
 .../predicates/NetworkDomainState.java          |  50 ----
 .../cloudcontrol/predicates/ServerState.java    |  58 -----
 .../cloudcontrol/predicates/ServerStatus.java   |  58 -----
 .../predicates/VMToolsRunningStatus.java        |  51 ----
 .../cloudcontrol/predicates/VlanState.java      |  52 ----
 .../DimensionDataCloudControlResponseUtils.java |  49 ----
 .../compute/functions/CleanupServerTest.java    |  27 +-
 ...CloudControlComputeServiceContextModule.java |  45 ----
 .../features/NetworkApiLiveTest.java            |  16 +-
 .../features/ServerApiLiveTest.java             |  26 +-
 ...aseDimensionDataCloudControlApiLiveTest.java |  53 ++++
 15 files changed, 397 insertions(+), 400 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/DimensionDataCloudControlApiMetadata.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/DimensionDataCloudControlApiMetadata.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/DimensionDataCloudControlApiMetadata.java
index d344e42..a352129 100644
--- 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/DimensionDataCloudControlApiMetadata.java
+++ 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/DimensionDataCloudControlApiMetadata.java
@@ -20,12 +20,15 @@ import com.google.common.collect.ImmutableSet;
 import com.google.inject.Module;
 import org.jclouds.apis.ApiMetadata;
 import org.jclouds.compute.ComputeServiceContext;
+import 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule;
 import 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlHttpApiModule;
 import 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlParserModule;
 import org.jclouds.rest.internal.BaseHttpApiMetadata;
 
 import java.net.URI;
+import java.util.Properties;
 
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataProperties.OPERATION_TIMEOUT;
 import static org.jclouds.reflect.Reflection2.typeToken;
 
 public class DimensionDataCloudControlApiMetadata extends 
BaseHttpApiMetadata<DimensionDataCloudControlApi> {
@@ -46,14 +49,16 @@ public class DimensionDataCloudControlApiMetadata extends 
BaseHttpApiMetadata<Di
    public static class Builder extends 
BaseHttpApiMetadata.Builder<DimensionDataCloudControlApi, Builder> {
 
       protected Builder() {
+         final Properties defaultProperties = 
DimensionDataCloudControlApiMetadata.defaultProperties();
+         defaultProperties.put(OPERATION_TIMEOUT, 30 * 60 * 1000);
          id("dimensiondata-cloudcontrol").name("DimensionData CloudControl 
API").identityName("user name")
                .credentialName("user password")
                
.documentation(URI.create("http://www.dimensiondata.com/en-US/Solutions/Cloud";))
                
.defaultEndpoint("https://api-REGION.dimensiondata.com/caas";).version("2.4")
-               
.defaultProperties(DimensionDataCloudControlApiMetadata.defaultProperties())
-               .view(typeToken(ComputeServiceContext.class)).defaultModules(
+               
.defaultProperties(defaultProperties).view(typeToken(ComputeServiceContext.class)).defaultModules(
                ImmutableSet.<Class<? extends 
Module>>builder().add(DimensionDataCloudControlHttpApiModule.class)
-                     
.add(DimensionDataCloudControlParserModule.class).build());
+                     .add(DimensionDataCloudControlParserModule.class)
+                     
.add(DimensionDataCloudControlComputeServiceContextModule.class).build());
       }
 
       @Override

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServer.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServer.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServer.java
index cb1f724..662121f 100644
--- 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServer.java
+++ 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServer.java
@@ -26,10 +26,8 @@ import 
org.jclouds.dimensiondata.cloudcontrol.domain.FirewallRule;
 import org.jclouds.dimensiondata.cloudcontrol.domain.NatRule;
 import org.jclouds.dimensiondata.cloudcontrol.domain.PublicIpBlock;
 import org.jclouds.dimensiondata.cloudcontrol.domain.Server;
-import org.jclouds.dimensiondata.cloudcontrol.domain.State;
 import org.jclouds.dimensiondata.cloudcontrol.features.NetworkApi;
 import org.jclouds.dimensiondata.cloudcontrol.features.ServerApi;
-import 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils;
 import org.jclouds.logging.Logger;
 
 import javax.annotation.Resource;
@@ -39,8 +37,9 @@ import javax.inject.Singleton;
 import java.util.List;
 
 import static java.lang.String.format;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.SERVER_DELETED_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.SERVER_STOPPED_PREDICATE;
 import static 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.generateFirewallRuleName;
-import static 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.waitForServerState;
 
 @Singleton
 public class CleanupServer implements Function<String, Boolean> {
@@ -51,11 +50,17 @@ public class CleanupServer implements Function<String, 
Boolean> {
 
    private final DimensionDataCloudControlApi api;
    private final Timeouts timeouts;
+   private Predicate<String> serverStoppedPredicate;
+   private Predicate<String> serverDeletedPredicate;
 
    @Inject
-   CleanupServer(final DimensionDataCloudControlApi api, final Timeouts 
timeouts) {
+   CleanupServer(final DimensionDataCloudControlApi api, final Timeouts 
timeouts,
+         @Named(SERVER_STOPPED_PREDICATE) final Predicate<String> 
serverStoppedPredicate,
+         @Named(SERVER_DELETED_PREDICATE) final Predicate<String> 
serverDeletedPredicate) {
       this.api = api;
       this.timeouts = timeouts;
+      this.serverStoppedPredicate = serverStoppedPredicate;
+      this.serverDeletedPredicate = serverDeletedPredicate;
    }
 
    @Override
@@ -118,11 +123,15 @@ public class CleanupServer implements Function<String, 
Boolean> {
 
       serverApi.powerOffServer(serverId);
       String message = format("Server(%s) not terminated within %d ms.", 
serverId, timeouts.nodeTerminated);
-      DimensionDataCloudControlResponseUtils
-            .waitForServerStatus(serverApi, serverId, false, true, 
timeouts.nodeTerminated, message);
+      if (!serverStoppedPredicate.apply(serverId)) {
+         throw new IllegalStateException(message);
+      }
       serverApi.deleteServer(serverId);
       String deleteFailureMessage = format("Server(%s) not deleted within %d 
ms.", serverId, timeouts.nodeTerminated);
-      waitForServerState(serverApi, serverId, State.DELETED, 
timeouts.nodeTerminated, deleteFailureMessage);
+
+      if (!serverDeletedPredicate.apply(serverId)) {
+         throw new IllegalStateException(deleteFailureMessage);
+      }
       return true;
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataCloudControlComputeServiceContextModule.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataCloudControlComputeServiceContextModule.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataCloudControlComputeServiceContextModule.java
new file mode 100644
index 0000000..dca9512
--- /dev/null
+++ 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataCloudControlComputeServiceContextModule.java
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.dimensiondata.cloudcontrol.config;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Predicate;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi;
+import org.jclouds.dimensiondata.cloudcontrol.domain.NetworkDomain;
+import org.jclouds.dimensiondata.cloudcontrol.domain.Server;
+import org.jclouds.dimensiondata.cloudcontrol.domain.State;
+import org.jclouds.dimensiondata.cloudcontrol.domain.Vlan;
+import org.jclouds.dimensiondata.cloudcontrol.domain.VmTools;
+import org.jclouds.dimensiondata.cloudcontrol.features.NetworkApi;
+import org.jclouds.dimensiondata.cloudcontrol.features.ServerApi;
+import org.jclouds.logging.Logger;
+
+import javax.annotation.Resource;
+import javax.inject.Named;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataProperties.OPERATION_TIMEOUT;
+import static org.jclouds.util.Predicates2.retry;
+
+public class DimensionDataCloudControlComputeServiceContextModule extends 
AbstractModule {
+
+   @Resource
+   private Logger logger = Logger.NULL;
+
+   public static final String VLAN_DELETED_PREDICATE = 
"VLAN_DELETED_PREDICATE";
+   public static final String VLAN_NORMAL_PREDICATE = "VLAN_NORMAL_PREDICATE";
+   public static final String NETWORK_DOMAIN_DELETED_PREDICATE = 
"NETWORK_DOMAIN_DELETED_PREDICATE";
+   public static final String NETWORK_DOMAIN_NORMAL_PREDICATE = 
"NETWORK_DOMAIN_NORMAL_PREDICATE";
+   public static final String SERVER_STARTED_PREDICATE = 
"SERVER_STARTED_PREDICATE";
+   public static final String SERVER_STOPPED_PREDICATE = 
"SERVER_STOPPED_PREDICATE";
+   public static final String SERVER_DELETED_PREDICATE = 
"SERVER_DELETED_PREDICATE";
+   public static final String SERVER_NORMAL_PREDICATE = 
"SERVER_NORMAL_PREDICATE";
+   public static final String VM_TOOLS_RUNNING_PREDICATE = 
"VM_TOOLS_RUNNING_PREDICATE";
+
+   @Override
+   protected void configure() {
+
+   }
+
+   @Provides
+   @Named(VLAN_DELETED_PREDICATE)
+   protected Predicate<String> provideVlanDeletedPredicate(final 
DimensionDataCloudControlApi api,
+         @Named(OPERATION_TIMEOUT) final Long operationTimeout, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new VlanState(api.getNetworkApi(), State.DELETED), 
operationTimeout, pollPeriod.pollInitialPeriod,
+            pollPeriod.pollMaxPeriod);
+   }
+
+   @Provides
+   @Named(VLAN_NORMAL_PREDICATE)
+   protected Predicate<String> provideVlanNormalPredicate(final 
DimensionDataCloudControlApi api,
+         @Named(OPERATION_TIMEOUT) final Long operationTimeout, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new VlanState(api.getNetworkApi(), State.NORMAL), 
operationTimeout, pollPeriod.pollInitialPeriod,
+            pollPeriod.pollMaxPeriod);
+   }
+
+   @Provides
+   @Named(NETWORK_DOMAIN_DELETED_PREDICATE)
+   protected Predicate<String> provideNetworkDomainDeletedPredicate(final 
DimensionDataCloudControlApi api,
+         @Named(OPERATION_TIMEOUT) final Long operationTimeout, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new NetworkDomainState(api.getNetworkApi(), State.DELETED), 
operationTimeout,
+            pollPeriod.pollInitialPeriod, pollPeriod.pollMaxPeriod);
+   }
+
+   @Provides
+   @Named(NETWORK_DOMAIN_NORMAL_PREDICATE)
+   protected Predicate<String> provideNetworkDomainNormalPredicate(final 
DimensionDataCloudControlApi api,
+         @Named(OPERATION_TIMEOUT) final Long operationTimeout, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new NetworkDomainState(api.getNetworkApi(), State.NORMAL), 
operationTimeout,
+            pollPeriod.pollInitialPeriod, pollPeriod.pollMaxPeriod);
+   }
+
+   @Provides
+   @Named(SERVER_STARTED_PREDICATE)
+   protected Predicate<String> provideServerStartedPredicate(final 
DimensionDataCloudControlApi api,
+         final ComputeServiceConstants.Timeouts timeouts, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new ServerStatus(api.getServerApi(), true, true), 
timeouts.nodeRunning, pollPeriod.pollInitialPeriod,
+            pollPeriod.pollMaxPeriod);
+   }
+
+   @Provides
+   @Named(SERVER_STOPPED_PREDICATE)
+   @VisibleForTesting
+   public Predicate<String> provideServerStoppedPredicate(final 
DimensionDataCloudControlApi api,
+         final ComputeServiceConstants.Timeouts timeouts, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new ServerStatus(api.getServerApi(), false, true), 
timeouts.nodeSuspended,
+            pollPeriod.pollInitialPeriod, pollPeriod.pollMaxPeriod);
+   }
+
+   @Provides
+   @Named(SERVER_DELETED_PREDICATE)
+   @VisibleForTesting
+   public Predicate<String> provideServerDeletedPredicate(final 
DimensionDataCloudControlApi api,
+         final ComputeServiceConstants.Timeouts timeouts, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new ServerState(api.getServerApi(), State.DELETED), 
timeouts.nodeTerminated,
+            pollPeriod.pollInitialPeriod, pollPeriod.pollMaxPeriod);
+   }
+
+   @Provides
+   @Named(SERVER_NORMAL_PREDICATE)
+   protected Predicate<String> provideServerNormalPredicate(final 
DimensionDataCloudControlApi api,
+         final ComputeServiceConstants.Timeouts timeouts, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new ServerState(api.getServerApi(), State.NORMAL), 
timeouts.nodeRunning,
+            pollPeriod.pollInitialPeriod, pollPeriod.pollMaxPeriod);
+   }
+
+   @Provides
+   @Named(VM_TOOLS_RUNNING_PREDICATE)
+   protected Predicate<String> provideVMToolsRunningPredicate(final 
DimensionDataCloudControlApi api,
+         @Named(OPERATION_TIMEOUT) final Long operationTimeout, final 
ComputeServiceConstants.PollPeriod pollPeriod) {
+      return retry(new VMToolsRunningStatus(api.getServerApi()), 
operationTimeout, pollPeriod.pollInitialPeriod,
+            pollPeriod.pollMaxPeriod);
+   }
+
+   private class VlanState implements Predicate<String> {
+
+      private final State state;
+      private final NetworkApi networkApi;
+
+      private VlanState(final NetworkApi networkApi, final State state) {
+         this.networkApi = networkApi;
+         this.state = state;
+      }
+
+      @Override
+      public boolean apply(final String vlanId) {
+         checkNotNull(vlanId, "vlanId");
+         logger.trace("looking for state on vlan %s", vlanId);
+         final Vlan vlan = networkApi.getVlan(vlanId);
+         final boolean isDeleted = (vlan == null) && (state == State.DELETED);
+         return isDeleted || ((vlan != null) && vlan.state() == state);
+      }
+   }
+
+   private class NetworkDomainState implements Predicate<String> {
+
+      private final State state;
+      private final NetworkApi networkApi;
+
+      private NetworkDomainState(final NetworkApi networkApi, final State 
state) {
+         this.networkApi = networkApi;
+         this.state = state;
+      }
+
+      @Override
+      public boolean apply(final String networkDomainId) {
+         checkNotNull(networkDomainId, "networkDomainId");
+         logger.trace("looking for state on network domain %s", 
networkDomainId);
+         final NetworkDomain networkDomain = 
networkApi.getNetworkDomain(networkDomainId);
+         final boolean isDeleted = networkDomain == null && state == 
State.DELETED;
+         return isDeleted || (networkDomain != null && networkDomain.state() 
== state);
+      }
+   }
+
+   private class ServerStatus implements Predicate<String> {
+
+      private final ServerApi api;
+      private final boolean started;
+      private final boolean deployed;
+
+      private ServerStatus(final ServerApi api, final boolean started, final 
boolean deployed) {
+         this.api = api;
+         this.started = started;
+         this.deployed = deployed;
+      }
+
+      @Override
+      public boolean apply(final String serverId) {
+         checkNotNull(serverId, "serverId");
+         logger.trace("looking for start status on Server %s", serverId);
+         final Server server = api.getServer(serverId);
+
+         // perhaps request isn't available, yet
+         if (server == null)
+            return false;
+         logger.trace("Looking for Server %s to be started: %s currently: %s", 
server.id(), started, server.started());
+         if (server.state().isFailed()) {
+            throw new IllegalStateException(String.format("Server %s is in 
FAILED state", server.id()));
+         }
+         return server.started() == started && server.deployed() == deployed;
+      }
+   }
+
+   private class ServerState implements Predicate<String> {
+
+      private final ServerApi api;
+      private final State state;
+
+      private ServerState(final ServerApi api, final State state) {
+         this.api = api;
+         this.state = state;
+      }
+
+      @Override
+      public boolean apply(final String serverId) {
+         checkNotNull(serverId, "serverId");
+         logger.trace("looking for state on Server %s", serverId);
+         final Server server = api.getServer(serverId);
+
+         if (server == null && state == State.DELETED) {
+            return true;
+         }
+
+         if (server.state().isFailed()) {
+            throw new IllegalStateException(String.format("Server %s is in 
FAILED state", server.id()));
+         } else {
+            return server.state() == state;
+         }
+      }
+   }
+
+   private class VMToolsRunningStatus implements Predicate<String> {
+
+      private final ServerApi api;
+
+      private VMToolsRunningStatus(final ServerApi api) {
+         this.api = api;
+      }
+
+      @Override
+      public boolean apply(final String serverId) {
+         checkNotNull(serverId, "serverId");
+         logger.trace("looking for guest tools state on Server %s", serverId);
+         final Server server = api.getServer(serverId);
+         if (server == null) {
+            throw new IllegalStateException(String.format("Server %s is not 
found", serverId));
+         }
+         final VmTools vmTools = server.guest().vmTools();
+         return vmTools != null && vmTools.runningStatus() == 
VmTools.RunningStatus.RUNNING;
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataProperties.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataProperties.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataProperties.java
new file mode 100644
index 0000000..6ca97fc
--- /dev/null
+++ 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataProperties.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.dimensiondata.cloudcontrol.config;
+
+/**
+ * Configuration properties and constants used in Dimension Data Cloud Control 
connections.
+ */
+public class DimensionDataProperties {
+
+   public static final String OPERATION_TIMEOUT = 
"jclouds.dimensiondata.cloudcontrol.operation.timeout";
+}
+

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/NetworkDomainState.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/NetworkDomainState.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/NetworkDomainState.java
deleted file mode 100644
index 5741b32..0000000
--- 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/NetworkDomainState.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.dimensiondata.cloudcontrol.predicates;
-
-import com.google.common.base.Predicate;
-import org.jclouds.dimensiondata.cloudcontrol.domain.NetworkDomain;
-import org.jclouds.dimensiondata.cloudcontrol.domain.State;
-import org.jclouds.dimensiondata.cloudcontrol.features.NetworkApi;
-import org.jclouds.logging.Logger;
-
-import javax.annotation.Resource;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public class NetworkDomainState implements Predicate<String> {
-
-   @Resource
-   protected Logger logger = Logger.NULL;
-
-   private final State state;
-   private final NetworkApi networkApi;
-
-   public NetworkDomainState(NetworkApi networkApi, State state) {
-      this.networkApi = networkApi;
-      this.state = state;
-   }
-
-   @Override
-   public boolean apply(String networkDomainId) {
-      checkNotNull(networkDomainId, "networkDomainId");
-      logger.trace("looking for state on network domain %s", networkDomainId);
-      final NetworkDomain networkDomain = 
networkApi.getNetworkDomain(networkDomainId);
-      final boolean isDeleted = networkDomain == null && state == 
State.DELETED;
-      return isDeleted || (networkDomain != null && networkDomain.state() == 
state);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/ServerState.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/ServerState.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/ServerState.java
deleted file mode 100644
index 232a30b..0000000
--- 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/ServerState.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.dimensiondata.cloudcontrol.predicates;
-
-import com.google.common.base.Predicate;
-import org.jclouds.dimensiondata.cloudcontrol.domain.Server;
-import org.jclouds.dimensiondata.cloudcontrol.domain.State;
-import org.jclouds.dimensiondata.cloudcontrol.features.ServerApi;
-import org.jclouds.logging.Logger;
-
-import javax.annotation.Resource;
-import java.text.MessageFormat;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public class ServerState implements Predicate<String> {
-
-   @Resource
-   protected Logger logger = Logger.NULL;
-   private final ServerApi api;
-   private final State state;
-
-   public ServerState(ServerApi api, State state) {
-      this.api = api;
-      this.state = state;
-   }
-
-   @Override
-   public boolean apply(String serverId) {
-      checkNotNull(serverId, "serverId");
-      logger.trace("looking for state on Server %s", serverId);
-      final Server server = api.getServer(serverId);
-
-      if (server == null && state == State.DELETED) {
-         return true;
-      }
-
-      if (server.state().isFailed()) {
-         throw new IllegalStateException(MessageFormat.format("Server {0} is 
in FAILED state", server.id()));
-      } else {
-         return server.state().equals(state);
-      }
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/ServerStatus.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/ServerStatus.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/ServerStatus.java
deleted file mode 100644
index 96e6f4f..0000000
--- 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/ServerStatus.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.dimensiondata.cloudcontrol.predicates;
-
-import com.google.common.base.Predicate;
-import org.jclouds.dimensiondata.cloudcontrol.domain.Server;
-import org.jclouds.dimensiondata.cloudcontrol.features.ServerApi;
-import org.jclouds.logging.Logger;
-
-import javax.annotation.Resource;
-import java.text.MessageFormat;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public class ServerStatus implements Predicate<String> {
-
-   @Resource
-   protected Logger logger = Logger.NULL;
-   private final ServerApi api;
-   private final boolean started;
-   private final boolean deployed;
-
-   public ServerStatus(ServerApi api, boolean started, boolean deployed) {
-      this.api = api;
-      this.started = started;
-      this.deployed = deployed;
-   }
-
-   @Override
-   public boolean apply(String serverId) {
-      checkNotNull(serverId, "serverId");
-      logger.trace("looking for state on Server %s", serverId);
-      final Server server = api.getServer(serverId);
-
-      // perhaps request isn't available, yet
-      if (server == null)
-         return false;
-      logger.trace("%s: looking for server %s deployed: currently: %s", 
server, server.state());
-      if (server.state().isFailed()) {
-         throw new IllegalStateException(MessageFormat.format("Server {0} is 
in FAILED state", server.id()));
-      }
-      return server.started() == started && server.deployed() == deployed;
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/VMToolsRunningStatus.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/VMToolsRunningStatus.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/VMToolsRunningStatus.java
deleted file mode 100644
index 2875a0e..0000000
--- 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/VMToolsRunningStatus.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.dimensiondata.cloudcontrol.predicates;
-
-import com.google.common.base.Predicate;
-import org.jclouds.dimensiondata.cloudcontrol.domain.Server;
-import org.jclouds.dimensiondata.cloudcontrol.domain.VmTools;
-import org.jclouds.dimensiondata.cloudcontrol.features.ServerApi;
-import org.jclouds.logging.Logger;
-
-import javax.annotation.Resource;
-import java.text.MessageFormat;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public class VMToolsRunningStatus implements Predicate<String> {
-
-   @Resource
-   protected Logger logger = Logger.NULL;
-   private final ServerApi api;
-
-   public VMToolsRunningStatus(ServerApi api) {
-      this.api = api;
-   }
-
-   @Override
-   public boolean apply(String serverId) {
-      checkNotNull(serverId, "serverId");
-      logger.trace("looking for state on Server %s", serverId);
-      final Server server = api.getServer(serverId);
-      if (server == null) {
-         throw new IllegalStateException(MessageFormat.format("Server {0} is 
not found", serverId));
-      }
-      final VmTools vmTools = server.guest().vmTools();
-      return vmTools != null && 
vmTools.runningStatus().equals(VmTools.RunningStatus.RUNNING);
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/VlanState.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/VlanState.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/VlanState.java
deleted file mode 100644
index 119e2d6..0000000
--- 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/predicates/VlanState.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.dimensiondata.cloudcontrol.predicates;
-
-import com.google.common.base.Predicate;
-import org.jclouds.dimensiondata.cloudcontrol.domain.State;
-import org.jclouds.dimensiondata.cloudcontrol.domain.Vlan;
-import org.jclouds.dimensiondata.cloudcontrol.features.NetworkApi;
-import org.jclouds.logging.Logger;
-
-import javax.annotation.Resource;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public class VlanState implements Predicate<String> {
-
-   @Resource
-   protected Logger logger = Logger.NULL;
-
-   private final State state;
-   private final NetworkApi networkApi;
-
-   public VlanState(NetworkApi networkApi, State state) {
-      this.networkApi = networkApi;
-      this.state = state;
-   }
-
-   @Override
-   public boolean apply(String vlanId) {
-      checkNotNull(vlanId, "vlanId");
-      logger.trace("looking for state on vlan %s", vlanId);
-      final Vlan vlan = networkApi.getVlan(vlanId);
-      final boolean isDeleted = (vlan == null) && (state == State.DELETED);
-      return isDeleted || ((vlan != null) && vlan.state() == state);
-
-   }
-}
-

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/utils/DimensionDataCloudControlResponseUtils.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/utils/DimensionDataCloudControlResponseUtils.java
 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/utils/DimensionDataCloudControlResponseUtils.java
index a339d5d..5072560 100644
--- 
a/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/utils/DimensionDataCloudControlResponseUtils.java
+++ 
b/dimensiondata/src/main/java/org/jclouds/dimensiondata/cloudcontrol/utils/DimensionDataCloudControlResponseUtils.java
@@ -16,17 +16,6 @@
  */
 package org.jclouds.dimensiondata.cloudcontrol.utils;
 
-import org.jclouds.dimensiondata.cloudcontrol.domain.State;
-import org.jclouds.dimensiondata.cloudcontrol.features.NetworkApi;
-import org.jclouds.dimensiondata.cloudcontrol.features.ServerApi;
-import org.jclouds.dimensiondata.cloudcontrol.predicates.NetworkDomainState;
-import org.jclouds.dimensiondata.cloudcontrol.predicates.ServerState;
-import org.jclouds.dimensiondata.cloudcontrol.predicates.ServerStatus;
-import org.jclouds.dimensiondata.cloudcontrol.predicates.VMToolsRunningStatus;
-import org.jclouds.dimensiondata.cloudcontrol.predicates.VlanState;
-
-import static org.jclouds.util.Predicates2.retry;
-
 public class DimensionDataCloudControlResponseUtils {
 
    private static String convertServerId(String serverId) {
@@ -36,42 +25,4 @@ public class DimensionDataCloudControlResponseUtils {
    public static String generateFirewallRuleName(String serverId) {
       return String.format("fw.%s", convertServerId(serverId));
    }
-
-   public static void waitForNetworkDomainState(NetworkApi api, String 
networkDomainId, State state, long timeoutMillis,
-         String message) {
-      boolean isNetworkDomainInState = retry(new NetworkDomainState(api, 
state), timeoutMillis).apply(networkDomainId);
-      if (!isNetworkDomainInState) {
-         throw new IllegalStateException(message);
-      }
-   }
-
-   public static void waitForVlanState(NetworkApi api, String vlanId, State 
state, long timeoutMillis, String message) {
-      boolean isVlanInState = retry(new VlanState(api, state), 
timeoutMillis).apply(vlanId);
-      if (!isVlanInState) {
-         throw new IllegalStateException(message);
-      }
-   }
-
-   public static void waitForServerState(ServerApi api, String serverId, State 
state, long timeoutMillis,
-         String message) {
-      boolean isServerInState = retry(new ServerState(api, state), 
timeoutMillis).apply(serverId);
-      if (!isServerInState) {
-         throw new IllegalStateException(message);
-      }
-   }
-
-   public static void waitForServerStatus(ServerApi api, String serverId, 
boolean started, boolean deployed,
-         long timeoutMillis, String message) {
-      boolean serverHasStatus = retry(new ServerStatus(api, started, 
deployed), timeoutMillis).apply(serverId);
-      if (!serverHasStatus) {
-         throw new IllegalStateException(message);
-      }
-   }
-
-   public static void waitForVmToolsRunning(ServerApi api, String serverId, 
long timeoutMillis, String message) {
-      boolean vmwareToolsRunning = retry(new VMToolsRunningStatus(api), 
timeoutMillis).apply(serverId);
-      if (!vmwareToolsRunning) {
-         throw new IllegalStateException(message);
-      }
-   }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServerTest.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServerTest.java
 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServerTest.java
index 802707d..b535743 100644
--- 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServerTest.java
+++ 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/compute/functions/CleanupServerTest.java
@@ -16,12 +16,14 @@
  */
 package org.jclouds.dimensiondata.cloudcontrol.compute.functions;
 
+import com.google.common.base.Predicate;
 import com.google.common.collect.Lists;
 import org.easymock.EasyMock;
 import org.jclouds.collect.IterableWithMarkers;
 import org.jclouds.collect.PagedIterables;
 import org.jclouds.compute.reference.ComputeServiceConstants;
 import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi;
+import 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule;
 import org.jclouds.dimensiondata.cloudcontrol.domain.CPU;
 import org.jclouds.dimensiondata.cloudcontrol.domain.CpuSpeed;
 import org.jclouds.dimensiondata.cloudcontrol.domain.FirewallRule;
@@ -63,13 +65,18 @@ public class CleanupServerTest {
    private NatRule.Builder natRuleBuilder;
    private PublicIpBlock.Builder publicIpBlockBuilder;
    private FirewallRule.Builder firewallRuleBuilder;
+   private DimensionDataCloudControlComputeServiceContextModule contextModule;
 
    @BeforeMethod
+
    public void setUp() throws Exception {
       serverApi = EasyMock.createMock(ServerApi.class);
       networkApi = EasyMock.createMock(NetworkApi.class);
+
       api = EasyMock.createMock(DimensionDataCloudControlApi.class);
 
+      contextModule = new 
DimensionDataCloudControlComputeServiceContextModule();
+
       internalIp = "172.0.0.1";
       final String datacenterId = "EU10";
       serverBuilder = Server.builder().id(serverId).name("jclouds 
server").memoryGb(10)
@@ -119,7 +126,14 @@ public class CleanupServerTest {
 
    private void applyAndAssertDeleted() {
       replay(serverApi, networkApi, api);
-      cleanupServer = new CleanupServer(api, new 
ComputeServiceConstants.Timeouts());
+      Predicate<String> serverStoppedPredicate = contextModule
+            .provideServerStoppedPredicate(api, new 
ComputeServiceConstants.Timeouts(),
+                  new ComputeServiceConstants.PollPeriod());
+      Predicate<String> serverDeletedPredicate = contextModule
+            .provideServerDeletedPredicate(api, new 
ComputeServiceConstants.Timeouts(),
+                  new ComputeServiceConstants.PollPeriod());
+      cleanupServer = new CleanupServer(api, new 
ComputeServiceConstants.Timeouts(), serverStoppedPredicate,
+            serverDeletedPredicate);
       assertTrue(cleanupServer.apply(serverId));
    }
 
@@ -128,7 +142,14 @@ public class CleanupServerTest {
       final Server server = serverBuilder.state(State.FAILED_ADD).build();
       loadServerExpectations(server);
       replay(api, serverApi, networkApi);
-      cleanupServer = new CleanupServer(api, new 
ComputeServiceConstants.Timeouts());
+      Predicate<String> serverStoppedPredicate = contextModule
+            .provideServerStoppedPredicate(api, new 
ComputeServiceConstants.Timeouts(),
+                  new ComputeServiceConstants.PollPeriod());
+      Predicate<String> serverDeletedPredicate = contextModule
+            .provideServerDeletedPredicate(api, new 
ComputeServiceConstants.Timeouts(),
+                  new ComputeServiceConstants.PollPeriod());
+      cleanupServer = new CleanupServer(api, new 
ComputeServiceConstants.Timeouts(), serverStoppedPredicate,
+            serverDeletedPredicate);
       applyWithExpectedErrorMessage("Server(serverId) not deleted as it is in 
state(FailedAdd).");
    }
 
@@ -210,7 +231,7 @@ public class CleanupServerTest {
    }
 
    private void loadServerExpectations(Server server) {
-      expect(api.getServerApi()).andReturn(serverApi);
+      expect(api.getServerApi()).andReturn(serverApi).anyTimes();
       expect(serverApi.getServer(serverId)).andReturn(server);
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataCloudControlComputeServiceContextModule.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataCloudControlComputeServiceContextModule.java
 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataCloudControlComputeServiceContextModule.java
deleted file mode 100644
index 8866a44..0000000
--- 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/config/DimensionDataCloudControlComputeServiceContextModule.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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.dimensiondata.cloudcontrol.config;
-
-import com.google.common.base.Function;
-import com.google.inject.TypeLiteral;
-import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.OsFamily;
-import 
org.jclouds.dimensiondata.cloudcontrol.compute.functions.BaseImageToImage;
-import 
org.jclouds.dimensiondata.cloudcontrol.compute.functions.OperatingSystemToOsFamily;
-import org.jclouds.dimensiondata.cloudcontrol.domain.BaseImage;
-import org.jclouds.dimensiondata.cloudcontrol.domain.Datacenter;
-import org.jclouds.dimensiondata.cloudcontrol.domain.OperatingSystem;
-import 
org.jclouds.dimensiondata.cloudcontrol.domain.internal.ServerWithExternalIp;
-
-public class DimensionDataCloudControlComputeServiceContextModule
-      extends ComputeServiceAdapterContextModule<ServerWithExternalIp, 
BaseImage, BaseImage, Datacenter> {
-
-   @Override
-   protected void configure() {
-      super.configure();
-
-      bind(new TypeLiteral<Function<BaseImage, Image>>() {
-      }).to(BaseImageToImage.class);
-      bind(new TypeLiteral<Function<OperatingSystem, OsFamily>>() {
-      }).to(OperatingSystemToOsFamily.class);
-
-   }
-
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/NetworkApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/NetworkApiLiveTest.java
 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/NetworkApiLiveTest.java
index 735f1bc..1d7f427 100644
--- 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/NetworkApiLiveTest.java
+++ 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/NetworkApiLiveTest.java
@@ -21,7 +21,6 @@ import com.google.common.collect.Lists;
 import org.jclouds.dimensiondata.cloudcontrol.domain.FirewallRuleTarget;
 import org.jclouds.dimensiondata.cloudcontrol.domain.IpRange;
 import org.jclouds.dimensiondata.cloudcontrol.domain.Placement;
-import org.jclouds.dimensiondata.cloudcontrol.domain.State;
 import 
org.jclouds.dimensiondata.cloudcontrol.internal.BaseDimensionDataCloudControlApiLiveTest;
 import org.jclouds.rest.ResourceAlreadyExistsException;
 import org.testng.annotations.AfterClass;
@@ -33,9 +32,8 @@ import java.util.List;
 import static 
org.jclouds.dimensiondata.cloudcontrol.features.NetworkApiMockTest.DEFAULT_ACTION;
 import static 
org.jclouds.dimensiondata.cloudcontrol.features.NetworkApiMockTest.DEFAULT_IP_VERSION;
 import static 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.generateFirewallRuleName;
-import static 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.waitForNetworkDomainState;
-import static 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.waitForVlanState;
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
 
 @Test(groups = "live", testName = "NetworkApiLiveTest", singleThreaded = true)
 public class NetworkApiLiveTest extends 
BaseDimensionDataCloudControlApiLiveTest {
@@ -77,7 +75,7 @@ public class NetworkApiLiveTest extends 
BaseDimensionDataCloudControlApiLiveTest
             NetworkApiLiveTest.class.getSimpleName(), 
DEFAULT_PRIVATE_IPV4_BASE_ADDRESS,
             DEFAULT_PRIVATE_IPV4_PREFIX_SIZE);
       assertNotNull(vlanId);
-      waitForVlanState(api(), vlanId, State.NORMAL, 30 * 60 * 1000, "Error - 
unable to deploy vlan");
+      assertTrue(vlanNormalPredicate.apply(vlanId), "vlan is not in a NORMAL 
state after timeout");
    }
 
    @Test
@@ -86,8 +84,8 @@ public class NetworkApiLiveTest extends 
BaseDimensionDataCloudControlApiLiveTest
       networkDomainId = api()
             .deployNetworkDomain(DATACENTER, networkDomainName, 
NetworkApiLiveTest.class.getSimpleName(), "ESSENTIALS");
       assertNotNull(networkDomainId);
-      waitForNetworkDomainState(api(), networkDomainId, State.NORMAL, 30 * 60 
* 1000,
-            "Error - unable to deploy network domain");
+      assertTrue(networkDomainNormalPredicate.apply(networkDomainId),
+            "network domain is not in a NORMAL state after timeout");
    }
 
    @Test(expectedExceptions = ResourceAlreadyExistsException.class)
@@ -108,12 +106,12 @@ public class NetworkApiLiveTest extends 
BaseDimensionDataCloudControlApiLiveTest
       }
       if (vlanId != null) {
          api().deleteVlan(vlanId);
-         waitForVlanState(api(), vlanId, State.DELETED, 30 * 60 * 1000, "Error 
deleting vlan");
+         assertTrue(vlanDeletedPredicate.apply(vlanId), "vlan is not in a 
DELETED state after timeout");
       }
       if (networkDomainId != null) {
          api().deleteNetworkDomain(networkDomainId);
-         waitForNetworkDomainState(api(), networkDomainId, State.DELETED, 30 * 
60 * 1000,
-               "Error deleting network domain");
+         assertTrue(networkDomainDeletedPredicate.apply(networkDomainId),
+               "network domain is not in a DELETED state after timeout");
       }
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/ServerApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/ServerApiLiveTest.java
 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/ServerApiLiveTest.java
index c8de243..e30f92c 100644
--- 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/ServerApiLiveTest.java
+++ 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/features/ServerApiLiveTest.java
@@ -23,7 +23,6 @@ import org.jclouds.dimensiondata.cloudcontrol.domain.Disk;
 import org.jclouds.dimensiondata.cloudcontrol.domain.NIC;
 import org.jclouds.dimensiondata.cloudcontrol.domain.NetworkInfo;
 import org.jclouds.dimensiondata.cloudcontrol.domain.Server;
-import org.jclouds.dimensiondata.cloudcontrol.domain.State;
 import 
org.jclouds.dimensiondata.cloudcontrol.domain.options.CloneServerOptions;
 import 
org.jclouds.dimensiondata.cloudcontrol.internal.BaseDimensionDataCloudControlApiLiveTest;
 import org.testng.annotations.AfterClass;
@@ -31,9 +30,6 @@ import org.testng.annotations.Test;
 
 import java.util.List;
 
-import static 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.waitForServerState;
-import static 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.waitForServerStatus;
-import static 
org.jclouds.dimensiondata.cloudcontrol.utils.DimensionDataCloudControlResponseUtils.waitForVmToolsRunning;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
@@ -66,40 +62,40 @@ public class ServerApiLiveTest extends 
BaseDimensionDataCloudControlApiLiveTest
       List<Disk> disks = 
ImmutableList.of(Disk.builder().scsiId(0).speed("STANDARD").build());
       serverId = api().deployServer(deployedServerName, IMAGE_ID, started, 
networkInfo, "P$$ssWwrrdGoDd!", disks, null);
       assertNotNull(serverId);
-      waitForServerStatus(api(), serverId, true, true, 30 * 60 * 1000, 
"Error");
-      waitForServerState(api(), serverId, State.NORMAL, 30 * 60 * 1000, 
"Error");
+      assertTrue(serverStartedPredicate.apply(serverId), "server did not start 
after timeout");
+      assertTrue(serverNormalPredicate.apply(serverId), "server was not NORMAL 
after timeout");
    }
 
    @Test(dependsOnMethods = "testDeployAndStartServer")
    public void testReconfigureServer() {
       api().reconfigureServer(serverId, 4, CpuSpeed.HIGHPERFORMANCE.name(), 1);
-      waitForServerState(api(), serverId, State.NORMAL, 30 * 60 * 1000, 
"Error");
+      assertTrue(serverNormalPredicate.apply(serverId), "server was not NORMAL 
after timeout");
    }
 
    @Test(dependsOnMethods = "testDeployAndStartServer")
    public void testRebootServer() {
       api().rebootServer(serverId);
-      waitForServerState(api(), serverId, State.NORMAL, 30 * 60 * 1000, 
"Error");
-      waitForVmToolsRunning(api(), serverId, 30 * 60 * 1000, "Error");
+      assertTrue(serverNormalPredicate.apply(serverId), "server was not NORMAL 
after timeout");
+      assertTrue(vmtoolsRunningPredicate.apply(serverId), "server vm tools not 
running after timeout");
    }
 
    @Test(dependsOnMethods = "testRebootServer")
    public void testPowerOffServer() {
       api().powerOffServer(serverId);
-      waitForServerStatus(api(), serverId, false, true, 30 * 60 * 1000, 
"Error");
+      assertTrue(serverStoppedPredicate.apply(serverId), "server did not power 
off after timeout");
    }
 
    @Test(dependsOnMethods = "testPowerOffServer")
    public void testStartServer() {
       api().startServer(serverId);
-      waitForServerStatus(api(), serverId, true, true, 30 * 60 * 1000, 
"Error");
-      waitForVmToolsRunning(api(), serverId, 30 * 60 * 1000, "Error");
+      assertTrue(serverStartedPredicate.apply(serverId), "server did not start 
after timeout");
+      assertTrue(vmtoolsRunningPredicate.apply(serverId), "server vm tools not 
running after timeout");
    }
 
    @Test(dependsOnMethods = "testStartServer")
    public void testShutdownServer() {
       api().shutdownServer(serverId);
-      waitForServerStatus(api(), serverId, false, true, 30 * 60 * 1000, 
"Error");
+      assertTrue(serverStoppedPredicate.apply(serverId), "server did not 
shutdown after timeout");
    }
 
    @Test(dependsOnMethods = "testShutdownServer")
@@ -108,14 +104,14 @@ public class ServerApiLiveTest extends 
BaseDimensionDataCloudControlApiLiveTest
             .guestOsCustomization(false).build();
       cloneImageId = api().cloneServer(serverId, "ServerApiLiveTest-" + 
System.currentTimeMillis(), options);
       assertNotNull(cloneImageId);
-      waitForServerState(api(), serverId, State.NORMAL, 30 * 60 * 1000, 
"Error");
+      assertTrue(serverNormalPredicate.apply(serverId), "server was not NORMAL 
after timeout");
    }
 
    @AfterClass(alwaysRun = true)
    public void testDeleteServer() {
       if (serverId != null) {
          api().deleteServer(serverId);
-         waitForServerState(api(), serverId, State.DELETED, 30 * 60 * 1000, 
"Error");
+         assertTrue(serverDeletedPredicate.apply(serverId), "server was not 
DELETED after timeout");
       }
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/bf34887e/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/internal/BaseDimensionDataCloudControlApiLiveTest.java
----------------------------------------------------------------------
diff --git 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/internal/BaseDimensionDataCloudControlApiLiveTest.java
 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/internal/BaseDimensionDataCloudControlApiLiveTest.java
index 06ccb65..affbe16 100644
--- 
a/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/internal/BaseDimensionDataCloudControlApiLiveTest.java
+++ 
b/dimensiondata/src/test/java/org/jclouds/dimensiondata/cloudcontrol/internal/BaseDimensionDataCloudControlApiLiveTest.java
@@ -16,6 +16,12 @@
  */
 package org.jclouds.dimensiondata.cloudcontrol.internal;
 
+import com.google.common.base.Predicate;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Module;
+import com.google.inject.TypeLiteral;
+import com.google.inject.name.Names;
 import org.jclouds.apis.ApiMetadata;
 import org.jclouds.apis.BaseApiLiveTest;
 import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi;
@@ -24,6 +30,18 @@ import org.jclouds.logging.config.LoggingModule;
 import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
 import org.testng.annotations.Test;
 
+import java.util.Properties;
+
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.NETWORK_DOMAIN_DELETED_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.NETWORK_DOMAIN_NORMAL_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.SERVER_DELETED_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.SERVER_NORMAL_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.SERVER_STARTED_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.SERVER_STOPPED_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.VLAN_DELETED_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.VLAN_NORMAL_PREDICATE;
+import static 
org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.VM_TOOLS_RUNNING_PREDICATE;
+
 @Test(groups = "live")
 public class BaseDimensionDataCloudControlApiLiveTest extends 
BaseApiLiveTest<DimensionDataCloudControlApi> {
 
@@ -34,6 +52,16 @@ public class BaseDimensionDataCloudControlApiLiveTest 
extends BaseApiLiveTest<Di
    protected static final String DATACENTER = System.getProperty("datacenter", 
"NW20-EPC-LAB04");
    protected static final String SERVER_ID = System.getProperty("serverId", 
"b1c537bb-018c-49ba-beef-e0600e948149");
 
+   protected Predicate<String> vlanDeletedPredicate;
+   protected Predicate<String> vlanNormalPredicate;
+   protected Predicate<String> networkDomainDeletedPredicate;
+   protected Predicate<String> networkDomainNormalPredicate;
+   protected Predicate<String> serverStoppedPredicate;
+   protected Predicate<String> serverStartedPredicate;
+   protected Predicate<String> serverDeletedPredicate;
+   protected Predicate<String> serverNormalPredicate;
+   protected Predicate<String> vmtoolsRunningPredicate;
+
    public BaseDimensionDataCloudControlApiLiveTest() {
       provider = "dimensiondata-cloudcontrol";
    }
@@ -48,4 +76,29 @@ public class BaseDimensionDataCloudControlApiLiveTest 
extends BaseApiLiveTest<Di
       return new SLF4JLoggingModule();
    }
 
+   @Override
+   protected DimensionDataCloudControlApi create(Properties props, 
Iterable<Module> modules) {
+      Injector injector = 
newBuilder().modules(modules).overrides(props).buildInjector();
+      vlanDeletedPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(VLAN_DELETED_PREDICATE)));
+      vlanNormalPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(VLAN_NORMAL_PREDICATE)));
+      networkDomainDeletedPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(NETWORK_DOMAIN_DELETED_PREDICATE)));
+      networkDomainNormalPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(NETWORK_DOMAIN_NORMAL_PREDICATE)));
+      serverStartedPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(SERVER_STARTED_PREDICATE)));
+      serverStoppedPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(SERVER_STOPPED_PREDICATE)));
+      serverDeletedPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(SERVER_DELETED_PREDICATE)));
+      serverNormalPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(SERVER_NORMAL_PREDICATE)));
+      vmtoolsRunningPredicate = injector.getInstance(Key.get(new 
TypeLiteral<Predicate<String>>() {
+      }, Names.named(VM_TOOLS_RUNNING_PREDICATE)));
+
+      return injector.getInstance(DimensionDataCloudControlApi.class);
+   }
+
 }

Reply via email to