You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/11/02 12:43:21 UTC
[5/5] jclouds-labs git commit: Remove DigitalOcean v1
Remove DigitalOcean v1
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/114b3528
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/114b3528
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/114b3528
Branch: refs/heads/master
Commit: 114b35289fbd39f40a036179310cade5d941cc13
Parents: ca24089
Author: Ignasi Barrera <na...@apache.org>
Authored: Fri Oct 30 22:36:02 2015 +0100
Committer: Ignasi Barrera <na...@apache.org>
Committed: Fri Oct 30 22:36:02 2015 +0100
----------------------------------------------------------------------
digitalocean/README.txt | 1 -
digitalocean/pom.xml | 130 ----
.../jclouds/digitalocean/DigitalOceanApi.java | 70 --
.../digitalocean/DigitalOceanApiMetadata.java | 90 ---
.../DigitalOceanProviderMetadata.java | 78 --
...DigitalOceanComputeServiceContextModule.java | 166 ----
.../extensions/DigitalOceanImageExtension.java | 132 ----
.../functions/DropletStatusToStatus.java | 47 --
.../functions/DropletToNodeMetadata.java | 162 ----
.../compute/functions/ImageToImage.java | 66 --
.../compute/functions/RegionToLocation.java | 58 --
.../compute/functions/SizeToHardware.java | 60 --
...plateOptionsToStatementWithoutPublicKey.java | 60 --
.../options/DigitalOceanTemplateOptions.java | 179 -----
.../strategy/CreateKeyPairsThenCreateNodes.java | 205 -----
.../DigitalOceanComputeServiceAdapter.java | 183 -----
.../compute/util/LocationNamingUtils.java | 70 --
.../config/DigitalOceanHttpApiModule.java | 65 --
.../config/DigitalOceanParserModule.java | 141 ----
.../digitalocean/domain/BaseResponse.java | 118 ---
.../digitalocean/domain/Distribution.java | 66 --
.../jclouds/digitalocean/domain/Droplet.java | 250 ------
.../digitalocean/domain/DropletCreation.java | 120 ---
.../org/jclouds/digitalocean/domain/Event.java | 141 ----
.../org/jclouds/digitalocean/domain/Image.java | 160 ----
.../digitalocean/domain/OperatingSystem.java | 135 ----
.../org/jclouds/digitalocean/domain/Region.java | 98 ---
.../org/jclouds/digitalocean/domain/Size.java | 161 ----
.../org/jclouds/digitalocean/domain/SshKey.java | 96 ---
.../domain/options/CreateDropletOptions.java | 161 ----
.../digitalocean/features/DropletApi.java | 327 --------
.../jclouds/digitalocean/features/EventApi.java | 58 --
.../jclouds/digitalocean/features/ImageApi.java | 140 ----
.../digitalocean/features/KeyPairApi.java | 106 ---
.../digitalocean/features/RegionApi.java | 51 --
.../jclouds/digitalocean/features/SizesApi.java | 51 --
.../handlers/DigitalOceanErrorHandler.java | 59 --
...usFromPayloadHttpCommandExecutorService.java | 131 ----
.../http/filters/AuthenticationFilter.java | 55 --
.../predicates/SameFingerprint.java | 61 --
.../org/jclouds/digitalocean/ssh/DSAKeys.java | 172 -----
.../digitalocean/strategy/ListSshKeys.java | 80 --
.../DigitalOceanProviderMetadataTest.java | 32 -
.../DigitalOceanComputeServiceLiveTest.java | 59 --
.../DigitalOceanImageExtensionLiveTest.java | 40 -
.../compute/config/EventDonePredicateTest.java | 76 --
.../functions/DropletStatusToStatusTest.java | 39 -
.../functions/DropletToNodeMetadataTest.java | 198 -----
.../compute/functions/ImageToImageTest.java | 58 --
.../compute/functions/RegionToLocationTest.java | 54 --
.../compute/functions/SizeToHardwareTest.java | 48 --
...eOptionsToStatementWithoutPublicKeyTest.java | 75 --
.../DigitalOceanTemplateOptionsTest.java | 49 --
.../compute/util/LocationNamingUtilsTest.java | 109 ---
.../domain/OperatingSystemTest.java | 107 ---
.../features/DropletApiLiveTest.java | 205 -----
.../features/DropletApiMockTest.java | 770 -------------------
.../digitalocean/features/EventApiLiveTest.java | 56 --
.../digitalocean/features/EventApiMockTest.java | 93 ---
.../digitalocean/features/ImageApiLiveTest.java | 139 ----
.../digitalocean/features/ImageApiMockTest.java | 262 -------
.../features/KeyPairApiLiveTest.java | 76 --
.../features/KeyPairApiMockTest.java | 213 -----
.../features/RegionApiLiveTest.java | 46 --
.../features/RegionApiMockTest.java | 54 --
.../digitalocean/features/SizeApiLiveTest.java | 46 --
.../digitalocean/features/SizesApiMockTest.java | 54 --
...omPayloadHttpCommandExecutorServiceTest.java | 112 ---
.../http/filters/AuthenticationFilterTest.java | 58 --
.../internal/BaseDigitalOceanLiveTest.java | 90 ---
.../internal/BaseDigitalOceanMockTest.java | 107 ---
.../predicates/SameFingerprintTest.java | 72 --
.../jclouds/digitalocean/ssh/DSAKeysTest.java | 54 --
.../strategy/ListSshKeysLiveTest.java | 83 --
.../src/test/resources/access-denied.json | 5 -
.../src/test/resources/droplet-creation.json | 10 -
digitalocean/src/test/resources/droplet.json | 17 -
digitalocean/src/test/resources/droplets.json | 18 -
digitalocean/src/test/resources/error.json | 5 -
.../src/test/resources/event-pending.json | 10 -
digitalocean/src/test/resources/event.json | 10 -
digitalocean/src/test/resources/eventid.json | 4 -
digitalocean/src/test/resources/image1.json | 12 -
digitalocean/src/test/resources/image2.json | 12 -
digitalocean/src/test/resources/image3.json | 12 -
digitalocean/src/test/resources/images.json | 32 -
digitalocean/src/test/resources/key.json | 8 -
digitalocean/src/test/resources/keys.json | 10 -
digitalocean/src/test/resources/not-found.json | 5 -
digitalocean/src/test/resources/regions.json | 25 -
digitalocean/src/test/resources/sizes.json | 45 --
digitalocean/src/test/resources/ssh-dsa.txt | 1 -
digitalocean/src/test/resources/ssh-rsa.txt | 1 -
pom.xml | 1 -
94 files changed, 8537 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/README.txt
----------------------------------------------------------------------
diff --git a/digitalocean/README.txt b/digitalocean/README.txt
deleted file mode 100644
index 357023e..0000000
--- a/digitalocean/README.txt
+++ /dev/null
@@ -1 +0,0 @@
-The jclouds provider for DigitalOcean (https://www.digitalocean.com/).
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/pom.xml
----------------------------------------------------------------------
diff --git a/digitalocean/pom.xml b/digitalocean/pom.xml
deleted file mode 100644
index 1382502..0000000
--- a/digitalocean/pom.xml
+++ /dev/null
@@ -1,130 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.jclouds.labs</groupId>
- <artifactId>jclouds-labs</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- </parent>
-
- <!-- TODO: when out of labs, switch to org.apache.jclouds.provider -->
- <groupId>org.apache.jclouds.labs</groupId>
- <artifactId>digitalocean</artifactId>
- <name>jclouds DigitalOcean Provider</name>
- <description>ComputeService binding to the DigitalOcean API</description>
- <packaging>bundle</packaging>
-
- <properties>
- <test.digitalocean.endpoint>https://api.digitalocean.com/</test.digitalocean.endpoint>
- <test.digitalocean.api-version></test.digitalocean.api-version>
- <test.digitalocean.identity>FIXME</test.digitalocean.identity>
- <test.digitalocean.credential>FIXME</test.digitalocean.credential>
- <!-- CentOS 6.5 x64 -->
- <test.digitalocean.template>imageId=centos-6-5-x64</test.digitalocean.template>
- <jclouds.osgi.export>org.jclouds.digitalocean*;version="${jclouds.version}"</jclouds.osgi.export>
- <jclouds.osgi.import>
- org.jclouds.compute.internal;version="${jclouds.version}",
- org.jclouds.rest.internal;version="${jclouds.version}",
- org.jclouds*;version="${jclouds.version}",
- *
- </jclouds.osgi.import>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.jclouds</groupId>
- <artifactId>jclouds-compute</artifactId>
- <version>${jclouds.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.jclouds.driver</groupId>
- <artifactId>jclouds-sshj</artifactId>
- <version>${jclouds.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.jclouds</groupId>
- <artifactId>jclouds-core</artifactId>
- <version>${jclouds.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.jclouds</groupId>
- <artifactId>jclouds-compute</artifactId>
- <version>${jclouds.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.squareup.okhttp</groupId>
- <artifactId>mockwebserver</artifactId>
- <scope>test</scope>
- <exclusions>
- <!-- Already provided by jclouds-sshj -->
- <exclusion>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcprov-jdk15on</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>com.google.auto.service</groupId>
- <artifactId>auto-service</artifactId>
- <optional>true</optional>
- </dependency>
- </dependencies>
-
- <profiles>
- <profile>
- <id>live</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <executions>
- <execution>
- <id>integration</id>
- <phase>integration-test</phase>
- <goals>
- <goal>test</goal>
- </goals>
- <configuration>
- <threadCount>1</threadCount>
- <systemPropertyVariables>
- <test.digitalocean.endpoint>${test.digitalocean.endpoint}</test.digitalocean.endpoint>
- <test.digitalocean.api-version>${test.digitalocean.api-version}</test.digitalocean.api-version>
- <test.digitalocean.build-version>${test.digitalocean.build-version}</test.digitalocean.build-version>
- <test.digitalocean.credential>${test.digitalocean.credential}</test.digitalocean.credential>
- <test.digitalocean.template>${test.digitalocean.template}</test.digitalocean.template>
- </systemPropertyVariables>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
-</project>
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanApi.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanApi.java b/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanApi.java
deleted file mode 100644
index 4ff0c00..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanApi.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean;
-
-import java.io.Closeable;
-
-import org.jclouds.digitalocean.features.DropletApi;
-import org.jclouds.digitalocean.features.EventApi;
-import org.jclouds.digitalocean.features.ImageApi;
-import org.jclouds.digitalocean.features.KeyPairApi;
-import org.jclouds.digitalocean.features.RegionApi;
-import org.jclouds.digitalocean.features.SizesApi;
-import org.jclouds.rest.annotations.Delegate;
-
-/**
- * Provides synchronous access to DigitalOcean API.
- */
-public interface DigitalOceanApi extends Closeable {
-
- /**
- * Returns the Droplet management API.
- */
- @Delegate
- DropletApi getDropletApi();
-
- /**
- * Returns the Image management API.
- */
- @Delegate
- ImageApi getImageApi();
-
- /**
- * Returns the Sizes management API.
- */
- @Delegate
- SizesApi getSizesApi();
-
- /**
- * Returns the Region management API.
- */
- @Delegate
- RegionApi getRegionApi();
-
- /**
- * Returns the SSH key management API.
- */
- @Delegate
- KeyPairApi getKeyPairApi();
-
- /**
- * Returns the Event API.
- */
- @Delegate
- EventApi getEventApi();
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanApiMetadata.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanApiMetadata.java b/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanApiMetadata.java
deleted file mode 100644
index 611b228..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanApiMetadata.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean;
-
-import java.net.URI;
-import java.util.Properties;
-
-import org.jclouds.apis.ApiMetadata;
-import org.jclouds.compute.ComputeServiceContext;
-import org.jclouds.digitalocean.compute.config.DigitalOceanComputeServiceContextModule;
-import org.jclouds.digitalocean.config.DigitalOceanHttpApiModule;
-import org.jclouds.digitalocean.config.DigitalOceanHttpApiModule.DigitalOceanHttpCommandExecutorServiceModule;
-import org.jclouds.digitalocean.config.DigitalOceanParserModule;
-import org.jclouds.rest.internal.BaseHttpApiMetadata;
-
-import com.google.common.collect.ImmutableSet;
-import com.google.inject.Module;
-
-/**
- * Implementation of {@link BaseHttpApiMetadata} for the DigitalOcean API
- */
-public class DigitalOceanApiMetadata extends BaseHttpApiMetadata<DigitalOceanApi> {
-
- @Override
- public Builder toBuilder() {
- return new Builder().fromApiMetadata(this);
- }
-
- public DigitalOceanApiMetadata() {
- this(new Builder());
- }
-
- protected DigitalOceanApiMetadata(Builder builder) {
- super(builder);
- }
-
- public static Properties defaultProperties() {
- Properties properties = BaseHttpApiMetadata.defaultProperties();
- return properties;
- }
-
- public static class Builder extends BaseHttpApiMetadata.Builder<DigitalOceanApi, Builder> {
-
- protected Builder() {
- super(DigitalOceanApi.class);
- id("digitalocean")
- .name("DigitalOcean API")
- .identityName("Client Id")
- .credentialName("API Key")
- .documentation(URI.create("https://cloud.digitalocean.com/api_access"))
- .defaultEndpoint("https://api.digitalocean.com")
- .defaultProperties(DigitalOceanApiMetadata.defaultProperties())
- .view(ComputeServiceContext.class)
- .defaultModules(ImmutableSet.<Class<? extends Module>> of(
- DigitalOceanHttpApiModule.class,
- DigitalOceanHttpCommandExecutorServiceModule.class,
- DigitalOceanParserModule.class,
- DigitalOceanComputeServiceContextModule.class));
- }
-
- @Override
- public DigitalOceanApiMetadata build() {
- return new DigitalOceanApiMetadata(this);
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- @Override
- public Builder fromApiMetadata(ApiMetadata in) {
- return this;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanProviderMetadata.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanProviderMetadata.java b/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanProviderMetadata.java
deleted file mode 100644
index 3dbd814..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/DigitalOceanProviderMetadata.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean;
-
-import java.net.URI;
-import java.util.Properties;
-
-import org.jclouds.providers.ProviderMetadata;
-import org.jclouds.providers.internal.BaseProviderMetadata;
-
-import com.google.auto.service.AutoService;
-
-/**
- * Implementation of {@link ProviderMetadata} for DigitalOcean.
- */
-@AutoService(ProviderMetadata.class)
-public class DigitalOceanProviderMetadata extends BaseProviderMetadata {
-
- public static Builder builder() {
- return new Builder();
- }
-
- @Override
- public Builder toBuilder() {
- return builder().fromProviderMetadata(this);
- }
-
- public DigitalOceanProviderMetadata() {
- super(builder());
- }
-
- public DigitalOceanProviderMetadata(Builder builder) {
- super(builder);
- }
-
- public static Properties defaultProperties() {
- Properties properties = DigitalOceanApiMetadata.defaultProperties();
- return properties;
- }
-
- public static class Builder extends BaseProviderMetadata.Builder {
-
- protected Builder() {
- id("digitalocean")
- .name("DigitalOcean Compute Services")
- .apiMetadata(new DigitalOceanApiMetadata())
- .homepage(URI.create("https://www.digitalocean.com/"))
- .console(URI.create("https://cloud.digitalocean.com/"))
- .endpoint("https://api.digitalocean.com")
- .defaultProperties(DigitalOceanProviderMetadata.defaultProperties());
- }
-
- @Override
- public DigitalOceanProviderMetadata build() {
- return new DigitalOceanProviderMetadata(this);
- }
-
- @Override
- public Builder fromProviderMetadata(ProviderMetadata in) {
- super.fromProviderMetadata(in);
- return this;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/config/DigitalOceanComputeServiceContextModule.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/config/DigitalOceanComputeServiceContextModule.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/config/DigitalOceanComputeServiceContextModule.java
deleted file mode 100644
index aa68f91..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/config/DigitalOceanComputeServiceContextModule.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.config;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_IMAGE_AVAILABLE;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
-
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.compute.ComputeServiceAdapter;
-import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadata.Status;
-import org.jclouds.compute.extensions.ImageExtension;
-import org.jclouds.compute.functions.TemplateOptionsToStatement;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.compute.reference.ComputeServiceConstants.PollPeriod;
-import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
-import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.compute.extensions.DigitalOceanImageExtension;
-import org.jclouds.digitalocean.compute.functions.DropletStatusToStatus;
-import org.jclouds.digitalocean.compute.functions.DropletToNodeMetadata;
-import org.jclouds.digitalocean.compute.functions.ImageToImage;
-import org.jclouds.digitalocean.compute.functions.RegionToLocation;
-import org.jclouds.digitalocean.compute.functions.SizeToHardware;
-import org.jclouds.digitalocean.compute.functions.TemplateOptionsToStatementWithoutPublicKey;
-import org.jclouds.digitalocean.compute.options.DigitalOceanTemplateOptions;
-import org.jclouds.digitalocean.compute.strategy.CreateKeyPairsThenCreateNodes;
-import org.jclouds.digitalocean.compute.strategy.DigitalOceanComputeServiceAdapter;
-import org.jclouds.digitalocean.domain.Droplet;
-import org.jclouds.digitalocean.domain.Event;
-import org.jclouds.digitalocean.domain.Image;
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.digitalocean.domain.Size;
-import org.jclouds.domain.Location;
-import org.jclouds.util.Predicates2;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.inject.Injector;
-import com.google.inject.Provides;
-import com.google.inject.TypeLiteral;
-
-/**
- * Configures the compute service classes for the DigitalOcean API.
- */
-public class DigitalOceanComputeServiceContextModule extends
- ComputeServiceAdapterContextModule<Droplet, Size, Image, Region> {
-
- @Override
- protected void configure() {
- super.configure();
-
- bind(new TypeLiteral<ComputeServiceAdapter<Droplet, Size, Image, Region>>() {
- }).to(DigitalOceanComputeServiceAdapter.class);
-
- bind(new TypeLiteral<Function<Droplet, NodeMetadata>>() {
- }).to(DropletToNodeMetadata.class);
- bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
- }).to(ImageToImage.class);
- bind(new TypeLiteral<Function<Region, Location>>() {
- }).to(RegionToLocation.class);
- bind(new TypeLiteral<Function<Size, Hardware>>() {
- }).to(SizeToHardware.class);
- bind(new TypeLiteral<Function<Droplet.Status, Status>>() {
- }).to(DropletStatusToStatus.class);
-
- install(new LocationsFromComputeServiceAdapterModule<Droplet, Size, Image, Region>() {
- });
-
- bind(CreateNodesInGroupThenAddToSet.class).to(CreateKeyPairsThenCreateNodes.class);
- bind(TemplateOptions.class).to(DigitalOceanTemplateOptions.class);
- bind(TemplateOptionsToStatement.class).to(TemplateOptionsToStatementWithoutPublicKey.class);
-
- bind(new TypeLiteral<ImageExtension>() {
- }).to(DigitalOceanImageExtension.class);
- }
-
- @Override
- protected Optional<ImageExtension> provideImageExtension(Injector i) {
- return Optional.of(i.getInstance(ImageExtension.class));
- }
-
- @Provides
- @Singleton
- @Named(TIMEOUT_NODE_RUNNING)
- protected Predicate<Integer> provideDropletRunningPredicate(final DigitalOceanApi api, Timeouts timeouts,
- PollPeriod pollPeriod) {
- return Predicates2.retry(new EventDonePredicate(api), timeouts.nodeRunning, pollPeriod.pollInitialPeriod,
- pollPeriod.pollMaxPeriod);
- }
-
- @Provides
- @Singleton
- @Named(TIMEOUT_NODE_SUSPENDED)
- protected Predicate<Integer> provideDropletSuspendedPredicate(final DigitalOceanApi api, Timeouts timeouts,
- PollPeriod pollPeriod) {
- return Predicates2.retry(new EventDonePredicate(api), timeouts.nodeSuspended, pollPeriod.pollInitialPeriod,
- pollPeriod.pollMaxPeriod);
- }
-
- @Provides
- @Singleton
- @Named(TIMEOUT_NODE_TERMINATED)
- protected Predicate<Integer> provideDropletTerminatedPredicate(final DigitalOceanApi api, Timeouts timeouts,
- PollPeriod pollPeriod) {
- return Predicates2.retry(new EventDonePredicate(api), timeouts.nodeTerminated, pollPeriod.pollInitialPeriod,
- pollPeriod.pollMaxPeriod);
- }
-
- @Provides
- @Singleton
- @Named(TIMEOUT_IMAGE_AVAILABLE)
- protected Predicate<Integer> provideImageAvailablePredicate(final DigitalOceanApi api, Timeouts timeouts,
- PollPeriod pollPeriod) {
- return Predicates2.retry(new EventDonePredicate(api), timeouts.imageAvailable, pollPeriod.pollInitialPeriod,
- pollPeriod.pollMaxPeriod);
- }
-
- @VisibleForTesting
- static class EventDonePredicate implements Predicate<Integer> {
-
- private final DigitalOceanApi api;
-
- public EventDonePredicate(DigitalOceanApi api) {
- this.api = checkNotNull(api, "api must not be null");
- }
-
- @Override
- public boolean apply(Integer input) {
- Event event = api.getEventApi().get(input);
- switch (event.getStatus()) {
- case DONE:
- return true;
- case PENDING:
- return false;
- case ERROR:
- default:
- throw new IllegalStateException("Resource is in invalid status: " + event.getStatus().name());
- }
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/extensions/DigitalOceanImageExtension.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/extensions/DigitalOceanImageExtension.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/extensions/DigitalOceanImageExtension.java
deleted file mode 100644
index e45523c..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/extensions/DigitalOceanImageExtension.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.extensions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Iterables.find;
-import static com.google.common.util.concurrent.Futures.immediateFuture;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_IMAGE_AVAILABLE;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
-
-import java.util.NoSuchElementException;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.compute.domain.CloneImageTemplate;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.ImageTemplate;
-import org.jclouds.compute.domain.ImageTemplateBuilder;
-import org.jclouds.compute.extensions.ImageExtension;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.Droplet;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.primitives.Ints;
-import com.google.common.util.concurrent.ListenableFuture;
-
-/**
- * The {@link ImageExtension} implementation for the DigitalOcean provider.
- */
-@Singleton
-public class DigitalOceanImageExtension implements ImageExtension {
-
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- private final DigitalOceanApi api;
- private final Predicate<Integer> imageAvailablePredicate;
- private final Predicate<Integer> nodeStoppedPredicate;
- private final Function<org.jclouds.digitalocean.domain.Image, Image> imageTransformer;
-
- @Inject
- DigitalOceanImageExtension(DigitalOceanApi api,
- @Named(TIMEOUT_IMAGE_AVAILABLE) Predicate<Integer> imageAvailablePredicate,
- @Named(TIMEOUT_NODE_SUSPENDED) Predicate<Integer> nodeStoppedPredicate,
- Function<org.jclouds.digitalocean.domain.Image, Image> imageTransformer) {
- this.api = Preconditions.checkNotNull(api, "api cannot be null");
- this.imageAvailablePredicate = checkNotNull(imageAvailablePredicate, "imageAvailablePredicate cannot be null");
- this.nodeStoppedPredicate = checkNotNull(nodeStoppedPredicate, "nodeStoppedPredicate cannot be null");
- this.imageTransformer = checkNotNull(imageTransformer, "imageTransformer cannot be null");
- }
-
- @Override
- public ImageTemplate buildImageTemplateFromNode(String name, String id) {
- Droplet droplet = api.getDropletApi().get(Integer.parseInt(id));
-
- if (droplet == null) {
- throw new NoSuchElementException("Cannot find droplet with id: " + id);
- }
-
- return new ImageTemplateBuilder.CloneImageTemplateBuilder().nodeId(id).name(name).build();
- }
-
- @Override
- public ListenableFuture<Image> createImage(ImageTemplate template) {
- checkState(template instanceof CloneImageTemplate, "DigitalOcean only supports creating images through cloning.");
- final CloneImageTemplate cloneTemplate = (CloneImageTemplate) template;
-
- // Droplet needs to be stopped
- int powerOffEvent = api.getDropletApi().powerOff(Integer.parseInt(cloneTemplate.getSourceNodeId()));
- nodeStoppedPredicate.apply(powerOffEvent);
-
- int snapshotEvent = api.getDropletApi().snapshot(Integer.parseInt(cloneTemplate.getSourceNodeId()),
- cloneTemplate.getName());
-
- logger.info(">> registered new Image, waiting for it to become available");
-
- // Until the process completes we don't have enough information to build an image to return
- imageAvailablePredicate.apply(snapshotEvent);
-
- org.jclouds.digitalocean.domain.Image snapshot = find(api.getImageApi().list(),
- new Predicate<org.jclouds.digitalocean.domain.Image>() {
- @Override
- public boolean apply(org.jclouds.digitalocean.domain.Image input) {
- return input.getName().equals(cloneTemplate.getName());
- }
- });
-
- return immediateFuture(imageTransformer.apply(snapshot));
- }
-
- @Override
- public boolean deleteImage(String id) {
- try {
- // The id of the image can be an id or a slug. Use the corresponding method of the API depending on what is
- // provided. If it can be parsed as a number, use the method to destroy by ID. Otherwise, destroy by slug.
- Integer imageId = Ints.tryParse(id);
- if (imageId != null) {
- logger.debug(">> image does not have a slug. Using the id to delete the image...");
- api.getImageApi().delete(imageId);
- } else {
- logger.debug(">> image has a slug. Using it to delete the image...");
- api.getImageApi().delete(id);
- }
- return true;
- } catch (Exception ex) {
- return false;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatus.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatus.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatus.java
deleted file mode 100644
index 859c694..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatus.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.functions;
-
-import javax.inject.Singleton;
-
-import org.jclouds.compute.domain.NodeMetadata.Status;
-import org.jclouds.digitalocean.domain.Droplet;
-
-import com.google.common.base.Function;
-import com.google.common.base.Functions;
-import com.google.common.collect.ImmutableMap;
-
-/**
- * Transforms an {@link Status} to the jclouds portable model.
- */
-@Singleton
-public class DropletStatusToStatus implements Function<Droplet.Status, Status> {
-
- private static final Function<Droplet.Status, Status> toPortableStatus = Functions.forMap(
- ImmutableMap.<Droplet.Status, Status> builder()
- .put(Droplet.Status.NEW, Status.PENDING)
- .put(Droplet.Status.ACTIVE, Status.RUNNING)
- .put(Droplet.Status.ARCHIVE, Status.TERMINATED)
- .put(Droplet.Status.OFF, Status.SUSPENDED)
- .build(),
- Status.UNRECOGNIZED);
-
- @Override
- public Status apply(final Droplet.Status input) {
- return toPortableStatus.apply(input);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadata.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadata.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadata.java
deleted file mode 100644
index 5be3133..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadata.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.find;
-import static com.google.common.collect.Iterables.tryFind;
-import static org.jclouds.digitalocean.compute.util.LocationNamingUtils.extractRegionId;
-
-import java.util.Map;
-import java.util.Set;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.collect.Memoized;
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadata.Status;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.compute.functions.GroupNamingConvention;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.digitalocean.domain.Droplet;
-import org.jclouds.domain.Credentials;
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
-/**
- * Transforms an {@link Droplet} to the jclouds portable model.
- */
-@Singleton
-public class DropletToNodeMetadata implements Function<Droplet, NodeMetadata> {
-
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- private final Supplier<Map<String, ? extends Image>> images;
- private final Supplier<Map<String, ? extends Hardware>> hardwares;
- private final Supplier<Set<? extends Location>> locations;
- private final Function<Droplet.Status, Status> toPortableStatus;
- private final GroupNamingConvention groupNamingConvention;
- private final Map<String, Credentials> credentialStore;
-
- @Inject
- DropletToNodeMetadata(Supplier<Map<String, ? extends Image>> images,
- Supplier<Map<String, ? extends Hardware>> hardwares, @Memoized Supplier<Set<? extends Location>> locations,
- Function<Droplet.Status, Status> toPortableStatus, GroupNamingConvention.Factory groupNamingConvention,
- Map<String, Credentials> credentialStore) {
- this.images = checkNotNull(images, "images cannot be null");
- this.hardwares = checkNotNull(hardwares, "hardwares cannot be null");
- this.locations = checkNotNull(locations, "locations cannot be null");
- this.toPortableStatus = checkNotNull(toPortableStatus, "toPortableStatus cannot be null");
- this.groupNamingConvention = checkNotNull(groupNamingConvention, "groupNamingConvention cannot be null")
- .createWithoutPrefix();
- this.credentialStore = checkNotNull(credentialStore, "credentialStore cannot be null");
- }
-
- @Override
- public NodeMetadata apply(Droplet input) {
- NodeMetadataBuilder builder = new NodeMetadataBuilder();
- builder.ids(String.valueOf(input.getId()));
- builder.name(input.getName());
- builder.hostname(input.getName());
- builder.group(groupNamingConvention.extractGroup(input.getName()));
-
- builder.hardware(getHardware(input.getSizeId()));
- builder.location(getLocation(input.getRegionId()));
-
- Optional<? extends Image> image = findImage(input.getImageId());
- if (image.isPresent()) {
- builder.imageId(image.get().getId());
- builder.operatingSystem(image.get().getOperatingSystem());
- } else {
- logger.info(">> image with id %s for droplet %s was not found. "
- + "This might be because the image that was used to create the droplet has a new id.",
- input.getImageId(), input.getId());
- }
-
- builder.status(toPortableStatus.apply(input.getStatus()));
- builder.backendStatus(input.getStatus().name());
-
- if (input.getIp() != null) {
- builder.publicAddresses(ImmutableSet.of(input.getIp()));
- }
- if (input.getPrivateIp() != null) {
- builder.privateAddresses(ImmutableSet.of(input.getPrivateIp()));
- }
-
- // DigitalOcean does not provide a way to get the credentials.
- // Try to return them from the credential store
- Credentials credentials = credentialStore.get("node#" + input.getId());
- if (credentials instanceof LoginCredentials) {
- builder.credentials(LoginCredentials.class.cast(credentials));
- }
-
- return builder.build();
- }
-
- protected Optional<? extends Image> findImage(Integer id) {
- // Try to find the image by ID in the cache. The cache is indexed by slug (for public images) and by id (for
- // private ones).
- final String imageId = String.valueOf(id);
- Optional<? extends Image> image = Optional.fromNullable(images.get().get(imageId));
- if (!image.isPresent()) {
- // If it is a public image (indexed by slug) but the "int" form of the id was provided, try to find it in the
- // whole list of cached images
- image = tryFind(images.get().values(), new Predicate<Image>() {
- @Override
- public boolean apply(Image input) {
- return input.getProviderId().equals(imageId);
- }
- });
- }
- return image;
- }
-
- protected Hardware getHardware(Integer id) {
- // Hardwares are indexed by slug, but the droplet only provides its ID.
- final String hardwareId = String.valueOf(id);
- return Iterables.find(hardwares.get().values(), new Predicate<Hardware>() {
- @Override
- public boolean apply(Hardware input) {
- return input.getProviderId().equals(hardwareId);
- }
- });
- }
-
- protected Location getLocation(final Integer id) {
- return find(locations.get(), new Predicate<Location>() {
- @Override
- public boolean apply(Location location) {
- return id.equals(extractRegionId(location));
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/ImageToImage.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/ImageToImage.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/ImageToImage.java
deleted file mode 100644
index 46f18d0..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/ImageToImage.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.functions;
-
-import static org.jclouds.compute.domain.OperatingSystem.builder;
-
-import javax.inject.Singleton;
-
-import org.jclouds.compute.domain.Image.Status;
-import org.jclouds.compute.domain.ImageBuilder;
-import org.jclouds.digitalocean.domain.Image;
-import org.jclouds.digitalocean.domain.OperatingSystem;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
-
-/**
- * Transforms an {@link Image} to the jclouds portable model.
- */
-@Singleton
-public class ImageToImage implements Function<Image, org.jclouds.compute.domain.Image> {
-
- @Override
- public org.jclouds.compute.domain.Image apply(final Image input) {
- String description = input.getOs().getDistribution().getValue() + " " + input.getName();
- ImageBuilder builder = new ImageBuilder();
- // Private images don't have a slug
- builder.id(input.getSlug() != null ? input.getSlug() : String.valueOf(input.getId()));
- builder.providerId(String.valueOf(input.getId()));
- builder.name(input.getName());
- builder.description(description);
- builder.status(Status.AVAILABLE);
-
- OperatingSystem os = input.getOs();
-
- builder.operatingSystem(builder()
- .name(os.getDistribution().getValue())
- .family(os.getDistribution().getOsFamily())
- .description(description)
- .arch(os.getArch())
- .version(os.getVersion())
- .is64Bit(os.is64bit())
- .build());
-
- ImmutableMap.Builder<String, String> metadata = ImmutableMap.builder();
- metadata.put("publicImage", String.valueOf(input.isPublicImage()));
- builder.userMetadata(metadata.build());
-
- return builder.build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/RegionToLocation.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/RegionToLocation.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/RegionToLocation.java
deleted file mode 100644
index 9dc0d30..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/RegionToLocation.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.jclouds.digitalocean.compute.util.LocationNamingUtils.encodeRegionIdAndName;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LocationBuilder;
-import org.jclouds.domain.LocationScope;
-import org.jclouds.location.suppliers.all.JustProvider;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-
-/**
- * Transforms an {@link Region} to the jclouds portable model.
- */
-@Singleton
-public class RegionToLocation implements Function<Region, Location> {
-
- private final JustProvider justProvider;
-
- @Inject
- RegionToLocation(JustProvider justProvider) {
- this.justProvider = checkNotNull(justProvider, "justProvider cannot be null");
- }
-
- @Override
- public Location apply(Region input) {
- LocationBuilder builder = new LocationBuilder();
- builder.id(input.getSlug());
- builder.description(encodeRegionIdAndName(input));
- builder.scope(LocationScope.REGION);
- builder.parent(getOnlyElement(justProvider.get()));
- builder.iso3166Codes(ImmutableSet.<String> of());
- return builder.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/SizeToHardware.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/SizeToHardware.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/SizeToHardware.java
deleted file mode 100644
index 26b8001..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/SizeToHardware.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.functions;
-
-import javax.inject.Singleton;
-
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.HardwareBuilder;
-import org.jclouds.compute.domain.Processor;
-import org.jclouds.compute.domain.Volume.Type;
-import org.jclouds.compute.domain.VolumeBuilder;
-import org.jclouds.digitalocean.domain.Size;
-
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
-
-/**
- * Transforms an {@link Size} to the jclouds portable model.
- */
-@Singleton
-public class SizeToHardware implements Function<Size, Hardware> {
-
- @Override
- public Hardware apply(Size input) {
- HardwareBuilder builder = new HardwareBuilder();
- builder.id(input.getSlug());
- builder.providerId(String.valueOf(input.getId()));
- builder.name(input.getName());
- builder.ram(input.getMemory());
- // DigitalOcean does not provide the processor speed. We configure it to
- // make the bigger template the faster.
- builder.processor(new Processor(input.getCpu(), input.getCpu()));
-
- builder.volume(new VolumeBuilder()
- .size(Float.valueOf(input.getDisk()))
- .type(Type.LOCAL)
- .build());
-
- ImmutableMap.Builder<String, String> metadata = ImmutableMap.builder();
- metadata.put("costPerHour", input.getCostPerHour());
- metadata.put("costPerMonth", input.getCostPerMonth());
- builder.userMetadata(metadata.build());
-
- return builder.build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKey.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKey.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKey.java
deleted file mode 100644
index 5311723..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKey.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.functions;
-
-import javax.inject.Singleton;
-
-import org.jclouds.compute.functions.TemplateOptionsToStatement;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.scriptbuilder.InitScript;
-import org.jclouds.scriptbuilder.domain.Statement;
-import org.jclouds.scriptbuilder.domain.StatementList;
-import org.jclouds.scriptbuilder.statements.ssh.InstallRSAPrivateKey;
-
-import com.google.common.collect.ImmutableList;
-
-/**
- * Convert the template options into a statement, but ignoring the public key.
- * <p>
- * The {@link org.jclouds.digitalocean.compute.strategy.DigitalOceanComputeServiceAdapter} already takes care of
- * installing it using the {@link org.jclouds.digitalocean.features.KeyPairApi}.
- */
-@Singleton
-public class TemplateOptionsToStatementWithoutPublicKey extends TemplateOptionsToStatement {
-
- @Override
- public Statement apply(TemplateOptions options) {
- ImmutableList.Builder<Statement> builder = ImmutableList.builder();
- if (options.getRunScript() != null) {
- builder.add(options.getRunScript());
- }
- if (options.getPrivateKey() != null) {
- builder.add(new InstallRSAPrivateKey(options.getPrivateKey()));
- }
-
- ImmutableList<Statement> bootstrap = builder.build();
- if (!bootstrap.isEmpty()) {
- if (options.getTaskName() == null && !(options.getRunScript() instanceof InitScript)) {
- options.nameTask("bootstrap");
- }
- return bootstrap.size() == 1 ? bootstrap.get(0) : new StatementList(bootstrap);
- }
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptions.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptions.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptions.java
deleted file mode 100644
index 6aa541c..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptions.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.options;
-
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Set;
-
-import org.jclouds.compute.options.TemplateOptions;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
-import com.google.common.collect.ImmutableSet;
-
-/**
- * Custom options for the DigitalOcean API.
- */
-public class DigitalOceanTemplateOptions extends TemplateOptions implements Cloneable {
-
- private Set<Integer> sshKeyIds = ImmutableSet.of();
- private Boolean privateNetworking;
- private Boolean backupsEnabled;
- private boolean autoCreateKeyPair = true;
-
- /**
- * Enables a private network interface if the region supports private networking.
- */
- public DigitalOceanTemplateOptions privateNetworking(boolean privateNetworking) {
- this.privateNetworking = privateNetworking;
- return this;
- }
-
- /**
- * Enabled backups for the droplet.
- */
- public DigitalOceanTemplateOptions backupsEnabled(boolean backupsEnabled) {
- this.backupsEnabled = backupsEnabled;
- return this;
- }
-
- /**
- * Sets the ssh key ids to be added to the droplet.
- */
- public DigitalOceanTemplateOptions sshKeyIds(Iterable<Integer> sshKeyIds) {
- this.sshKeyIds = ImmutableSet.copyOf(checkNotNull(sshKeyIds, "sshKeyIds cannot be null"));
- return this;
- }
-
- /**
- * Sets whether an SSH key pair should be created automatically.
- */
- public DigitalOceanTemplateOptions autoCreateKeyPair(boolean autoCreateKeyPair) {
- this.autoCreateKeyPair = autoCreateKeyPair;
- return this;
- }
-
- public Set<Integer> getSshKeyIds() {
- return sshKeyIds;
- }
-
- public Boolean getPrivateNetworking() {
- return privateNetworking;
- }
-
- public Boolean getBackupsEnabled() {
- return backupsEnabled;
- }
-
- public boolean getAutoCreateKeyPair() {
- return autoCreateKeyPair;
- }
-
- @Override
- public DigitalOceanTemplateOptions clone() {
- DigitalOceanTemplateOptions options = new DigitalOceanTemplateOptions();
- copyTo(options);
- return options;
- }
-
- @Override
- public void copyTo(TemplateOptions to) {
- super.copyTo(to);
- if (to instanceof DigitalOceanTemplateOptions) {
- DigitalOceanTemplateOptions eTo = DigitalOceanTemplateOptions.class.cast(to);
- if (privateNetworking != null) {
- eTo.privateNetworking(privateNetworking);
- }
- if (backupsEnabled != null) {
- eTo.backupsEnabled(backupsEnabled);
- }
- eTo.autoCreateKeyPair(autoCreateKeyPair);
- eTo.sshKeyIds(sshKeyIds);
- }
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(super.hashCode(), backupsEnabled, privateNetworking, autoCreateKeyPair, sshKeyIds);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- DigitalOceanTemplateOptions other = (DigitalOceanTemplateOptions) obj;
- return super.equals(other) && equal(this.backupsEnabled, other.backupsEnabled)
- && equal(this.privateNetworking, other.privateNetworking)
- && equal(this.autoCreateKeyPair, other.autoCreateKeyPair) && equal(this.sshKeyIds, other.sshKeyIds);
- }
-
- @Override
- public ToStringHelper string() {
- ToStringHelper toString = super.string().omitNullValues();
- toString.add("privateNetworking", privateNetworking);
- toString.add("backupsEnabled", backupsEnabled);
- if (!sshKeyIds.isEmpty()) {
- toString.add("sshKeyIds", sshKeyIds);
- }
- toString.add("autoCreateKeyPair", autoCreateKeyPair);
- return toString;
- }
-
- public static class Builder {
-
- /**
- * @see DigitalOceanTemplateOptions#privateNetworking
- */
- public static DigitalOceanTemplateOptions privateNetworking(boolean privateNetworking) {
- DigitalOceanTemplateOptions options = new DigitalOceanTemplateOptions();
- return options.privateNetworking(privateNetworking);
- }
-
- /**
- * @see DigitalOceanTemplateOptions#backupsEnabled
- */
- public static DigitalOceanTemplateOptions backupsEnabled(boolean backupsEnabled) {
- DigitalOceanTemplateOptions options = new DigitalOceanTemplateOptions();
- return options.backupsEnabled(backupsEnabled);
- }
-
- /**
- * @see DigitalOceanTemplateOptions#sshKeyIds
- */
- public static DigitalOceanTemplateOptions sshKeyIds(Iterable<Integer> sshKeyIds) {
- DigitalOceanTemplateOptions options = new DigitalOceanTemplateOptions();
- return options.sshKeyIds(sshKeyIds);
- }
-
- /**
- * @see DigitalOceanTemplateOptions#autoCreateKeyPair
- */
- public static DigitalOceanTemplateOptions autoCreateKeyPair(boolean autoCreateKeyPair) {
- DigitalOceanTemplateOptions options = new DigitalOceanTemplateOptions();
- return options.autoCreateKeyPair(autoCreateKeyPair);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/strategy/CreateKeyPairsThenCreateNodes.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/strategy/CreateKeyPairsThenCreateNodes.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/strategy/CreateKeyPairsThenCreateNodes.java
deleted file mode 100644
index 511a314..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/strategy/CreateKeyPairsThenCreateNodes.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.strategy;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.tryFind;
-
-import java.security.PublicKey;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.Constants;
-import org.jclouds.compute.config.CustomizationResponse;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.compute.functions.GroupNamingConvention;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
-import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
-import org.jclouds.compute.strategy.ListNodesStrategy;
-import org.jclouds.compute.strategy.impl.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.compute.options.DigitalOceanTemplateOptions;
-import org.jclouds.digitalocean.domain.SshKey;
-import org.jclouds.digitalocean.predicates.SameFingerprint;
-import org.jclouds.digitalocean.strategy.ListSshKeys;
-import org.jclouds.logging.Logger;
-import org.jclouds.ssh.SshKeyPairGenerator;
-
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Strings;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-
-@Singleton
-public class CreateKeyPairsThenCreateNodes extends CreateNodesWithGroupEncodedIntoNameThenAddToSet {
-
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- private final DigitalOceanApi api;
- private final SshKeyPairGenerator keyGenerator;
- private final ListSshKeys listSshKeys;
- private final Function<String, PublicKey> sshKeyToPublicKey;
-
- @Inject
- protected CreateKeyPairsThenCreateNodes(
- CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy,
- ListNodesStrategy listNodesStrategy,
- GroupNamingConvention.Factory namingConvention,
- @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
- CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory,
- DigitalOceanApi api, SshKeyPairGenerator keyGenerator, ListSshKeys.Factory listSshKeysFactory,
- Function<String, PublicKey> sshKeyToPublicKey) {
- super(addNodeWithGroupStrategy, listNodesStrategy, namingConvention, userExecutor,
- customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
- this.api = checkNotNull(api, "api cannot be null");
- this.keyGenerator = checkNotNull(keyGenerator, "keyGenerator cannot be null");
- checkNotNull(listSshKeysFactory, "listSshKeysFactory cannot be null");
- checkNotNull(userExecutor, "userExecutor cannot be null");
- this.listSshKeys = listSshKeysFactory.create(userExecutor);
- this.sshKeyToPublicKey = checkNotNull(sshKeyToPublicKey, "sshKeyToPublicKey cannot be null");
- }
-
- @Override
- public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template,
- Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes,
- Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
-
- DigitalOceanTemplateOptions options = template.getOptions().as(DigitalOceanTemplateOptions.class);
- Set<Integer> generatedSshKeyIds = Sets.newHashSet();
-
- // If no key has been configured and the auto-create option is set, then generate a key pair
- if (options.getSshKeyIds().isEmpty() && options.getAutoCreateKeyPair()
- && Strings.isNullOrEmpty(options.getPublicKey())) {
- generateKeyPairAndAddKeyToSet(options, generatedSshKeyIds);
- }
-
- // If there is a script to run in the node, make sure a pivate key has been configured so jclouds will be able to
- // access the node
- if (options.getRunScript() != null && Strings.isNullOrEmpty(options.getLoginPrivateKey())) {
- logger.warn(">> A runScript has been configured but no SSH key has been provided."
- + " Authentication will delegate to the ssh-agent");
- }
-
- // If there is a key configured, then make sure there is a key pair for it
- if (!Strings.isNullOrEmpty(options.getPublicKey())) {
- createKeyPairForPublicKeyInOptionsAndAddToSet(options, generatedSshKeyIds);
- }
-
- // Set all keys (the provided and the auto-generated) in the options object so the
- // DigitalOceanComputeServiceAdapter adds them all
- options.sshKeyIds(Sets.union(generatedSshKeyIds, options.getSshKeyIds()));
-
- Map<?, ListenableFuture<Void>> responses = super.execute(group, count, template, goodNodes, badNodes,
- customizationResponses);
-
- // Key pairs in DigitalOcean are only required to create the Droplets. They aren't used anymore so it is better
- // to delete the auto-generated key pairs at this point where we know exactly which ones have been
- // auto-generated by jclouds.
- registerAutoGeneratedKeyPairCleanupCallbacks(responses, generatedSshKeyIds);
-
- return responses;
- }
-
- private void createKeyPairForPublicKeyInOptionsAndAddToSet(DigitalOceanTemplateOptions options,
- Set<Integer> generatedSshKeyIds) {
- logger.debug(">> checking if the key pair already exists...");
-
- PublicKey userKey = sshKeyToPublicKey.apply(options.getPublicKey());
- Optional<SshKey> key = tryFind(listSshKeys.execute(), new SameFingerprint(userKey));
-
- if (!key.isPresent()) {
- logger.debug(">> key pair not found. creating a new one...");
-
- String userFingerprint = SameFingerprint.computeFingerprint(userKey);
- SshKey newKey = api.getKeyPairApi().create(userFingerprint, options.getPublicKey());
-
- generatedSshKeyIds.add(newKey.getId());
- logger.debug(">> key pair created! %s", newKey);
- } else {
- logger.debug(">> key pair found! %s", key.get());
- generatedSshKeyIds.add(key.get().getId());
- }
- }
-
- private void generateKeyPairAndAddKeyToSet(DigitalOceanTemplateOptions options, Set<Integer> generatedSshKeyIds) {
- logger.debug(">> creating default keypair for node...");
-
- Map<String, String> defaultKeys = keyGenerator.get();
-
- PublicKey defaultPublicKey = sshKeyToPublicKey.apply(defaultKeys.get("public"));
- String fingerprint = SameFingerprint.computeFingerprint(defaultPublicKey);
- SshKey defaultKey = api.getKeyPairApi().create(fingerprint, defaultKeys.get("public"));
-
- generatedSshKeyIds.add(defaultKey.getId());
-
- logger.debug(">> keypair created! %s", defaultKey);
-
- // If a private key has not been explicitly set, configure the auto-generated one
- if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) {
- options.overrideLoginPrivateKey(defaultKeys.get("private"));
- }
- }
-
- private void registerAutoGeneratedKeyPairCleanupCallbacks(Map<?, ListenableFuture<Void>> responses,
- final Set<Integer> generatedSshKeyIds) {
- // The Futures.allAsList fails immediately if some of the futures fail. The Futures.successfulAsList, however,
- // returns a list containing the results or 'null' for those futures that failed. We want to wait for all them
- // (even if they fail), so better use the latter form.
- ListenableFuture<List<Void>> aggregatedResponses = Futures.successfulAsList(responses.values());
-
- // Key pairs must be cleaned up after all futures completed (even if some failed).
- Futures.addCallback(aggregatedResponses, new FutureCallback<List<Void>>() {
- @Override
- public void onSuccess(List<Void> result) {
- cleanupAutoGeneratedKeyPairs(generatedSshKeyIds);
- }
-
- @Override
- public void onFailure(Throwable t) {
- cleanupAutoGeneratedKeyPairs(generatedSshKeyIds);
- }
-
- private void cleanupAutoGeneratedKeyPairs(Set<Integer> generatedSshKeyIds) {
- logger.debug(">> cleaning up auto-generated key pairs...");
- for (Integer sshKeyId : generatedSshKeyIds) {
- try {
- api.getKeyPairApi().delete(sshKeyId);
- } catch (Exception ex) {
- logger.warn(">> could not delete key pair %s: %s", sshKeyId, ex.getMessage());
- }
- }
- }
-
- }, userExecutor);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/strategy/DigitalOceanComputeServiceAdapter.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/strategy/DigitalOceanComputeServiceAdapter.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/strategy/DigitalOceanComputeServiceAdapter.java
deleted file mode 100644
index db1704c..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/strategy/DigitalOceanComputeServiceAdapter.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.strategy;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.contains;
-import static com.google.common.collect.Iterables.filter;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_SUSPENDED;
-import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED;
-import static org.jclouds.digitalocean.compute.util.LocationNamingUtils.extractRegionId;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.jclouds.compute.ComputeServiceAdapter;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.compute.options.DigitalOceanTemplateOptions;
-import org.jclouds.digitalocean.domain.Droplet;
-import org.jclouds.digitalocean.domain.DropletCreation;
-import org.jclouds.digitalocean.domain.Image;
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.digitalocean.domain.Size;
-import org.jclouds.digitalocean.domain.options.CreateDropletOptions;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Predicate;
-import com.google.common.primitives.Ints;
-
-/**
- * Implementation of the Compute Service for the DigitalOcean API.
- */
-public class DigitalOceanComputeServiceAdapter implements ComputeServiceAdapter<Droplet, Size, Image, Region> {
-
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- private final DigitalOceanApi api;
- private final Predicate<Integer> nodeRunningPredicate;
- private final Predicate<Integer> nodeStoppedPredicate;
- private final Predicate<Integer> nodeTerminatedPredicate;
-
- @Inject
- DigitalOceanComputeServiceAdapter(DigitalOceanApi api,
- @Named(TIMEOUT_NODE_RUNNING) Predicate<Integer> nodeRunningPredicate,
- @Named(TIMEOUT_NODE_SUSPENDED) Predicate<Integer> nodeStoppedPredicate,
- @Named(TIMEOUT_NODE_TERMINATED) Predicate<Integer> nodeTerminatedPredicate) {
- this.api = checkNotNull(api, "api cannot be null");
- this.nodeRunningPredicate = checkNotNull(nodeRunningPredicate, "nodeRunningPredicate cannot be null");
- this.nodeStoppedPredicate = checkNotNull(nodeStoppedPredicate, "nodeStoppedPredicate cannot be null");
- this.nodeTerminatedPredicate = checkNotNull(nodeTerminatedPredicate, "nodeTerminatedPredicate cannot be null");
- }
-
- @Override
- public NodeAndInitialCredentials<Droplet> createNodeWithGroupEncodedIntoName(String group, final String name,
- Template template) {
- DigitalOceanTemplateOptions templateOptions = template.getOptions().as(DigitalOceanTemplateOptions.class);
- CreateDropletOptions.Builder options = CreateDropletOptions.builder();
-
- // DigitalOcean specific options
- if (!templateOptions.getSshKeyIds().isEmpty()) {
- options.addSshKeyIds(templateOptions.getSshKeyIds());
- }
- if (templateOptions.getPrivateNetworking() != null) {
- options.privateNetworking(templateOptions.getPrivateNetworking());
- }
- if (templateOptions.getBackupsEnabled() != null) {
- options.backupsEnabled(templateOptions.getBackupsEnabled());
- }
-
- // Find the location where the Droplet has to be created
- int regionId = extractRegionId(template.getLocation());
-
- DropletCreation dropletCreation = api.getDropletApi().create(name,
- Integer.parseInt(template.getImage().getProviderId()),
- Integer.parseInt(template.getHardware().getProviderId()), regionId, options.build());
-
- // We have to actively wait until the droplet has been provisioned until
- // we can build the entire Droplet object we want to return
- nodeRunningPredicate.apply(dropletCreation.getEventId());
- Droplet droplet = api.getDropletApi().get(dropletCreation.getId());
-
- LoginCredentials defaultCredentials = LoginCredentials.builder().user("root")
- .privateKey(templateOptions.getLoginPrivateKey()).build();
-
- return new NodeAndInitialCredentials<Droplet>(droplet, String.valueOf(droplet.getId()), defaultCredentials);
- }
-
- @Override
- public Iterable<Image> listImages() {
- return api.getImageApi().list();
- }
-
- @Override
- public Iterable<Size> listHardwareProfiles() {
- return api.getSizesApi().list();
- }
-
- @Override
- public Iterable<Region> listLocations() {
- return api.getRegionApi().list();
- }
-
- @Override
- public Iterable<Droplet> listNodes() {
- return api.getDropletApi().list();
- }
-
- @Override
- public Iterable<Droplet> listNodesByIds(final Iterable<String> ids) {
- return filter(listNodes(), new Predicate<Droplet>() {
- @Override
- public boolean apply(Droplet droplet) {
- return contains(ids, String.valueOf(droplet.getId()));
- }
- });
- }
-
- @Override
- public Image getImage(String id) {
- // The id of the image can be an id or a slug. Use the corresponding method of the API depending on what is
- // provided. If it can be parsed as a number, use the method to get by ID. Otherwise, get by slug.
- Integer imageId = Ints.tryParse(id);
- return imageId != null ? api.getImageApi().get(imageId) : api.getImageApi().get(id);
- }
-
- @Override
- public Droplet getNode(String id) {
- return api.getDropletApi().get(Integer.parseInt(id));
- }
-
- @Override
- public void destroyNode(String id) {
- // We have to wait here, as the api does not properly populate the state
- // but fails if there is a pending event
- int event = api.getDropletApi().destroy(Integer.parseInt(id), true);
- nodeTerminatedPredicate.apply(event);
- }
-
- @Override
- public void rebootNode(String id) {
- // We have to wait here, as the api does not properly populate the state
- // but fails if there is a pending event
- int event = api.getDropletApi().reboot(Integer.parseInt(id));
- nodeRunningPredicate.apply(event);
- }
-
- @Override
- public void resumeNode(String id) {
- // We have to wait here, as the api does not properly populate the state
- // but fails if there is a pending event
- int event = api.getDropletApi().powerOn(Integer.parseInt(id));
- nodeRunningPredicate.apply(event);
- }
-
- @Override
- public void suspendNode(String id) {
- // We have to wait here, as the api does not properly populate the state
- // but fails if there is a pending event
- int event = api.getDropletApi().powerOff(Integer.parseInt(id));
- nodeStoppedPredicate.apply(event);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/compute/util/LocationNamingUtils.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/util/LocationNamingUtils.java b/digitalocean/src/main/java/org/jclouds/digitalocean/compute/util/LocationNamingUtils.java
deleted file mode 100644
index 13a34b2..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/compute/util/LocationNamingUtils.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.compute.util;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.domain.Location;
-
-/**
- * Utility class to encode and decode the region id and name in a {@link Location}.
- */
-public class LocationNamingUtils {
-
- /**
- * Extracts the region id for the given location.
- *
- * @param location The location to extract the region id from.
- * @return The id of the region.
- */
- public static int extractRegionId(Location location) {
- checkNotNull(location, "location cannot be null");
- String regionIdAndName = location.getDescription();
- int index = regionIdAndName.indexOf('/');
- checkArgument(index >= 0, "location description should be in the form 'regionId/regionName' but was: %s",
- regionIdAndName);
- return Integer.parseInt(regionIdAndName.substring(0, index));
- }
-
- /**
- * Extracts the region name for the given location.
- *
- * @param location The location to extract the region name from.
- * @return The name of the region.
- */
- public static String extractRegionName(Location location) {
- checkNotNull(location, "location cannot be null");
- String regionIdAndName = location.getDescription();
- int index = regionIdAndName.indexOf('/');
- checkArgument(index >= 0, "location description should be in the form 'regionId/regionName' but was: %s",
- regionIdAndName);
- return regionIdAndName.substring(index + 1);
- }
-
- /**
- * Encodes the id and name of the given region into a String so it can be populated in a {@link Location} object.
- *
- * @param region The region to encode.
- * @return The encoded id and name for the given region.
- */
- public static String encodeRegionIdAndName(Region region) {
- checkNotNull(region, "region cannot be null");
- return region.getId() + "/" + region.getName();
- }
-}