Skip to content
Permalink
Browse files
JCLOUDS-1492 Dimension Data Feature API Predicates are not usable (#1)
  • Loading branch information
trevorflanagan authored and nacx committed Apr 1, 2019
1 parent aad98e6 commit d7d37d6b7cd53a3f465cc55d68ce7590d074343a
Showing 7 changed files with 78 additions and 112 deletions.
@@ -16,6 +16,8 @@
*/
package org.jclouds.dimensiondata.cloudcontrol;

import com.google.common.base.Predicate;
import com.google.inject.Provides;
import org.jclouds.dimensiondata.cloudcontrol.features.AccountApi;
import org.jclouds.dimensiondata.cloudcontrol.features.CustomerImageApi;
import org.jclouds.dimensiondata.cloudcontrol.features.InfrastructureApi;
@@ -25,8 +27,20 @@
import org.jclouds.dimensiondata.cloudcontrol.features.TagApi;
import org.jclouds.rest.annotations.Delegate;

import javax.inject.Named;
import java.io.Closeable;

import static org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.CUSTOMER_IMAGE_DELETED_PREDICATE;
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;

public interface DimensionDataCloudControlApi extends Closeable {

@Delegate
@@ -49,4 +63,45 @@ public interface DimensionDataCloudControlApi extends Closeable {

@Delegate
CustomerImageApi getCustomerImageApi();

@Provides
@Named(VLAN_DELETED_PREDICATE)
Predicate<String> vlanDeletedPredicate();

@Provides
@Named(NETWORK_DOMAIN_DELETED_PREDICATE)
Predicate<String> networkDomainDeletedPredicate();

@Provides
@Named(NETWORK_DOMAIN_NORMAL_PREDICATE)
Predicate<String> networkDomainNormalPredicate();

@Provides
@Named(VLAN_NORMAL_PREDICATE)
Predicate<String> vlanNormalPredicate();

@Provides
@Named(SERVER_STOPPED_PREDICATE)
Predicate<String> serverStoppedPredicate();

@Provides
@Named(SERVER_DELETED_PREDICATE)
Predicate<String> serverDeletedPredicate();

@Provides
@Named(SERVER_STARTED_PREDICATE)
Predicate<String> serverStartedPredicate();

@Provides
@Named(SERVER_NORMAL_PREDICATE)
Predicate<String> serverNormalPredicate();

@Provides
@Named(VM_TOOLS_RUNNING_PREDICATE)
Predicate<String> vmToolsRunningPredicate();

@Provides
@Named(CUSTOMER_IMAGE_DELETED_PREDICATE)
Predicate<String> customerImageDeletedPredicate();

}
@@ -18,6 +18,7 @@

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;
@@ -31,6 +32,7 @@ public abstract class OsImage extends BaseImage {
type = TYPE;
}

@Nullable
public abstract String osImageKey();

@SerializedNames({ "id", "name", "description", "cluster", "guest", "datacenterId", "cpu", "memoryGb", "nic", "disk",
@@ -18,8 +18,6 @@

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import org.jclouds.Fallbacks;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
@@ -68,11 +66,6 @@
import javax.ws.rs.core.MediaType;
import java.util.List;

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.VLAN_DELETED_PREDICATE;
import static org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.VLAN_NORMAL_PREDICATE;

/**
* For examples of how to use this API please refer to https://jclouds.apache.org/guides/dimensiondata/
*/
@@ -308,22 +301,6 @@ String createPortList(@PayloadParam("networkDomainId") String networkDomainId, @
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
void deletePortList(@PayloadParam("id") String portListId);

@Provides
@Named(VLAN_DELETED_PREDICATE)
Predicate<String> vlanDeletedPredicate();

@Provides
@Named(NETWORK_DOMAIN_DELETED_PREDICATE)
Predicate<String> networkDomainDeletedPredicate();

@Provides
@Named(NETWORK_DOMAIN_NORMAL_PREDICATE)
Predicate<String> networkDomainNormalPredicate();

@Provides
@Named(VLAN_NORMAL_PREDICATE)
Predicate<String> vlanNormalPredicate();

@Singleton
final class ParseFirewallRules extends ParseJson<FirewallRules> {

@@ -18,8 +18,6 @@

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import org.jclouds.Fallbacks;
import org.jclouds.collect.IterableWithMarker;
@@ -61,11 +59,6 @@
import javax.ws.rs.core.MediaType;
import java.util.List;

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;

/**
* For examples of how to use this API please refer to https://jclouds.apache.org/guides/dimensiondata/
*/
@@ -180,22 +173,6 @@ String cloneServer(@PayloadParam("id") String id, @PayloadParam("imageName") Str
@MapBinder(BindToJsonPayload.class)
void shutdownServer(@PayloadParam("id") String id);

@Provides
@Named(SERVER_STOPPED_PREDICATE)
Predicate<String> serverStoppedPredicate();

@Provides
@Named(SERVER_DELETED_PREDICATE)
Predicate<String> serverDeletedPredicate();

@Provides
@Named(SERVER_STARTED_PREDICATE)
Predicate<String> serverStartedPredicate();

@Provides
@Named(SERVER_NORMAL_PREDICATE)
Predicate<String> serverNormalPredicate();

@Singleton
final class ParseServers extends ParseJson<Servers> {

@@ -101,7 +101,7 @@ public void testDeployVlan() {
NetworkApiLiveTest.class.getSimpleName() + new Date().getTime(), DEFAULT_PRIVATE_IPV4_BASE_ADDRESS,
DEFAULT_PRIVATE_IPV4_PREFIX_SIZE);
assertNotNull(vlanId);
assertTrue(vlanNormalPredicate.apply(vlanId), "vlan is not in a NORMAL state after timeout");
assertTrue(api.vlanNormalPredicate().apply(vlanId), "vlan is not in a NORMAL state after timeout");
}

@Test
@@ -110,7 +110,7 @@ public void testDeployNetworkDomain() {
networkDomainId = api().deployNetworkDomain(datacenters.iterator().next(), networkDomainName,
NetworkApiLiveTest.class.getSimpleName() + new Date().getTime() + "description", "ESSENTIALS");
assertNotNull(networkDomainId);
assertTrue(networkDomainNormalPredicate.apply(networkDomainId),
assertTrue(api.networkDomainNormalPredicate().apply(networkDomainId),
"network domain is not in a NORMAL state after timeout");
}

@@ -131,11 +131,11 @@ public void tearDown() {
}
if (vlanId != null) {
api().deleteVlan(vlanId);
assertTrue(vlanDeletedPredicate.apply(vlanId), "vlan is not in a DELETED state after timeout");
assertTrue(api.vlanDeletedPredicate().apply(vlanId), "vlan is not in a DELETED state after timeout");
}
if (networkDomainId != null) {
api().deleteNetworkDomain(networkDomainId);
assertTrue(networkDomainDeletedPredicate.apply(networkDomainId),
assertTrue(api.networkDomainDeletedPredicate().apply(networkDomainId),
"network domain is not in a DELETED state after timeout");
}
}
@@ -95,14 +95,14 @@ public void testDeployAndStartServer() {
serverId = api.getServerApi()
.deployServer(deployedServerName, imageId, started, networkInfo, "P$$ssWwrrdGoDd!", disks, null);
assertNotNull(serverId);
assertTrue(serverStartedPredicate.apply(serverId), "server did not start after timeout");
assertTrue(serverNormalPredicate.apply(serverId), "server was not NORMAL after timeout");
assertTrue(api.serverStartedPredicate().apply(serverId), "server did not start after timeout");
assertTrue(api.serverNormalPredicate().apply(serverId), "server was not NORMAL after timeout");
}

@Test(dependsOnMethods = "testDeployAndStartServer")
public void testReconfigureServer() {
api.getServerApi().reconfigureServer(serverId, 4, CpuSpeed.HIGHPERFORMANCE.name(), 1);
assertTrue(serverNormalPredicate.apply(serverId), "server was not NORMAL after timeout");
assertTrue(api.serverNormalPredicate().apply(serverId), "server was not NORMAL after timeout");
}

@Test(dependsOnMethods = "testDeployAndStartServer")
@@ -136,8 +136,8 @@ public boolean apply(Tag input) {
@Test(dependsOnMethods = "testDeployAndStartServer")
public void testRebootServer() {
api.getServerApi().rebootServer(serverId);
assertTrue(serverNormalPredicate.apply(serverId), "server was not NORMAL after timeout");
assertTrue(vmtoolsRunningPredicate.apply(serverId), "server vm tools not running after timeout");
assertTrue(api.serverNormalPredicate().apply(serverId), "server was not NORMAL after timeout");
assertTrue(api.vmToolsRunningPredicate().apply(serverId), "server vm tools not running after timeout");
}

@Test(dependsOnMethods = "testDeployAndStartServer")
@@ -200,20 +200,20 @@ public void testRemovePublicIpBlock() {
@Test(dependsOnMethods = "testRebootServer")
public void testPowerOffServer() {
api.getServerApi().powerOffServer(serverId);
assertTrue(serverStoppedPredicate.apply(serverId), "server did not power off after timeout");
assertTrue(api.serverStoppedPredicate().apply(serverId), "server did not power off after timeout");
}

@Test(dependsOnMethods = "testPowerOffServer")
public void testStartServer() {
api.getServerApi().startServer(serverId);
assertTrue(serverStartedPredicate.apply(serverId), "server did not start after timeout");
assertTrue(vmtoolsRunningPredicate.apply(serverId), "server vm tools not running after timeout");
assertTrue(api.serverStartedPredicate().apply(serverId), "server did not start after timeout");
assertTrue(api.vmToolsRunningPredicate().apply(serverId), "server vm tools not running after timeout");
}

@Test(dependsOnMethods = "testStartServer")
public void testShutdownServer() {
api.getServerApi().shutdownServer(serverId);
assertTrue(serverStoppedPredicate.apply(serverId), "server did not shutdown after timeout");
assertTrue(api.serverStoppedPredicate().apply(serverId), "server did not shutdown after timeout");
}

@Test(dependsOnMethods = "testShutdownServer")
@@ -223,7 +223,7 @@ public void testCloneServerToMakeCustomerImage() {
cloneImageId = api.getServerApi()
.cloneServer(serverId, "ServerApiLiveTest-" + System.currentTimeMillis(), options);
assertNotNull(cloneImageId);
assertTrue(serverNormalPredicate.apply(serverId), "server was not NORMAL after timeout");
assertTrue(api.serverNormalPredicate().apply(serverId), "server was not NORMAL after timeout");
}

@Test(dependsOnMethods = "testCloneServerToMakeCustomerImage")
@@ -248,7 +248,8 @@ public void testGetCustomerImage() {
public void testDeleteCustomerImage() {
boolean deleted = api.getCustomerImageApi().deleteCustomerImage(cloneImageId);
assertTrue(deleted);
assertTrue(customerImageDeletedPredicate.apply(cloneImageId), "customer image was not DELETED after timeout");
assertTrue(api.customerImageDeletedPredicate().apply(cloneImageId),
"customer image was not DELETED after timeout");
}

@AfterClass(alwaysRun = true)
@@ -258,15 +259,15 @@ public void testDeleteServerAndNetworking() {
}
if (serverId != null) {
api.getServerApi().deleteServer(serverId);
assertTrue(serverDeletedPredicate.apply(serverId), "server was not DELETED after timeout");
assertTrue(api.serverDeletedPredicate().apply(serverId), "server was not DELETED after timeout");
}
if (vlanId != null) {
api.getNetworkApi().deleteVlan(vlanId);
assertTrue(vlanDeletedPredicate.apply(vlanId), "vlan is not in a DELETED state after timeout");
assertTrue(api.vlanDeletedPredicate().apply(vlanId), "vlan is not in a DELETED state after timeout");
}
if (networkDomainId != null) {
api.getNetworkApi().deleteNetworkDomain(networkDomainId);
assertTrue(networkDomainDeletedPredicate.apply(networkDomainId),
assertTrue(api.networkDomainDeletedPredicate().apply(networkDomainId),
"network domain is not in a DELETED state after timeout");
}
if (tagKeyId != null && !tagKeyId.isEmpty()) {
@@ -287,7 +288,7 @@ private void deployVlan() {
ServerApiLiveTest.class.getSimpleName() + new Date().getTime(), DEFAULT_PRIVATE_IPV4_BASE_ADDRESS,
DEFAULT_PRIVATE_IPV4_PREFIX_SIZE);
assertNotNull(vlanId);
assertTrue(vlanNormalPredicate.apply(vlanId), "vlan is not in a NORMAL state after timeout");
assertTrue(api.vlanNormalPredicate().apply(vlanId), "vlan is not in a NORMAL state after timeout");
}

private String deployNetworkDomain() {
@@ -296,7 +297,7 @@ private String deployNetworkDomain() {
networkDomainId = api.getNetworkApi().deployNetworkDomain(datacenterId, networkDomainName,
ServerApiLiveTest.class.getSimpleName() + new Date().getTime() + "description", "ESSENTIALS");
assertNotNull(networkDomainId);
assertTrue(networkDomainNormalPredicate.apply(networkDomainId),
assertTrue(api.networkDomainNormalPredicate().apply(networkDomainId),
"network domain is not in a NORMAL state after timeout");
return datacenterId;
}
@@ -16,14 +16,10 @@
*/
package org.jclouds.dimensiondata.cloudcontrol.internal;

import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet;
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.ContextBuilder;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.apis.BaseApiLiveTest;
@@ -44,16 +40,6 @@
import java.util.Set;

import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService;
import static org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlComputeServiceContextModule.CUSTOMER_IMAGE_DELETED_PREDICATE;
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> {
@@ -67,17 +53,6 @@ public class BaseDimensionDataCloudControlApiLiveTest extends BaseApiLiveTest<Di
protected static final Integer DEFAULT_PRIVATE_IPV4_PREFIX_SIZE = 24;
protected static final String DEFAULT_PROTOCOL = "TCP";

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;
protected Predicate<String> customerImageDeletedPredicate;

public BaseDimensionDataCloudControlApiLiveTest() {
provider = "dimensiondata-cloudcontrol";
}
@@ -115,27 +90,6 @@ protected LoggingModule getLoggingModule() {
@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)));
customerImageDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral<Predicate<String>>() {
}, Names.named(CUSTOMER_IMAGE_DELETED_PREDICATE)));

return injector.getInstance(DimensionDataCloudControlApi.class);
}

0 comments on commit d7d37d6

Please sign in to comment.