Skip to content
Permalink
Browse files
Updated Rackspace examples to 1.9.0
  • Loading branch information
Everett Toews committed Mar 30, 2015
1 parent 9a4bc2e commit 741371e6eba0a4fa8dd7d6ef05a6c657fca1825c
Showing 59 changed files with 239 additions and 230 deletions.
@@ -22,11 +22,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.jclouds.examples</groupId>
<artifactId>rackspace-examples</artifactId>
<version>1.8.1</version>
<version>1.9.0</version>
<name>rackspace-examples</name>

<properties>
<jclouds.version>1.8.1</jclouds.version>
<jclouds.version>1.9.0</jclouds.version>
</properties>

<dependencies>
@@ -77,6 +77,11 @@
<artifactId>rackspace-clouddns-us</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.labs</groupId>
<artifactId>rackspace-cdn-us</artifactId>
<version>${jclouds.version}</version>
</dependency>
<!-- Rackspace UK dependencies -->
<dependency>
<groupId>org.apache.jclouds.provider</groupId>
@@ -118,6 +123,11 @@
<artifactId>rackspace-clouddns-uk</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.labs</groupId>
<artifactId>rackspace-cdn-uk</artifactId>
<version>${jclouds.version}</version>
</dependency>
<!-- 3rd party dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
@@ -129,6 +139,11 @@
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.0-rc2</version>
</dependency>
</dependencies>

<build>
@@ -45,7 +45,7 @@ public class Authentication implements Closeable {
private final NovaApi nova;

/**
* To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
* To get a username and API key see http://jclouds.apache.org/guides/rackspace/
*
* The first argument (args[0]) must be your username
* The second argument (args[1]) must be your API key or password
@@ -87,13 +87,13 @@ public Authentication(String[] args) {
}

/**
* Calling getConfiguredZones() causes jclouds to authenticate. If authentication doesn't work, the call to
* getConfiguredZones() will result in an org.jclouds.rest.AuthorizationException
* Calling getConfiguredRegions() causes jclouds to authenticate. If authentication doesn't work, the call to
* getConfiguredRegions() will result in an org.jclouds.rest.AuthorizationException
*/
private void authenticateOnCall() {
System.out.format("Authenticate On Call%n");

nova.getConfiguredZones();
nova.getConfiguredRegions();

System.out.format(" Authenticated%n");
}
@@ -137,18 +137,18 @@ private void deleteCloudBlockStorage() throws IOException {
.credentials(username, apiKey)
.buildApi(CinderApi.class);

for (String zone : cinderApi.getConfiguredZones()) {
for (String region : cinderApi.getConfiguredRegions()) {
try {
System.out.format("Delete Snapshots in %s%n", zone);
SnapshotApi snapshotApi = cinderApi.getSnapshotApiForZone(zone);
System.out.format("Delete Snapshots in %s%n", region);
SnapshotApi snapshotApi = cinderApi.getSnapshotApi(region);

for (Snapshot snapshot : snapshotApi.list()) {
System.out.format(" %s%n", snapshot.getName());
snapshotApi.delete(snapshot.getId());
}

System.out.format("Delete Volumes in %s%n", zone);
VolumeApi volumeApi = cinderApi.getVolumeApiForZone(zone);
System.out.format("Delete Volumes in %s%n", region);
VolumeApi volumeApi = cinderApi.getVolumeApi(region);

for (Volume volume : volumeApi.list()) {
System.out.format(" %s%n", volume.getName());
@@ -167,19 +167,19 @@ private void deleteCloudServers() throws IOException {
.credentials(username, apiKey)
.buildApi(NovaApi.class);

for (String zone : novaApi.getConfiguredZones()) {
for (String region : novaApi.getConfiguredRegions()) {
try {
System.out.format("Delete Key Pairs in %s%n", zone);
KeyPairApi keyPairApi = novaApi.getKeyPairExtensionForZone(zone).get();
System.out.format("Delete Key Pairs in %s%n", region);
KeyPairApi keyPairApi = novaApi.getKeyPairApi(region).get();

for (KeyPair keyPair : keyPairApi.list()) {
System.out.format(" %s%n", keyPair.getName());
keyPairApi.delete(keyPair.getName());
}

System.out.format("Delete Servers in %s%n", zone);
VolumeAttachmentApi volumeAttachmentApi = novaApi.getVolumeAttachmentExtensionForZone(zone).get();
ServerApi serverApi = novaApi.getServerApiForZone(zone);
System.out.format("Delete Servers in %s%n", region);
VolumeAttachmentApi volumeAttachmentApi = novaApi.getVolumeAttachmentApi(region).get();
ServerApi serverApi = novaApi.getServerApi(region);

for (Server server : serverApi.listInDetail().concat().toList()) {
for (VolumeAttachment volumeAttachment : volumeAttachmentApi.listAttachmentsOnServer(server.getId())) {
@@ -202,21 +202,21 @@ private void deleteCloudDatabases() throws IOException {
.credentials(username, apiKey)
.buildApi(TroveApi.class);

for (String zone : troveApi.getConfiguredZones()) {
for (String region : troveApi.getConfiguredRegions()) {
try {
System.out.format("Delete Database Instances of DBs and Users in %s%n", zone);
InstanceApi instanceApi = troveApi.getInstanceApiForZone(zone);
System.out.format("Delete Database Instances of DBs and Users in %s%n", region);
InstanceApi instanceApi = troveApi.getInstanceApi(region);

for (Instance instance : instanceApi.list()) {
System.out.format(" %s%n", instance.getName());
DatabaseApi databaseApi = troveApi.getDatabaseApiForZoneAndInstance(zone, instance.getId());
DatabaseApi databaseApi = troveApi.getDatabaseApi(region, instance.getId());

for (String database : databaseApi.list()) {
System.out.format(" %s%n", database);
databaseApi.delete(database);
}

UserApi userApi = troveApi.getUserApiForZoneAndInstance(zone, instance.getId());
UserApi userApi = troveApi.getUserApi(region, instance.getId());

for (User user : userApi.list()) {
System.out.format(" %s%n", user.getName());
@@ -259,10 +259,10 @@ private void deleteLoadBalancers() throws IOException {
.credentials(username, apiKey)
.buildApi(CloudLoadBalancersApi.class);

for (String zone : clbApi.getConfiguredZones()) {
for (String region : clbApi.getConfiguredRegions()) {
try {
System.out.format("Delete Load Balancers in %s%n", zone);
LoadBalancerApi lbApi = clbApi.getLoadBalancerApiForZone(zone);
System.out.format("Delete Load Balancers in %s%n", region);
LoadBalancerApi lbApi = clbApi.getLoadBalancerApi(region);

for (LoadBalancer loadBalancer : lbApi.list().concat()) {
System.out.format(" %s%n", loadBalancer.getName());
@@ -282,10 +282,10 @@ private void deleteQueues() throws IOException {
.buildApi(MarconiApi.class);
UUID uuid = UUID.randomUUID(); // any UUID can be used to list all queues

for (String zone : marconiApi.getConfiguredZones()) {
for (String region : marconiApi.getConfiguredRegions()) {
try {
System.out.format("Delete Queues in %s%n", zone);
QueueApi queueApi = marconiApi.getQueueApiForZoneAndClient(zone, uuid);
System.out.format("Delete Queues in %s%n", region);
QueueApi queueApi = marconiApi.getQueueApi(region, uuid);

for (Queue queue : queueApi.list(false).concat()) {
System.out.format(" %s%n", queue.getName());
@@ -304,10 +304,10 @@ private void deleteAutoscale() throws IOException {
.credentials(username, apiKey)
.buildApi(AutoscaleApi.class);

for (String zone : autoscaleApi.getConfiguredZones()) {
for (String region : autoscaleApi.getConfiguredRegions()) {
try {
System.out.format("Delete Autoscale Groups in %s%n", zone);
GroupApi groupApi = autoscaleApi.getGroupApiForZone(zone);
System.out.format("Delete Autoscale Groups in %s%n", region);
GroupApi groupApi = autoscaleApi.getGroupApi(region);

for (GroupState groupState : groupApi.listGroupStates()) {
System.out.format(" %s%n", groupState.getId());
@@ -47,7 +47,7 @@ public class Logging implements Closeable {
private final NovaApi nova;

/**
* To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
* To get a username and API key see http://jclouds.apache.org/guides/rackspace/
*
* The first argument (args[0]) must be your username
* The second argument (args[1]) must be your API key
@@ -81,13 +81,13 @@ public Logging(String username, String apiKey) {
}

private void getConfiguredZones() {
// Calling getConfiguredZones() talks to the cloud which gets logged
Set<String> zones = nova.getConfiguredZones();
// Calling getConfiguredRegions() talks to the cloud which gets logged
Set<String> regions = nova.getConfiguredRegions();

System.out.format("Zones%n");

for (String zone : zones) {
System.out.format(" %s%n", zone);
for (String region : regions) {
System.out.format(" %s%n", region);
}
}

@@ -38,7 +38,7 @@ public class SmokeTest {

/**
* To get a username and API key see
* http://www.jclouds.org/documentation/quickstart/rackspace/
* http://jclouds.apache.org/guides/rackspace/
*
* The first argument (args[0]) must be your username
* The second argument (args[1]) must be your API key
@@ -20,7 +20,7 @@

import static org.jclouds.examples.rackspace.autoscale.Constants.NAME;
import static org.jclouds.examples.rackspace.autoscale.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.autoscale.Constants.ZONE;
import static org.jclouds.examples.rackspace.autoscale.Constants.REGION;

import java.io.Closeable;
import java.io.IOException;
@@ -49,7 +49,7 @@ public class AutoscaleCleanup implements Closeable {

/**
* To get a username and API key see
* http://www.jclouds.org/documentation/quickstart/rackspace/
* http://jclouds.apache.org/guides/rackspace/
*
* The first argument (args[0]) must be your username
* The second argument (args[1]) must be your API key
@@ -73,15 +73,15 @@ public AutoscaleCleanup(String username, String apiKey) {
.credentials(username, apiKey)
.buildApi(AutoscaleApi.class);

groupApi = autoscaleApi.getGroupApiForZone(ZONE);
groupApi = autoscaleApi.getGroupApi(REGION);
}

private void autoscaleCleanup() {
System.out.format("Cleanup autoscale %n");

// Remove ALL policies and groups with that name
for (GroupState g : groupApi.listGroupStates()) {
PolicyApi pa = autoscaleApi.getPolicyApiForZoneAndGroup(ZONE, g.getId());
PolicyApi pa = autoscaleApi.getPolicyApi(REGION, g.getId());
for(ScalingPolicy p : pa.list()) {
if(p.getName().equals(NAME)) {
System.out.format("Found matching policy: %s with cooldown %s%n", p.getId(), p.getCooldown());
@@ -26,7 +26,7 @@ public interface Constants {
// To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-autoscale-uk".
// Note that autoscale is not yet supported for the UK.
public static final String PROVIDER = System.getProperty("provider.autoscale", "rackspace-autoscale-us");
public static final String ZONE = System.getProperty("zone", "DFW");
public static final String REGION = System.getProperty("region", "DFW");

public static final String NAME = "jclouds-example";
public static final String SERVICE_NET = "11111111-1111-1111-1111-111111111111";
@@ -22,7 +22,7 @@
import static org.jclouds.examples.rackspace.autoscale.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.autoscale.Constants.PUBLIC_NET;
import static org.jclouds.examples.rackspace.autoscale.Constants.SERVICE_NET;
import static org.jclouds.examples.rackspace.autoscale.Constants.ZONE;
import static org.jclouds.examples.rackspace.autoscale.Constants.REGION;

import java.io.Closeable;
import java.io.IOException;
@@ -59,7 +59,7 @@ public class CreatePolicy implements Closeable {

/**
* To get a username and API key see
* http://www.jclouds.org/documentation/quickstart/rackspace/
* http://jclouds.apache.org/guides/rackspace/
*
* The first argument (args[0]) must be your username
* The second argument (args[1]) must be your API key
@@ -83,7 +83,7 @@ public CreatePolicy(String username, String apiKey) {
.credentials(username, apiKey)
.buildApi(AutoscaleApi.class);

groupApi = autoscaleApi.getGroupApiForZone(ZONE);
groupApi = autoscaleApi.getGroupApi(REGION);
}

private void createPolicy() {
@@ -20,7 +20,7 @@

import static org.jclouds.examples.rackspace.autoscale.Constants.NAME;
import static org.jclouds.examples.rackspace.autoscale.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.autoscale.Constants.ZONE;
import static org.jclouds.examples.rackspace.autoscale.Constants.REGION;

import java.io.Closeable;
import java.io.IOException;
@@ -41,13 +41,11 @@
*/
public class CreateWebhook implements Closeable {
private final AutoscaleApi autoscaleApi;
private final GroupApi groupApi;
private final PolicyApi policyApi;
private final WebhookApi webhookApi;

/**
* To get a username and API key see
* http://www.jclouds.org/documentation/quickstart/rackspace/
* http://jclouds.apache.org/guides/rackspace/
*
* The first argument (args[0]) must be your username
* The second argument (args[1]) must be your API key
@@ -71,11 +69,11 @@ public CreateWebhook(String username, String apiKey) {
.credentials(username, apiKey)
.buildApi(AutoscaleApi.class);

groupApi = autoscaleApi.getGroupApiForZone(ZONE);
GroupApi groupApi = autoscaleApi.getGroupApi(REGION);
String groupId = Utils.getGroupId(groupApi);
policyApi = autoscaleApi.getPolicyApiForZoneAndGroup(ZONE, groupId);
PolicyApi policyApi = autoscaleApi.getPolicyApi(REGION, groupId);
String policyId = Utils.getPolicyId(policyApi);
webhookApi = autoscaleApi.getWebhookApiForZoneAndGroupAndPolicy(ZONE, groupId, policyId);
webhookApi = autoscaleApi.getWebhookApi(REGION, groupId, policyId);
}

private void createWebhook() {
@@ -19,7 +19,7 @@
package org.jclouds.examples.rackspace.autoscale;

import static org.jclouds.examples.rackspace.autoscale.Constants.PROVIDER;
import static org.jclouds.examples.rackspace.autoscale.Constants.ZONE;
import static org.jclouds.examples.rackspace.autoscale.Constants.REGION;

import java.io.Closeable;
import java.io.IOException;
@@ -43,13 +43,12 @@
*/
public class ExecuteWebhook implements Closeable {
private final AutoscaleApi autoscaleApi;
private final GroupApi groupApi;
private final PolicyApi policyApi;
private final WebhookApi webhookApi;

/**
* To get a username and API key see
* http://www.jclouds.org/documentation/quickstart/rackspace/
* http://jclouds.apache.org/guides/rackspace/
*
* The first argument (args[0]) must be your username
* The second argument (args[1]) must be your API key
@@ -73,11 +72,11 @@ public ExecuteWebhook(String username, String apiKey) {
.credentials(username, apiKey)
.buildApi(AutoscaleApi.class);

groupApi = autoscaleApi.getGroupApiForZone(ZONE);
GroupApi groupApi = autoscaleApi.getGroupApi(REGION);
String groupId = Utils.getGroupId(groupApi);
policyApi = autoscaleApi.getPolicyApiForZoneAndGroup(ZONE, groupId);
policyApi = autoscaleApi.getPolicyApi(REGION, groupId);
String policyId = Utils.getPolicyId(policyApi);
webhookApi = autoscaleApi.getWebhookApiForZoneAndGroupAndPolicy(ZONE, groupId, policyId);
webhookApi = autoscaleApi.getWebhookApi(REGION, groupId, policyId);
}

private void executeWebhook() {

0 comments on commit 741371e

Please sign in to comment.