From c6e9754c543b4f0303c67c23da7e3a6b6223793d Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 6 Jul 2018 11:30:56 +0100 Subject: [PATCH 01/21] Example of Dimension Data CloudControl provider. Deploy - network domain, vlan and server with tags. --- compute-basics/pom.xml | 5 + dimensiondata/pom.xml | 83 +++++++++++++ .../DeployNetworkDomainVlanAndServer.java | 113 ++++++++++++++++++ pom.xml | 1 + 4 files changed, 202 insertions(+) create mode 100644 dimensiondata/pom.xml create mode 100644 dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java diff --git a/compute-basics/pom.xml b/compute-basics/pom.xml index 088eb88e..217da906 100644 --- a/compute-basics/pom.xml +++ b/compute-basics/pom.xml @@ -41,6 +41,11 @@ jclouds-allcompute ${jclouds.version} + + org.apache.jclouds.labs + dimensiondata-cloudcontrol + 2.2.0-SNAPSHOT + diff --git a/dimensiondata/pom.xml b/dimensiondata/pom.xml new file mode 100644 index 00000000..bb2345c1 --- /dev/null +++ b/dimensiondata/pom.xml @@ -0,0 +1,83 @@ + + + + 4.0.0 + + + org.apache.jclouds.examples + jclouds-examples + 2.1.0 + + + org.apache.jclouds.examples + dimensiondata-cloudcontrol-examples + dimensiondata-cloudcontrol-examples + 2.1.0 + + + 2.1.0 + + + + + org.apache.jclouds.labs + dimensiondata-cloudcontrol + 2.2.0-SNAPSHOT + + + org.apache.jclouds + jclouds-compute + ${jclouds.version} + + + org.apache.jclouds.driver + jclouds-slf4j + ${jclouds.version} + + + + ch.qos.logback + logback-classic + 1.0.13 + + + org.apache.jclouds.driver + jclouds-slf4j + 2.2.0-SNAPSHOT + compile + + + + + + + maven-compiler-plugin + 3.1 + + ${project.build.sourceEncoding} + 1.6 + 1.6 + + + + + \ No newline at end of file diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java new file mode 100644 index 00000000..b683b26a --- /dev/null +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java @@ -0,0 +1,113 @@ +package org.jclouds.examples.dimensiondata.cloudcontrol; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +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.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; +import org.jclouds.dimensiondata.cloudcontrol.domain.*; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; + +import java.util.Collections; +import java.util.List; + +public class DeployNetworkDomainVlanAndServer +{ + + private static final String AU_9 = "AU9"; + + public static void main(String[] args) + { + String provider = "dimensiondata-cloudcontrol"; + String endpoint = args[0]; + String username = args[1]; + String password = args[2]; + ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider); + DimensionDataCloudControlApi api = contextBuilder + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .buildApi(DimensionDataCloudControlApi.class); + + Injector injector = contextBuilder.buildInjector(); + + String tagKeyId = api.getTagApi().createTagKey("owner", "owner of the asset", true, false); + + String networkDomainId = deployNetworkDomain(api, injector, tagKeyId); + String vlanId = deployVlan(api, injector, networkDomainId, tagKeyId); + + deployServer(api, injector, networkDomainId, vlanId, tagKeyId); + } + + private static void deployServer(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String vlanId, String tagKeyId) + { + String imageId = getOsImage(api); + + NetworkInfo networkInfo = NetworkInfo + .create(networkDomainId, NIC.builder().vlanId(vlanId).build(), Lists.newArrayList()); + List disks = ImmutableList.of(Disk.builder().scsiId(0).speed("STANDARD").build()); + String serverId = api.getServerApi() + .deployServer("jclouds-server", imageId, true, networkInfo, "P$$ssWwrrdGoDd!", disks, null); + + Predicate serverStartedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_STARTED_PREDICATE"))); + Predicate serverNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_NORMAL_PREDICATE"))); + + // Wait for Server to be started and NORMAL + serverStartedPredicate.apply(serverId); + serverNormalPredicate.apply(serverId); + + api.getTagApi().applyTags(networkDomainId, "SERVER", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); + } + + private static String getOsImage(DimensionDataCloudControlApi api) + { + return api.getServerImageApi().listOsImages().concat() + .firstMatch(new Predicate() + { + @Override + public boolean apply(@Nullable OsImage input) + { + return input.datacenterId().equals(AU_9); + } + }).get().id(); + } + + private static String deployNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String tagKeyId) + { + Predicate networkDomainNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("NETWORK_DOMAIN_NORMAL_PREDICATE"))); + + // Deploy Network Domain & wait for NORMAL state + String networkDomainId = api.getNetworkApi().deployNetworkDomain(AU_9, "jclouds-example", "jclouds-example", "ESSENTIALS"); + networkDomainNormalPredicate.apply(networkDomainId); + + api.getTagApi().applyTags(networkDomainId, "NETWORK_DOMAIN", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); + return networkDomainId; + } + + private static String deployVlan(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String tagKeyId) + { + Predicate vlanNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("VLAN_NORMAL_PREDICATE"))); + + // Deploy VLAN & wait for NORMAL state + String vlanId = api.getNetworkApi().deployVlan(networkDomainId, "jclouds-example-vlan", "jclouds-example-vlan", "10.0.0.0", 24); + vlanNormalPredicate.apply(vlanId); + + api.getTagApi().applyTags(vlanId, "VLAN", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); + return vlanId; + } +} diff --git a/pom.xml b/pom.xml index b2aa1834..41f2eb88 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,7 @@ google-lb openstack rackspace + dimensiondata From 75ff669ecd9143fcd28d659f574526cc54a8b6d4 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 6 Jul 2018 11:34:33 +0100 Subject: [PATCH 02/21] Example of Dimension Data CloudControl provider. Deploy - network domain, vlan and server with tags. --- .../DeployNetworkDomainVlanAndServer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java index b683b26a..1f1f324e 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java @@ -1,3 +1,19 @@ +/* + * 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.examples.dimensiondata.cloudcontrol; import com.google.common.base.Predicate; @@ -67,7 +83,7 @@ private static void deployServer(DimensionDataCloudControlApi api, Injector inje serverStartedPredicate.apply(serverId); serverNormalPredicate.apply(serverId); - api.getTagApi().applyTags(networkDomainId, "SERVER", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); + api.getTagApi().applyTags(serverId, "SERVER", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); } private static String getOsImage(DimensionDataCloudControlApi api) From 82706ad28be092d44e6d3544829a9a7ac3f6c71a Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 6 Jul 2018 11:57:41 +0100 Subject: [PATCH 03/21] Example of Dimension Data CloudControl provider. Delete - network domain, vlan and server with tags. --- .../DeleteServerVlanAndNetworkDomain.java | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java new file mode 100644 index 00000000..93a38e4c --- /dev/null +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java @@ -0,0 +1,144 @@ +/* + * 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.examples.dimensiondata.cloudcontrol; + +import com.google.common.base.Predicate; +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.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; +import org.jclouds.dimensiondata.cloudcontrol.domain.NetworkDomain; +import org.jclouds.dimensiondata.cloudcontrol.domain.Server; +import org.jclouds.dimensiondata.cloudcontrol.domain.TagKey; +import org.jclouds.dimensiondata.cloudcontrol.domain.Vlan; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; + +public class DeleteServerVlanAndNetworkDomain +{ + private static final String AU_9 = "AU9"; + + public static void main(String[] args) + { + String provider = "dimensiondata-cloudcontrol"; + String endpoint = args[0]; + String username = args[1]; + String password = args[2]; + ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider); + DimensionDataCloudControlApi api = contextBuilder + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .buildApi(DimensionDataCloudControlApi.class); + + Injector injector = contextBuilder.buildInjector(); + + final String networkDomainName = "jclouds-example"; + String networkDomainId = getNetworkDomainId(api, networkDomainName); + final String serverName = "jclouds-server"; + final String vlanName = "jclouds-example-vlan"; + + deleteServer(api, injector, serverName); + deleteVlan(api, injector, vlanName, networkDomainId); + deleteNetworkDomain(api, injector, networkDomainId); + + deleteTagKey(api, injector, "owner"); + } + + private static void deleteTagKey(DimensionDataCloudControlApi api, Injector injector, final String tagkeyName) + { + String id = api.getTagApi().listTagKeys().concat().firstMatch(new Predicate() + { + @Override + public boolean apply(TagKey input) + { + return input.name().equals(tagkeyName); + } + }).get().id(); + api.getTagApi().deleteTagKey(id); + } + + private static String getNetworkDomainId(DimensionDataCloudControlApi api, final String networkDomainName) + { + return api.getNetworkApi().listNetworkDomains().concat().firstMatch(new Predicate() + { + @Override + public boolean apply(NetworkDomain input) + { + return input.name().equals(networkDomainName); + } + }).get().id(); + } + + private static void deleteVlan(DimensionDataCloudControlApi api, Injector injector, final String vlanName, String networkDomainId) + { + String vlanId = api.getNetworkApi().listVlans(networkDomainId).concat().firstMatch(new Predicate() + { + @Override + public boolean apply(Vlan input) + { + return input.name().equals(vlanName); + } + }).get().id(); + api.getNetworkApi().deleteVlan(vlanId); + + Predicate vlanDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("VLAN_DELETED_PREDICATE"))); + + // Wait for VLAN to be DELETED + vlanDeletedPredicate.apply(vlanId); + } + + private static void deleteNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String networkDomainId) + { + api.getNetworkApi().deleteNetworkDomain(networkDomainId); + + Predicate networkDomainDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("NETWORK_DOMAIN_DELETED_PREDICATE"))); + + // Wait for NETWORK DOMAIN to be DELETED + networkDomainDeletedPredicate.apply(networkDomainId); + } + + private static void deleteServer(DimensionDataCloudControlApi api, Injector injector, final String serverName) + { + + String serverId = api.getServerApi().listServers().concat().firstMatch(new Predicate() + { + @Override + public boolean apply(Server input) + { + return input.name().equals(serverName); + } + }).get().id(); + + api.getServerApi().deleteServer(serverId); + + Predicate serverDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_DELETED_PREDICATE"))); + + // Wait for Server to be DELETED + serverDeletedPredicate.apply(serverId); + } + +} From 94fb9226d46e680866c0364d30d73bc904454777 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 6 Jul 2018 12:51:11 +0100 Subject: [PATCH 04/21] Example of Dimension Data CloudControl provider. Delete - network domain, vlan and server with tags. --- .../DeleteServerVlanAndNetworkDomain.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java index 93a38e4c..85d2429c 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java @@ -122,23 +122,34 @@ private static void deleteNetworkDomain(DimensionDataCloudControlApi api, Inject private static void deleteServer(DimensionDataCloudControlApi api, Injector injector, final String serverName) { - String serverId = api.getServerApi().listServers().concat().firstMatch(new Predicate() + Server server = api.getServerApi().listServers().concat().firstMatch(new Predicate() { @Override public boolean apply(Server input) { return input.name().equals(serverName); } - }).get().id(); + }).get(); + + if (server.started()) + { + api.getServerApi().shutdownServer(server.id()); + Predicate serverStoppedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_STOPPED_PREDICATE"))); + + // Wait for Server to be STOPPED + serverStoppedPredicate.apply(server.id()); + } - api.getServerApi().deleteServer(serverId); + api.getServerApi().deleteServer(server.id()); Predicate serverDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { }, Names.named("SERVER_DELETED_PREDICATE"))); // Wait for Server to be DELETED - serverDeletedPredicate.apply(serverId); + serverDeletedPredicate.apply(server.id()); } } From cc838c9f0df11c77a46675b6db432ced0879f0da Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 6 Jul 2018 13:36:50 +0100 Subject: [PATCH 05/21] Example of Dimension Data CloudControl provider. Delete - network domain, vlan and server with tags. --- dimensiondata/src/main/resources/logback.xml | 89 ++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 dimensiondata/src/main/resources/logback.xml diff --git a/dimensiondata/src/main/resources/logback.xml b/dimensiondata/src/main/resources/logback.xml new file mode 100644 index 00000000..b869509c --- /dev/null +++ b/dimensiondata/src/main/resources/logback.xml @@ -0,0 +1,89 @@ + + + + + + + - %m%n + + + + + target/test-data/jclouds.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-wire.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-compute.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-ssh.log + + + %d %-5p [%c] [%thread] %m%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 5dc2c82d64375ab85f1e72ba859590c9a0db8bd9 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 6 Jul 2018 13:40:27 +0100 Subject: [PATCH 06/21] Example of Dimension Data CloudControl provider --- .../DeleteServerVlanAndNetworkDomain.java | 33 +++++++++++++---- .../DeployNetworkDomainVlanAndServer.java | 35 +++++++++++++------ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java index 85d2429c..9c347950 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java @@ -58,7 +58,6 @@ public static void main(String[] args) deleteServer(api, injector, serverName); deleteVlan(api, injector, vlanName, networkDomainId); deleteNetworkDomain(api, injector, networkDomainId); - deleteTagKey(api, injector, "owner"); } @@ -99,6 +98,11 @@ public boolean apply(Vlan input) }).get().id(); api.getNetworkApi().deleteVlan(vlanId); + waitForDeleteVlan(injector, vlanId); + } + + private static void waitForDeleteVlan(Injector injector, String vlanId) + { Predicate vlanDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { }, Names.named("VLAN_DELETED_PREDICATE"))); @@ -111,6 +115,11 @@ private static void deleteNetworkDomain(DimensionDataCloudControlApi api, Inject { api.getNetworkApi().deleteNetworkDomain(networkDomainId); + waitForDeleteNetworkDomain(injector, networkDomainId); + } + + private static void waitForDeleteNetworkDomain(Injector injector, String networkDomainId) + { Predicate networkDomainDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { }, Names.named("NETWORK_DOMAIN_DELETED_PREDICATE"))); @@ -134,16 +143,16 @@ public boolean apply(Server input) if (server.started()) { api.getServerApi().shutdownServer(server.id()); - Predicate serverStoppedPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("SERVER_STOPPED_PREDICATE"))); - - // Wait for Server to be STOPPED - serverStoppedPredicate.apply(server.id()); + waitForServerStopped(injector, server); } api.getServerApi().deleteServer(server.id()); + waitForServerDeleted(injector, server); + } + + private static void waitForServerDeleted(Injector injector, Server server) + { Predicate serverDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { }, Names.named("SERVER_DELETED_PREDICATE"))); @@ -152,4 +161,14 @@ public boolean apply(Server input) serverDeletedPredicate.apply(server.id()); } + private static void waitForServerStopped(Injector injector, Server server) + { + Predicate serverStoppedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_STOPPED_PREDICATE"))); + + // Wait for Server to be STOPPED + serverStoppedPredicate.apply(server.id()); + } + } diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java index 1f1f324e..9d49d2b7 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java @@ -72,6 +72,13 @@ private static void deployServer(DimensionDataCloudControlApi api, Injector inje String serverId = api.getServerApi() .deployServer("jclouds-server", imageId, true, networkInfo, "P$$ssWwrrdGoDd!", disks, null); + waitForServerStartedAndNormal(injector, serverId); + + api.getTagApi().applyTags(serverId, "SERVER", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); + } + + private static void waitForServerStartedAndNormal(Injector injector, String serverId) + { Predicate serverStartedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { }, Names.named("SERVER_STARTED_PREDICATE"))); @@ -82,8 +89,6 @@ private static void deployServer(DimensionDataCloudControlApi api, Injector inje // Wait for Server to be started and NORMAL serverStartedPredicate.apply(serverId); serverNormalPredicate.apply(serverId); - - api.getTagApi().applyTags(serverId, "SERVER", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); } private static String getOsImage(DimensionDataCloudControlApi api) @@ -101,29 +106,39 @@ public boolean apply(@Nullable OsImage input) private static String deployNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String tagKeyId) { - Predicate networkDomainNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("NETWORK_DOMAIN_NORMAL_PREDICATE"))); // Deploy Network Domain & wait for NORMAL state String networkDomainId = api.getNetworkApi().deployNetworkDomain(AU_9, "jclouds-example", "jclouds-example", "ESSENTIALS"); - networkDomainNormalPredicate.apply(networkDomainId); + waitForNetworkDomainNormal(injector, networkDomainId); api.getTagApi().applyTags(networkDomainId, "NETWORK_DOMAIN", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); return networkDomainId; } - private static String deployVlan(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String tagKeyId) + private static void waitForNetworkDomainNormal(Injector injector, String networkDomainId) { - Predicate vlanNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() + Predicate networkDomainNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("VLAN_NORMAL_PREDICATE"))); + }, Names.named("NETWORK_DOMAIN_NORMAL_PREDICATE"))); + networkDomainNormalPredicate.apply(networkDomainId); + } + + private static String deployVlan(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String tagKeyId) + { // Deploy VLAN & wait for NORMAL state String vlanId = api.getNetworkApi().deployVlan(networkDomainId, "jclouds-example-vlan", "jclouds-example-vlan", "10.0.0.0", 24); - vlanNormalPredicate.apply(vlanId); + waitForVlanNormal(injector, vlanId); api.getTagApi().applyTags(vlanId, "VLAN", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); return vlanId; } + + private static void waitForVlanNormal(Injector injector, String vlanId) + { + Predicate vlanNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("VLAN_NORMAL_PREDICATE"))); + vlanNormalPredicate.apply(vlanId); + } } From 1981a401457a2b765b767a997c442f740e5639e3 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 5 Oct 2018 16:38:51 +0100 Subject: [PATCH 07/21] Example of Dimension Data CloudControl provider - Network Domain Tear Down --- .../DeleteServerVlanAndNetworkDomain.java | 58 ++------ .../DeployNetworkDomainVlanAndServer.java | 40 +----- .../cloudcontrol/NetworkDomainTearDown.java | 131 ++++++++++++++++++ .../cloudcontrol/WaitForUtils.java | 82 +++++++++++ 4 files changed, 225 insertions(+), 86 deletions(-) create mode 100644 dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java create mode 100644 dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java index 9c347950..fd632e87 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java @@ -19,10 +19,7 @@ import com.google.common.base.Predicate; 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.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; import org.jclouds.dimensiondata.cloudcontrol.domain.NetworkDomain; @@ -31,6 +28,8 @@ import org.jclouds.dimensiondata.cloudcontrol.domain.Vlan; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import static org.jclouds.examples.dimensiondata.cloudcontrol.WaitForUtils.*; + public class DeleteServerVlanAndNetworkDomain { private static final String AU_9 = "AU9"; @@ -58,10 +57,10 @@ public static void main(String[] args) deleteServer(api, injector, serverName); deleteVlan(api, injector, vlanName, networkDomainId); deleteNetworkDomain(api, injector, networkDomainId); - deleteTagKey(api, injector, "owner"); + deleteTagKey(api, "owner"); } - private static void deleteTagKey(DimensionDataCloudControlApi api, Injector injector, final String tagkeyName) + private static void deleteTagKey(DimensionDataCloudControlApi api, final String tagkeyName) { String id = api.getTagApi().listTagKeys().concat().firstMatch(new Predicate() { @@ -88,27 +87,17 @@ public boolean apply(NetworkDomain input) private static void deleteVlan(DimensionDataCloudControlApi api, Injector injector, final String vlanName, String networkDomainId) { - String vlanId = api.getNetworkApi().listVlans(networkDomainId).concat().firstMatch(new Predicate() + Vlan vlan = api.getNetworkApi().listVlans(networkDomainId).concat().firstMatch(new Predicate() { @Override public boolean apply(Vlan input) { return input.name().equals(vlanName); } - }).get().id(); - api.getNetworkApi().deleteVlan(vlanId); - - waitForDeleteVlan(injector, vlanId); - } - - private static void waitForDeleteVlan(Injector injector, String vlanId) - { - Predicate vlanDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("VLAN_DELETED_PREDICATE"))); + }).get(); + api.getNetworkApi().deleteVlan(vlan.id()); - // Wait for VLAN to be DELETED - vlanDeletedPredicate.apply(vlanId); + waitForDeleteVlan(injector, vlan); } private static void deleteNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String networkDomainId) @@ -118,19 +107,8 @@ private static void deleteNetworkDomain(DimensionDataCloudControlApi api, Inject waitForDeleteNetworkDomain(injector, networkDomainId); } - private static void waitForDeleteNetworkDomain(Injector injector, String networkDomainId) - { - Predicate networkDomainDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("NETWORK_DOMAIN_DELETED_PREDICATE"))); - - // Wait for NETWORK DOMAIN to be DELETED - networkDomainDeletedPredicate.apply(networkDomainId); - } - private static void deleteServer(DimensionDataCloudControlApi api, Injector injector, final String serverName) { - Server server = api.getServerApi().listServers().concat().firstMatch(new Predicate() { @Override @@ -151,24 +129,4 @@ public boolean apply(Server input) waitForServerDeleted(injector, server); } - private static void waitForServerDeleted(Injector injector, Server server) - { - Predicate serverDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("SERVER_DELETED_PREDICATE"))); - - // Wait for Server to be DELETED - serverDeletedPredicate.apply(server.id()); - } - - private static void waitForServerStopped(Injector injector, Server server) - { - Predicate serverStoppedPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("SERVER_STOPPED_PREDICATE"))); - - // Wait for Server to be STOPPED - serverStoppedPredicate.apply(server.id()); - } - } diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java index 9d49d2b7..368832e3 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java @@ -21,10 +21,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; 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.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; import org.jclouds.dimensiondata.cloudcontrol.domain.*; @@ -54,7 +51,7 @@ public static void main(String[] args) Injector injector = contextBuilder.buildInjector(); - String tagKeyId = api.getTagApi().createTagKey("owner", "owner of the asset", true, false); + String tagKeyId = api.getTagApi().createTagKey("jclouds", "owner of the asset", true, false); String networkDomainId = deployNetworkDomain(api, injector, tagKeyId); String vlanId = deployVlan(api, injector, networkDomainId, tagKeyId); @@ -72,25 +69,11 @@ private static void deployServer(DimensionDataCloudControlApi api, Injector inje String serverId = api.getServerApi() .deployServer("jclouds-server", imageId, true, networkInfo, "P$$ssWwrrdGoDd!", disks, null); - waitForServerStartedAndNormal(injector, serverId); + WaitForUtils.waitForServerStartedAndNormal(injector, serverId); api.getTagApi().applyTags(serverId, "SERVER", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); } - private static void waitForServerStartedAndNormal(Injector injector, String serverId) - { - Predicate serverStartedPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("SERVER_STARTED_PREDICATE"))); - Predicate serverNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("SERVER_NORMAL_PREDICATE"))); - - // Wait for Server to be started and NORMAL - serverStartedPredicate.apply(serverId); - serverNormalPredicate.apply(serverId); - } - private static String getOsImage(DimensionDataCloudControlApi api) { return api.getServerImageApi().listOsImages().concat() @@ -109,36 +92,21 @@ private static String deployNetworkDomain(DimensionDataCloudControlApi api, Inje // Deploy Network Domain & wait for NORMAL state String networkDomainId = api.getNetworkApi().deployNetworkDomain(AU_9, "jclouds-example", "jclouds-example", "ESSENTIALS"); - waitForNetworkDomainNormal(injector, networkDomainId); + WaitForUtils.waitForNetworkDomainNormal(injector, networkDomainId); api.getTagApi().applyTags(networkDomainId, "NETWORK_DOMAIN", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); return networkDomainId; } - private static void waitForNetworkDomainNormal(Injector injector, String networkDomainId) - { - Predicate networkDomainNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("NETWORK_DOMAIN_NORMAL_PREDICATE"))); - networkDomainNormalPredicate.apply(networkDomainId); - } - private static String deployVlan(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String tagKeyId) { // Deploy VLAN & wait for NORMAL state String vlanId = api.getNetworkApi().deployVlan(networkDomainId, "jclouds-example-vlan", "jclouds-example-vlan", "10.0.0.0", 24); - waitForVlanNormal(injector, vlanId); + WaitForUtils.waitForVlanNormal(injector, vlanId); api.getTagApi().applyTags(vlanId, "VLAN", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); return vlanId; } - private static void waitForVlanNormal(Injector injector, String vlanId) - { - Predicate vlanNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() - { - }, Names.named("VLAN_NORMAL_PREDICATE"))); - vlanNormalPredicate.apply(vlanId); - } } diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java new file mode 100644 index 00000000..62071f43 --- /dev/null +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -0,0 +1,131 @@ +package org.jclouds.examples.dimensiondata.cloudcontrol; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Injector; +import com.google.inject.Module; +import org.jclouds.ContextBuilder; +import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; +import org.jclouds.dimensiondata.cloudcontrol.domain.*; +import org.jclouds.dimensiondata.cloudcontrol.options.DatacenterIdListFilters; +import org.jclouds.logging.Logger; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; + +import static org.jclouds.examples.dimensiondata.cloudcontrol.WaitForUtils.*; + +public class NetworkDomainTearDown +{ + private static final Logger logger = Logger.CONSOLE; + + public static void main(String[] args) + { + String provider = "dimensiondata-cloudcontrol"; + String endpoint = args[0]; + String username = args[1]; + String password = args[2]; + String networkDomainId = args[3]; + ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider); + DimensionDataCloudControlApi api = contextBuilder + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .buildApi(DimensionDataCloudControlApi.class); + + Injector injector = contextBuilder.buildInjector(); + logger.info("Deleting resources for network domain %s", networkDomainId); + NetworkDomain networkDomain = api.getNetworkApi().getNetworkDomain(networkDomainId); + if (networkDomain == null) + { + logger.info("Network Domain with ID %s is not found", networkDomainId); + return; + } + if (networkDomain.state() != State.NORMAL) + { + logger.info("Network Domain with ID %s is not in a NORMAL state, cannot delete", networkDomain.id()); + return; + } + + String datacenterId = networkDomain.datacenterId(); + + removePublicIpBlocks(networkDomainId, api); + + deleteNatRules(networkDomainId, api); + + deleteFirewallRules(networkDomainId, api); + + deleteServers(api, injector, datacenterId); + + deleteVlans(api, injector, networkDomain); + + deleteNetworkDomain(networkDomainId, api, injector); + } + + private static void removePublicIpBlocks(String networkDomainId, DimensionDataCloudControlApi api) + { + for (PublicIpBlock publicIpBlock : api.getNetworkApi().listPublicIPv4AddressBlocks(networkDomainId).concat().toList()) + { + logger.info("Deleting PublicIpBlock with ID %s", publicIpBlock.id()); + api.getNetworkApi().removePublicIpBlock(publicIpBlock.id()); + } + } + + private static void deleteFirewallRules(String networkDomainId, DimensionDataCloudControlApi api) + { + for (FirewallRule firewallRule : api.getNetworkApi().listFirewallRules(networkDomainId).concat().toList()) + { + logger.info("Deleting FirewallRule with ID %s", firewallRule.id()); + api.getNetworkApi().deleteNatRule(firewallRule.id()); + } + } + + private static void deleteNatRules(String networkDomainId, DimensionDataCloudControlApi api) + { + for (NatRule natRule : api.getNetworkApi().listNatRules(networkDomainId).concat().toList()) + { + logger.info("Deleting NatRule with ID %s", natRule.id()); + api.getNetworkApi().deleteNatRule(natRule.id()); + } + } + + private static void deleteNetworkDomain(String networkDomainId, DimensionDataCloudControlApi api, Injector injector) + { + logger.info("Deleting Network Domain with ID %s", networkDomainId); + api.getNetworkApi().deleteNetworkDomain(networkDomainId); + waitForDeleteNetworkDomain(injector, networkDomainId); + } + + private static void deleteVlans(DimensionDataCloudControlApi api, Injector injector, NetworkDomain networkDomain) + { + for (Vlan vlan : api.getNetworkApi().listVlans(networkDomain.id()).concat().toList()) + { + if (vlan.state() != State.NORMAL) + { + logger.info("Vlan with ID %s is not in a NORMAL state, cannot delete", vlan.id()); + continue; + } + logger.info("Deleting Vlan with ID %s", vlan.id()); + api.getNetworkApi().deleteVlan(vlan.id()); + waitForDeleteVlan(injector, vlan); + } + } + + private static void deleteServers(DimensionDataCloudControlApi api, Injector injector, String datacenterId) + { + for (Server server : api.getServerApi().listServers(DatacenterIdListFilters.Builder.datacenterId(datacenterId))) + { + if (server.state() != State.NORMAL) + { + logger.info("Server with ID %s is not in a NORMAL state, cannot delete", server.id()); + continue; + } + if (server.started()) + { + logger.info("Deleting Server with ID %s", server.id()); + api.getServerApi().shutdownServer(server.id()); + waitForServerStopped(injector, server); + } + api.getServerApi().deleteServer(server.id()); + waitForServerDeleted(injector, server); + } + } + +} diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java new file mode 100644 index 00000000..be5b991f --- /dev/null +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java @@ -0,0 +1,82 @@ +package org.jclouds.examples.dimensiondata.cloudcontrol; + +import com.google.common.base.Predicate; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.TypeLiteral; +import com.google.inject.name.Names; +import org.jclouds.dimensiondata.cloudcontrol.domain.Server; +import org.jclouds.dimensiondata.cloudcontrol.domain.Vlan; + +public class WaitForUtils +{ + public static void waitForServerStopped(Injector injector, Server server) + { + Predicate serverStoppedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_STOPPED_PREDICATE"))); + + // Wait for Server to be STOPPED + serverStoppedPredicate.apply(server.id()); + } + + static void waitForDeleteVlan(Injector injector, Vlan vlan) + { + Predicate vlanDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("VLAN_DELETED_PREDICATE"))); + + // Wait for VLAN to be DELETED + vlanDeletedPredicate.apply(vlan.id()); + } + + static void waitForDeleteNetworkDomain(Injector injector, String networkDomainId) + { + Predicate networkDomainDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("NETWORK_DOMAIN_DELETED_PREDICATE"))); + + // Wait for NETWORK DOMAIN to be DELETED + networkDomainDeletedPredicate.apply(networkDomainId); + } + + static void waitForServerDeleted(Injector injector, Server server) + { + Predicate serverDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_DELETED_PREDICATE"))); + + // Wait for Server to be DELETED + serverDeletedPredicate.apply(server.id()); + } + + static void waitForServerStartedAndNormal(Injector injector, String serverId) + { + Predicate serverStartedPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_STARTED_PREDICATE"))); + Predicate serverNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("SERVER_NORMAL_PREDICATE"))); + + // Wait for Server to be started and NORMAL + serverStartedPredicate.apply(serverId); + serverNormalPredicate.apply(serverId); + } + + static void waitForNetworkDomainNormal(Injector injector, String networkDomainId) + { + Predicate networkDomainNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("NETWORK_DOMAIN_NORMAL_PREDICATE"))); + networkDomainNormalPredicate.apply(networkDomainId); + } + + static void waitForVlanNormal(Injector injector, String vlanId) + { + Predicate vlanNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() + { + }, Names.named("VLAN_NORMAL_PREDICATE"))); + vlanNormalPredicate.apply(vlanId); + } +} From 7ba7cf590845add116fc79c8ea0896200ca2ee76 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 5 Oct 2018 17:01:03 +0100 Subject: [PATCH 08/21] Example of Dimension Data CloudControl provider - Network Domain Tear Down --- .../dimensiondata/cloudcontrol/NetworkDomainTearDown.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java index 62071f43..b1938f5e 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -72,8 +72,11 @@ private static void deleteFirewallRules(String networkDomainId, DimensionDataClo { for (FirewallRule firewallRule : api.getNetworkApi().listFirewallRules(networkDomainId).concat().toList()) { - logger.info("Deleting FirewallRule with ID %s", firewallRule.id()); - api.getNetworkApi().deleteNatRule(firewallRule.id()); + if (firewallRule.ruleType().equals("CLIENT_RULE")) + { + logger.info("Deleting FirewallRule with ID %s", firewallRule.id()); + api.getNetworkApi().deleteFirewallRule(firewallRule.id()); + } } } From 5c021b69546233beae94e1af18141fb39059c94a Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Fri, 5 Oct 2018 17:07:36 +0100 Subject: [PATCH 09/21] Example of Dimension Data CloudControl provider - Network Domain Tear Down --- .../cloudcontrol/NetworkDomainTearDown.java | 16 ++++++++++++++++ .../dimensiondata/cloudcontrol/WaitForUtils.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java index b1938f5e..7bc07e3d 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -1,3 +1,19 @@ +/* + * 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.examples.dimensiondata.cloudcontrol; import com.google.common.collect.ImmutableSet; diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java index be5b991f..41b5d46b 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java @@ -1,3 +1,19 @@ +/* + * 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.examples.dimensiondata.cloudcontrol; import com.google.common.base.Predicate; From e769676f9f01a899903609e2ed0ef86643bccabb Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Sun, 7 Oct 2018 09:20:46 +0100 Subject: [PATCH 10/21] Example of Dimension Data CloudControl provider - Network Domain Tear Down --- blobstore-basics/pom.xml | 2 +- blobstore-largeblob/pom.xml | 2 +- blobstore-uploader/dependency-reduced-pom.xml | 3 +-- blobstore-uploader/pom.xml | 2 +- chef-basics/pom.xml | 2 +- compute-basics/pom.xml | 2 +- dimensiondata/pom.xml | 4 ++-- glacier/pom.xml | 2 +- google-lb/pom.xml | 2 +- openstack/pom.xml | 2 +- pom.xml | 2 +- rackspace/pom.xml | 2 +- 12 files changed, 13 insertions(+), 14 deletions(-) diff --git a/blobstore-basics/pom.xml b/blobstore-basics/pom.xml index 9da345e7..92e62f18 100644 --- a/blobstore-basics/pom.xml +++ b/blobstore-basics/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples blobstore-basics - 2.1.0 + 2.2.0-SNAPSHOT blobstore-basics jclouds blobstore example that creates a container, then displays the size of each container diff --git a/blobstore-largeblob/pom.xml b/blobstore-largeblob/pom.xml index 068f584e..ba2bbdf4 100644 --- a/blobstore-largeblob/pom.xml +++ b/blobstore-largeblob/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples blobstore-largeblob - 2.1.0 + 2.2.0-SNAPSHOT blobstore-largeblob jclouds blobstore example that creates a container, then uploads a large file using parallel multipart upload diff --git a/blobstore-uploader/dependency-reduced-pom.xml b/blobstore-uploader/dependency-reduced-pom.xml index 2a895db8..ef33fd24 100644 --- a/blobstore-uploader/dependency-reduced-pom.xml +++ b/blobstore-uploader/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 blobstore-uploader blob-uploader - 2.1.0 + 2.2.0-SNAPSHOT @@ -34,4 +34,3 @@ 2.1.0 - diff --git a/blobstore-uploader/pom.xml b/blobstore-uploader/pom.xml index 57f70141..9367e85e 100644 --- a/blobstore-uploader/pom.xml +++ b/blobstore-uploader/pom.xml @@ -24,7 +24,7 @@ blobstore-uploader blob-uploader - 2.1.0 + 2.2.0-SNAPSHOT 2.1.0 diff --git a/chef-basics/pom.xml b/chef-basics/pom.xml index 49fec29c..9a9f66a9 100644 --- a/chef-basics/pom.xml +++ b/chef-basics/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples chef-basics - 2.1.0 + 2.2.0-SNAPSHOT chef-basics jclouds chef example that adds a node to a group, then installs an Apache web server on all nodes diff --git a/compute-basics/pom.xml b/compute-basics/pom.xml index 217da906..2e6fbc78 100644 --- a/compute-basics/pom.xml +++ b/compute-basics/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples compute-basics - 2.1.0 + 2.2.0-SNAPSHOT compute-basics jclouds compute example that adds a node to a group, then executes "echo hello" on all nodes diff --git a/dimensiondata/pom.xml b/dimensiondata/pom.xml index bb2345c1..afbda9b7 100644 --- a/dimensiondata/pom.xml +++ b/dimensiondata/pom.xml @@ -25,13 +25,13 @@ org.apache.jclouds.examples jclouds-examples - 2.1.0 + 2.2.0-SNAPSHOT org.apache.jclouds.examples dimensiondata-cloudcontrol-examples dimensiondata-cloudcontrol-examples - 2.1.0 + 2.2.0-SNAPSHOT 2.1.0 diff --git a/glacier/pom.xml b/glacier/pom.xml index 9af4df22..262015ec 100644 --- a/glacier/pom.xml +++ b/glacier/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples glacier-examples - 2.1.0 + 2.2.0-SNAPSHOT glacier-examples diff --git a/google-lb/pom.xml b/google-lb/pom.xml index 4dc67342..a855eba0 100644 --- a/google-lb/pom.xml +++ b/google-lb/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples google-lb - 2.1.0 + 2.2.0-SNAPSHOT google-lb jclouds-labs-google example that shows using the compute specific api and constructing a load balancer. diff --git a/openstack/pom.xml b/openstack/pom.xml index 5bd40fd3..8bc970f6 100644 --- a/openstack/pom.xml +++ b/openstack/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples openstack-examples - 2.1.0 + 2.2.0-SNAPSHOT openstack-examples diff --git a/pom.xml b/pom.xml index 41f2eb88..fb3411db 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 4.0.0 org.apache.jclouds.examples jclouds-examples - 2.1.0 + 2.2.0-SNAPSHOT pom jclouds examples diff --git a/rackspace/pom.xml b/rackspace/pom.xml index 2557e346..a55aa0a9 100644 --- a/rackspace/pom.xml +++ b/rackspace/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples rackspace-examples - 2.1.0 + 2.2.0-SNAPSHOT rackspace-examples From 4558069a951080dfa80f85f2fb7d013409f52911 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Sun, 7 Oct 2018 11:32:34 +0100 Subject: [PATCH 11/21] Creating executable jar --- dimensiondata/pom.xml | 19 ++++++++- .../main/assembly/jar-with-dependencies.xml | 42 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 dimensiondata/src/main/assembly/jar-with-dependencies.xml diff --git a/dimensiondata/pom.xml b/dimensiondata/pom.xml index afbda9b7..871ba55f 100644 --- a/dimensiondata/pom.xml +++ b/dimensiondata/pom.xml @@ -28,7 +28,6 @@ 2.2.0-SNAPSHOT - org.apache.jclouds.examples dimensiondata-cloudcontrol-examples dimensiondata-cloudcontrol-examples 2.2.0-SNAPSHOT @@ -78,6 +77,24 @@ 1.6 + + maven-assembly-plugin + 2.2.1 + + + src/main/assembly/jar-with-dependencies.xml + + + + + make-assembly + package + + single + + + + \ No newline at end of file diff --git a/dimensiondata/src/main/assembly/jar-with-dependencies.xml b/dimensiondata/src/main/assembly/jar-with-dependencies.xml new file mode 100644 index 00000000..aaa208c1 --- /dev/null +++ b/dimensiondata/src/main/assembly/jar-with-dependencies.xml @@ -0,0 +1,42 @@ + + + + + jar-with-dependencies + + jar + + false + + + metaInf-services + + + + + / + true + true + runtime + + + \ No newline at end of file From b2050be4d52458d3079c94ce87a2c66741095823 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Mon, 8 Oct 2018 12:11:32 +0100 Subject: [PATCH 12/21] Example of Dimension Data CloudControl provider --- .../cloudcontrol/NetworkDomainTearDown.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java index 7bc07e3d..cebd1e99 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -28,6 +28,16 @@ import static org.jclouds.examples.dimensiondata.cloudcontrol.WaitForUtils.*; +/** + * This example shows how a Network Domain and all of it's associated assets are removed. + * Takes 4 Program Arguments: + *
    + *
      1 Endpoint URL
    + *
      2 Usernamme
    + *
      3 Password
    + *
      4 Network Domain Id
    + *
+ */ public class NetworkDomainTearDown { private static final Logger logger = Logger.CONSOLE; @@ -51,12 +61,12 @@ public static void main(String[] args) NetworkDomain networkDomain = api.getNetworkApi().getNetworkDomain(networkDomainId); if (networkDomain == null) { - logger.info("Network Domain with ID %s is not found", networkDomainId); + logger.info("Network Domain with Id %s is not found", networkDomainId); return; } if (networkDomain.state() != State.NORMAL) { - logger.info("Network Domain with ID %s is not in a NORMAL state, cannot delete", networkDomain.id()); + logger.info("Network Domain with Id %s is not in a NORMAL state, cannot delete", networkDomain.id()); return; } @@ -79,7 +89,7 @@ private static void removePublicIpBlocks(String networkDomainId, DimensionDataCl { for (PublicIpBlock publicIpBlock : api.getNetworkApi().listPublicIPv4AddressBlocks(networkDomainId).concat().toList()) { - logger.info("Deleting PublicIpBlock with ID %s", publicIpBlock.id()); + logger.info("Deleting PublicIpBlock with Id %s", publicIpBlock.id()); api.getNetworkApi().removePublicIpBlock(publicIpBlock.id()); } } @@ -90,7 +100,7 @@ private static void deleteFirewallRules(String networkDomainId, DimensionDataClo { if (firewallRule.ruleType().equals("CLIENT_RULE")) { - logger.info("Deleting FirewallRule with ID %s", firewallRule.id()); + logger.info("Deleting FirewallRule with Id %s", firewallRule.id()); api.getNetworkApi().deleteFirewallRule(firewallRule.id()); } } @@ -100,14 +110,14 @@ private static void deleteNatRules(String networkDomainId, DimensionDataCloudCon { for (NatRule natRule : api.getNetworkApi().listNatRules(networkDomainId).concat().toList()) { - logger.info("Deleting NatRule with ID %s", natRule.id()); + logger.info("Deleting NatRule with Id %s", natRule.id()); api.getNetworkApi().deleteNatRule(natRule.id()); } } private static void deleteNetworkDomain(String networkDomainId, DimensionDataCloudControlApi api, Injector injector) { - logger.info("Deleting Network Domain with ID %s", networkDomainId); + logger.info("Deleting Network Domain with Id %s", networkDomainId); api.getNetworkApi().deleteNetworkDomain(networkDomainId); waitForDeleteNetworkDomain(injector, networkDomainId); } @@ -118,10 +128,10 @@ private static void deleteVlans(DimensionDataCloudControlApi api, Injector injec { if (vlan.state() != State.NORMAL) { - logger.info("Vlan with ID %s is not in a NORMAL state, cannot delete", vlan.id()); + logger.info("Vlan with Id %s is not in a NORMAL state, cannot delete", vlan.id()); continue; } - logger.info("Deleting Vlan with ID %s", vlan.id()); + logger.info("Deleting Vlan with Id %s", vlan.id()); api.getNetworkApi().deleteVlan(vlan.id()); waitForDeleteVlan(injector, vlan); } @@ -131,17 +141,23 @@ private static void deleteServers(DimensionDataCloudControlApi api, Injector inj { for (Server server : api.getServerApi().listServers(DatacenterIdListFilters.Builder.datacenterId(datacenterId))) { + if (server.state() == State.FAILED_ADD) + { + logger.info("Server with Id %s is not in a FAILED_ADD state, manually run Clean Server operation.", server.id()); + continue; + } if (server.state() != State.NORMAL) { - logger.info("Server with ID %s is not in a NORMAL state, cannot delete", server.id()); + logger.info("Server with Id %s is not in a NORMAL state, current state %s - cannot delete", server.id(), server.state()); continue; } if (server.started()) { - logger.info("Deleting Server with ID %s", server.id()); + logger.info("Shutting down Server with Id %s", server.id()); api.getServerApi().shutdownServer(server.id()); waitForServerStopped(injector, server); } + logger.info("Deleting Server with Id %s", server.id()); api.getServerApi().deleteServer(server.id()); waitForServerDeleted(injector, server); } From 20a5a65ecfc0a15d49ed3acff009cabe468b99b9 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Mon, 8 Oct 2018 12:46:38 +0100 Subject: [PATCH 13/21] Ignore any exceptions when deleting servers or vlans for best effort cleanup --- .../cloudcontrol/NetworkDomainTearDown.java | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java index cebd1e99..cba95428 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -126,14 +126,21 @@ private static void deleteVlans(DimensionDataCloudControlApi api, Injector injec { for (Vlan vlan : api.getNetworkApi().listVlans(networkDomain.id()).concat().toList()) { - if (vlan.state() != State.NORMAL) + try { - logger.info("Vlan with Id %s is not in a NORMAL state, cannot delete", vlan.id()); - continue; + if (vlan.state() != State.NORMAL) + { + logger.info("Vlan with Id %s is not in a NORMAL state, cannot delete", vlan.id()); + continue; + } + logger.info("Deleting Vlan with Id %s", vlan.id()); + api.getNetworkApi().deleteVlan(vlan.id()); + waitForDeleteVlan(injector, vlan); + } + catch (Exception e) + { + logger.error("Unable to delete Vlan with Id %s due to: %s", vlan.id(), e.getMessage()); } - logger.info("Deleting Vlan with Id %s", vlan.id()); - api.getNetworkApi().deleteVlan(vlan.id()); - waitForDeleteVlan(injector, vlan); } } @@ -141,25 +148,32 @@ private static void deleteServers(DimensionDataCloudControlApi api, Injector inj { for (Server server : api.getServerApi().listServers(DatacenterIdListFilters.Builder.datacenterId(datacenterId))) { - if (server.state() == State.FAILED_ADD) - { - logger.info("Server with Id %s is not in a FAILED_ADD state, manually run Clean Server operation.", server.id()); - continue; - } - if (server.state() != State.NORMAL) + try { - logger.info("Server with Id %s is not in a NORMAL state, current state %s - cannot delete", server.id(), server.state()); - continue; + if (server.state() == State.FAILED_ADD) + { + logger.info("Server with Id %s is not in a FAILED_ADD state, manually run Clean Server operation.", server.id()); + continue; + } + if (server.state() != State.NORMAL) + { + logger.info("Server with Id %s is not in a NORMAL state, current state %s - cannot delete", server.id(), server.state()); + continue; + } + if (server.started()) + { + logger.info("Shutting down Server with Id %s", server.id()); + api.getServerApi().shutdownServer(server.id()); + waitForServerStopped(injector, server); + } + logger.info("Deleting Server with Id %s", server.id()); + api.getServerApi().deleteServer(server.id()); + waitForServerDeleted(injector, server); } - if (server.started()) + catch (Exception e) { - logger.info("Shutting down Server with Id %s", server.id()); - api.getServerApi().shutdownServer(server.id()); - waitForServerStopped(injector, server); + logger.error("Unable to Delete Server with Id %s due to: %s", server.id(), e.getMessage()); } - logger.info("Deleting Server with Id %s", server.id()); - api.getServerApi().deleteServer(server.id()); - waitForServerDeleted(injector, server); } } From f5cc1cda6d42378b9bbd4c390ce4004365e1d560 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Mon, 8 Oct 2018 16:16:09 +0100 Subject: [PATCH 14/21] Example of Dimension Data CloudControl provider --- .../cloudcontrol/NetworkDomainTearDown.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java index cba95428..5d989ac7 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -16,6 +16,7 @@ */ package org.jclouds.examples.dimensiondata.cloudcontrol; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; import com.google.inject.Module; @@ -80,9 +81,19 @@ public static void main(String[] args) deleteServers(api, injector, datacenterId); + ImmutableList servers = api.getServerApi().listServers().concat().toList(); + if (!servers.isEmpty()) + { + logger.info("Could not delete all Servers. Servers not deleted:"); + for (Server server : servers) + { + logger.info("Id %s, Name %s, State, %s", server.id(), server.name(), server.state()); + } + } deleteVlans(api, injector, networkDomain); deleteNetworkDomain(networkDomainId, api, injector); + } private static void removePublicIpBlocks(String networkDomainId, DimensionDataCloudControlApi api) From 3e1290a9e81b651ffc4212a56884969bef2782e0 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Mon, 8 Oct 2018 17:18:09 +0100 Subject: [PATCH 15/21] Adding comments to the code, in order to prep for adding guide to https://jclouds.apache.org/guides --- .../DeleteServerVlanAndNetworkDomain.java | 70 ++++++++++- .../DeployNetworkDomainVlanAndServer.java | 109 +++++++++++++++--- 2 files changed, 157 insertions(+), 22 deletions(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java index fd632e87..f58f8f60 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java @@ -30,25 +30,47 @@ import static org.jclouds.examples.dimensiondata.cloudcontrol.WaitForUtils.*; +/** + * This class will attempt to delete the assets created in org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer: + *
    Server
+ *
    Vlan
+ *
    Network Domain
+ *
    Tag Key
+ */ public class DeleteServerVlanAndNetworkDomain { - private static final String AU_9 = "AU9"; + private static final String DIMENSIONDATA_CLOUDCONTROL_PROVIDER = "dimensiondata-cloudcontrol"; public static void main(String[] args) { - String provider = "dimensiondata-cloudcontrol"; + /* + * Build an instance of the Dimension DataCloud Control Provider using the endpoint provided. + * Typically the endpoint will be of the form https://api-GEO.dimensiondata.com/caas + * We also need to provide authenticate details, a username and password. + * + * Internally the Dimension Data CloudControl Provider will use the org.jclouds.dimensiondata.cloudcontrol.features.AccountApi + * to lookup the organization identifier so that it is used as part of the requests. + * + */ String endpoint = args[0]; String username = args[1]; String password = args[2]; - ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider); + ContextBuilder contextBuilder = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER); DimensionDataCloudControlApi api = contextBuilder .endpoint(endpoint) .credentials(username, password) .modules(ImmutableSet.of(new SLF4JLoggingModule())) .buildApi(DimensionDataCloudControlApi.class); + /* + * Retrieve the Guice injector from the context. + * We will use this for retrieving the some Predicates that are used by the following operations. + */ Injector injector = contextBuilder.buildInjector(); + /* + * Referencing the asset created in org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer + */ final String networkDomainName = "jclouds-example"; String networkDomainId = getNetworkDomainId(api, networkDomainName); final String serverName = "jclouds-server"; @@ -62,6 +84,9 @@ public static void main(String[] args) private static void deleteTagKey(DimensionDataCloudControlApi api, final String tagkeyName) { + /* + * Find the Tag Key and Delete using the id. + */ String id = api.getTagApi().listTagKeys().concat().firstMatch(new Predicate() { @Override @@ -75,6 +100,9 @@ public boolean apply(TagKey input) private static String getNetworkDomainId(DimensionDataCloudControlApi api, final String networkDomainName) { + /* + * Find the Network Domain that was deployed by listing all Network Domains filtering by name + */ return api.getNetworkApi().listNetworkDomains().concat().firstMatch(new Predicate() { @Override @@ -87,6 +115,9 @@ public boolean apply(NetworkDomain input) private static void deleteVlan(DimensionDataCloudControlApi api, Injector injector, final String vlanName, String networkDomainId) { + /* + * Find the Vlan that was deployed by listing all Vlans for the Network Domain and filtering by name + */ Vlan vlan = api.getNetworkApi().listVlans(networkDomainId).concat().firstMatch(new Predicate() { @Override @@ -95,20 +126,38 @@ public boolean apply(Vlan input) return input.name().equals(vlanName); } }).get(); + + /* + * Delete the Vlan using the id. + */ api.getNetworkApi().deleteVlan(vlan.id()); + /* + * A Vlan delete is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Vlan is not found. + */ waitForDeleteVlan(injector, vlan); } private static void deleteNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String networkDomainId) { + /* + * Network Domain is deleted using the id. + */ api.getNetworkApi().deleteNetworkDomain(networkDomainId); + /* + * A Network Domain delete is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Network Domain is not found. + */ waitForDeleteNetworkDomain(injector, networkDomainId); } private static void deleteServer(DimensionDataCloudControlApi api, Injector injector, final String serverName) { + /* + * We list all servers known to this organisation. We filter the one that matches the server name we used to create it. + */ Server server = api.getServerApi().listServers().concat().firstMatch(new Predicate() { @Override @@ -120,12 +169,27 @@ public boolean apply(Server input) if (server.started()) { + /* + * A Server must not be started in order to delete it. We call the shutdown server operation. + */ api.getServerApi().shutdownServer(server.id()); + + /* + * A Shutdown Server operation is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Server is shutdown. + */ waitForServerStopped(injector, server); } + /* + * Server is deleted using the id. + */ api.getServerApi().deleteServer(server.id()); + /* + * A Server delete is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Server is not found. + */ waitForServerDeleted(injector, server); } diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java index 368832e3..9ec10620 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java @@ -16,7 +16,6 @@ */ package org.jclouds.examples.dimensiondata.cloudcontrol; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -24,33 +23,61 @@ import com.google.inject.Module; import org.jclouds.ContextBuilder; import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; -import org.jclouds.dimensiondata.cloudcontrol.domain.*; -import org.jclouds.javax.annotation.Nullable; +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.TagInfo; +import org.jclouds.dimensiondata.cloudcontrol.options.DatacenterIdListFilters; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import java.util.Collections; import java.util.List; +import static org.jclouds.examples.dimensiondata.cloudcontrol.WaitForUtils.*; + +/** + * This class will attempt to Deploy: + *
    Network Domain
+ *
    Vlan
+ *
    Server
+ * For each of these deployed assets we will tag them so that we know they were created by jclouds. + */ public class DeployNetworkDomainVlanAndServer { private static final String AU_9 = "AU9"; + private static final String DIMENSIONDATA_CLOUDCONTROL_PROVIDER = "dimensiondata-cloudcontrol"; public static void main(String[] args) { - String provider = "dimensiondata-cloudcontrol"; String endpoint = args[0]; String username = args[1]; String password = args[2]; - ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider); + /* + * Build an instance of the Dimension DataCloud Control Provider using the endpoint provided. + * Typically the endpoint will be of the form https://api-GEO.dimensiondata.com/caas + * We also need to provide authenticate details, a username and password. + * + * Internally the Dimension Data CloudControl Provider will use the org.jclouds.dimensiondata.cloudcontrol.features.AccountApi + * to lookup the organization identifier so that it is used as part of the requests. + * + */ + ContextBuilder contextBuilder = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER); DimensionDataCloudControlApi api = contextBuilder .endpoint(endpoint) .credentials(username, password) .modules(ImmutableSet.of(new SLF4JLoggingModule())) .buildApi(DimensionDataCloudControlApi.class); + /* + * Retrieve the Guice injector from the context. + * We will use this for retrieving the some Predicates that are used by the following operations. + */ Injector injector = contextBuilder.buildInjector(); + /* + * Create a tag key. We will use this to tag the assets that we create. + */ String tagKeyId = api.getTagApi().createTagKey("jclouds", "owner of the asset", true, false); String networkDomainId = deployNetworkDomain(api, injector, tagKeyId); @@ -61,39 +88,71 @@ public static void main(String[] args) private static void deployServer(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String vlanId, String tagKeyId) { + /* + * The server we deploy will use a pre-configured image. + * + * In Dimension Data Cloud Control we support OS Images and + * Customer Images (user created using the org.jclouds.dimensiondata.cloudcontrol.features.ServerApi.cloneServer operation) + */ String imageId = getOsImage(api); + /* + * The Server that gets deployed will have some network configuration. It gets assigned to the Vlan that was created previously. + */ NetworkInfo networkInfo = NetworkInfo .create(networkDomainId, NIC.builder().vlanId(vlanId).build(), Lists.newArrayList()); + /* + * The Server that gets deployed will have some additional disk configuration. + */ List disks = ImmutableList.of(Disk.builder().scsiId(0).speed("STANDARD").build()); + + /* + * The Server is deployed using the OS Image we selected, + * a flag to signal if we want it started or not, an admin pass and the additional configuration we built. + */ String serverId = api.getServerApi() .deployServer("jclouds-server", imageId, true, networkInfo, "P$$ssWwrrdGoDd!", disks, null); - WaitForUtils.waitForServerStartedAndNormal(injector, serverId); + /* + * A Server deployment is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Server's State has moved from PENDING_ADD to NORMAL. + */ + waitForServerStartedAndNormal(injector, serverId); + /* + * Apply a Tag to the Server. We use AssetType SERVER. + * We pass in the tagKeyId and a value that we want to associate, in this case jclouds. + */ api.getTagApi().applyTags(serverId, "SERVER", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); } private static String getOsImage(DimensionDataCloudControlApi api) { - return api.getServerImageApi().listOsImages().concat() - .firstMatch(new Predicate() - { - @Override - public boolean apply(@Nullable OsImage input) - { - return input.datacenterId().equals(AU_9); - } - }).get().id(); + /* + * We list available OS Images filtering on the Region (Datacenter) we wish to operate on. + */ + return api.getServerImageApi().listOsImages(DatacenterIdListFilters.Builder.datacenterId(AU_9)).iterator().next().id(); } private static String deployNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String tagKeyId) { - // Deploy Network Domain & wait for NORMAL state + /* + * Deploy Network Domain to the Region we wish to operate on. The response from this API is the Network Domain Identifier. + */ String networkDomainId = api.getNetworkApi().deployNetworkDomain(AU_9, "jclouds-example", "jclouds-example", "ESSENTIALS"); - WaitForUtils.waitForNetworkDomainNormal(injector, networkDomainId); + /* + * A Network Domain deployment is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Network Domain's State has moved from PENDING_ADD to NORMAL. + * We pass the Network Domain Identifier we wish to check the state of. + */ + waitForNetworkDomainNormal(injector, networkDomainId); + + /* + * Apply a Tag to the Network Domain. We use AssetType NETWORK_DOMAIN. + * We pass in the tagKeyId and a value that we want to associate, in this case jclouds. + */ api.getTagApi().applyTags(networkDomainId, "NETWORK_DOMAIN", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); return networkDomainId; } @@ -101,10 +160,22 @@ private static String deployNetworkDomain(DimensionDataCloudControlApi api, Inje private static String deployVlan(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String tagKeyId) { - // Deploy VLAN & wait for NORMAL state + /* + * Deploy the Vlan and associate it with the Network Domain that was previously created. + * The Vlan is deployed with a privateIpv4BaseAddress and privateIpv4PrefixSize + */ String vlanId = api.getNetworkApi().deployVlan(networkDomainId, "jclouds-example-vlan", "jclouds-example-vlan", "10.0.0.0", 24); - WaitForUtils.waitForVlanNormal(injector, vlanId); + /* + * A Vlan deployment is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Vlan's State has moved from PENDING_ADD to NORMAL. + */ + waitForVlanNormal(injector, vlanId); + + /* + * Apply a Tag to the Vlan. We use AssetType VLAN. + * We pass in the tagKeyId and a value that we want to associate, in this case jclouds. + */ api.getTagApi().applyTags(vlanId, "VLAN", Collections.singletonList(TagInfo.create(tagKeyId, "jclouds"))); return vlanId; } From 9f7b5cff46d85aba4264e1d2a476667ae44ee956 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Tue, 9 Oct 2018 11:17:04 +0100 Subject: [PATCH 16/21] Adding comments to the code, in order to prep for adding guide to https://jclouds.apache.org/guides --- .../DeleteServerVlanAndNetworkDomain.java | 97 ++++++++++--------- 1 file changed, 52 insertions(+), 45 deletions(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java index f58f8f60..dcb2f3e4 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java @@ -16,16 +16,17 @@ */ package org.jclouds.examples.dimensiondata.cloudcontrol; +import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; import com.google.inject.Module; import org.jclouds.ContextBuilder; 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.TagKey; import org.jclouds.dimensiondata.cloudcontrol.domain.Vlan; +import org.jclouds.dimensiondata.cloudcontrol.options.DatacenterIdListFilters; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import static org.jclouds.examples.dimensiondata.cloudcontrol.WaitForUtils.*; @@ -39,6 +40,7 @@ */ public class DeleteServerVlanAndNetworkDomain { + private static final String AU_9 = "AU9"; private static final String DIMENSIONDATA_CLOUDCONTROL_PROVIDER = "dimensiondata-cloudcontrol"; public static void main(String[] args) @@ -79,7 +81,7 @@ public static void main(String[] args) deleteServer(api, injector, serverName); deleteVlan(api, injector, vlanName, networkDomainId); deleteNetworkDomain(api, injector, networkDomainId); - deleteTagKey(api, "owner"); + deleteTagKey(api, "jclouds"); } private static void deleteTagKey(DimensionDataCloudControlApi api, final String tagkeyName) @@ -87,30 +89,26 @@ private static void deleteTagKey(DimensionDataCloudControlApi api, final String /* * Find the Tag Key and Delete using the id. */ - String id = api.getTagApi().listTagKeys().concat().firstMatch(new Predicate() + Optional tagKeyOptional = api.getTagApi().listTagKeys().concat().firstMatch(new Predicate() { @Override public boolean apply(TagKey input) { return input.name().equals(tagkeyName); } - }).get().id(); - api.getTagApi().deleteTagKey(id); + }); + if (tagKeyOptional.isPresent()) + { + api.getTagApi().deleteTagKey(tagKeyOptional.get().id()); + } } private static String getNetworkDomainId(DimensionDataCloudControlApi api, final String networkDomainName) { /* - * Find the Network Domain that was deployed by listing all Network Domains filtering by name + * Find the Network Domain that was deployed by doing a filtered lookup using the datacenter and the network domain name. */ - return api.getNetworkApi().listNetworkDomains().concat().firstMatch(new Predicate() - { - @Override - public boolean apply(NetworkDomain input) - { - return input.name().equals(networkDomainName); - } - }).get().id(); + return api.getNetworkApi().listNetworkDomainsWithDatacenterIdAndName(AU_9, networkDomainName).concat().toList().get(0).id(); } private static void deleteVlan(DimensionDataCloudControlApi api, Injector injector, final String vlanName, String networkDomainId) @@ -118,25 +116,29 @@ private static void deleteVlan(DimensionDataCloudControlApi api, Injector inject /* * Find the Vlan that was deployed by listing all Vlans for the Network Domain and filtering by name */ - Vlan vlan = api.getNetworkApi().listVlans(networkDomainId).concat().firstMatch(new Predicate() + Optional vlanOptional = api.getNetworkApi().listVlans(networkDomainId).concat().firstMatch(new Predicate() { @Override public boolean apply(Vlan input) { return input.name().equals(vlanName); } - }).get(); + }); + if (vlanOptional.isPresent()) + { + Vlan vlan = vlanOptional.get(); - /* - * Delete the Vlan using the id. - */ - api.getNetworkApi().deleteVlan(vlan.id()); + /* + * Delete the Vlan using the id. + */ + api.getNetworkApi().deleteVlan(vlan.id()); - /* - * A Vlan delete is an asynchronous process. We need to wait for it to complete. The Dimension Data provider - * has built in predicates that will block execution and check that the Vlan is not found. - */ - waitForDeleteVlan(injector, vlan); + /* + * A Vlan delete is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Vlan is not found. + */ + waitForDeleteVlan(injector, vlan); + } } private static void deleteNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String networkDomainId) @@ -156,41 +158,46 @@ private static void deleteNetworkDomain(DimensionDataCloudControlApi api, Inject private static void deleteServer(DimensionDataCloudControlApi api, Injector injector, final String serverName) { /* - * We list all servers known to this organisation. We filter the one that matches the server name we used to create it. + * We list all servers known to this organisation for the datacenter we are operating on. We filter the one that matches the server name we used to create it. */ - Server server = api.getServerApi().listServers().concat().firstMatch(new Predicate() + Optional serverOptional = api.getServerApi().listServers(DatacenterIdListFilters.Builder.datacenterId(AU_9)).firstMatch(new Predicate() { @Override public boolean apply(Server input) { return input.name().equals(serverName); } - }).get(); + }); - if (server.started()) + if (serverOptional.isPresent()) { + Server server = serverOptional.get(); + if (server.started()) + { + /* + * A Server must not be started in order to delete it. We call the shutdown server operation. + */ + api.getServerApi().shutdownServer(server.id()); + + /* + * A Shutdown Server operation is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Server is shutdown. + */ + waitForServerStopped(injector, server); + } + /* - * A Server must not be started in order to delete it. We call the shutdown server operation. + * Server is deleted using the id. */ - api.getServerApi().shutdownServer(server.id()); + api.getServerApi().deleteServer(server.id()); /* - * A Shutdown Server operation is an asynchronous process. We need to wait for it to complete. The Dimension Data provider - * has built in predicates that will block execution and check that the Server is shutdown. + * A Server delete is an asynchronous process. We need to wait for it to complete. The Dimension Data provider + * has built in predicates that will block execution and check that the Server is not found. */ - waitForServerStopped(injector, server); - } + waitForServerDeleted(injector, server); - /* - * Server is deleted using the id. - */ - api.getServerApi().deleteServer(server.id()); - - /* - * A Server delete is an asynchronous process. We need to wait for it to complete. The Dimension Data provider - * has built in predicates that will block execution and check that the Server is not found. - */ - waitForServerDeleted(injector, server); + } } } From 99c618d34a919ad9fd4e16dc60d6e7042c50be37 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Wed, 10 Oct 2018 14:01:38 +0100 Subject: [PATCH 17/21] Example of Dimension Data CloudControl provider. Code review comments. --- blobstore-basics/pom.xml | 2 +- blobstore-largeblob/pom.xml | 2 +- blobstore-uploader/dependency-reduced-pom.xml | 2 +- blobstore-uploader/pom.xml | 2 +- chef-basics/pom.xml | 2 +- compute-basics/pom.xml | 2 +- dimensiondata/README.md | 64 ++++++++++++++ dimensiondata/pom.xml | 48 +++++------ .../DeleteServerVlanAndNetworkDomain.java | 74 +++++++++------- .../DeployNetworkDomainVlanAndServer.java | 78 ++++++++++------- .../cloudcontrol/NetworkDomainTearDown.java | 86 +++++++++++-------- .../cloudcontrol/WaitForUtils.java | 28 ++++-- glacier/pom.xml | 2 +- google-lb/pom.xml | 2 +- openstack/pom.xml | 2 +- rackspace/pom.xml | 2 +- 16 files changed, 259 insertions(+), 139 deletions(-) create mode 100644 dimensiondata/README.md diff --git a/blobstore-basics/pom.xml b/blobstore-basics/pom.xml index 92e62f18..9da345e7 100644 --- a/blobstore-basics/pom.xml +++ b/blobstore-basics/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples blobstore-basics - 2.2.0-SNAPSHOT + 2.1.0 blobstore-basics jclouds blobstore example that creates a container, then displays the size of each container diff --git a/blobstore-largeblob/pom.xml b/blobstore-largeblob/pom.xml index ba2bbdf4..068f584e 100644 --- a/blobstore-largeblob/pom.xml +++ b/blobstore-largeblob/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples blobstore-largeblob - 2.2.0-SNAPSHOT + 2.1.0 blobstore-largeblob jclouds blobstore example that creates a container, then uploads a large file using parallel multipart upload diff --git a/blobstore-uploader/dependency-reduced-pom.xml b/blobstore-uploader/dependency-reduced-pom.xml index ef33fd24..a5ca3add 100644 --- a/blobstore-uploader/dependency-reduced-pom.xml +++ b/blobstore-uploader/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 blobstore-uploader blob-uploader - 2.2.0-SNAPSHOT + 2.1.0 diff --git a/blobstore-uploader/pom.xml b/blobstore-uploader/pom.xml index 9367e85e..57f70141 100644 --- a/blobstore-uploader/pom.xml +++ b/blobstore-uploader/pom.xml @@ -24,7 +24,7 @@ blobstore-uploader blob-uploader - 2.2.0-SNAPSHOT + 2.1.0 2.1.0 diff --git a/chef-basics/pom.xml b/chef-basics/pom.xml index 9a9f66a9..49fec29c 100644 --- a/chef-basics/pom.xml +++ b/chef-basics/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples chef-basics - 2.2.0-SNAPSHOT + 2.1.0 chef-basics jclouds chef example that adds a node to a group, then installs an Apache web server on all nodes diff --git a/compute-basics/pom.xml b/compute-basics/pom.xml index 2e6fbc78..217da906 100644 --- a/compute-basics/pom.xml +++ b/compute-basics/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples compute-basics - 2.2.0-SNAPSHOT + 2.1.0 compute-basics jclouds compute example that adds a node to a group, then executes "echo hello" on all nodes diff --git a/dimensiondata/README.md b/dimensiondata/README.md new file mode 100644 index 00000000..77f1c7f6 --- /dev/null +++ b/dimensiondata/README.md @@ -0,0 +1,64 @@ +# Dimension Data Examples +Example code that uses jclouds to perform common tasks on an Dimension Data CloudControl. The class names are self-explanatory and the code is well commented for you to follow along. + +- [Requirements](#requirements) +- [Environment](#environment) +- [The Examples](#examples) +- [Support and Feedback](#support-and-feedback) + +## Requirements + +1. Username and password for Dimension Data CloudControl - See the [Getting Started guide](http://jclouds.apache.org/guides/dimensiondata/). +1. Java Development Kit (JDK) version 6 or later - [Download](http://www.oracle.com/technetwork/java/javase/downloads/index.html). +1. Apache Maven - [Maven in 5 Minutes](http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html). +1. Git - [Download](http://git-scm.com/downloads). + +## Environment +To setup an environment to compile and run the examples use these commands: + +``` +git clone https://github.com/jclouds/jclouds-examples.git +cd jclouds-examples/dimensiondata/ +``` + +To download all dependencies, run: + +``` +mvn dependency:copy-dependencies "-DoutputDirectory=./lib" +``` + +If you also want to download the source jars, run: + +``` +mvn dependency:copy-dependencies "-DoutputDirectory=./lib" "-Dclassifier=sources" +``` + +## Examples + +To run individual examples from the command line use these commands: + +Note: If you're on Windows, the only change you need to make is to use a ';' instead of a ':' in the paths. + +``` +javac -classpath "lib/*:src/main/java/:src/main/resources/" src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/*.java +``` + +Every example class has a main method that takes the following arguments in the listed order + +1. API Endpoint +1. Username +1. Password + +Try out an example. + +``` +java -classpath "lib/*:src/main/java/:src/main/resources/" org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer apiEndpoint username password +``` + +Watch the terminal for output! + +## Support and Feedback + +Your feedback is appreciated! If you have specific issues with Dimension Data CloudControl support in jclouds, we'd prefer that you file an issue via [JIRA](https://issues.apache.org/jira/browse/JCLOUDS). + +If you have questions or need help, please join our [community](http://jclouds.apache.org/community/) and subscribe to the jclouds user mailing list. diff --git a/dimensiondata/pom.xml b/dimensiondata/pom.xml index 871ba55f..8dcb1c2c 100644 --- a/dimensiondata/pom.xml +++ b/dimensiondata/pom.xml @@ -33,14 +33,14 @@ 2.2.0-SNAPSHOT - 2.1.0 + 2.2.0-SNAPSHOT org.apache.jclouds.labs dimensiondata-cloudcontrol - 2.2.0-SNAPSHOT + ${jclouds.version} org.apache.jclouds @@ -48,9 +48,9 @@ ${jclouds.version} - org.apache.jclouds.driver - jclouds-slf4j - ${jclouds.version} + org.apache.jclouds.driver + jclouds-slf4j + ${jclouds.version} @@ -61,7 +61,7 @@ org.apache.jclouds.driver jclouds-slf4j - 2.2.0-SNAPSHOT + ${jclouds.version} compile @@ -73,27 +73,27 @@ 3.1 ${project.build.sourceEncoding} - 1.6 - 1.6 + 1.7 + 1.7 - maven-assembly-plugin - 2.2.1 - - - src/main/assembly/jar-with-dependencies.xml - - - - - make-assembly - package - - single - - - + maven-assembly-plugin + 2.2.1 + + + jar-with-dependencies + + + + + make-assembly + package + + single + + + diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java index dcb2f3e4..b5865347 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java @@ -20,7 +20,6 @@ import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; -import com.google.inject.Module; import org.jclouds.ContextBuilder; import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; import org.jclouds.dimensiondata.cloudcontrol.domain.Server; @@ -28,19 +27,21 @@ import org.jclouds.dimensiondata.cloudcontrol.domain.Vlan; import org.jclouds.dimensiondata.cloudcontrol.options.DatacenterIdListFilters; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.rest.ApiContext; import static org.jclouds.examples.dimensiondata.cloudcontrol.WaitForUtils.*; /** * This class will attempt to delete the assets created in org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer: - *
    Server
- *
    Vlan
- *
    Network Domain
- *
    Tag Key
+ *
    + *
  • Server
  • + *
  • Vlan
  • + *
  • Network Domain
  • + *
  • Tag Key
  • */ public class DeleteServerVlanAndNetworkDomain { - private static final String AU_9 = "AU9"; + private static final String REGION = System.getProperty("jclouds.region", "AU9"); private static final String DIMENSIONDATA_CLOUDCONTROL_PROVIDER = "dimensiondata-cloudcontrol"; public static void main(String[] args) @@ -57,31 +58,42 @@ public static void main(String[] args) String endpoint = args[0]; String username = args[1]; String password = args[2]; - ContextBuilder contextBuilder = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER); - DimensionDataCloudControlApi api = contextBuilder - .endpoint(endpoint) - .credentials(username, password) - .modules(ImmutableSet.of(new SLF4JLoggingModule())) - .buildApi(DimensionDataCloudControlApi.class); + ApiContext ctx = null; + try + { + ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER) + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .build(); - /* - * Retrieve the Guice injector from the context. - * We will use this for retrieving the some Predicates that are used by the following operations. - */ - Injector injector = contextBuilder.buildInjector(); + /* + * Retrieve the Guice injector from the context. + * We will use this for retrieving the some Predicates that are used by the following operations. + */ + Injector injector = ctx.utils().injector(); + DimensionDataCloudControlApi api = ctx.getApi(); - /* - * Referencing the asset created in org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer - */ - final String networkDomainName = "jclouds-example"; - String networkDomainId = getNetworkDomainId(api, networkDomainName); - final String serverName = "jclouds-server"; - final String vlanName = "jclouds-example-vlan"; - - deleteServer(api, injector, serverName); - deleteVlan(api, injector, vlanName, networkDomainId); - deleteNetworkDomain(api, injector, networkDomainId); - deleteTagKey(api, "jclouds"); + /* + * Referencing the asset created in org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer + */ + final String networkDomainName = "jclouds-example"; + String networkDomainId = getNetworkDomainId(api, networkDomainName); + final String serverName = "jclouds-server"; + final String vlanName = "jclouds-example-vlan"; + + deleteServer(api, injector, serverName); + deleteVlan(api, injector, vlanName, networkDomainId); + deleteNetworkDomain(api, injector, networkDomainId); + deleteTagKey(api, "jclouds"); + } + finally + { + if (ctx != null) + { + ctx.close(); + } + } } private static void deleteTagKey(DimensionDataCloudControlApi api, final String tagkeyName) @@ -108,7 +120,7 @@ private static String getNetworkDomainId(DimensionDataCloudControlApi api, final /* * Find the Network Domain that was deployed by doing a filtered lookup using the datacenter and the network domain name. */ - return api.getNetworkApi().listNetworkDomainsWithDatacenterIdAndName(AU_9, networkDomainName).concat().toList().get(0).id(); + return api.getNetworkApi().listNetworkDomainsWithDatacenterIdAndName(REGION, networkDomainName).concat().toList().get(0).id(); } private static void deleteVlan(DimensionDataCloudControlApi api, Injector injector, final String vlanName, String networkDomainId) @@ -160,7 +172,7 @@ private static void deleteServer(DimensionDataCloudControlApi api, Injector inje /* * We list all servers known to this organisation for the datacenter we are operating on. We filter the one that matches the server name we used to create it. */ - Optional serverOptional = api.getServerApi().listServers(DatacenterIdListFilters.Builder.datacenterId(AU_9)).firstMatch(new Predicate() + Optional serverOptional = api.getServerApi().listServers(DatacenterIdListFilters.Builder.datacenterId(REGION)).firstMatch(new Predicate() { @Override public boolean apply(Server input) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java index 9ec10620..8b906c70 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java @@ -20,7 +20,6 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.inject.Injector; -import com.google.inject.Module; import org.jclouds.ContextBuilder; import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; import org.jclouds.dimensiondata.cloudcontrol.domain.Disk; @@ -29,6 +28,7 @@ import org.jclouds.dimensiondata.cloudcontrol.domain.TagInfo; import org.jclouds.dimensiondata.cloudcontrol.options.DatacenterIdListFilters; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.rest.ApiContext; import java.util.Collections; import java.util.List; @@ -37,15 +37,18 @@ /** * This class will attempt to Deploy: - *
      Network Domain
    - *
      Vlan
    - *
      Server
    + *
      + *
    • Network Domain
    • + *
    • Vlan
    • + *
    • Server
    • + *
    + *

    * For each of these deployed assets we will tag them so that we know they were created by jclouds. */ public class DeployNetworkDomainVlanAndServer { - private static final String AU_9 = "AU9"; + private static final String REGION = System.getProperty("jclouds.region", "AU9"); private static final String DIMENSIONDATA_CLOUDCONTROL_PROVIDER = "dimensiondata-cloudcontrol"; public static void main(String[] args) @@ -62,31 +65,43 @@ public static void main(String[] args) * to lookup the organization identifier so that it is used as part of the requests. * */ - ContextBuilder contextBuilder = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER); - DimensionDataCloudControlApi api = contextBuilder - .endpoint(endpoint) - .credentials(username, password) - .modules(ImmutableSet.of(new SLF4JLoggingModule())) - .buildApi(DimensionDataCloudControlApi.class); - - /* - * Retrieve the Guice injector from the context. - * We will use this for retrieving the some Predicates that are used by the following operations. - */ - Injector injector = contextBuilder.buildInjector(); - - /* - * Create a tag key. We will use this to tag the assets that we create. - */ - String tagKeyId = api.getTagApi().createTagKey("jclouds", "owner of the asset", true, false); - - String networkDomainId = deployNetworkDomain(api, injector, tagKeyId); - String vlanId = deployVlan(api, injector, networkDomainId, tagKeyId); - - deployServer(api, injector, networkDomainId, vlanId, tagKeyId); + ApiContext ctx = null; + try + { + ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER) + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .build(); + + /* + * Retrieve the Guice injector from the context. + * We will use this for retrieving the some Predicates that are used by the following operations. + */ + Injector injector = ctx.utils().injector(); + DimensionDataCloudControlApi api = ctx.getApi(); + + /* + * Create a tag key. We will use this to tag the assets that we create. + */ + String tagKeyId = api.getTagApi().createTagKey("jclouds", "owner of the asset", true, false); + + String networkDomainId = deployNetworkDomain(api, injector, tagKeyId); + String vlanId = deployVlan(api, injector, networkDomainId, tagKeyId); + + deployServer(api, injector, networkDomainId, vlanId, tagKeyId); + } + finally + { + if (ctx != null) + { + ctx.close(); + } + } } - private static void deployServer(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String vlanId, String tagKeyId) + private static void deployServer(DimensionDataCloudControlApi api, Injector injector, String + networkDomainId, String vlanId, String tagKeyId) { /* * The server we deploy will use a pre-configured image. @@ -131,7 +146,7 @@ private static String getOsImage(DimensionDataCloudControlApi api) /* * We list available OS Images filtering on the Region (Datacenter) we wish to operate on. */ - return api.getServerImageApi().listOsImages(DatacenterIdListFilters.Builder.datacenterId(AU_9)).iterator().next().id(); + return api.getServerImageApi().listOsImages(DatacenterIdListFilters.Builder.datacenterId(REGION)).iterator().next().id(); } private static String deployNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String tagKeyId) @@ -140,7 +155,7 @@ private static String deployNetworkDomain(DimensionDataCloudControlApi api, Inje /* * Deploy Network Domain to the Region we wish to operate on. The response from this API is the Network Domain Identifier. */ - String networkDomainId = api.getNetworkApi().deployNetworkDomain(AU_9, "jclouds-example", "jclouds-example", "ESSENTIALS"); + String networkDomainId = api.getNetworkApi().deployNetworkDomain(REGION, "jclouds-example", "jclouds-example", "ESSENTIALS"); /* * A Network Domain deployment is an asynchronous process. We need to wait for it to complete. The Dimension Data provider @@ -157,7 +172,8 @@ private static String deployNetworkDomain(DimensionDataCloudControlApi api, Inje return networkDomainId; } - private static String deployVlan(DimensionDataCloudControlApi api, Injector injector, String networkDomainId, String tagKeyId) + private static String deployVlan(DimensionDataCloudControlApi api, Injector injector, String + networkDomainId, String tagKeyId) { /* diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java index 5d989ac7..16eb8090 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -19,13 +19,13 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.inject.Injector; -import com.google.inject.Module; import org.jclouds.ContextBuilder; import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi; import org.jclouds.dimensiondata.cloudcontrol.domain.*; import org.jclouds.dimensiondata.cloudcontrol.options.DatacenterIdListFilters; import org.jclouds.logging.Logger; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.rest.ApiContext; import static org.jclouds.examples.dimensiondata.cloudcontrol.WaitForUtils.*; @@ -50,50 +50,68 @@ public static void main(String[] args) String username = args[1]; String password = args[2]; String networkDomainId = args[3]; - ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider); - DimensionDataCloudControlApi api = contextBuilder - .endpoint(endpoint) - .credentials(username, password) - .modules(ImmutableSet.of(new SLF4JLoggingModule())) - .buildApi(DimensionDataCloudControlApi.class); - - Injector injector = contextBuilder.buildInjector(); - logger.info("Deleting resources for network domain %s", networkDomainId); - NetworkDomain networkDomain = api.getNetworkApi().getNetworkDomain(networkDomainId); - if (networkDomain == null) - { - logger.info("Network Domain with Id %s is not found", networkDomainId); - return; - } - if (networkDomain.state() != State.NORMAL) + + ApiContext ctx = null; + try { - logger.info("Network Domain with Id %s is not in a NORMAL state, cannot delete", networkDomain.id()); - return; - } + ctx = ContextBuilder.newBuilder(provider) + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .build(); + + /* + * Retrieve the Guice injector from the context. + * We will use this for retrieving the some Predicates that are used by the following operations. + */ + Injector injector = ctx.utils().injector(); + DimensionDataCloudControlApi api = ctx.getApi(); + + + logger.info("Deleting resources for network domain %s", networkDomainId); + NetworkDomain networkDomain = api.getNetworkApi().getNetworkDomain(networkDomainId); + if (networkDomain == null) + { + logger.info("Network Domain with Id %s is not found", networkDomainId); + return; + } + if (networkDomain.state() != State.NORMAL) + { + logger.info("Network Domain with Id %s is not in a NORMAL state, cannot delete", networkDomain.id()); + return; + } - String datacenterId = networkDomain.datacenterId(); + String datacenterId = networkDomain.datacenterId(); - removePublicIpBlocks(networkDomainId, api); + removePublicIpBlocks(networkDomainId, api); - deleteNatRules(networkDomainId, api); + deleteNatRules(networkDomainId, api); - deleteFirewallRules(networkDomainId, api); + deleteFirewallRules(networkDomainId, api); - deleteServers(api, injector, datacenterId); + deleteServers(api, injector, datacenterId); - ImmutableList servers = api.getServerApi().listServers().concat().toList(); - if (!servers.isEmpty()) + ImmutableList servers = api.getServerApi().listServers().concat().toList(); + if (!servers.isEmpty()) + { + logger.info("Could not delete all Servers. Servers not deleted:"); + for (Server server : servers) + { + logger.info("Id %s, Name %s, State, %s", server.id(), server.name(), server.state()); + } + return; + } + deleteVlans(api, injector, networkDomain); + + deleteNetworkDomain(networkDomainId, api, injector); + } + finally { - logger.info("Could not delete all Servers. Servers not deleted:"); - for (Server server : servers) + if (ctx != null) { - logger.info("Id %s, Name %s, State, %s", server.id(), server.name(), server.state()); + ctx.close(); } } - deleteVlans(api, injector, networkDomain); - - deleteNetworkDomain(networkDomainId, api, injector); - } private static void removePublicIpBlocks(String networkDomainId, DimensionDataCloudControlApi api) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java index 41b5d46b..53bae182 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/WaitForUtils.java @@ -26,11 +26,21 @@ public class WaitForUtils { - public static void waitForServerStopped(Injector injector, Server server) + + private static final String SERVER_STARTED_PREDICATE = "SERVER_STARTED_PREDICATE"; + private static final String SERVER_NORMAL_PREDICATE = "SERVER_NORMAL_PREDICATE"; + private static final String NETWORK_DOMAIN_NORMAL_PREDICATE = "NETWORK_DOMAIN_NORMAL_PREDICATE"; + private static final String VLAN_NORMAL_PREDICATE = "VLAN_NORMAL_PREDICATE"; + private static final String SERVER_DELETED_PREDICATE = "SERVER_DELETED_PREDICATE"; + private static final String NETWORK_DOMAIN_DELETED_PREDICATE = "NETWORK_DOMAIN_DELETED_PREDICATE"; + private static final String VLAN_DELETED_PREDICATE = "VLAN_DELETED_PREDICATE"; + private static final String SERVER_STOPPED_PREDICATE = "SERVER_STOPPED_PREDICATE"; + + static void waitForServerStopped(Injector injector, Server server) { Predicate serverStoppedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("SERVER_STOPPED_PREDICATE"))); + }, Names.named(SERVER_STOPPED_PREDICATE))); // Wait for Server to be STOPPED serverStoppedPredicate.apply(server.id()); @@ -40,7 +50,7 @@ static void waitForDeleteVlan(Injector injector, Vlan vlan) { Predicate vlanDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("VLAN_DELETED_PREDICATE"))); + }, Names.named(VLAN_DELETED_PREDICATE))); // Wait for VLAN to be DELETED vlanDeletedPredicate.apply(vlan.id()); @@ -50,7 +60,7 @@ static void waitForDeleteNetworkDomain(Injector injector, String networkDomainId { Predicate networkDomainDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("NETWORK_DOMAIN_DELETED_PREDICATE"))); + }, Names.named(NETWORK_DOMAIN_DELETED_PREDICATE))); // Wait for NETWORK DOMAIN to be DELETED networkDomainDeletedPredicate.apply(networkDomainId); @@ -60,7 +70,7 @@ static void waitForServerDeleted(Injector injector, Server server) { Predicate serverDeletedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("SERVER_DELETED_PREDICATE"))); + }, Names.named(SERVER_DELETED_PREDICATE))); // Wait for Server to be DELETED serverDeletedPredicate.apply(server.id()); @@ -70,10 +80,10 @@ static void waitForServerStartedAndNormal(Injector injector, String serverId) { Predicate serverStartedPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("SERVER_STARTED_PREDICATE"))); + }, Names.named(SERVER_STARTED_PREDICATE))); Predicate serverNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("SERVER_NORMAL_PREDICATE"))); + }, Names.named(SERVER_NORMAL_PREDICATE))); // Wait for Server to be started and NORMAL serverStartedPredicate.apply(serverId); @@ -84,7 +94,7 @@ static void waitForNetworkDomainNormal(Injector injector, String networkDomainId { Predicate networkDomainNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("NETWORK_DOMAIN_NORMAL_PREDICATE"))); + }, Names.named(NETWORK_DOMAIN_NORMAL_PREDICATE))); networkDomainNormalPredicate.apply(networkDomainId); } @@ -92,7 +102,7 @@ static void waitForVlanNormal(Injector injector, String vlanId) { Predicate vlanNormalPredicate = injector.getInstance(Key.get(new TypeLiteral>() { - }, Names.named("VLAN_NORMAL_PREDICATE"))); + }, Names.named(VLAN_NORMAL_PREDICATE))); vlanNormalPredicate.apply(vlanId); } } diff --git a/glacier/pom.xml b/glacier/pom.xml index 262015ec..9af4df22 100644 --- a/glacier/pom.xml +++ b/glacier/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples glacier-examples - 2.2.0-SNAPSHOT + 2.1.0 glacier-examples diff --git a/google-lb/pom.xml b/google-lb/pom.xml index a855eba0..4dc67342 100644 --- a/google-lb/pom.xml +++ b/google-lb/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples google-lb - 2.2.0-SNAPSHOT + 2.1.0 google-lb jclouds-labs-google example that shows using the compute specific api and constructing a load balancer. diff --git a/openstack/pom.xml b/openstack/pom.xml index 8bc970f6..5bd40fd3 100644 --- a/openstack/pom.xml +++ b/openstack/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples openstack-examples - 2.2.0-SNAPSHOT + 2.1.0 openstack-examples diff --git a/rackspace/pom.xml b/rackspace/pom.xml index a55aa0a9..2557e346 100644 --- a/rackspace/pom.xml +++ b/rackspace/pom.xml @@ -22,7 +22,7 @@ 4.0.0 org.apache.jclouds.examples rackspace-examples - 2.2.0-SNAPSHOT + 2.1.0 rackspace-examples From 7855306f5e1abba39a13031603a691999cfa169e Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Wed, 10 Oct 2018 17:10:51 +0100 Subject: [PATCH 18/21] Example of Dimension Data CloudControl provider. Code review comments. --- .../main/assembly/jar-with-dependencies.xml | 42 ------------------- 1 file changed, 42 deletions(-) delete mode 100644 dimensiondata/src/main/assembly/jar-with-dependencies.xml diff --git a/dimensiondata/src/main/assembly/jar-with-dependencies.xml b/dimensiondata/src/main/assembly/jar-with-dependencies.xml deleted file mode 100644 index aaa208c1..00000000 --- a/dimensiondata/src/main/assembly/jar-with-dependencies.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - jar-with-dependencies - - jar - - false - - - metaInf-services - - - - - / - true - true - runtime - - - \ No newline at end of file From 8bb536c8bc257e75377febb02c797e53b38fa3a2 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Thu, 11 Oct 2018 10:24:16 +0100 Subject: [PATCH 19/21] Example of Dimension Data CloudControl provider. Code review comments. --- dimensiondata/README.md | 23 +++++++-------- .../DeleteServerVlanAndNetworkDomain.java | 28 +++++++----------- .../DeployNetworkDomainVlanAndServer.java | 29 +++++++------------ .../cloudcontrol/NetworkDomainTearDown.java | 19 ++++-------- 4 files changed, 35 insertions(+), 64 deletions(-) diff --git a/dimensiondata/README.md b/dimensiondata/README.md index 77f1c7f6..30a418f5 100644 --- a/dimensiondata/README.md +++ b/dimensiondata/README.md @@ -21,38 +21,35 @@ git clone https://github.com/jclouds/jclouds-examples.git cd jclouds-examples/dimensiondata/ ``` -To download all dependencies, run: +To package the examples jar file and dependencies run: ``` -mvn dependency:copy-dependencies "-DoutputDirectory=./lib" -``` - -If you also want to download the source jars, run: - -``` -mvn dependency:copy-dependencies "-DoutputDirectory=./lib" "-Dclassifier=sources" +mvn package ``` ## Examples To run individual examples from the command line use these commands: -Note: If you're on Windows, the only change you need to make is to use a ';' instead of a ':' in the paths. - ``` -javac -classpath "lib/*:src/main/java/:src/main/resources/" src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/*.java +cd target ``` -Every example class has a main method that takes the following arguments in the listed order +Every example class has a main method that takes the following arguments in the listed order: 1. API Endpoint 1. Username 1. Password +If there are other arguments required they will follow. The command line format looks like this: +``` +java -cp dimensiondata-cloudcontrol-examples--jar-with-dependencies.jar apiEndpoint username password +``` + Try out an example. ``` -java -classpath "lib/*:src/main/java/:src/main/resources/" org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer apiEndpoint username password +java -cp dimensiondata-cloudcontrol-examples--jar-with-dependencies.jar org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer apiEndpoint username password ``` Watch the terminal for output! diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java index b5865347..8260277c 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeleteServerVlanAndNetworkDomain.java @@ -38,10 +38,11 @@ *

  • Vlan
  • *
  • Network Domain
  • *
  • Tag Key
  • + *
*/ public class DeleteServerVlanAndNetworkDomain { - private static final String REGION = System.getProperty("jclouds.region", "AU9"); + private static final String ZONE = System.getProperty("jclouds.zone", "AU9"); private static final String DIMENSIONDATA_CLOUDCONTROL_PROVIDER = "dimensiondata-cloudcontrol"; public static void main(String[] args) @@ -58,15 +59,13 @@ public static void main(String[] args) String endpoint = args[0]; String username = args[1]; String password = args[2]; - ApiContext ctx = null; - try - { - ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER) - .endpoint(endpoint) - .credentials(username, password) - .modules(ImmutableSet.of(new SLF4JLoggingModule())) - .build(); + try (ApiContext ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER) + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .build()) + { /* * Retrieve the Guice injector from the context. * We will use this for retrieving the some Predicates that are used by the following operations. @@ -87,13 +86,6 @@ public static void main(String[] args) deleteNetworkDomain(api, injector, networkDomainId); deleteTagKey(api, "jclouds"); } - finally - { - if (ctx != null) - { - ctx.close(); - } - } } private static void deleteTagKey(DimensionDataCloudControlApi api, final String tagkeyName) @@ -120,7 +112,7 @@ private static String getNetworkDomainId(DimensionDataCloudControlApi api, final /* * Find the Network Domain that was deployed by doing a filtered lookup using the datacenter and the network domain name. */ - return api.getNetworkApi().listNetworkDomainsWithDatacenterIdAndName(REGION, networkDomainName).concat().toList().get(0).id(); + return api.getNetworkApi().listNetworkDomainsWithDatacenterIdAndName(ZONE, networkDomainName).concat().toList().get(0).id(); } private static void deleteVlan(DimensionDataCloudControlApi api, Injector injector, final String vlanName, String networkDomainId) @@ -172,7 +164,7 @@ private static void deleteServer(DimensionDataCloudControlApi api, Injector inje /* * We list all servers known to this organisation for the datacenter we are operating on. We filter the one that matches the server name we used to create it. */ - Optional serverOptional = api.getServerApi().listServers(DatacenterIdListFilters.Builder.datacenterId(REGION)).firstMatch(new Predicate() + Optional serverOptional = api.getServerApi().listServers(DatacenterIdListFilters.Builder.datacenterId(ZONE)).firstMatch(new Predicate() { @Override public boolean apply(Server input) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java index 8b906c70..f6521e45 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/DeployNetworkDomainVlanAndServer.java @@ -40,7 +40,7 @@ *
    *
  • Network Domain
  • *
  • Vlan
  • - *
  • Server
  • + *
  • Server
  • cd .. *
*

* For each of these deployed assets we will tag them so that we know they were created by jclouds. @@ -48,7 +48,7 @@ public class DeployNetworkDomainVlanAndServer { - private static final String REGION = System.getProperty("jclouds.region", "AU9"); + private static final String ZONE = System.getProperty("jclouds.zone", "AU9"); private static final String DIMENSIONDATA_CLOUDCONTROL_PROVIDER = "dimensiondata-cloudcontrol"; public static void main(String[] args) @@ -65,15 +65,12 @@ public static void main(String[] args) * to lookup the organization identifier so that it is used as part of the requests. * */ - ApiContext ctx = null; - try + try (ApiContext ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER) + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .build()) { - ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER) - .endpoint(endpoint) - .credentials(username, password) - .modules(ImmutableSet.of(new SLF4JLoggingModule())) - .build(); - /* * Retrieve the Guice injector from the context. * We will use this for retrieving the some Predicates that are used by the following operations. @@ -91,13 +88,7 @@ public static void main(String[] args) deployServer(api, injector, networkDomainId, vlanId, tagKeyId); } - finally - { - if (ctx != null) - { - ctx.close(); - } - } + } private static void deployServer(DimensionDataCloudControlApi api, Injector injector, String @@ -146,7 +137,7 @@ private static String getOsImage(DimensionDataCloudControlApi api) /* * We list available OS Images filtering on the Region (Datacenter) we wish to operate on. */ - return api.getServerImageApi().listOsImages(DatacenterIdListFilters.Builder.datacenterId(REGION)).iterator().next().id(); + return api.getServerImageApi().listOsImages(DatacenterIdListFilters.Builder.datacenterId(ZONE)).iterator().next().id(); } private static String deployNetworkDomain(DimensionDataCloudControlApi api, Injector injector, String tagKeyId) @@ -155,7 +146,7 @@ private static String deployNetworkDomain(DimensionDataCloudControlApi api, Inje /* * Deploy Network Domain to the Region we wish to operate on. The response from this API is the Network Domain Identifier. */ - String networkDomainId = api.getNetworkApi().deployNetworkDomain(REGION, "jclouds-example", "jclouds-example", "ESSENTIALS"); + String networkDomainId = api.getNetworkApi().deployNetworkDomain(ZONE, "jclouds-example", "jclouds-example", "ESSENTIALS"); /* * A Network Domain deployment is an asynchronous process. We need to wait for it to complete. The Dimension Data provider diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java index 16eb8090..00cbe862 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -51,14 +51,12 @@ public static void main(String[] args) String password = args[2]; String networkDomainId = args[3]; - ApiContext ctx = null; - try + try (ApiContext ctx = ContextBuilder.newBuilder(provider) + .endpoint(endpoint) + .credentials(username, password) + .modules(ImmutableSet.of(new SLF4JLoggingModule())) + .build()) { - ctx = ContextBuilder.newBuilder(provider) - .endpoint(endpoint) - .credentials(username, password) - .modules(ImmutableSet.of(new SLF4JLoggingModule())) - .build(); /* * Retrieve the Guice injector from the context. @@ -105,13 +103,6 @@ public static void main(String[] args) deleteNetworkDomain(networkDomainId, api, injector); } - finally - { - if (ctx != null) - { - ctx.close(); - } - } } private static void removePublicIpBlocks(String networkDomainId, DimensionDataCloudControlApi api) From 2d46a4b589cf48a778d3b3070703bf0d2db4ac31 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Thu, 11 Oct 2018 10:34:51 +0100 Subject: [PATCH 20/21] Example of Dimension Data CloudControl provider. Code review comments. --- .../dimensiondata/cloudcontrol/NetworkDomainTearDown.java | 8 ++++---- pom.xml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java index 00cbe862..8048f4c3 100644 --- a/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java +++ b/dimensiondata/src/main/java/org/jclouds/examples/dimensiondata/cloudcontrol/NetworkDomainTearDown.java @@ -33,10 +33,10 @@ * This example shows how a Network Domain and all of it's associated assets are removed. * Takes 4 Program Arguments: *

    - *
      1 Endpoint URL
    - *
      2 Usernamme
    - *
      3 Password
    - *
      4 Network Domain Id
    + *
  • Endpoint URL
  • + *
  • Usernamme
  • + *
  • Password
  • + *
  • Network Domain Id
  • *
*/ public class NetworkDomainTearDown diff --git a/pom.xml b/pom.xml index fb3411db..41f2eb88 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 4.0.0 org.apache.jclouds.examples jclouds-examples - 2.2.0-SNAPSHOT + 2.1.0 pom jclouds examples From b3e54fb68ec087c402fa16710d0d07ab39cb54a3 Mon Sep 17 00:00:00 2001 From: Trevor Flanagan Date: Thu, 11 Oct 2018 10:42:49 +0100 Subject: [PATCH 21/21] Example of Dimension Data CloudControl provider. Code review comments. --- dimensiondata/README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dimensiondata/README.md b/dimensiondata/README.md index 30a418f5..54a379b9 100644 --- a/dimensiondata/README.md +++ b/dimensiondata/README.md @@ -31,10 +31,6 @@ mvn package To run individual examples from the command line use these commands: -``` -cd target -``` - Every example class has a main method that takes the following arguments in the listed order: 1. API Endpoint @@ -43,13 +39,13 @@ Every example class has a main method that takes the following arguments in the If there are other arguments required they will follow. The command line format looks like this: ``` -java -cp dimensiondata-cloudcontrol-examples--jar-with-dependencies.jar apiEndpoint username password +java -cp target\dimensiondata-cloudcontrol-examples--jar-with-dependencies.jar apiEndpoint username password ``` Try out an example. ``` -java -cp dimensiondata-cloudcontrol-examples--jar-with-dependencies.jar org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer apiEndpoint username password +java -cp target\dimensiondata-cloudcontrol-examples--jar-with-dependencies.jar org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer apiEndpoint username password ``` Watch the terminal for output!