diff options
Diffstat (limited to 'docker-api')
3 files changed, 124 insertions, 0 deletions
diff --git a/docker-api/pom.xml b/docker-api/pom.xml new file mode 100644 index 00000000000..3e06f4e9223 --- /dev/null +++ b/docker-api/pom.xml @@ -0,0 +1,63 @@ +<?xml version="1.0"?> +<!-- Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.yahoo.vespa</groupId> + <artifactId>parent</artifactId> + <version>6-SNAPSHOT</version> + </parent> + + <artifactId>docker-api</artifactId> + <version>6-SNAPSHOT</version> + <packaging>container-plugin</packaging> + <name>${project.artifactId}</name> + + <dependencies> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>container-dev</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.github.docker-java</groupId> + <artifactId>docker-java</artifactId> + <version>3.0.3</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </exclusion> + + </exclusions> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>com.yahoo.vespa</groupId> + <artifactId>bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <compilerArgs> + <arg>-Xlint:all</arg> + <arg>-Werror</arg> + </compilerArgs> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/docker/api/docker/DockerApi.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/docker/api/docker/DockerApi.java new file mode 100644 index 00000000000..f114adfb988 --- /dev/null +++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/docker/api/docker/DockerApi.java @@ -0,0 +1,56 @@ +package com.yahoo.vespa.hosted.docker.api.docker; + +import com.github.dockerjava.core.DefaultDockerClientConfig; +import com.github.dockerjava.core.DockerClientImpl; +import com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory; + +import com.github.dockerjava.api.DockerClient; +import com.yahoo.component.AbstractComponent; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +/** + * A class wrapping the DockerJava library for OSGI to avoid dependency problem between this library and Vespa. + * @author dybdahl + */ +public class DockerApi extends AbstractComponent { + private static final String LABEL_NAME_MANAGEDBY = "com.yahoo.vespa.managedby"; + private static final String LABEL_VALUE_MANAGEDBY = "node-admin"; + private static final Map<String, String> CONTAINER_LABELS = new HashMap<>(); + + private static final int DOCKER_MAX_PER_ROUTE_CONNECTIONS = 10; + private static final int DOCKER_MAX_TOTAL_CONNECTIONS = 100; + private static final int DOCKER_CONNECT_TIMEOUT_MILLIS = (int) TimeUnit.SECONDS.toMillis(100); + private static final int DOCKER_READ_TIMEOUT_MILLIS = (int) TimeUnit.MINUTES.toMillis(30); + + static { + CONTAINER_LABELS.put(LABEL_NAME_MANAGEDBY, LABEL_VALUE_MANAGEDBY); + } + + private final DockerClient dockerClient; + + public DockerApi() { + dockerClient = DockerClientImpl.getInstance(new DefaultDockerClientConfig.Builder() + // Talks HTTP(S) over a TCP port. The docker client library does only support tcp:// and unix:// + .withDockerHost("unix:///host/var/run/docker.sock") // Alternatively, but + // does not work due to certificate issues as if Aug 18th 2016: config.uri().replace("https", "tcp")) + .withDockerTlsVerify(false) + //.withCustomSslConfig(new VespaSSLConfig(config)) + // We can specify which version of the docker remote API to use, otherwise, use latest + // e.g. .withApiVersion("1.23") + .build()) + .withDockerCmdExecFactory( + new JerseyDockerCmdExecFactory() + .withMaxPerRouteConnections(DOCKER_MAX_PER_ROUTE_CONNECTIONS) + .withMaxTotalConnections(DOCKER_MAX_TOTAL_CONNECTIONS) + .withConnectTimeout(DOCKER_CONNECT_TIMEOUT_MILLIS) + .withReadTimeout(DOCKER_READ_TIMEOUT_MILLIS) + ); + } + + public DockerClient getDockerClient() { + return dockerClient; + } +} diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/docker/api/docker/package-info.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/docker/api/docker/package-info.java new file mode 100644 index 00000000000..004507fb58f --- /dev/null +++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/docker/api/docker/package-info.java @@ -0,0 +1,5 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@ExportPackage +package com.yahoo.vespa.hosted.docker.api.docker; + +import com.yahoo.osgi.annotation.ExportPackage; |