Promoted DigitalOcean v2
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/a6044372 Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/a6044372 Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/a6044372 Branch: refs/heads/master Commit: a6044372ce5bf8be3a1d7817684ad9a27aef321c Parents: 7d5854b Author: Ignasi Barrera <[email protected]> Authored: Thu Jan 21 00:58:53 2016 +0100 Committer: Ignasi Barrera <[email protected]> Committed: Thu Jan 21 00:59:12 2016 +0100 ---------------------------------------------------------------------- digitalocean2/pom.xml | 152 ------- .../jclouds/digitalocean2/DigitalOcean2Api.java | 73 ---- .../digitalocean2/DigitalOcean2ApiMetadata.java | 111 ----- .../DigitalOcean2ProviderMetadata.java | 78 ---- .../DigitalOcean2ComputeServiceAdapter.java | 243 ----------- ...igitalOcean2ComputeServiceContextModule.java | 218 ---------- .../extensions/DigitalOcean2ImageExtension.java | 149 ------- .../functions/DropletStatusToStatus.java | 46 --- .../functions/DropletToNodeMetadata.java | 165 -------- .../compute/functions/ImageInRegionToImage.java | 92 ----- .../compute/functions/RegionToLocation.java | 59 --- .../compute/functions/SizeToHardware.java | 58 --- ...plateOptionsToStatementWithoutPublicKey.java | 59 --- .../compute/internal/ImageInRegion.java | 54 --- .../options/DigitalOcean2TemplateOptions.java | 174 -------- .../strategy/CreateKeyPairsThenCreateNodes.java | 216 ---------- .../config/DigitalOcean2HttpApiModule.java | 57 --- .../config/DigitalOcean2Properties.java | 33 -- .../config/DigitalOcean2RateLimitModule.java | 30 -- .../config/DigitalOceanParserModule.java | 144 ------- .../jclouds/digitalocean2/domain/Action.java | 71 ---- .../jclouds/digitalocean2/domain/Backup.java | 43 -- .../digitalocean2/domain/Distribution.java | 69 ---- .../jclouds/digitalocean2/domain/Droplet.java | 92 ----- .../digitalocean2/domain/DropletCreate.java | 66 --- .../org/jclouds/digitalocean2/domain/Image.java | 48 --- .../jclouds/digitalocean2/domain/Kernel.java | 35 -- .../org/jclouds/digitalocean2/domain/Key.java | 39 -- .../jclouds/digitalocean2/domain/Networks.java | 77 ---- .../digitalocean2/domain/OperatingSystem.java | 60 --- .../jclouds/digitalocean2/domain/Region.java | 39 -- .../org/jclouds/digitalocean2/domain/Size.java | 46 --- .../jclouds/digitalocean2/domain/Snapshot.java | 47 --- .../domain/internal/PaginatedCollection.java | 111 ----- .../domain/options/CreateDropletOptions.java | 179 --------- .../domain/options/ImageListOptions.java | 74 ---- .../domain/options/ListOptions.java | 60 --- ...DigitalOcean2RateLimitExceededException.java | 81 ---- .../digitalocean2/features/ActionApi.java | 113 ------ .../digitalocean2/features/DropletApi.java | 350 ---------------- .../digitalocean2/features/ImageApi.java | 131 ------ .../jclouds/digitalocean2/features/KeyApi.java | 164 -------- .../digitalocean2/features/RegionApi.java | 107 ----- .../jclouds/digitalocean2/features/SizeApi.java | 100 ----- .../functions/BaseToPagedIterable.java | 59 --- .../functions/LinkToImageListOptions.java | 67 ---- .../functions/LinkToListOptions.java | 61 --- .../handlers/DigitalOcean2ErrorHandler.java | 72 ---- .../handlers/RateLimitRetryHandler.java | 111 ----- .../org/jclouds/digitalocean2/ssh/DSAKeys.java | 172 -------- .../jclouds/digitalocean2/ssh/ECDSAKeys.java | 343 ---------------- .../DigitalOcean2ProviderMetadataTest.java | 29 -- .../DigitalOcean2ComputeServiceLiveTest.java | 66 --- .../DigitalOcean2TemplateBuilderLiveTest.java | 55 --- .../compute/config/ActionDonePredicateTest.java | 74 ---- .../config/DropletInStatusPredicateTest.java | 58 --- .../config/DropletTerminatedPredicateTest.java | 57 --- .../DigitalOcean2ImageExtensionLiveTest.java | 40 -- .../functions/DropletStatusToStatusTest.java | 36 -- .../functions/DropletToNodeMetadataTest.java | 237 ----------- .../functions/ImageInRegionToImageTest.java | 98 ----- .../compute/functions/RegionToLocationTest.java | 56 --- .../compute/functions/SizeToHardwareTest.java | 49 --- ...eOptionsToStatementWithoutPublicKeyTest.java | 75 ---- .../DigitalOcean2TemplateOptionsTest.java | 52 --- .../domain/OperatingSystemTest.java | 104 ----- .../exceptions/RateLimitExceptionMockTest.java | 63 --- .../features/ActionApiLiveTest.java | 70 ---- .../features/ActionApiMockTest.java | 110 ----- .../features/DropletApiLiveTest.java | 186 --------- .../features/DropletApiMockTest.java | 401 ------------------- .../features/ImageApiLiveTest.java | 97 ----- .../features/ImageApiMockTest.java | 150 ------- .../digitalocean2/features/KeyApiLiveTest.java | 99 ----- .../digitalocean2/features/KeyApiMockTest.java | 203 ---------- .../features/RegionApiLiveTest.java | 62 --- .../features/RegionApiMockTest.java | 77 ---- .../digitalocean2/features/SizeApiLiveTest.java | 62 --- .../digitalocean2/features/SizeApiMockTest.java | 77 ---- .../functions/LinkToImageListOptionsTest.java | 65 --- .../functions/LinkToListOptionsTest.java | 58 --- .../handlers/RateLimitRetryHandlerTest.java | 153 ------- .../internal/BaseDigitalOcean2ApiLiveTest.java | 140 ------- .../internal/BaseDigitalOcean2ApiMockTest.java | 142 ------- .../jclouds/digitalocean2/ssh/DSAKeysTest.java | 54 --- .../digitalocean2/ssh/ECDSAKeysTest.java | 55 --- digitalocean2/src/test/resources/action.json | 33 -- .../src/test/resources/actions-first.json | 168 -------- .../src/test/resources/actions-last.json | 106 ----- .../src/test/resources/backups-first.json | 26 -- .../src/test/resources/backups-last.json | 26 -- .../src/test/resources/droplet-create-req.json | 12 - .../src/test/resources/droplet-create-res.json | 35 -- digitalocean2/src/test/resources/droplet.json | 105 ----- .../src/test/resources/droplets-first.json | 115 ------ .../src/test/resources/droplets-last.json | 115 ------ digitalocean2/src/test/resources/image.json | 24 -- .../src/test/resources/images-first.json | 108 ----- .../src/test/resources/images-last.json | 123 ------ .../src/test/resources/kernels-first.json | 38 -- .../src/test/resources/kernels-last.json | 38 -- digitalocean2/src/test/resources/key.json | 8 - .../src/test/resources/keys-first.json | 43 -- digitalocean2/src/test/resources/keys-last.json | 25 -- .../src/test/resources/logback-test.xml | 42 -- .../src/test/resources/power-cycle.json | 33 -- digitalocean2/src/test/resources/power-off.json | 33 -- digitalocean2/src/test/resources/power-on.json | 33 -- digitalocean2/src/test/resources/reboot.json | 33 -- .../src/test/resources/regions-first.json | 111 ----- .../src/test/resources/regions-last.json | 128 ------ digitalocean2/src/test/resources/shutdown.json | 33 -- .../src/test/resources/sizes-first.json | 123 ------ .../src/test/resources/sizes-last.json | 98 ----- digitalocean2/src/test/resources/snapshot.json | 33 -- .../src/test/resources/snapshots-first.json | 27 -- .../src/test/resources/snapshots-last.json | 27 -- digitalocean2/src/test/resources/ssh-dsa.pub | 1 - digitalocean2/src/test/resources/ssh-ecdsa.pub | 1 - pom.xml | 1 - 120 files changed, 10613 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/pom.xml ---------------------------------------------------------------------- diff --git a/digitalocean2/pom.xml b/digitalocean2/pom.xml deleted file mode 100644 index 5b211d4..0000000 --- a/digitalocean2/pom.xml +++ /dev/null @@ -1,152 +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> - - <groupId>org.apache.jclouds.labs</groupId> - <artifactId>digitalocean2</artifactId> - <name>jclouds DigitalOcean v2 API Provider</name> - <description>jclouds provider for Digital Ocean v2 Compute API</description> - - <properties> - <test.digitalocean2.endpoint>https://api.digitalocean.com/v2/</test.digitalocean2.endpoint> - <test.digitalocean2.api-version>2</test.digitalocean2.api-version> - <test.digitalocean2.identity>FIXME</test.digitalocean2.identity> - <test.digitalocean2.credential>FIXME</test.digitalocean2.credential> - <test.digitalocean2.template>osFamily=UBUNTU,os64Bit=true</test.digitalocean2.template> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-core</artifactId> - <version>${jclouds.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds.api</groupId> - <artifactId>oauth</artifactId> - <version>${jclouds.version}</version> - <type>jar</type> - </dependency> - <dependency> - <groupId>org.apache.jclouds.api</groupId> - <artifactId>oauth</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> - </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>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.driver</groupId> - <artifactId>jclouds-slf4j</artifactId> - <version>${jclouds.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-sshj</artifactId> - <version>${jclouds.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <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.value</groupId> - <artifactId>auto-value</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.google.auto.service</groupId> - <artifactId>auto-service</artifactId> - <scope>provided</scope> - </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> - <systemPropertyVariables> - <test.digitalocean2.endpoint>${test.digitalocean2.endpoint}</test.digitalocean2.endpoint> - <test.digitalocean2.api-version>${test.digitalocean2.api-version}</test.digitalocean2.api-version> - <test.digitalocean2.build-version>${test.digitalocean2.build-version}</test.digitalocean2.build-version> - <test.digitalocean2.identity>${test.digitalocean2.identity}</test.digitalocean2.identity> - <test.digitalocean2.credential>${test.digitalocean2.credential}</test.digitalocean2.credential> - <test.digitalocean2.template>${test.digitalocean2.template}</test.digitalocean2.template> - </systemPropertyVariables> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project> http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2Api.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2Api.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2Api.java deleted file mode 100644 index 773fa59..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2Api.java +++ /dev/null @@ -1,73 +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.digitalocean2; - -import java.io.Closeable; - -import org.jclouds.digitalocean2.features.ActionApi; -import org.jclouds.digitalocean2.features.DropletApi; -import org.jclouds.digitalocean2.features.ImageApi; -import org.jclouds.digitalocean2.features.KeyApi; -import org.jclouds.digitalocean2.features.RegionApi; -import org.jclouds.digitalocean2.features.SizeApi; -import org.jclouds.rest.annotations.Delegate; - -import com.google.common.annotations.Beta; - -/** - * Provides access to DigitalOcean. - */ -@Beta -public interface DigitalOcean2Api extends Closeable { - - /** - * Provides access to Droplet features - */ - @Delegate - DropletApi dropletApi(); - - /** - * Provides access to SSH Key features - */ - @Delegate - KeyApi keyApi(); - - /** - * Provides access to Images - */ - @Delegate - ImageApi imageApi(); - - /** - * Provides access to Actions - */ - @Delegate - ActionApi actionApi(); - - /** - * Provides access to Sizes - */ - @Delegate - SizeApi sizeApi(); - - /** - * Provides access to Regions - */ - @Delegate - RegionApi regionApi(); - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2ApiMetadata.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2ApiMetadata.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2ApiMetadata.java deleted file mode 100644 index 25b42c7..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2ApiMetadata.java +++ /dev/null @@ -1,111 +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.digitalocean2; - -import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.compute.config.ComputeServiceProperties.POLL_INITIAL_PERIOD; -import static org.jclouds.compute.config.ComputeServiceProperties.POLL_MAX_PERIOD; -import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE; -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.oauth.v2.config.CredentialType.BEARER_TOKEN_CREDENTIALS; -import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE; -import static org.jclouds.oauth.v2.config.OAuthProperties.CREDENTIAL_TYPE; -import static org.jclouds.oauth.v2.config.OAuthProperties.JWS_ALG; -import static org.jclouds.reflect.Reflection2.typeToken; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.apis.ApiMetadata; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.digitalocean2.compute.config.DigitalOcean2ComputeServiceContextModule; -import org.jclouds.digitalocean2.config.DigitalOcean2HttpApiModule; -import org.jclouds.digitalocean2.config.DigitalOceanParserModule; -import org.jclouds.oauth.v2.config.OAuthModule; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Implementation of {@link ApiMetadata} for DigitalOcean v2 API - */ -public class DigitalOcean2ApiMetadata extends BaseHttpApiMetadata<DigitalOcean2Api> { - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public DigitalOcean2ApiMetadata() { - this(new Builder()); - } - - protected DigitalOcean2ApiMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - Properties properties = BaseHttpApiMetadata.defaultProperties(); - properties.put("oauth.endpoint", "https://cloud.digitalocean.com/v1/oauth/token"); - properties.put(JWS_ALG, "RS256"); - properties.put(AUDIENCE, "https://cloud.digitalocean.com/v1/oauth/token"); - properties.put(CREDENTIAL_TYPE, BEARER_TOKEN_CREDENTIALS.toString()); - properties.put(PROPERTY_SESSION_INTERVAL, 3600); - properties.put(TEMPLATE, "osFamily=UBUNTU,os64Bit=true"); - properties.put(POLL_INITIAL_PERIOD, 5000); - properties.put(POLL_MAX_PERIOD, 20000); - // Node operations in DigitalOcean can be quite slow. Use a 5 minutes - // timeout by default - properties.put(TIMEOUT_NODE_RUNNING, 300000); - properties.put(TIMEOUT_NODE_SUSPENDED, 300000); - properties.put(TIMEOUT_NODE_TERMINATED, 300000); - return properties; - } - - public static class Builder extends BaseHttpApiMetadata.Builder<DigitalOcean2Api, Builder> { - - protected Builder() { - id("digitalocean2") - .name("Digital Ocean v2 API") - .identityName("Not used for OAuth") - .credentialName("Must be oauth2 Bearer Token") - .documentation(URI.create("https://developers.digitalocean.com/v2/")) - .defaultEndpoint("https://api.digitalocean.com/v2") - .defaultProperties(DigitalOcean2ApiMetadata.defaultProperties()) - .view(typeToken(ComputeServiceContext.class)) - .defaultModules(ImmutableSet.<Class<? extends Module>>builder() - .add(DigitalOcean2HttpApiModule.class) - .add(OAuthModule.class) - .add(DigitalOceanParserModule.class) - .add(DigitalOcean2ComputeServiceContextModule.class) - .build()); - } - - @Override - public DigitalOcean2ApiMetadata build() { - return new DigitalOcean2ApiMetadata(this); - } - - @Override - protected Builder self() { - return this; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2ProviderMetadata.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2ProviderMetadata.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2ProviderMetadata.java deleted file mode 100644 index 0f64f78..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/DigitalOcean2ProviderMetadata.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.digitalocean2; - -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 org.jclouds.providers.ProviderMetadata} for DigitalOcean. - */ -@AutoService(ProviderMetadata.class) -public class DigitalOcean2ProviderMetadata extends BaseProviderMetadata { - - public static Builder builder() { - return new Builder(); - } - - @Override - public Builder toBuilder() { - return builder().fromProviderMetadata(this); - } - - public DigitalOcean2ProviderMetadata() { - super(builder()); - } - - public DigitalOcean2ProviderMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - Properties properties = DigitalOcean2ApiMetadata.defaultProperties(); - return properties; - } - - public static class Builder extends BaseProviderMetadata.Builder { - - protected Builder() { - id("digitalocean2") - .name("DigitalOcean Compute Services") - .apiMetadata(new DigitalOcean2ApiMetadata()) - .homepage(URI.create("https://www.digitalocean.com/")) - .console(URI.create("https://cloud.digitalocean.com/")) - .endpoint("https://api.digitalocean.com/v2") - .defaultProperties(DigitalOcean2ProviderMetadata.defaultProperties()); - } - - @Override - public DigitalOcean2ProviderMetadata build() { - return new DigitalOcean2ProviderMetadata(this); - } - - @Override - public Builder fromProviderMetadata(ProviderMetadata in) { - super.fromProviderMetadata(in); - return this; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/DigitalOcean2ComputeServiceAdapter.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/DigitalOcean2ComputeServiceAdapter.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/DigitalOcean2ComputeServiceAdapter.java deleted file mode 100644 index f520f45..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/DigitalOcean2ComputeServiceAdapter.java +++ /dev/null @@ -1,243 +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.digitalocean2.compute; - -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.contains; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Sets.newHashSet; -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.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue; - -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 org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.digitalocean2.DigitalOcean2Api; -import org.jclouds.digitalocean2.compute.internal.ImageInRegion; -import org.jclouds.digitalocean2.compute.options.DigitalOcean2TemplateOptions; -import org.jclouds.digitalocean2.domain.Droplet; -import org.jclouds.digitalocean2.domain.DropletCreate; -import org.jclouds.digitalocean2.domain.Image; -import org.jclouds.digitalocean2.domain.Region; -import org.jclouds.digitalocean2.domain.Size; -import org.jclouds.digitalocean2.domain.options.CreateDropletOptions; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.json.Json; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.primitives.Ints; - -/** - * Implementation of the Compute Service for the DigitalOcean API. - */ -public class DigitalOcean2ComputeServiceAdapter implements ComputeServiceAdapter<Droplet, Size, ImageInRegion, Region> { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - private final DigitalOcean2Api api; - private final Predicate<Integer> nodeRunningPredicate; - private final Predicate<Integer> nodeStoppedPredicate; - private final Predicate<Integer> nodeTerminatedPredicate; - private final Json json; - - @Inject DigitalOcean2ComputeServiceAdapter(DigitalOcean2Api api, - @Named(TIMEOUT_NODE_RUNNING) Predicate<Integer> nodeRunningPredicate, - @Named(TIMEOUT_NODE_SUSPENDED) Predicate<Integer> nodeStoppedPredicate, - @Named(TIMEOUT_NODE_TERMINATED) Predicate<Integer> nodeTerminatedPredicate, - Json json) { - this.api = api; - this.nodeRunningPredicate = nodeRunningPredicate; - this.nodeStoppedPredicate = nodeStoppedPredicate; - this.nodeTerminatedPredicate = nodeTerminatedPredicate; - this.json = json; - } - - @Override - public NodeAndInitialCredentials<Droplet> createNodeWithGroupEncodedIntoName(String group, final String name, - Template template) { - DigitalOcean2TemplateOptions templateOptions = template.getOptions().as(DigitalOcean2TemplateOptions.class); - CreateDropletOptions.Builder options = CreateDropletOptions.builder(); - - // DigitalOcean specific options - options.privateNetworking(templateOptions.getPrivateNetworking()); - options.backupsEnabled(templateOptions.getBackupsEnabled()); - if (!templateOptions.getSshKeyIds().isEmpty()) { - options.addSshKeyIds(templateOptions.getSshKeyIds()); - } - - Map<String, String> metadataAndTags = metadataAndTagsAsCommaDelimitedValue(templateOptions); - if (!metadataAndTags.isEmpty()) { - @SuppressWarnings("unchecked") - List<String> regionFeatures = (List<String>) template.getLocation().getMetadata().get("features"); - if (regionFeatures.contains("metadata")) { - options.userData(json.toJson(metadataAndTags)); - } else { - logger.debug(">> region %s does not support metadata, ignoring provided user data", template.getLocation() - .getId()); - } - } - - DropletCreate dropletCreated = api.dropletApi().create(name, - template.getLocation().getId(), - template.getHardware().getProviderId(), - template.getImage().getProviderId(), - 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(dropletCreated.droplet().id()); - Droplet droplet = api.dropletApi().get(dropletCreated.droplet().id()); - - LoginCredentials defaultCredentials = LoginCredentials.builder().user("root") - .privateKey(templateOptions.getLoginPrivateKey()).build(); - - return new NodeAndInitialCredentials<Droplet>(droplet, String.valueOf(droplet.id()), defaultCredentials); - } - - @Override - public Iterable<ImageInRegion> listImages() { - // Images can claim to be available in a region that is currently marked as "unavailable". We shouldn't return - // the images scoped to those regions. - final Set<String> availableRegionsIds = newHashSet(transform(listLocations(), new Function<Region, String>() { - @Override - public String apply(Region input) { - return input.slug(); - } - })); - - // Public images re globally available, but non-public ones can only be available in certain regions. - // For these kind of images, return one instance of an ImageInRegion for each region where the image is - // available. This way we can properly scope global and concrete images so they can be properly looked up. - return concat(filter(api.imageApi().list().concat().transform(new Function<Image, Iterable<ImageInRegion>>() { - @Override - public Iterable<ImageInRegion> apply(final Image image) { - return transform(image.regions(), new Function<String, ImageInRegion>() { - @Override - public ImageInRegion apply(String region) { - return availableRegionsIds.contains(region) ? ImageInRegion.create(image, region) : null; - } - }); - } - }), notNull())); - } - - @Override - public Iterable<Size> listHardwareProfiles() { - return filter(api.sizeApi().list().concat(), new Predicate<Size>() { - @Override - public boolean apply(Size size) { - return size.available(); - } - }); - } - - @Override - public Iterable<Region> listLocations() { - // DigitalOcean lists regions that are unavailable for droplet creation - return filter(api.regionApi().list().concat(), new Predicate<Region>() { - @Override - public boolean apply(Region region) { - return region.available(); - } - }); - } - - @Override - public Iterable<Droplet> listNodes() { - return api.dropletApi().list().concat(); - } - - @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.id())); - } - }); - } - - @Override - public ImageInRegion getImage(String id) { - String region = ImageInRegion.extractRegion(id); - String imageId = ImageInRegion.extractImageId(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 numericId = Ints.tryParse(imageId); - Image image = numericId == null ? api.imageApi().get(imageId) : api.imageApi().get(numericId); - return image == null ? null : ImageInRegion.create(image, region); - } - - @Override - public Droplet getNode(String id) { - return api.dropletApi().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 dropletId = Integer.parseInt(id); - api.dropletApi().delete(dropletId); - checkState(nodeTerminatedPredicate.apply(dropletId), "node was not destroyed in the configured timeout"); - } - - @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 dropletId = Integer.parseInt(id); - api.dropletApi().reboot(dropletId); - checkState(nodeRunningPredicate.apply(dropletId), "node did not restart in the configured timeout"); - } - - @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 dropletId = Integer.parseInt(id); - api.dropletApi().powerOn(dropletId); - checkState(nodeRunningPredicate.apply(dropletId), "node did not started in the configured timeout"); - } - - @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 dropletId = Integer.parseInt(id); - api.dropletApi().powerOff(dropletId); - checkState(nodeStoppedPredicate.apply(dropletId), "node did not stop in the configured timeout"); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/config/DigitalOcean2ComputeServiceContextModule.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/config/DigitalOcean2ComputeServiceContextModule.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/config/DigitalOcean2ComputeServiceContextModule.java deleted file mode 100644 index 03caf85..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/config/DigitalOcean2ComputeServiceContextModule.java +++ /dev/null @@ -1,218 +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.digitalocean2.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 static org.jclouds.util.Predicates2.retry; - -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.Image; -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.digitalocean2.DigitalOcean2Api; -import org.jclouds.digitalocean2.compute.DigitalOcean2ComputeServiceAdapter; -import org.jclouds.digitalocean2.compute.extensions.DigitalOcean2ImageExtension; -import org.jclouds.digitalocean2.compute.functions.DropletStatusToStatus; -import org.jclouds.digitalocean2.compute.functions.DropletToNodeMetadata; -import org.jclouds.digitalocean2.compute.functions.ImageInRegionToImage; -import org.jclouds.digitalocean2.compute.functions.RegionToLocation; -import org.jclouds.digitalocean2.compute.functions.SizeToHardware; -import org.jclouds.digitalocean2.compute.functions.TemplateOptionsToStatementWithoutPublicKey; -import org.jclouds.digitalocean2.compute.internal.ImageInRegion; -import org.jclouds.digitalocean2.compute.options.DigitalOcean2TemplateOptions; -import org.jclouds.digitalocean2.compute.strategy.CreateKeyPairsThenCreateNodes; -import org.jclouds.digitalocean2.domain.Action; -import org.jclouds.digitalocean2.domain.Droplet; -import org.jclouds.digitalocean2.domain.Region; -import org.jclouds.digitalocean2.domain.Size; -import org.jclouds.domain.Location; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Named; - -/** - * Configures the compute service classes for the DigitalOcean API. - */ -public class DigitalOcean2ComputeServiceContextModule extends - ComputeServiceAdapterContextModule<Droplet, Size, ImageInRegion, Region> { - - @Override - protected void configure() { - super.configure(); - - bind(new TypeLiteral<ComputeServiceAdapter<Droplet, Size, ImageInRegion, Region>>() { - }).to(DigitalOcean2ComputeServiceAdapter.class); - - bind(new TypeLiteral<Function<Droplet, NodeMetadata>>() { - }).to(DropletToNodeMetadata.class); - bind(new TypeLiteral<Function<ImageInRegion, Image>>() { - }).to(ImageInRegionToImage.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, ImageInRegion, Region>() { - }); - - bind(CreateNodesInGroupThenAddToSet.class).to(CreateKeyPairsThenCreateNodes.class); - bind(TemplateOptions.class).to(DigitalOcean2TemplateOptions.class); - bind(TemplateOptionsToStatement.class).to(TemplateOptionsToStatementWithoutPublicKey.class); - - bind(new TypeLiteral<ImageExtension>() { - }).to(DigitalOcean2ImageExtension.class); - } - - @Provides - @Named(TIMEOUT_NODE_RUNNING) - protected Predicate<Integer> provideDropletRunningPredicate(final DigitalOcean2Api api, Timeouts timeouts, - PollPeriod pollPeriod) { - return retry(new DropletInStatusPredicate(api, Droplet.Status.ACTIVE), timeouts.nodeRunning, - pollPeriod.pollInitialPeriod, pollPeriod.pollMaxPeriod); - } - - @Provides - @Named(TIMEOUT_NODE_SUSPENDED) - protected Predicate<Integer> provideDropletSuspendedPredicate(final DigitalOcean2Api api, Timeouts timeouts, - PollPeriod pollPeriod) { - return retry(new DropletInStatusPredicate(api, Droplet.Status.OFF), timeouts.nodeSuspended, - pollPeriod.pollInitialPeriod, pollPeriod.pollMaxPeriod); - } - - @Provides - @Named(TIMEOUT_NODE_TERMINATED) - protected Predicate<Integer> provideDropletTerminatedPredicate(final DigitalOcean2Api api, Timeouts timeouts, - PollPeriod pollPeriod) { - return retry(new DropletTerminatedPredicate(api), timeouts.nodeTerminated, pollPeriod.pollInitialPeriod, - pollPeriod.pollMaxPeriod); - } - - @Provides - @Named(TIMEOUT_IMAGE_AVAILABLE) - protected Predicate<Integer> provideImageAvailablePredicate(final DigitalOcean2Api api, Timeouts timeouts, - PollPeriod pollPeriod) { - return retry(new ActionDonePredicate(api), timeouts.imageAvailable, pollPeriod.pollInitialPeriod, - pollPeriod.pollMaxPeriod); - } - - @Provides - @Singleton - protected Predicate<Region> provideRegionAvailablePredicate(final DigitalOcean2Api api, Timeouts timeouts, - PollPeriod pollPeriod) { - return retry(new RegionAvailablePredicate(), timeouts.imageAvailable, pollPeriod.pollInitialPeriod, - pollPeriod.pollMaxPeriod); - } - - @Provides - protected Predicate<Integer> provideActionCompletedPredicate(final DigitalOcean2Api api, Timeouts timeouts, - PollPeriod pollPeriod) { - return retry(new ActionDonePredicate(api), timeouts.imageAvailable, pollPeriod.pollInitialPeriod, - pollPeriod.pollMaxPeriod); - } - - @VisibleForTesting - static class ActionDonePredicate implements Predicate<Integer> { - - private final DigitalOcean2Api api; - - public ActionDonePredicate(DigitalOcean2Api api) { - this.api = checkNotNull(api, "api must not be null"); - } - - @Override - public boolean apply(Integer input) { - checkNotNull(input, "action id cannot be null"); - Action current = api.actionApi().get(input); - switch (current.status()) { - case COMPLETED: - return true; - case IN_PROGRESS: - return false; - case ERRORED: - default: - throw new IllegalStateException("Resource is in invalid status: " + current.status().name()); - } - } - - } - - @VisibleForTesting - static class DropletTerminatedPredicate implements Predicate<Integer> { - - private final DigitalOcean2Api api; - - public DropletTerminatedPredicate(DigitalOcean2Api api) { - this.api = checkNotNull(api, "api must not be null"); - } - - @Override - public boolean apply(Integer input) { - checkNotNull(input, "droplet id"); - Droplet droplet = api.dropletApi().get(input); - return droplet == null; - } - } - - @VisibleForTesting - static class DropletInStatusPredicate implements Predicate<Integer> { - - private final DigitalOcean2Api api; - private final Droplet.Status status; - - public DropletInStatusPredicate(DigitalOcean2Api api, Droplet.Status status) { - this.api = checkNotNull(api, "api must not be null"); - this.status = checkNotNull(status, "status must not be null"); - } - - @Override - public boolean apply(Integer input) { - checkNotNull(input, "droplet id"); - Droplet droplet = api.dropletApi().get(input); - return droplet != null && status == droplet.status(); - } - } - - @VisibleForTesting - static class RegionAvailablePredicate implements Predicate<Region> { - @Override - public boolean apply(Region input) { - return input.available(); - } - - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java deleted file mode 100644 index 3baf146..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java +++ /dev/null @@ -1,149 +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.digitalocean2.compute.extensions; - -import static com.google.common.base.Preconditions.checkState; -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 java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -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.digitalocean2.DigitalOcean2Api; -import org.jclouds.digitalocean2.compute.internal.ImageInRegion; -import org.jclouds.digitalocean2.domain.Action; -import org.jclouds.digitalocean2.domain.Droplet; -import org.jclouds.digitalocean2.domain.Droplet.Status; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.primitives.Ints; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.UncheckedTimeoutException; - -/** - * The {@link org.jclouds.compute.extensions.ImageExtension} implementation for the DigitalOcean provider. - */ -@Singleton -public class DigitalOcean2ImageExtension implements ImageExtension { - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - private final DigitalOcean2Api api; - private final Predicate<Integer> imageAvailablePredicate; - private final Predicate<Integer> nodeStoppedPredicate; - private final Function<ImageInRegion, Image> imageTransformer; - private final ListeningExecutorService userExecutor; - - @Inject DigitalOcean2ImageExtension(DigitalOcean2Api api, - @Named(TIMEOUT_IMAGE_AVAILABLE) Predicate<Integer> imageAvailablePredicate, - @Named(TIMEOUT_NODE_SUSPENDED) Predicate<Integer> nodeStoppedPredicate, - Function<ImageInRegion, Image> imageTransformer, - @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor) { - this.api = api; - this.imageAvailablePredicate = imageAvailablePredicate; - this.nodeStoppedPredicate = nodeStoppedPredicate; - this.imageTransformer = imageTransformer; - this.userExecutor = userExecutor; - } - - @Override - public ImageTemplate buildImageTemplateFromNode(String name, String id) { - Droplet droplet = api.dropletApi().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; - int dropletId = Integer.parseInt(cloneTemplate.getSourceNodeId()); - - // Droplet needs to be stopped - final Droplet droplet = api.dropletApi().get(dropletId); - if (droplet.status() != Status.OFF) { - api.dropletApi().powerOff(dropletId); - checkState(nodeStoppedPredicate.apply(dropletId), "node was not powered off in the configured timeout"); - } - - final Action snapshotEvent = api.dropletApi().snapshot(Integer.parseInt(cloneTemplate.getSourceNodeId()), - cloneTemplate.getName()); - - logger.info(">> registered new Image, waiting for it to become available"); - - return userExecutor.submit(new Callable<Image>() { - @Override - public Image call() throws Exception { - if (imageAvailablePredicate.apply(snapshotEvent.id())) { - org.jclouds.digitalocean2.domain.Image snapshot = api.imageApi().list().concat() - .firstMatch(new Predicate<org.jclouds.digitalocean2.domain.Image>() { - @Override - public boolean apply(org.jclouds.digitalocean2.domain.Image input) { - return input.name().equals(cloneTemplate.getName()); - } - }).get(); - - return imageTransformer.apply(ImageInRegion.create(snapshot, droplet.region().slug())); - } - - throw new UncheckedTimeoutException("Image was not created within the time limit: " - + cloneTemplate.getName()); - } - }); - } - - @Override - public boolean deleteImage(String id) { - String imageId = ImageInRegion.extractImageId(id); - Integer numericId = Ints.tryParse(imageId); // User images don't have a slug, so we expect a numeric id here - - if (numericId != null) { - try { - logger.debug(">> deleting image %s...", id); - api.imageApi().delete(numericId); - return true; - } catch (Exception ex) { - logger.error(ex, ">> error deleting image %s", id); - } - } else { - logger.warn(">> image %s is not a user image and cannot be deleted", id); - } - - return false; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/DropletStatusToStatus.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/DropletStatusToStatus.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/DropletStatusToStatus.java deleted file mode 100644 index 6edadb9..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/DropletStatusToStatus.java +++ /dev/null @@ -1,46 +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.digitalocean2.compute.functions; - -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata.Status; -import org.jclouds.digitalocean2.domain.Droplet; -import com.google.common.base.Function; -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableMap; - -/** - * Transforms an {@link org.jclouds.compute.domain.NodeMetadata.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/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/DropletToNodeMetadata.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/DropletToNodeMetadata.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/DropletToNodeMetadata.java deleted file mode 100644 index 11594f8..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/DropletToNodeMetadata.java +++ /dev/null @@ -1,165 +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.digitalocean2.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.find; -import static org.jclouds.digitalocean2.compute.internal.ImageInRegion.encodeId; - -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.digitalocean2.compute.internal.ImageInRegion; -import org.jclouds.digitalocean2.domain.Droplet; -import org.jclouds.digitalocean2.domain.Networks; -import org.jclouds.digitalocean2.domain.Region; -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.FluentIterable; -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.id())); - builder.name(input.name()); - builder.hostname(input.name()); - builder.group(groupNamingConvention.extractGroup(input.name())); - - builder.hardware(getHardware(input.sizeSlug())); - builder.location(getLocation(input.region())); - - Optional<? extends Image> image = findImage(input.image(), input.region().slug()); - 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.image().id(), input.id()); - } - - builder.status(toPortableStatus.apply(input.status())); - builder.backendStatus(input.status().name()); - - if (!input.getPublicAddresses().isEmpty()) { - builder.publicAddresses(FluentIterable - .from(input.getPublicAddresses()) - .transform(new Function<Networks.Address, String>() { - @Override - public String apply(final Networks.Address input) { - return input.ip(); - } - }) - ); - } - - if (!input.getPrivateAddresses().isEmpty()) { - builder.privateAddresses(FluentIterable - .from(input.getPrivateAddresses()) - .transform(new Function<Networks.Address, String>() { - @Override - public String apply(final Networks.Address input) { - return input.ip(); - } - }) - ); - } - - // DigitalOcean does not provide a way to get the credentials. - // Try to return them from the credential store - Credentials credentials = credentialStore.get("node#" + input.id()); - if (credentials instanceof LoginCredentials) { - builder.credentials(LoginCredentials.class.cast(credentials)); - } - - return builder.build(); - } - - protected Optional<? extends Image> findImage(org.jclouds.digitalocean2.domain.Image image, String region) { - return Optional.fromNullable(images.get().get(encodeId(ImageInRegion.create(image, region)))); - } - - protected Hardware getHardware(final String slug) { - return Iterables.find(hardwares.get().values(), new Predicate<Hardware>() { - @Override - public boolean apply(Hardware input) { - return input.getId().equals(slug); - } - }); - } - - protected Location getLocation(final Region region) { - return find(locations.get(), new Predicate<Location>() { - @Override - public boolean apply(Location location) { - return region != null && region.slug().equals(location.getId()); - } - }, null); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/ImageInRegionToImage.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/ImageInRegionToImage.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/ImageInRegionToImage.java deleted file mode 100644 index 08c6c71..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/ImageInRegionToImage.java +++ /dev/null @@ -1,92 +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.digitalocean2.compute.functions; - -import static com.google.common.collect.Iterables.find; -import static org.jclouds.compute.domain.OperatingSystem.builder; -import static org.jclouds.digitalocean2.compute.internal.ImageInRegion.encodeId; - -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.collect.Memoized; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Image.Status; -import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.digitalocean2.compute.internal.ImageInRegion; -import org.jclouds.digitalocean2.domain.OperatingSystem; -import org.jclouds.domain.Location; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; - -/** - * Transforms an {@link ImageInRegion} to the jclouds portable model. - */ -@Singleton -public class ImageInRegionToImage implements Function<ImageInRegion, Image> { - - private final Supplier<Set<? extends Location>> locations; - - @Inject ImageInRegionToImage(@Memoized Supplier<Set<? extends Location>> locations) { - this.locations = locations; - } - - @Override - public Image apply(final ImageInRegion input) { - String description = input.image().distribution() + " " + input.image().name(); - ImageBuilder builder = new ImageBuilder(); - // Private images don't have a slug - builder.id(encodeId(input)); - builder.providerId(String.valueOf(input.image().id())); - builder.name(input.image().name()); - builder.description(description); - builder.status(Status.AVAILABLE); - builder.location(getLocation(input.region())); - - OperatingSystem os = OperatingSystem.create(input.image().name(), input.image().distribution()); - - builder.operatingSystem(builder() - .name(os.distribution().value()) - .family(os.distribution().osFamily()) - .description(description) - .arch(os.arch()) - .version(os.version()) - .is64Bit(os.is64bit()) - .build()); - - ImmutableMap.Builder<String, String> metadata = ImmutableMap.builder(); - metadata.put("publicImage", String.valueOf(input.image().isPublic())); - builder.userMetadata(metadata.build()); - - return builder.build(); - } - - protected Location getLocation(final String region) { - return find(locations.get(), new Predicate<Location>() { - @Override - public boolean apply(Location location) { - return region.equals(location.getId()); - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/RegionToLocation.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/RegionToLocation.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/RegionToLocation.java deleted file mode 100644 index adde1b7..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/RegionToLocation.java +++ /dev/null @@ -1,59 +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.digitalocean2.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.getOnlyElement; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.digitalocean2.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.ImmutableMap; -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.slug()); - builder.description(input.name()); - builder.scope(LocationScope.REGION); - builder.parent(getOnlyElement(justProvider.get())); - builder.iso3166Codes(ImmutableSet.<String> of()); - builder.metadata(ImmutableMap.<String, Object> of("available", input.available(), "features", input.features())); - return builder.build(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/SizeToHardware.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/SizeToHardware.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/SizeToHardware.java deleted file mode 100644 index 5645d3b..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/SizeToHardware.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.digitalocean2.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.digitalocean2.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.slug()); - builder.providerId(input.slug()); - builder.name(input.slug()); - builder.ram(input.memory()); - // No cpu speed from DigitalOcean API, so assume more cores == faster - builder.processor(new Processor(input.vcpus(), input.vcpus())); - - builder.volume(new VolumeBuilder() - .size(Float.valueOf(input.disk())) - .type(Type.LOCAL) - .build()); - - ImmutableMap.Builder<String, String> metadata = ImmutableMap.builder(); - metadata.put("costPerHour", String.valueOf(input.priceHourly())); - metadata.put("costPerMonth", String.valueOf(input.priceMonthly())); - builder.userMetadata(metadata.build()); - - return builder.build(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/TemplateOptionsToStatementWithoutPublicKey.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/TemplateOptionsToStatementWithoutPublicKey.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/TemplateOptionsToStatementWithoutPublicKey.java deleted file mode 100644 index 52dcb0e..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/functions/TemplateOptionsToStatementWithoutPublicKey.java +++ /dev/null @@ -1,59 +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.digitalocean2.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.DigitalOcean2ComputeServiceAdapter.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/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/internal/ImageInRegion.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/internal/ImageInRegion.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/internal/ImageInRegion.java deleted file mode 100644 index b5beb8d..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/internal/ImageInRegion.java +++ /dev/null @@ -1,54 +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.digitalocean2.compute.internal; - -import org.jclouds.digitalocean2.domain.Image; - -import com.google.auto.value.AutoValue; - -/** - * Scopes an image to a particular region. - */ -@AutoValue -public abstract class ImageInRegion { - - public abstract Image image(); - public abstract String region(); - - public static ImageInRegion create(Image image, String region) { - return new AutoValue_ImageInRegion(image, region); - } - - public static String encodeId(ImageInRegion imageInRegion) { - // Private images don't have a slug - return String.format("%s/%s", imageInRegion.region(), slugOrId(imageInRegion.image())); - } - - public static String extractRegion(String imageId) { - return imageId.substring(0, imageId.indexOf('/')); - } - - public static String extractImageId(String imageId) { - return imageId.substring(imageId.indexOf('/') + 1); - } - - private static String slugOrId(Image image) { - return image.slug() != null ? image.slug() : String.valueOf(image.id()); - } - - ImageInRegion() { } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a6044372/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/options/DigitalOcean2TemplateOptions.java ---------------------------------------------------------------------- diff --git a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/options/DigitalOcean2TemplateOptions.java b/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/options/DigitalOcean2TemplateOptions.java deleted file mode 100644 index cafcdb1..0000000 --- a/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/options/DigitalOcean2TemplateOptions.java +++ /dev/null @@ -1,174 +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.digitalocean2.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.ToStringHelper; -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableSet; - -/** - * Custom options for the DigitalOcean API. - */ -public class DigitalOcean2TemplateOptions extends TemplateOptions implements Cloneable { - - private Set<Integer> sshKeyIds = ImmutableSet.of(); - private boolean privateNetworking = false; - private boolean backupsEnabled = false; - private boolean autoCreateKeyPair = true; - - /** - * Enables a private network interface if the region supports private networking. - */ - public DigitalOcean2TemplateOptions privateNetworking(boolean privateNetworking) { - this.privateNetworking = privateNetworking; - return this; - } - - /** - * Enabled backups for the droplet. - */ - public DigitalOcean2TemplateOptions backupsEnabled(boolean backupsEnabled) { - this.backupsEnabled = backupsEnabled; - return this; - } - - /** - * Sets the ssh key ids to be added to the droplet. - */ - public DigitalOcean2TemplateOptions 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 DigitalOcean2TemplateOptions 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 DigitalOcean2TemplateOptions clone() { - DigitalOcean2TemplateOptions options = new DigitalOcean2TemplateOptions(); - copyTo(options); - return options; - } - - @Override - public void copyTo(TemplateOptions to) { - super.copyTo(to); - if (to instanceof DigitalOcean2TemplateOptions) { - DigitalOcean2TemplateOptions eTo = DigitalOcean2TemplateOptions.class.cast(to); - eTo.privateNetworking(privateNetworking); - 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; - } - DigitalOcean2TemplateOptions other = (DigitalOcean2TemplateOptions) 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 DigitalOcean2TemplateOptions#privateNetworking - */ - public static DigitalOcean2TemplateOptions privateNetworking(boolean privateNetworking) { - DigitalOcean2TemplateOptions options = new DigitalOcean2TemplateOptions(); - return options.privateNetworking(privateNetworking); - } - - /** - * @see DigitalOcean2TemplateOptions#backupsEnabled - */ - public static DigitalOcean2TemplateOptions backupsEnabled(boolean backupsEnabled) { - DigitalOcean2TemplateOptions options = new DigitalOcean2TemplateOptions(); - return options.backupsEnabled(backupsEnabled); - } - - /** - * @see DigitalOcean2TemplateOptions#sshKeyIds - */ - public static DigitalOcean2TemplateOptions sshKeyIds(Iterable<Integer> sshKeyIds) { - DigitalOcean2TemplateOptions options = new DigitalOcean2TemplateOptions(); - return options.sshKeyIds(sshKeyIds); - } - - /** - * @see DigitalOcean2TemplateOptions#autoCreateKeyPair - */ - public static DigitalOcean2TemplateOptions autoCreateKeyPair(boolean autoCreateKeyPair) { - DigitalOcean2TemplateOptions options = new DigitalOcean2TemplateOptions(); - return options.autoCreateKeyPair(autoCreateKeyPair); - } - } -}
