Remove Docker. It is now on the main repo
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/39cd6698 Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/39cd6698 Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/39cd6698 Branch: refs/heads/master Commit: 39cd6698e28d722c6861934a84e07a70cd961e9b Parents: 4494646 Author: Ignasi Barrera <[email protected]> Authored: Tue Aug 30 11:37:32 2016 +0200 Committer: Ignasi Barrera <[email protected]> Committed: Tue Aug 30 11:37:32 2016 +0200 ---------------------------------------------------------------------- docker/README.md | 89 --- docker/pom.xml | 192 ----- .../main/java/org/jclouds/docker/DockerApi.java | 41 - .../org/jclouds/docker/DockerApiMetadata.java | 100 --- .../DockerComputeServiceContextModule.java | 62 -- .../compute/config/LoginPortLookupModule.java | 40 - .../functions/ContainerToNodeMetadata.java | 141 ---- .../functions/CustomLoginPortFromImage.java | 84 -- .../docker/compute/functions/ImageToImage.java | 103 --- .../functions/LoginPortForContainer.java | 51 -- .../functions/PublicPortForContainerPort.java | 58 -- .../docker/compute/functions/StateToStatus.java | 38 - .../compute/options/DockerTemplateOptions.java | 780 ------------------- .../strategy/DockerComputeServiceAdapter.java | 353 --------- .../docker/config/DockerHttpApiModule.java | 68 -- .../config/DockerOkHttpClientSupplier.java | 63 -- .../docker/config/DockerParserModule.java | 29 - .../java/org/jclouds/docker/domain/Config.java | 265 ------- .../org/jclouds/docker/domain/Container.java | 273 ------- .../jclouds/docker/domain/ContainerSummary.java | 52 -- .../java/org/jclouds/docker/domain/Exec.java | 35 - .../jclouds/docker/domain/ExecCreateParams.java | 72 -- .../org/jclouds/docker/domain/ExecInspect.java | 40 - .../jclouds/docker/domain/ExecStartParams.java | 47 -- .../org/jclouds/docker/domain/ExposedPorts.java | 40 - .../org/jclouds/docker/domain/HostConfig.java | 203 ----- .../java/org/jclouds/docker/domain/Image.java | 84 -- .../org/jclouds/docker/domain/ImageHistory.java | 50 -- .../org/jclouds/docker/domain/ImageSummary.java | 51 -- .../java/org/jclouds/docker/domain/Info.java | 108 --- .../java/org/jclouds/docker/domain/Network.java | 215 ----- .../jclouds/docker/domain/NetworkSettings.java | 288 ------- .../java/org/jclouds/docker/domain/Node.java | 63 -- .../java/org/jclouds/docker/domain/Port.java | 41 - .../org/jclouds/docker/domain/Resource.java | 35 - .../java/org/jclouds/docker/domain/State.java | 58 -- .../org/jclouds/docker/domain/StatusCode.java | 35 - .../java/org/jclouds/docker/domain/Version.java | 48 -- .../jclouds/docker/features/ContainerApi.java | 252 ------ .../org/jclouds/docker/features/ImageApi.java | 139 ---- .../org/jclouds/docker/features/MiscApi.java | 140 ---- .../org/jclouds/docker/features/NetworkApi.java | 100 --- .../docker/handlers/DockerErrorHandler.java | 98 --- .../jclouds/docker/internal/NullSafeCopies.java | 95 --- .../jclouds/docker/options/AttachOptions.java | 114 --- .../jclouds/docker/options/BuildOptions.java | 66 -- .../jclouds/docker/options/CommitOptions.java | 104 --- .../docker/options/CreateImageOptions.java | 90 --- .../docker/options/DeleteImageOptions.java | 52 -- .../docker/options/ListContainerOptions.java | 92 --- .../docker/options/ListImageOptions.java | 38 - .../docker/options/RemoveContainerOptions.java | 69 -- .../suppliers/DockerSSLContextSupplier.java | 74 -- .../DockerUntrustedSSLContextSupplier.java | 69 -- .../docker/suppliers/SSLContextBuilder.java | 201 ----- .../jclouds/docker/util/DockerInputStream.java | 73 -- .../org/jclouds/docker/util/StdStreamData.java | 87 --- .../jclouds/docker/DockerApiMetadataTest.java | 47 -- .../docker/compute/BaseDockerApiLiveTest.java | 101 --- .../DockerComputeServiceAdapterLiveTest.java | 178 ----- .../compute/DockerComputeServiceLiveTest.java | 214 ----- .../docker/compute/SshToCustomPortLiveTest.java | 245 ------ .../functions/ContainerToNodeMetadataTest.java | 224 ------ .../functions/CustomLoginPortFromImageTest.java | 106 --- .../compute/functions/ImageToImageTest.java | 148 ---- .../compute/functions/StateToStatusTest.java | 81 -- .../options/DockerTemplateOptionsTest.java | 159 ---- .../PredicateLocateImageByNameTest.java | 111 --- .../docker/config/DockerParserModuleTest.java | 126 --- .../org/jclouds/docker/domain/ConfigTest.java | 62 -- .../jclouds/docker/domain/ContainerTest.java | 37 - .../docker/features/ContainerApiLiveTest.java | 152 ---- .../docker/features/ContainerApiMockTest.java | 236 ------ .../docker/features/ImageApiLiveTest.java | 86 -- .../docker/features/ImageApiMockTest.java | 145 ---- .../docker/features/MiscApiLiveTest.java | 182 ----- .../docker/features/MiscApiMockTest.java | 179 ----- .../docker/features/NetworkApiLiveTest.java | 125 --- .../docker/features/NetworkApiMockTest.java | 153 ---- .../docker/internal/BaseDockerMockTest.java | 84 -- .../docker/internal/BaseDockerParseTest.java | 33 - .../docker/internal/DockerTestUtils.java | 79 -- .../docker/parse/ContainerParseTest.java | 132 ---- .../parse/ContainerVersionMajor1Minor21.java | 264 ------- .../docker/parse/ContainersParseTest.java | 51 -- .../jclouds/docker/parse/HistoryParseTest.java | 63 -- .../jclouds/docker/parse/ImageParseTest.java | 83 -- .../jclouds/docker/parse/ImagesParseTest.java | 69 -- .../jclouds/docker/parse/Info2ParseTest.java | 72 -- .../org/jclouds/docker/parse/InfoParseTest.java | 70 -- .../jclouds/docker/parse/NetworkParseTest.java | 71 -- .../jclouds/docker/parse/NetworksParseTest.java | 97 --- .../jclouds/docker/parse/VersionParseTest.java | 46 -- docker/src/test/resources/Dockerfile | 20 - docker/src/test/resources/SimpleDockerfile | 18 - docker/src/test/resources/cert.pem | 22 - .../test/resources/container-1.21-create.json | 72 -- .../test/resources/container-1.21-inspect.json | 147 ---- .../src/test/resources/container-creation.json | 1 - docker/src/test/resources/container.json | 159 ---- docker/src/test/resources/containers.json | 36 - docker/src/test/resources/exec.json | 1 - docker/src/test/resources/exec.start | Bin 29 -> 0 bytes docker/src/test/resources/execInspect.json | 1 - docker/src/test/resources/history-apiver22.json | 28 - docker/src/test/resources/history.json | 32 - docker/src/test/resources/image.json | 83 -- docker/src/test/resources/images.json | 53 -- docker/src/test/resources/info.json | 34 - docker/src/test/resources/info2.json | 90 --- docker/src/test/resources/key.pem | 27 - docker/src/test/resources/logback.xml | 34 - docker/src/test/resources/network-creation.json | 4 - docker/src/test/resources/network.json | 30 - docker/src/test/resources/networks.json | 56 -- docker/src/test/resources/version.json | 9 - pom.xml | 3 +- 117 files changed, 1 insertion(+), 11618 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/README.md ---------------------------------------------------------------------- diff --git a/docker/README.md b/docker/README.md deleted file mode 100644 index fef97b3..0000000 --- a/docker/README.md +++ /dev/null @@ -1,89 +0,0 @@ -# Docker as a local cloud provider - -jclouds-docker is a local cloud provider modelled on [docker](http://www.docker.io). Similar to other jclouds supported -providers, it supports the same portable abstractions offered by jclouds. - -## Setup - -Please follow these steps to configure your workstation for jclouds-docker: - -- install the latest Docker release (please visit https://docs.docker.com/installation/) -- [enable remote access](https://docs.docker.com/engine/quickstart/#bind-docker-to-another-host-port-or-a-unix-socket) to Docker - -### Sample configuration for Linux systems using systemd - -Run following commands on a machine where is the Docker Engine installed. -It enables remote access (plain TCP - only for loopback address 127.0.0.1) -on standard port `2375`. - -```bash -# switch to root account -sudo su - - -# create override for docker start-script -mkdir /etc/systemd/system/docker.service.d -cat << EOT > /etc/systemd/system/docker.service.d/allow-tcp.conf -[Service] -ExecStart= -ExecStart=/usr/bin/docker daemon -H fd:// -H tcp:// -EOT - -# reload configuration and restart docker daemon -systemctl daemon-reload -systemctl restart docker - -# close the 'root' session -exit -``` - -If the `-H fd://` Docker daemon parameter doesn't work on your Linux (e.g. Fedora), -then replace it by `-H unix:///var/run/docker.sock` - -Find more details in [Control and configure Docker with systemd](https://docs.docker.com/engine/admin/systemd/) guide. - -### Running live tests - -The `DOCKER_HOST` environment variable has to be configured as it's used as a value for `test.docker.endpoint` system property. - -``` -export DOCKER_HOST="http://localhost:2375/" -mvn -Plive integration-test -``` - -# How it works - - - --------------- ------------- - | Image(s) | | Node(s) | - --------------- ------------- - --------- docker remote api ---------------------------------------- - | jclouds | ---------------------------> | DOCKER_HOST | - --------- ---------------------------------------- - -## Components - -- jclouds \- acts as a java client to access to docker features -- DOCKER_HOST \- hosts Docker API, NB: jclouds-docker assumes that the latest Docker is installed -- Image \- it is a docker image that can be started. -- Node \- is a docker container - -## Assumptions - -- jclouds-docker assumes that the images specified using the template are ssh'able. - --------------- - -# Notes: -- report any issues you find at [jclouds issues](https://issues.apache.org/jira/browse/JCLOUDS) -- jclouds-docker has been tested on Mac OSX and Linux. However, it has never been tried on Windows. - --------------- - -# Troubleshooting - -As jclouds docker support is quite new, issues may occasionally arise. -You can try to remove all containers to get things going again: - -```bash -docker rm -f `docker ps -aq` -``` http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/pom.xml ---------------------------------------------------------------------- diff --git a/docker/pom.xml b/docker/pom.xml deleted file mode 100644 index 8bbb98c..0000000 --- a/docker/pom.xml +++ /dev/null @@ -1,192 +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.jclouds.provider --> - <groupId>org.apache.jclouds.labs</groupId> - <artifactId>docker</artifactId> - <name>jclouds docker API</name> - <description>ComputeService binding to the Docker API</description> - <packaging>bundle</packaging> - - <properties> - <test.docker.api-version>1.21</test.docker.api-version> - <test.docker.identity>${env.DOCKER_CERT_PATH}/cert.pem</test.docker.identity> - <test.docker.credential>${env.DOCKER_CERT_PATH}/key.pem</test.docker.credential> - <test.docker.cacert.path>${env.DOCKER_CERT_PATH}/ca.pem</test.docker.cacert.path> - <test.docker.endpoint>${env.DOCKER_HOST}</test.docker.endpoint> - <test.jclouds.trust-all-certs>false</test.jclouds.trust-all-certs> - <jclouds.osgi.export>org.jclouds.docker*;version="${project.version}"</jclouds.osgi.export> - <jclouds.osgi.import> - org.jclouds.compute.internal;version="${project.version}", - org.jclouds.rest.internal;version="${project.version}", - org.jclouds*;version="${project.version}", - * - </jclouds.osgi.import> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.google.auto.service</groupId> - <artifactId>auto-service</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.google.auto.value</groupId> - <artifactId>auto-value</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-sshj</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-bouncycastle</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-okhttp</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.google.inject.extensions</groupId> - <artifactId>guice-multibindings</artifactId> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-core</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jclouds.driver</groupId> - <artifactId>jclouds-slf4j</artifactId> - <version>${project.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>org.jboss.shrinkwrap</groupId> - <artifactId>shrinkwrap-depchain</artifactId> - <version>1.2.2</version> - <type>pom</type> - <scope>test</scope> - </dependency> - </dependencies> - - <profiles> - <profile> - <id>live</id> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.9.1</version> - <executions> - <execution> - <id>regex-property</id> - <goals> - <goal>regex-property</goal> - </goals> - <configuration> - <name>test.docker.endpoint</name> - <value>${test.docker.endpoint}</value> - <regex>tcp</regex> - <replacement>https</replacement> - <failIfNoMatch>false</failIfNoMatch> - </configuration> - </execution> - </executions> - </plugin> - <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.docker.endpoint>${test.docker.endpoint}</test.docker.endpoint> - <test.docker.api-version>${test.docker.api-version}</test.docker.api-version> - <test.docker.identity>${test.docker.identity}</test.docker.identity> - <test.docker.credential>${test.docker.credential}</test.docker.credential> - <test.docker.cacert.path>${test.docker.cacert.path}</test.docker.cacert.path> - <test.jclouds.trust-all-certs>${test.jclouds.trust-all-certs}</test.jclouds.trust-all-certs> - </systemPropertyVariables> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/DockerApi.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/DockerApi.java b/docker/src/main/java/org/jclouds/docker/DockerApi.java deleted file mode 100644 index 4650eac..0000000 --- a/docker/src/main/java/org/jclouds/docker/DockerApi.java +++ /dev/null @@ -1,41 +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.docker; - -import java.io.Closeable; - -import org.jclouds.docker.features.ContainerApi; -import org.jclouds.docker.features.ImageApi; -import org.jclouds.docker.features.MiscApi; -import org.jclouds.docker.features.NetworkApi; -import org.jclouds.rest.annotations.Delegate; - -public interface DockerApi extends Closeable { - - @Delegate - MiscApi getMiscApi(); - - @Delegate - ContainerApi getContainerApi(); - - @Delegate - ImageApi getImageApi(); - - @Delegate - NetworkApi getNetworkApi(); - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java b/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java deleted file mode 100644 index 453f393..0000000 --- a/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java +++ /dev/null @@ -1,100 +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.docker; - -import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE; -import static org.jclouds.reflect.Reflection2.typeToken; -import java.net.URI; -import java.util.Properties; - -import org.jclouds.Constants; -import org.jclouds.apis.ApiMetadata; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.config.ComputeServiceProperties; -import org.jclouds.docker.compute.config.DockerComputeServiceContextModule; -import org.jclouds.docker.config.DockerHttpApiModule; -import org.jclouds.docker.config.DockerParserModule; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.auto.service.AutoService; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -@AutoService(ApiMetadata.class) -public class DockerApiMetadata extends BaseHttpApiMetadata<DockerApi> { - - public static final String DOCKER_CA_CERT_PATH = "docker.cacert.path"; - public static final String DOCKER_CA_CERT_DATA = "docker.cacert.data"; - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public DockerApiMetadata() { - this(new Builder()); - } - - protected DockerApiMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - Properties properties = BaseHttpApiMetadata.defaultProperties(); - properties.setProperty(Constants.PROPERTY_CONNECTION_TIMEOUT, "1200000"); // 15 minutes - properties.setProperty(ComputeServiceProperties.IMAGE_LOGIN_USER, "root:password"); - properties.setProperty(TEMPLATE, "osFamily=UBUNTU,os64Bit=true"); - properties.setProperty(DOCKER_CA_CERT_PATH, ""); - properties.setProperty(DOCKER_CA_CERT_DATA, ""); - return properties; - } - - public static class Builder extends BaseHttpApiMetadata.Builder<DockerApi, Builder> { - - protected Builder() { - super(DockerApi.class); - id("docker") - .name("Docker API") - .identityName("Path or data for certificate .pem file") - .credentialName("Path or data for key .pem file") - .documentation(URI.create("https://docs.docker.com/reference/api/docker_remote_api/")) - .version("1.21") - .defaultEndpoint("https://127.0.0.1:2376") - .defaultProperties(DockerApiMetadata.defaultProperties()) - .view(typeToken(ComputeServiceContext.class)) - .defaultModules(ImmutableSet.<Class<? extends Module>>of( - DockerParserModule.class, - DockerHttpApiModule.class, - DockerComputeServiceContextModule.class)); - } - - @Override - public DockerApiMetadata build() { - return new DockerApiMetadata(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/39cd6698/docker/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java b/docker/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java deleted file mode 100644 index f9e03f4..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/config/DockerComputeServiceContextModule.java +++ /dev/null @@ -1,62 +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.docker.compute.config; - -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.options.TemplateOptions; -import org.jclouds.docker.compute.functions.ContainerToNodeMetadata; -import org.jclouds.docker.compute.functions.ImageToImage; -import org.jclouds.docker.compute.functions.StateToStatus; -import org.jclouds.docker.compute.options.DockerTemplateOptions; -import org.jclouds.docker.compute.strategy.DockerComputeServiceAdapter; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.Image; -import org.jclouds.docker.domain.State; -import org.jclouds.domain.Location; -import org.jclouds.functions.IdentityFunction; - -import com.google.common.base.Function; -import com.google.inject.TypeLiteral; - -public class DockerComputeServiceContextModule extends - ComputeServiceAdapterContextModule<Container, Hardware, Image, Location> { - - @SuppressWarnings("unchecked") - @Override - protected void configure() { - super.configure(); - bind(new TypeLiteral<ComputeServiceAdapter<Container, Hardware, Image, Location>>() { - }).to(DockerComputeServiceAdapter.class); - bind(new TypeLiteral<Function<Container, NodeMetadata>>() { - }).to(ContainerToNodeMetadata.class); - bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() { - }).to(ImageToImage.class); - bind(new TypeLiteral<Function<Hardware, Hardware>>() { - }).to(Class.class.cast(IdentityFunction.class)); - bind(new TypeLiteral<Function<Location, Location>>() { - }).to(Class.class.cast(IdentityFunction.class)); - bind(new TypeLiteral<Function<State, NodeMetadata.Status>>() { - }).to(StateToStatus.class); - bind(TemplateOptions.class).to(DockerTemplateOptions.class); - - install(new LoginPortLookupModule()); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/compute/config/LoginPortLookupModule.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/config/LoginPortLookupModule.java b/docker/src/main/java/org/jclouds/docker/compute/config/LoginPortLookupModule.java deleted file mode 100644 index 2daf287..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/config/LoginPortLookupModule.java +++ /dev/null @@ -1,40 +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.docker.compute.config; - -import org.jclouds.docker.compute.functions.LoginPortForContainer; - -import com.google.inject.AbstractModule; -import com.google.inject.Binder; -import com.google.inject.multibindings.MapBinder; - -public class LoginPortLookupModule extends AbstractModule { - - @Override - protected void configure() { - // Declare it to initialize the binder allowing duplicates. Users may - // provide different functions for the same image in different modules, or - // we could provide predefined functions for known images. This allows - // users to set their own ones too. - loginPortLookupBinder(binder()); - } - - public static MapBinder<String, LoginPortForContainer> loginPortLookupBinder(Binder binder) { - return MapBinder.newMapBinder(binder, String.class, LoginPortForContainer.class).permitDuplicates(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java b/docker/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java deleted file mode 100644 index c3b5831..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/functions/ContainerToNodeMetadata.java +++ /dev/null @@ -1,141 +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.docker.compute.functions; - -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.inject.Inject; - -import org.jclouds.collect.Memoized; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.functions.GroupNamingConvention; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.NetworkSettings; -import org.jclouds.docker.domain.State; -import org.jclouds.domain.Location; -import org.jclouds.providers.ProviderMetadata; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.inject.Singleton; - -@Singleton -public class ContainerToNodeMetadata implements Function<Container, NodeMetadata> { - - /** - * This value is used when a container does not have an accessible - * login port (i.e. the SSH daemon is not running) due to being - * started outside jclouds. Client code should check for this value - * when accessing NodeMetadata from Docker. - */ - private static final Integer NO_LOGIN_PORT = Integer.valueOf(-1); - - private final ProviderMetadata providerMetadata; - private final Function<State, NodeMetadata.Status> toPortableStatus; - private final GroupNamingConvention nodeNamingConvention; - private final Supplier<Map<String, ? extends Image>> images; - private final Supplier<Set<? extends Location>> locations; - private final LoginPortForContainer loginPortForContainer; - - @Inject - ContainerToNodeMetadata(ProviderMetadata providerMetadata, - Function<State, NodeMetadata.Status> toPortableStatus, GroupNamingConvention.Factory namingConvention, - Supplier<Map<String, ? extends Image>> images, @Memoized Supplier<Set<? extends Location>> locations, - LoginPortForContainer loginPortForContainer) { - this.providerMetadata = providerMetadata; - this.toPortableStatus = toPortableStatus; - this.nodeNamingConvention = namingConvention.createWithoutPrefix(); - this.images = images; - this.locations = locations; - this.loginPortForContainer = loginPortForContainer; - } - - @Override - public NodeMetadata apply(Container container) { - String name = cleanUpName(container.name()); - String group = nodeNamingConvention.extractGroup(name); - NodeMetadataBuilder builder = new NodeMetadataBuilder(); - builder.ids(container.id()) - .name(name) - .group(group) - .hostname(container.config().hostname()) - // TODO Set up hardware - .hardware(new HardwareBuilder() - .id("") - .ram(container.config().memory()) - .processor(new Processor(container.config().cpuShares(), container.config().cpuShares())) - .build()); - builder.status(toPortableStatus.apply(container.state())); - builder.loginPort(loginPortForContainer.apply(container).or(NO_LOGIN_PORT)); - builder.publicAddresses(getPublicIpAddresses(container)); - builder.privateAddresses(getPrivateIpAddresses(container)); - builder.location(Iterables.getOnlyElement(locations.get())); - String imageId = container.image(); - builder.imageId(imageId); - if (images.get().containsKey(imageId)) { - Image image = images.get().get(imageId); - builder.operatingSystem(image.getOperatingSystem()); - } - return builder.build(); - } - - private String cleanUpName(String name) { - return name.startsWith("/") ? name.substring(1) : name; - } - - private Iterable<String> getPrivateIpAddresses(Container container) { - // A container can be attached to multiple networks. It can therefore have multiple private - // IPs. The NetworkSettings.ipAddress might in fact be blank, with the only IP being on - // network objects. - if (container.networkSettings() == null) return ImmutableList.of(); - ImmutableSet.Builder<String> builder = ImmutableSet.<String>builder(); - NetworkSettings settings = container.networkSettings(); - if (settings.ipAddress() != null && settings.ipAddress().length() > 0) { - builder.add(settings.ipAddress()); - } - if (settings.networks() != null) { - for (Map.Entry<String, NetworkSettings.Details> entry : settings.networks().entrySet()) { - String ipAddress = entry.getValue().ipAddress(); - if (ipAddress != null && ipAddress.length() > 0) { - builder.add(ipAddress); - } - } - } - return builder.build(); - } - - private List<String> getPublicIpAddresses(Container container) { - String dockerIpAddress; - if (container.node().isPresent()) { - dockerIpAddress = container.node().get().ip(); - } else { - dockerIpAddress = URI.create(providerMetadata.getEndpoint()).getHost(); - } - return ImmutableList.of(dockerIpAddress); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/compute/functions/CustomLoginPortFromImage.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/functions/CustomLoginPortFromImage.java b/docker/src/main/java/org/jclouds/docker/compute/functions/CustomLoginPortFromImage.java deleted file mode 100644 index 811cdd4..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/functions/CustomLoginPortFromImage.java +++ /dev/null @@ -1,84 +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.docker.compute.functions; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.inject.Inject; - -import org.jclouds.docker.domain.Container; - -import com.google.common.annotations.Beta; -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.collect.Maps; - -@Beta -public class CustomLoginPortFromImage implements LoginPortForContainer { - - private final Map<String, Set<LoginPortForContainer>> imageToPortLookup; - - @Inject - CustomLoginPortFromImage(Map<String, Set<LoginPortForContainer>> imageToPortLookup) { - this.imageToPortLookup = imageToPortLookup; - } - - @Override - public Optional<Integer> apply(final Container container) { - Map<String, Set<LoginPortForContainer>> matchingFunctions = Maps.filterKeys(imageToPortLookup, - new Predicate<String>() { - @Override - public boolean apply(String input) { - return container.config().image().matches(input); - } - }); - - // We allow to provide several forms in the image-to-function map: - // - redis - // - redis:12 - // - owner/redis:12 - // - registry:5000/owner/redis:12 - // We consider the longest match first, as it is the more accurate one - List<String> sortedImages = new ArrayList<String>(matchingFunctions.keySet()); - Collections.sort(sortedImages, LongestStringFirst); - - for (String currentImage : sortedImages) { - Set<LoginPortForContainer> functions = matchingFunctions.get(currentImage); - for (LoginPortForContainer function : functions) { - Optional<Integer> port = function.apply(container); - if (port.isPresent()) { - return port; - } - } - } - - return Optional.absent(); - } - - private static final Comparator<String> LongestStringFirst = new Comparator<String>() { - @Override - public int compare(String s1, String s2) { - return s2.length() - s1.length(); - } - }; - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java b/docker/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java deleted file mode 100644 index f030d9a..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/functions/ImageToImage.java +++ /dev/null @@ -1,103 +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.docker.compute.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; -import javax.inject.Named; - -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -public class ImageToImage implements Function<org.jclouds.docker.domain.Image, org.jclouds.compute.domain.Image> { - - private static final String CENTOS = "centos"; - private static final String UBUNTU = "ubuntu"; - - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; - - @Override - public Image apply(org.jclouds.docker.domain.Image from) { - checkNotNull(from, "image"); - - String firstRepoTag = Iterables.getFirst(from.repoTags(), "<none>"); - final int versionSeparatorPos = firstRepoTag.lastIndexOf(':'); - - final String name; - final String osVersion; - if (versionSeparatorPos > -1) { - name = firstRepoTag.substring(0, versionSeparatorPos); - osVersion = firstRepoTag.substring(versionSeparatorPos + 1); - } else { - name = firstRepoTag; - osVersion = firstRepoTag; - } - logger.debug("os version for item: %s is %s", firstRepoTag, osVersion); - - OsFamily osFamily = osFamily().apply(firstRepoTag); - - OperatingSystem os = OperatingSystem.builder() - .description(firstRepoTag) - .family(osFamily) - .version(osVersion) - .is64Bit(is64bit(from)) - .build(); - - return new ImageBuilder() - .ids(from.id()) - .name(name) - .description(firstRepoTag) - .operatingSystem(os) - .status(Image.Status.AVAILABLE) - .build(); - } - - private boolean is64bit(org.jclouds.docker.domain.Image inspectedImage) { - if (inspectedImage.architecture() == null) return true; - return inspectedImage.architecture().matches("x86_64|amd64"); - } - - /** - * Parses the item description to determine the OSFamily - * - * @return the @see OsFamily or OsFamily.UNRECOGNIZED - */ - private Function<String, OsFamily> osFamily() { - return new Function<String, OsFamily>() { - - @Override - public OsFamily apply(final String description) { - if (description != null) { - if (description.contains(CENTOS)) return OsFamily.CENTOS; - else if (description.contains(UBUNTU)) return OsFamily.UBUNTU; - } - return OsFamily.UNRECOGNIZED; - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/compute/functions/LoginPortForContainer.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/functions/LoginPortForContainer.java b/docker/src/main/java/org/jclouds/docker/compute/functions/LoginPortForContainer.java deleted file mode 100644 index 723f9c0..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/functions/LoginPortForContainer.java +++ /dev/null @@ -1,51 +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.docker.compute.functions; - -import javax.inject.Inject; - -import org.jclouds.docker.compute.functions.LoginPortForContainer.LoginPortLookupChain; -import org.jclouds.docker.domain.Container; - -import com.google.common.annotations.Beta; -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.inject.ImplementedBy; - -@Beta -@ImplementedBy(LoginPortLookupChain.class) -public interface LoginPortForContainer extends Function<Container, Optional<Integer>> { - - @Beta - static final class LoginPortLookupChain implements LoginPortForContainer { - private final PublicPortForContainerPort publicPortForContainerPort; - private final CustomLoginPortFromImage customLoginPortFromImage; - - @Inject - LoginPortLookupChain(CustomLoginPortFromImage customLoginPortFromImage) { - this.publicPortForContainerPort = new PublicPortForContainerPort(22); - this.customLoginPortFromImage = customLoginPortFromImage; - } - - @Override - public Optional<Integer> apply(Container input) { - Optional<Integer> loginPort = publicPortForContainerPort.apply(input); - return loginPort.isPresent() ? loginPort : customLoginPortFromImage.apply(input); - } - - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/compute/functions/PublicPortForContainerPort.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/functions/PublicPortForContainerPort.java b/docker/src/main/java/org/jclouds/docker/compute/functions/PublicPortForContainerPort.java deleted file mode 100644 index 3b11547..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/functions/PublicPortForContainerPort.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.docker.compute.functions; - -import static com.google.common.collect.Iterables.getOnlyElement; - -import java.util.List; -import java.util.Map; - -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.Port; - -import com.google.common.annotations.Beta; -import com.google.common.base.Optional; - -@Beta -public class PublicPortForContainerPort implements LoginPortForContainer { - - private final int containerPort; - - public PublicPortForContainerPort(int containerPort) { - this.containerPort = containerPort; - } - - @Override - public Optional<Integer> apply(Container container) { - if (container.networkSettings() != null) { - Map<String, List<Map<String, String>>> ports = container.networkSettings().ports(); - if (ports != null && ports.containsKey(containerPort + "/tcp")) { - return Optional.of(Integer.parseInt(getOnlyElement(ports.get(containerPort + "/tcp")).get("HostPort"))); - } - // this is needed in case the container list is coming from - // listContainers - } else if (container.ports() != null) { - for (Port port : container.ports()) { - if (port.privatePort() == containerPort) { - return Optional.of(port.publicPort()); - } - } - } - return Optional.absent(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/compute/functions/StateToStatus.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/functions/StateToStatus.java b/docker/src/main/java/org/jclouds/docker/compute/functions/StateToStatus.java deleted file mode 100644 index ef9f616..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/functions/StateToStatus.java +++ /dev/null @@ -1,38 +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.docker.compute.functions; - -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata.Status; -import org.jclouds.docker.domain.State; - -import com.google.common.base.Function; - -/** - * Transforms an {@link org.jclouds.docker.domain.Container} to the jclouds portable model. - */ -@Singleton -public class StateToStatus implements Function<State, Status> { - - @Override - public Status apply(final State state) { - if (state == null) return Status.UNRECOGNIZED; - return state.running() ? Status.RUNNING : Status.TERMINATED; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java ---------------------------------------------------------------------- diff --git a/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java b/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java deleted file mode 100644 index 109d469..0000000 --- a/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java +++ /dev/null @@ -1,780 +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.docker.compute.options; - -import static com.google.common.base.Objects.equal; - -import java.util.List; -import java.util.Map; - -import com.google.common.base.Objects; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.docker.domain.Config; -import org.jclouds.docker.internal.NullSafeCopies; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.scriptbuilder.domain.Statement; - -/** - * Contains options supported by the - * {@link org.jclouds.compute.ComputeService#createNodesInGroup(String, int, TemplateOptions) - * createNodes} operation on the <em>docker</em> provider. - * - * <h2>Usage</h2> - * - * The recommended way to instantiate a DockerTemplateOptions object is to - * statically import {@code DockerTemplateOptions.Builder.*} and invoke one of - * the static creation methods, followed by an instance mutator if needed. - * - * <pre> - * {@code import static org.jclouds.docker.compute.options.DockerTemplateOptions.Builder.*; - * - * ComputeService api = // get connection - * templateBuilder.options(inboundPorts(22, 80, 8080, 443)); - * Set<? extends NodeMetadata> set = api.createNodesInGroup(tag, 2, templateBuilder.build());} - * </pre> - * - * <h2>Advanced Usage</h2> - * <p> - * In addition to basic configuration through its methods, this class also - * provides possibility to work directly with Docker API configuration object ( - * {@link Config.Builder}). When the - * {@link #configBuilder(org.jclouds.docker.domain.Config.Builder)} is used to - * configure not-<code>null</code> configBuilder, then this configuration object - * takes precedence over the other configuration in this class (i.e. the other - * config entries are not used) - * </p> - * <p> - * Note: The {@code image} property in the provided {@link Config.Builder} is rewritten by a placeholder value. - * The real value is configured by ComputeServiceAdapter. - * </p> - * - * <pre> - * {@code import static org.jclouds.docker.compute.options.DockerTemplateOptions.Builder.*; - * - * ComputeService api = // get connection - * DockerTemplateOptions options = DockerTemplateOptions.Builder - * .configBuilder( - * Config.builder().env(ImmutableList.<String> of("SSH_PORT=8822")) - * .hostConfig(HostConfig.builder().networkMode("host").build())); - * templateBuilder.options(options); - * Set<? extends NodeMetadata> set = api.createNodesInGroup("sample-group", 1, templateBuilder.build());} - * </pre> - */ -public class DockerTemplateOptions extends TemplateOptions implements Cloneable { - - private static final String NO_IMAGE = "jclouds-placeholder-for-image"; - - protected List<String> dns = ImmutableList.of(); - @Nullable protected String hostname; - @Nullable protected Integer memory; - @Nullable protected Integer cpuShares; - @Nullable List<String> entrypoint; - @Nullable List<String> commands; - protected Map<String, String> volumes = ImmutableMap.of(); - @Nullable protected List<String> env; - protected Map<Integer, Integer> portBindings = ImmutableMap.of(); - @Nullable protected String networkMode; - protected Map<String, String> extraHosts = ImmutableMap.of(); - protected List<String> volumesFrom = ImmutableList.of(); - protected boolean privileged; - protected boolean openStdin; - protected Config.Builder configBuilder; - - @Override - public DockerTemplateOptions clone() { - DockerTemplateOptions options = new DockerTemplateOptions(); - copyTo(options); - return options; - } - - @Override - public void copyTo(TemplateOptions to) { - super.copyTo(to); - if (to instanceof DockerTemplateOptions) { - DockerTemplateOptions eTo = DockerTemplateOptions.class.cast(to); - eTo.volumes(volumes); - eTo.hostname(hostname); - eTo.dns(dns); - eTo.memory(memory); - eTo.cpuShares(cpuShares); - eTo.entrypoint(entrypoint); - eTo.commands(commands); - eTo.env(env); - eTo.portBindings(portBindings); - eTo.networkMode(networkMode); - eTo.extraHosts(extraHosts); - eTo.volumesFrom(volumesFrom); - eTo.privileged(privileged); - eTo.openStdin(openStdin); - eTo.configBuilder(configBuilder); - } - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - DockerTemplateOptions that = DockerTemplateOptions.class.cast(o); - return super.equals(that) && - equal(this.volumes, that.volumes) && - equal(this.hostname, that.hostname) && - equal(this.dns, that.dns) && - equal(this.memory, that.memory) && - equal(this.cpuShares, that.cpuShares) && - equal(this.entrypoint, that.entrypoint) && - equal(this.commands, that.commands) && - equal(this.env, that.env) && - equal(this.portBindings, that.portBindings) && - equal(this.networkMode, that.networkMode) && - equal(this.extraHosts, that.extraHosts) && - equal(this.volumesFrom, that.volumesFrom) && - equal(this.privileged, that.privileged) && - equal(this.openStdin, that.openStdin) && - buildersEqual(this.configBuilder, that.configBuilder); - } - - - /** - * Compares two Config.Builder instances. - */ - private boolean buildersEqual(Config.Builder b1, Config.Builder b2) { - return b1 == b2 || (b1 != null && b2 != null && b1.build().equals(b2.build())); - } - - @Override - public int hashCode() { - return Objects.hashCode(super.hashCode(), volumes, hostname, dns, memory, entrypoint, commands, cpuShares, env, - portBindings, networkMode, extraHosts, volumesFrom, privileged, openStdin, configBuilder); - } - - @Override - public String toString() { - return Objects.toStringHelper(this) - .add("volumes", volumes) - .add("hostname", hostname) - .add("dns", dns) - .add("memory", memory) - .add("cpuShares", cpuShares) - .add("entrypoint", entrypoint) - .add("commands", commands) - .add("env", env) - .add("portBindings", portBindings) - .add("networkMode", networkMode) - .add("extraHosts", extraHosts) - .add("volumesFrom", volumesFrom) - .add("privileged", privileged) - .add("openStdin", openStdin) - .add("configBuilder", configBuilder) - .toString(); - } - - public DockerTemplateOptions volumes(Map<String, String> volumes) { - this.volumes = NullSafeCopies.copyOf(volumes); - return this; - } - - public DockerTemplateOptions dns(Iterable<String> dns) { - this.dns = NullSafeCopies.copyOf(dns); - return this; - } - - public DockerTemplateOptions dns(String...dns) { - this.dns = NullSafeCopies.copyOf(dns); - return this; - } - - public DockerTemplateOptions hostname(@Nullable String hostname) { - this.hostname = hostname; - return this; - } - - public DockerTemplateOptions memory(@Nullable Integer memory) { - this.memory = memory; - return this; - } - - public DockerTemplateOptions entrypoint(Iterable<String> entrypoint) { - this.entrypoint = NullSafeCopies.copyWithNullOf(entrypoint); - return this; - } - - public DockerTemplateOptions entrypoint(String... entrypoint) { - this.entrypoint = NullSafeCopies.copyWithNullOf(entrypoint); - return this; - } - - public DockerTemplateOptions commands(Iterable<String> commands) { - this.commands = NullSafeCopies.copyWithNullOf(commands); - return this; - } - - public DockerTemplateOptions commands(String...commands) { - this.commands = NullSafeCopies.copyWithNullOf(commands); - return this; - } - - public DockerTemplateOptions cpuShares(@Nullable Integer cpuShares) { - this.cpuShares = cpuShares; - return this; - } - - public DockerTemplateOptions env(Iterable<String> env) { - this.env = NullSafeCopies.copyWithNullOf(env); - return this; - } - - public DockerTemplateOptions env(String...env) { - this.env = NullSafeCopies.copyWithNullOf(env); - return this; - } - - /** - * Set port bindings between the Docker host and a container. - * <p> - * The {@link Map} keys are host ports number, and the value for an entry is the - * container port number. This is the same order as the arguments for the - * {@code --publish} command-line option to {@code docker run} which is - * {@code hostPort:containerPort}. - * - * @param portBindings the map of host to container port bindings - */ - public DockerTemplateOptions portBindings(Map<Integer, Integer> portBindings) { - this.portBindings = NullSafeCopies.copyOf(portBindings); - return this; - } - - /** - * Sets the networking mode for the container. - * <p> - * Supported values are: {@code bridge}, {@code none}, {@code host}, - * {@code networkname}, {@code networkid} or {@code container:[name|id]} - * - * @param networkMode - * @return this instance - */ - public DockerTemplateOptions networkMode(@Nullable String networkMode) { - this.networkMode = networkMode; - return this; - } - - /** - * Set extra hosts file entries for a container. - * <p> - * The {@link Map} keys are host names, and the value is an IP address that - * can be accessed by the container. This is the same order as the arguments for the - * {@code --add-host} command-line option to {@code docker run}. - * - * @param extraHosts the map of host names to IP addresses - */ - public DockerTemplateOptions extraHosts(Map<String, String> extraHosts) { - this.extraHosts = NullSafeCopies.copyOf(extraHosts); - return this; - } - - /** - * Set list of containers to mount volumes from onto this container. - * - * @param volumesFrom the list of container names - */ - public DockerTemplateOptions volumesFrom(Iterable<String> volumesFrom) { - this.volumesFrom = NullSafeCopies.copyOf(volumesFrom); - return this; - } - - /** - * By default, Docker containers are unprivileged and cannot execute privileged operations or access certain - * host devices. - * - * @param privileged Whether the container should run in privileged mode or not - * @return this instance - */ - public DockerTemplateOptions privileged(boolean privileged) { - this.privileged = privileged; - return this; - } - - /** - * Keep {@code STDIN} open when running interactive workloads in the container. - * - * @param openStdin Whether the container should keep STDIN open - * @return this instance - */ - public DockerTemplateOptions openStdin(boolean openStdin) { - this.openStdin = openStdin; - return this; - } - - /** - * This method sets Config.Builder configuration object, which can be used as - * a replacement for all the other settings from this class. Some values in - * the provided Config.Builder instance (the image name for instance) can be - * ignored or their value can be changed. - * - * @param configBuilder - * Config.Builder instance. This instance can be changed in this - * method! - */ - public DockerTemplateOptions configBuilder(Config.Builder configBuilder) { - this.configBuilder = configBuilder != null - ? Config.builder().fromConfig(configBuilder.image(NO_IMAGE).build()) - : null; - return this; - } - - public Map<String, String> getVolumes() { return volumes; } - - public List<String> getDns() { return dns; } - - public List<String> getVolumesFrom() { return volumesFrom; } - - public String getHostname() { return hostname; } - - public Integer getMemory() { return memory; } - - public List<String> getEntrypoint() { return entrypoint; } - - public List<String> getCommands() { return commands; } - - public Integer getCpuShares() { return cpuShares; } - - public List<String> getEnv() { return env; } - - public Map<Integer, Integer> getPortBindings() { return portBindings; } - - public String getNetworkMode() { return networkMode; } - - public Map<String, String> getExtraHosts() { return extraHosts; } - - public boolean getPrivileged() { return privileged; } - - public boolean getOpenStdin() { return openStdin; } - - public Config.Builder getConfigBuilder() { return configBuilder; } - - public static class Builder { - - /** - * @see DockerTemplateOptions#volumes(Map) - */ - public static DockerTemplateOptions volumes(Map<String, String> volumes) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.volumes(volumes); - } - - /** - * @see DockerTemplateOptions#dns(String...) - */ - public static DockerTemplateOptions dns(String...dns) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.dns(dns); - } - - /** - * @see DockerTemplateOptions#dns(List) - */ - public static DockerTemplateOptions dns(Iterable<String> dns) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.dns(dns); - } - - /** - * @see DockerTemplateOptions#hostname(String) - */ - public static DockerTemplateOptions hostname(@Nullable String hostname) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.hostname(hostname); - } - - /** - * @see DockerTemplateOptions#memory(Integer) - */ - public static DockerTemplateOptions memory(@Nullable Integer memory) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.memory(memory); - } - - /** - * @see DockerTemplateOptions#entrypoint(String...) - */ - public static DockerTemplateOptions entrypoint(String...entrypoint) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.entrypoint(entrypoint); - } - - /** - * @see DockerTemplateOptions#entrypoint(Iterable) - */ - public static DockerTemplateOptions entrypoint(Iterable<String> entrypoint) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.entrypoint(entrypoint); - } - - /** - * @see DockerTemplateOptions#commands(String...) - */ - public static DockerTemplateOptions commands(String...commands) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.commands(commands); - } - - /** - * @see DockerTemplateOptions#commands(Iterable) - */ - public static DockerTemplateOptions commands(Iterable<String> commands) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.commands(commands); - } - - /** - * @see DockerTemplateOptions#cpuShares(Integer) - */ - public static DockerTemplateOptions cpuShares(@Nullable Integer cpuShares) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.cpuShares(cpuShares); - } - - /** - * @see DockerTemplateOptions#env(String...) - */ - public static DockerTemplateOptions env(String...env) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.env(env); - } - - /** - * @see DockerTemplateOptions#env(Iterable) - */ - public static DockerTemplateOptions env(Iterable<String> env) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.env(env); - } - - /** - * @see DockerTemplateOptions#portBindings(Map) - */ - public static DockerTemplateOptions portBindings(Map<Integer, Integer> portBindings) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.portBindings(portBindings); - } - - /** - * @see DockerTemplateOptions#networkMode(String) - */ - public static DockerTemplateOptions networkMode(@Nullable String networkMode) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.networkMode(networkMode); - } - - /** - * @see DockerTemplateOptions#extraHosts(Map) - */ - public static DockerTemplateOptions extraHosts(Map<String, String> extraHosts) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.extraHosts(extraHosts); - } - - /** - * @see DockerTemplateOptions#privileged(boolean) - */ - public static DockerTemplateOptions privileged(boolean privileged) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.privileged(privileged); - } - - /** - * @see DockerTemplateOptions#openStdin(boolean) - */ - public static DockerTemplateOptions openStdin(boolean openStdin) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.openStdin(openStdin); - } - - /** - * @see DockerTemplateOptions#configBuilder(Config.Builder) - */ - public static DockerTemplateOptions configBuilder(Config.Builder configBuilder) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.configBuilder(configBuilder); - } - - /** - * @see DockerTemplateOptions#volumesFrom(Iterable) - */ - public static DockerTemplateOptions volumesFrom(Iterable<String> volumesFrom) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.volumesFrom(volumesFrom); - } - - /** - * @see TemplateOptions#inboundPorts(int...) - */ - public static DockerTemplateOptions inboundPorts(int... ports) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.inboundPorts(ports); - } - - /** - * @see TemplateOptions#blockOnPort(int, int) - */ - public static DockerTemplateOptions blockOnPort(int port, int seconds) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.blockOnPort(port, seconds); - } - - /** - * @see TemplateOptions#installPrivateKey(String) - */ - public static DockerTemplateOptions installPrivateKey(String rsaKey) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.installPrivateKey(rsaKey); - } - - /** - * @see TemplateOptions#authorizePublicKey(String) - */ - public static DockerTemplateOptions authorizePublicKey(String rsaKey) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.authorizePublicKey(rsaKey); - } - - /** - * @see TemplateOptions#userMetadata(Map) - */ - public static DockerTemplateOptions userMetadata(Map<String, String> userMetadata) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.userMetadata(userMetadata); - } - - /** - * @see TemplateOptions#nodeNames(Iterable) - */ - public static DockerTemplateOptions nodeNames(Iterable<String> nodeNames) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.nodeNames(nodeNames); - } - - /** - * @see TemplateOptions#networks(Iterable) - */ - public static DockerTemplateOptions networks(Iterable<String> networks) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.networks(networks); - } - - /** - * @see TemplateOptions#overrideLoginUser(String) - */ - public static DockerTemplateOptions overrideLoginUser(String user) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideLoginUser(user); - } - - /** - * @see TemplateOptions#overrideLoginPassword(String) - */ - public static DockerTemplateOptions overrideLoginPassword(String password) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideLoginPassword(password); - } - - /** - * @see TemplateOptions#overrideLoginPrivateKey(String) - */ - public static DockerTemplateOptions overrideLoginPrivateKey(String privateKey) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideLoginPrivateKey(privateKey); - } - - /** - * @see TemplateOptions#overrideAuthenticateSudo(boolean) - */ - public static DockerTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideAuthenticateSudo(authenticateSudo); - } - - /** - * @see TemplateOptions#overrideLoginCredentials(LoginCredentials) - */ - public static DockerTemplateOptions overrideLoginCredentials(LoginCredentials credentials) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.overrideLoginCredentials(credentials); - } - - /** - * @see TemplateOptions#blockUntilRunning(boolean) - */ - public static DockerTemplateOptions blockUntilRunning(boolean blockUntilRunning) { - DockerTemplateOptions options = new DockerTemplateOptions(); - return options.blockUntilRunning(blockUntilRunning); - } - - } - - // methods that only facilitate returning the correct object type - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions blockOnPort(int port, int seconds) { - return DockerTemplateOptions.class.cast(super.blockOnPort(port, seconds)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions inboundPorts(int... ports) { - return DockerTemplateOptions.class.cast(super.inboundPorts(ports)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions authorizePublicKey(String publicKey) { - return DockerTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions installPrivateKey(String privateKey) { - return DockerTemplateOptions.class.cast(super.installPrivateKey(privateKey)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions blockUntilRunning(boolean blockUntilRunning) { - return DockerTemplateOptions.class.cast(super.blockUntilRunning(blockUntilRunning)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions dontAuthorizePublicKey() { - return DockerTemplateOptions.class.cast(super.dontAuthorizePublicKey()); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions nameTask(String name) { - return DockerTemplateOptions.class.cast(super.nameTask(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions runAsRoot(boolean runAsRoot) { - return DockerTemplateOptions.class.cast(super.runAsRoot(runAsRoot)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions runScript(Statement script) { - return DockerTemplateOptions.class.cast(super.runScript(script)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideLoginCredentials(LoginCredentials overridingCredentials) { - return DockerTemplateOptions.class.cast(super.overrideLoginCredentials(overridingCredentials)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideLoginPassword(String password) { - return DockerTemplateOptions.class.cast(super.overrideLoginPassword(password)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideLoginPrivateKey(String privateKey) { - return DockerTemplateOptions.class.cast(super.overrideLoginPrivateKey(privateKey)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideLoginUser(String loginUser) { - return DockerTemplateOptions.class.cast(super.overrideLoginUser(loginUser)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions overrideAuthenticateSudo(boolean authenticateSudo) { - return DockerTemplateOptions.class.cast(super.overrideAuthenticateSudo(authenticateSudo)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions userMetadata(Map<String, String> userMetadata) { - return DockerTemplateOptions.class.cast(super.userMetadata(userMetadata)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions userMetadata(String key, String value) { - return DockerTemplateOptions.class.cast(super.userMetadata(key, value)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions nodeNames(Iterable<String> nodeNames) { - return DockerTemplateOptions.class.cast(super.nodeNames(nodeNames)); - } - - /** - * {@inheritDoc} - */ - @Override - public DockerTemplateOptions networks(Iterable<String> networks) { - return DockerTemplateOptions.class.cast(super.networks(networks)); - } - -}
