Skip to content
Merged
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
112 changes: 5 additions & 107 deletions src/main/java/com/github/dockerjava/core/DockerClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,10 @@ public class DockerClientConfig implements Serializable {

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_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 @@ -69,9 +57,6 @@ 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_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 @@ -83,34 +68,18 @@ public class DockerClientConfig implements Serializable {

private final String version, username, password, email, serverAddress, dockerCfgPath;

private final Integer readTimeout;

private final boolean loggingFilterEnabled;

private final boolean followRedirectsFilterEnabled;

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, 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.sslConfig = sslConfig;
this.maxTotalConnections = maxTotalConns;
this.maxPerRouteConnections = maxPerRouteConns;
}

private static Properties loadIncludedDockerProperties(Properties systemProperties) {
Expand Down Expand Up @@ -208,8 +177,7 @@ private static Properties overrideDockerPropertiesWithSystemProperties(Propertie

for (String key : new String[] { DOCKER_IO_URL_PROPERTY, DOCKER_IO_VERSION_PROPERTY,
DOCKER_IO_USERNAME_PROPERTY, 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_SERVER_ADDRESS_PROPERTY,
DOCKER_IO_DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CFG_PATH_PROPERTY, }) {
if (systemProperties.containsKey(key)) {
overriddenProperties.setProperty(key, systemProperties.getProperty(key));
Expand Down Expand Up @@ -261,18 +229,6 @@ public String getServerAddress() {
return serverAddress;
}

public Integer getReadTimeout() {
return readTimeout;
}

public boolean isLoggingFilterEnabled() {
return loggingFilterEnabled;
}

public boolean followRedirectsFilterEnabled() {
return followRedirectsFilterEnabled;
}

public SSLConfig getSslConfig() {
return sslConfig;
}
Expand All @@ -281,14 +237,6 @@ 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 && getServerAddress() != null) {
Expand Down Expand Up @@ -352,8 +300,6 @@ public boolean equals(Object o) {

DockerClientConfig that = (DockerClientConfig) o;

if (loggingFilterEnabled != that.loggingFilterEnabled)
return false;
if (sslConfig != null ? !sslConfig.equals(that.sslConfig) : that.sslConfig != null)
return false;
if (dockerCfgPath != null ? !dockerCfgPath.equals(that.dockerCfgPath) : that.dockerCfgPath != null)
Expand All @@ -362,8 +308,6 @@ public boolean equals(Object o) {
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)
Expand All @@ -386,8 +330,6 @@ 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);
return result;
}

Expand All @@ -396,19 +338,14 @@ public String toString() {
return "DockerClientConfig{" + "uri=" + uri + ", version='" + version + '\'' + ", username='" + username + '\''
+ ", password='" + password + '\'' + ", email='" + email + '\'' + ", serverAddress='" + serverAddress
+ '\'' + ", dockerCfgPath='" + dockerCfgPath + '\'' + ", sslConfig='" + sslConfig + '\''
+ ", readTimeout=" + readTimeout + ", loggingFilterEnabled=" + loggingFilterEnabled
+ ", followRedirectsFilterEnabled=" + followRedirectsFilterEnabled + '}';
+ '}';
}

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 SSLConfig sslConfig;

/**
Expand All @@ -424,21 +361,8 @@ 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")))
.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)));
}

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

public final DockerClientConfigBuilder withUri(String uri) {
Expand Down Expand Up @@ -472,31 +396,6 @@ 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;
return this;
}

public final DockerClientConfigBuilder withDockerCertPath(String dockerCertPath) {
if (dockerCertPath != null) {
this.sslConfig = new LocalDirectorySSLConfig(dockerCertPath);
Expand All @@ -516,8 +415,7 @@ public final DockerClientConfigBuilder withSSLConfig(SSLConfig config) {

public DockerClientConfig build() {
return new DockerClientConfig(uri, version, username, password, email, serverAddress, dockerCfgPath,
readTimeout, loggingFilterEnabled, followRedirectsFilterEnabled, sslConfig, maxTotalConnections,
maxPerRouteConnections);
sslConfig);
}
}

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

import org.apache.http.config.RegistryBuilder;
Expand Down Expand Up @@ -62,13 +64,13 @@
import com.github.dockerjava.api.command.VersionCmd;
import com.github.dockerjava.api.command.WaitContainerCmd;
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;
//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.filter.FollowRedirectsFilter;
import com.github.dockerjava.jaxrs.filter.JsonClientFilter;
import com.github.dockerjava.jaxrs.filter.ResponseStatusExceptionFilter;
import com.github.dockerjava.jaxrs.filter.SelectiveLoggingFilter;

public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory {

Expand All @@ -78,6 +80,18 @@ public class DockerCmdExecFactoryImpl implements DockerCmdExecFactory {

private WebTarget baseResource;

private Integer readTimeout = null;

private Integer connectTimeout = null;

private Integer maxTotalConnections = null;

private Integer maxPerRouteConnections = null;

private ClientRequestFilter[] clientRequestFilters = null;

private ClientResponseFilter[] clientResponseFilters = null;

@Override
public void init(DockerClientConfig dockerClientConfig) {
checkNotNull(dockerClientConfig, "config was not specified");
Expand All @@ -90,20 +104,30 @@ public void init(DockerClientConfig dockerClientConfig) {
clientConfig.register(JsonClientFilter.class);
clientConfig.register(JacksonJsonProvider.class);

if (dockerClientConfig.followRedirectsFilterEnabled()) {
clientConfig.register(FollowRedirectsFilter.class);
// logging may disabled via log level
clientConfig.register(new SelectiveLoggingFilter(LOGGER, true));

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

if (dockerClientConfig.isLoggingFilterEnabled()) {
clientConfig.register(new SelectiveLoggingFilter(LOGGER, true));
if (connectTimeout != null) {
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout);
}

if (dockerClientConfig.getReadTimeout() != null) {
int readTimeout = dockerClientConfig.getReadTimeout();
clientConfig.property(ClientProperties.READ_TIMEOUT, readTimeout);
if (clientResponseFilters != null) {
for (ClientResponseFilter clientResponseFilter : clientResponseFilters) {
if (clientResponseFilter != null)
clientConfig.register(clientResponseFilter);
}
}

// clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 10000);
if (clientRequestFilters != null) {
for (ClientRequestFilter clientRequestFilter : clientRequestFilters) {
if(clientRequestFilter != null)
clientConfig.register(clientRequestFilter);
}
}

URI originalUri = dockerClientConfig.getUri();

Expand All @@ -120,10 +144,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 Down Expand Up @@ -353,4 +377,34 @@ public void close() throws IOException {
client.close();
}

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

public DockerCmdExecFactoryImpl withConnectTimeout(Integer connectTimeout) {
this.connectTimeout = connectTimeout;
return this;
}

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

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

public DockerCmdExecFactoryImpl withClientResponseFilters(ClientResponseFilter... clientResponseFilter) {
this.clientResponseFilters = clientResponseFilter;
return this;
}

public DockerCmdExecFactoryImpl withClientRequestFilters(ClientRequestFilter... clientRequestFilters) {
this.clientRequestFilters = clientRequestFilters;
return this;
}

}
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.filter;

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.filter;

import java.io.IOException;

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.filter;

/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
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.filter;

import java.io.EOFException;
import java.io.IOException;
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.filter;

import java.io.IOException;
import java.util.Collections;
Expand Down
Loading