Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import java.io.IOException;

import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl;

public interface DockerCmdExecFactory extends Closeable {

public void init(DockerClientConfig dockerClientConfig);
public DockerCmdExecFactory withDockerClientConfig(DockerClientConfig dockerClientConfig);

public void init();

public AuthCmd.Exec createAuthCmdExec();

Expand Down
114 changes: 20 additions & 94 deletions src/main/java/com/github/dockerjava/core/DockerClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ public class DockerClientConfig implements Serializable {
private static final String DOCKER_IO_PASSWORD_PROPERTY = "docker.io.password";
private static final String DOCKER_IO_EMAIL_PROPERTY = "docker.io.email";
private static final String DOCKER_IO_SERVER_ADDRESS_PROPERTY = "docker.io.serverAddress";
private static final String DOCKER_IO_READ_TIMEOUT_PROPERTY = "docker.io.readTimeout";
// this is really confusing, as there are two ways to spell it
private static final String DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY = "docker.io.enableLoggingFilter";
private static final String DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY = "docker.io.followRedirectsFilter";
private static final String DOCKER_IO_ENABLE_LOGGING_PROPERTY = "docker.io.enableLogging";
private static final String DOCKER_IO_DOCKER_CERT_PATH_PROPERTY = "docker.io.dockerCertPath";
private static final String DOCKER_IO_DOCKER_CFG_PATH_PROPERTY = "docker.io.dockerCfgPath";
// connection pooling properties
private static final String DOCKER_IO_MAX_PER_ROUTE_PROPERTY = "docker.io.perRouteConnections";
private static final String DOCKER_IO_MAX_TOTAL_PROPERTY = "docker.io.totalConnections";

/**
* A map from the environment name to the interval name.
*/
Expand All @@ -53,9 +48,7 @@ public class DockerClientConfig implements Serializable {
m.put("DOCKER_PASSWORD", DOCKER_IO_PASSWORD_PROPERTY);
m.put("DOCKER_EMAIL", DOCKER_IO_EMAIL_PROPERTY);
m.put("DOCKER_SERVER_ADDRESS", DOCKER_IO_SERVER_ADDRESS_PROPERTY);
m.put("DOCKER_READ_TIMEOUT", DOCKER_IO_READ_TIMEOUT_PROPERTY);
m.put("DOCKER_LOGGING_FILTER_ENABLED", DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY);
m.put("DOCKER_FOLLOW_REDIRECTS_FILTER_ENABLED", DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY);
m.put("DOCKER_LOGGING_ENABLED", DOCKER_IO_ENABLE_LOGGING_PROPERTY);
m.put(DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CERT_PATH_PROPERTY);
m.put("DOCKER_CFG_PATH", DOCKER_IO_DOCKER_CFG_PATH_PROPERTY);
ENV_NAME_TO_IO_NAME = Collections.unmodifiableMap(m);
Expand All @@ -64,30 +57,21 @@ public class DockerClientConfig implements Serializable {
private static final String DOCKER_IO_PROPERTIES_PROPERTY = "docker.io.properties";
private URI uri;
private final String version, username, password, email, serverAddress, dockerCfgPath;
private final Integer readTimeout;
private final boolean loggingFilterEnabled;
private final boolean followRedirectsFilterEnabled;
private final boolean loggingEnabled;
private final SSLConfig sslConfig;

private final Integer maxTotalConnections;
private final Integer maxPerRouteConnections;

DockerClientConfig(URI uri, String version, String username, String password, String email, String serverAddress,
String dockerCfgPath, Integer readTimeout, boolean loggingFilterEnabled, boolean followRedirectsFilterEnabled,
SSLConfig sslConfig, Integer maxTotalConns, Integer maxPerRouteConns) {
String dockerCfgPath, boolean loggingEnabled,
SSLConfig sslConfig) {
this.uri = uri;
this.version = version;
this.username = username;
this.password = password;
this.email = email;
this.serverAddress = serverAddress;
this.dockerCfgPath = dockerCfgPath;
this.readTimeout = readTimeout;
this.loggingFilterEnabled = loggingFilterEnabled;
this.followRedirectsFilterEnabled = followRedirectsFilterEnabled;
this.loggingEnabled = loggingEnabled;
this.sslConfig = sslConfig;
this.maxTotalConnections = maxTotalConns;
this.maxPerRouteConnections = maxPerRouteConns;
}

private static Properties loadIncludedDockerProperties(Properties systemProperties) {
Expand Down Expand Up @@ -185,9 +169,7 @@ private static Properties overrideDockerPropertiesWithSystemProperties(Propertie
DOCKER_IO_PASSWORD_PROPERTY,
DOCKER_IO_EMAIL_PROPERTY,
DOCKER_IO_SERVER_ADDRESS_PROPERTY,
DOCKER_IO_READ_TIMEOUT_PROPERTY,
DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY,
DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY,
DOCKER_IO_ENABLE_LOGGING_PROPERTY,
DOCKER_IO_DOCKER_CERT_PATH_PROPERTY,
DOCKER_IO_DOCKER_CFG_PATH_PROPERTY,
}) {
Expand Down Expand Up @@ -241,16 +223,8 @@ public String getServerAddress() {
return serverAddress;
}

public Integer getReadTimeout() {
return readTimeout;
}

public boolean isLoggingFilterEnabled() {
return loggingFilterEnabled;
}

public boolean followRedirectsFilterEnabled() {
return followRedirectsFilterEnabled;
public boolean isLoggingEnabled() {
return loggingEnabled;
}

public SSLConfig getSslConfig() {
Expand All @@ -260,15 +234,7 @@ public SSLConfig getSslConfig() {
public String getDockerCfgPath() {
return dockerCfgPath;
}

public Integer getMaxTotalConnections() {
return maxTotalConnections;
}

public Integer getMaxPerRoutConnections() {
return maxPerRouteConnections;
}

private AuthConfig getAuthConfig() {
AuthConfig authConfig = null;
if (getUsername() != null && getPassword() != null && getEmail() != null
Expand Down Expand Up @@ -336,14 +302,13 @@ public boolean equals(Object o) {

DockerClientConfig that = (DockerClientConfig) o;

if (loggingFilterEnabled != that.loggingFilterEnabled) return false;
if (loggingEnabled != that.loggingEnabled) return false;
if (sslConfig != null ? !sslConfig.equals(that.sslConfig) : that.sslConfig != null)
return false;
if (dockerCfgPath != null ? !dockerCfgPath.equals(that.dockerCfgPath) : that.dockerCfgPath != null)
return false;
if (email != null ? !email.equals(that.email) : that.email != null) return false;
if (password != null ? !password.equals(that.password) : that.password != null) return false;
if (readTimeout != null ? !readTimeout.equals(that.readTimeout) : that.readTimeout != null) return false;
if (serverAddress != null ? !serverAddress.equals(that.serverAddress) : that.serverAddress != null)
return false;
if (uri != null ? !uri.equals(that.uri) : that.uri != null) return false;
Expand All @@ -363,8 +328,7 @@ public int hashCode() {
result = 31 * result + (serverAddress != null ? serverAddress.hashCode() : 0);
result = 31 * result + (dockerCfgPath != null ? dockerCfgPath.hashCode() : 0);
result = 31 * result + (sslConfig != null ? sslConfig.hashCode() : 0);
result = 31 * result + (readTimeout != null ? readTimeout.hashCode() : 0);
result = 31 * result + (loggingFilterEnabled ? 1 : 0);
result = 31 * result + (loggingEnabled ? 1 : 0);
return result;
}

Expand All @@ -379,17 +343,14 @@ public String toString() {
", serverAddress='" + serverAddress + '\'' +
", dockerCfgPath='" + dockerCfgPath + '\'' +
", sslConfig='" + sslConfig + '\'' +
", readTimeout=" + readTimeout +
", loggingFilterEnabled=" + loggingFilterEnabled +
", followRedirectsFilterEnabled=" + followRedirectsFilterEnabled +
", loggingEnabled=" + loggingEnabled +
'}';
}

public static class DockerClientConfigBuilder {
private URI uri;
private String version, username, password, email, serverAddress, dockerCfgPath;
private Integer readTimeout, maxTotalConnections, maxPerRouteConnections;
private boolean loggingFilterEnabled, followRedirectsFilterEnabled;
private boolean loggingEnabled;
private SSLConfig sslConfig;

/**
Expand All @@ -405,22 +366,11 @@ public DockerClientConfigBuilder withProperties(Properties p) {
.withPassword(p.getProperty(DOCKER_IO_PASSWORD_PROPERTY))
.withEmail(p.getProperty(DOCKER_IO_EMAIL_PROPERTY))
.withServerAddress(p.getProperty(DOCKER_IO_SERVER_ADDRESS_PROPERTY))
.withReadTimeout(Integer.valueOf(p.getProperty(DOCKER_IO_READ_TIMEOUT_PROPERTY, "0")))
.withLoggingFilter(Boolean.valueOf(p.getProperty(DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY, "true")))
.withFollowRedirectsFilter(Boolean.valueOf(p.getProperty(DOCKER_IO_FOLLOW_REDIRECTS_FILTER_PROPERTY, "false")))
.withLoggingEnabled(Boolean.valueOf(p.getProperty(DOCKER_IO_ENABLE_LOGGING_PROPERTY, "true")))
.withDockerCertPath(p.getProperty(DOCKER_IO_DOCKER_CERT_PATH_PROPERTY))
.withDockerCfgPath(p.getProperty(DOCKER_IO_DOCKER_CFG_PATH_PROPERTY))
.withMaxPerRouteConnections(integerValue(p.getProperty(DOCKER_IO_MAX_PER_ROUTE_PROPERTY)))
.withMaxTotalConnections(integerValue(p.getProperty(DOCKER_IO_MAX_TOTAL_PROPERTY)));
.withDockerCfgPath(p.getProperty(DOCKER_IO_DOCKER_CFG_PATH_PROPERTY));
}

private Integer integerValue(String value) {
if(value != null)
return Integer.valueOf(value);
else
return null;
}

public final DockerClientConfigBuilder withUri(String uri) {
checkNotNull(uri, "uri was not specified");
this.uri = URI.create(uri);
Expand Down Expand Up @@ -452,28 +402,8 @@ public DockerClientConfigBuilder withServerAddress(String serverAddress) {
return this;
}

public final DockerClientConfigBuilder withReadTimeout(Integer readTimeout) {
this.readTimeout = readTimeout;
return this;
}

public final DockerClientConfigBuilder withMaxTotalConnections(Integer maxTotalConnections) {
this.maxTotalConnections = maxTotalConnections;
return this;
}

public final DockerClientConfigBuilder withMaxPerRouteConnections(Integer maxPerRouteConnections) {
this.maxPerRouteConnections = maxPerRouteConnections;
return this;
}

public final DockerClientConfigBuilder withLoggingFilter(boolean loggingFilterEnabled) {
this.loggingFilterEnabled = loggingFilterEnabled;
return this;
}

public final DockerClientConfigBuilder withFollowRedirectsFilter(boolean followRedirectsFilterEnabled) {
this.followRedirectsFilterEnabled = followRedirectsFilterEnabled;
public final DockerClientConfigBuilder withLoggingEnabled(boolean loggingEnabled) {
this.loggingEnabled = loggingEnabled;
return this;
}

Expand Down Expand Up @@ -504,12 +434,8 @@ public DockerClientConfig build() {
email,
serverAddress,
dockerCfgPath,
readTimeout,
loggingFilterEnabled,
followRedirectsFilterEnabled,
sslConfig,
maxTotalConnections,
maxPerRouteConnections
loggingEnabled,
sslConfig
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public DockerClientImpl withDockerCmdExecFactory(
DockerCmdExecFactory dockerCmdExecFactory) {
checkNotNull(dockerCmdExecFactory,
"dockerCmdExecFactory was not specified");
this.dockerCmdExecFactory = dockerCmdExecFactory;
this.dockerCmdExecFactory.init(dockerClientConfig);
this.dockerCmdExecFactory = dockerCmdExecFactory.withDockerClientConfig(dockerClientConfig);
this.dockerCmdExecFactory.init();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.net.ssl.SSLContext;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.client.WebTarget;

import org.apache.http.config.RegistryBuilder;
Expand All @@ -22,31 +23,70 @@
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.apache.connector.ApacheClientProperties;


//import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
// see https://github.com/docker-java/docker-java/issues/196
import com.github.dockerjava.jaxrs.connector.ApacheConnectorProvider;
import com.github.dockerjava.jaxrs.util.FollowRedirectsFilter;
import com.github.dockerjava.jaxrs.util.JsonClientFilter;
import com.github.dockerjava.jaxrs.util.ResponseStatusExceptionFilter;
import com.github.dockerjava.jaxrs.util.SelectiveLoggingFilter;

import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;

import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import com.github.dockerjava.api.DockerClientException;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.util.FollowRedirectsFilter;
import com.github.dockerjava.core.util.JsonClientFilter;
import com.github.dockerjava.core.util.ResponseStatusExceptionFilter;
import com.github.dockerjava.core.util.SelectiveLoggingFilter;


public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory {

private static final Logger LOGGER = LoggerFactory
.getLogger(DockerCmdExecFactoryImpl.class.getName());

private DockerClientConfig dockerClientConfig;
private Client client;
private WebTarget baseResource;

private Integer readTimeout, maxTotalConnections, maxPerRouteConnections;

private Class<? extends ClientResponseFilter>[] clientResponseFilters;

public final DockerCmdExecFactoryImpl withReadTimeout(Integer readTimeout) {
this.readTimeout = readTimeout;
return this;
}

public final DockerCmdExecFactoryImpl withMaxTotalConnections(
Integer maxTotalConnections) {
this.maxTotalConnections = maxTotalConnections;
return this;
}

public final DockerCmdExecFactoryImpl withMaxPerRouteConnections(
Integer maxPerRouteConnections) {
this.maxPerRouteConnections = maxPerRouteConnections;
return this;
}

public DockerCmdExecFactoryImpl withClientResponseFilters(
Class<? extends ClientResponseFilter>[] clientResponseFilters) {
checkNotNull(dockerClientConfig, "config was not specified");
this.clientResponseFilters = clientResponseFilters;
return this;
}

@Override
public void init(DockerClientConfig dockerClientConfig) {
public DockerCmdExecFactoryImpl withDockerClientConfig(
DockerClientConfig dockerClientConfig) {
checkNotNull(dockerClientConfig, "config was not specified");
this.dockerClientConfig = dockerClientConfig;
return this;
}

@Override
public void init() {

ClientConfig clientConfig = new ClientConfig();
clientConfig.connectorProvider(new ApacheConnectorProvider());
Expand All @@ -57,16 +97,17 @@ public void init(DockerClientConfig dockerClientConfig) {
clientConfig.register(JsonClientFilter.class);
clientConfig.register(JacksonJsonProvider.class);

if (dockerClientConfig.followRedirectsFilterEnabled()) {
clientConfig.register(FollowRedirectsFilter.class);
if (dockerClientConfig.isLoggingEnabled()) {
clientConfig.register(new SelectiveLoggingFilter(LOGGER, true));
}

if (dockerClientConfig.isLoggingFilterEnabled()) {
clientConfig.register(new SelectiveLoggingFilter(LOGGER, true));
if (clientResponseFilters != null) {
for (Class<? extends ClientResponseFilter> filter : clientResponseFilters) {
clientConfig.register(filter);
}
}

if (dockerClientConfig.getReadTimeout() != null) {
int readTimeout = dockerClientConfig.getReadTimeout();
if (readTimeout != null) {
clientConfig.property(ClientProperties.READ_TIMEOUT, readTimeout);
}

Expand All @@ -86,12 +127,10 @@ public void init(DockerClientConfig dockerClientConfig) {
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(
getSchemeRegistry(originalUri, sslContext));

if (dockerClientConfig.getMaxTotalConnections() != null)
connManager
.setMaxTotal(dockerClientConfig.getMaxTotalConnections());
if (dockerClientConfig.getMaxPerRoutConnections() != null)
connManager.setDefaultMaxPerRoute(dockerClientConfig
.getMaxPerRoutConnections());
if (maxTotalConnections != null)
connManager.setMaxTotal(maxTotalConnections);
if (maxPerRouteConnections != null)
connManager.setDefaultMaxPerRoute(maxPerRouteConnections);

clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER,
connManager);
Expand All @@ -104,7 +143,7 @@ public void init(DockerClientConfig dockerClientConfig) {
}

client = clientBuilder.build();

if (originalUri.getScheme().equals("unix")) {
dockerClientConfig.setUri(UnixConnectionSocketFactory
.sanitizeUri(originalUri));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.dockerjava.core.util;
package com.github.dockerjava.jaxrs.util;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.dockerjava.core.util;
package com.github.dockerjava.jaxrs.util;


import javax.ws.rs.client.ClientRequestContext;
Expand Down
Loading