Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1114 from jan-zajic/feature/npipe
Browse files Browse the repository at this point in the history
Fix Issue #875 - windows named pipes
  • Loading branch information
davidxia authored Nov 27, 2018
2 parents 36e3b9d + 786c2ad commit e2b4fb6
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.14.5

- Support for Windows 10 Docker named pipes ([875][])

## 8.14.0

Released October 4 2018
Expand Down
39 changes: 28 additions & 11 deletions src/main/java/com/spotify/docker/client/DefaultDockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
import com.spotify.docker.client.messages.swarm.SwarmSpec;
import com.spotify.docker.client.messages.swarm.Task;
import com.spotify.docker.client.messages.swarm.UnlockKey;
import com.spotify.docker.client.npipe.NpipeConnectionSocketFactory;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -179,10 +181,12 @@
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.glassfish.hk2.api.MultiException;
import org.glassfish.jersey.apache.connector.ApacheClientProperties;
Expand Down Expand Up @@ -314,6 +318,7 @@ public void progress(ProgressMessage message) throws DockerException {
// ==========================================================================

private static final String UNIX_SCHEME = "unix";
private static final String NPIPE_SCHEME = "npipe";

private static final Logger log = LoggerFactory.getLogger(DefaultDockerClient.class);

Expand Down Expand Up @@ -438,12 +443,14 @@ protected DefaultDockerClient(final Builder builder) {

if (originalUri.getScheme().equals(UNIX_SCHEME)) {
this.uri = UnixConnectionSocketFactory.sanitizeUri(originalUri);
} else if (originalUri.getScheme().equals(NPIPE_SCHEME)) {
this.uri = NpipeConnectionSocketFactory.sanitizeUri(originalUri);
} else {
this.uri = originalUri;
}

final PoolingHttpClientConnectionManager cm = getConnectionManager(builder);
final PoolingHttpClientConnectionManager noTimeoutCm = getConnectionManager(builder);
final HttpClientConnectionManager cm = getConnectionManager(builder);
final HttpClientConnectionManager noTimeoutCm = getConnectionManager(builder);

final RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout((int) builder.connectTimeoutMillis)
Expand Down Expand Up @@ -530,15 +537,19 @@ public String getHost() {
return fromNullable(uri.getHost()).or("localhost");
}

private PoolingHttpClientConnectionManager getConnectionManager(Builder builder) {
final PoolingHttpClientConnectionManager cm =
new PoolingHttpClientConnectionManager(getSchemeRegistry(builder));

// Use all available connections instead of artificially limiting ourselves to 2 per server.
cm.setMaxTotal(builder.connectionPoolSize);
cm.setDefaultMaxPerRoute(cm.getMaxTotal());

return cm;
private HttpClientConnectionManager getConnectionManager(Builder builder) {
if (builder.uri.getScheme().equals(NPIPE_SCHEME)) {
final BasicHttpClientConnectionManager bm =
new BasicHttpClientConnectionManager(getSchemeRegistry(builder));
return bm;
} else {
final PoolingHttpClientConnectionManager cm =
new PoolingHttpClientConnectionManager(getSchemeRegistry(builder));
// Use all available connections instead of artificially limiting ourselves to 2 per server.
cm.setMaxTotal(builder.connectionPoolSize);
cm.setDefaultMaxPerRoute(cm.getMaxTotal());
return cm;
}
}

private Registry<ConnectionSocketFactory> getSchemeRegistry(final Builder builder) {
Expand All @@ -558,6 +569,10 @@ private Registry<ConnectionSocketFactory> getSchemeRegistry(final Builder builde
if (builder.uri.getScheme().equals(UNIX_SCHEME)) {
registryBuilder.register(UNIX_SCHEME, new UnixConnectionSocketFactory(builder.uri));
}

if (builder.uri.getScheme().equals(NPIPE_SCHEME)) {
registryBuilder.register(NPIPE_SCHEME, new NpipeConnectionSocketFactory(builder.uri));
}

return registryBuilder.build();
}
Expand Down Expand Up @@ -2924,6 +2939,8 @@ public static Builder fromEnv() throws DockerCertificateException {

if (endpoint.startsWith(UNIX_SCHEME + "://")) {
builder.uri(endpoint);
} else if (endpoint.startsWith(NPIPE_SCHEME + "://")) {
builder.uri(endpoint);
} else {
final String stripped = endpoint.replaceAll(".*://", "");
final HostAndPort hostAndPort = HostAndPort.fromString(stripped);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/spotify/docker/client/DockerHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public String getenv(final String name) {
private static SystemDelegate systemDelegate = defaultSystemDelegate;

private static final String DEFAULT_UNIX_ENDPOINT = "unix:///var/run/docker.sock";
private static final String DEFAULT_WINDOWS_ENDPOINT = "npipe:////./pipe/docker_engine";
private static final String DEFAULT_ADDRESS = "localhost";
private static final int DEFAULT_PORT = 2375;

Expand Down Expand Up @@ -187,6 +188,9 @@ static String defaultDockerEndpoint() {
final String os = osName.toLowerCase(Locale.ENGLISH);
if (os.equalsIgnoreCase("linux") || os.contains("mac")) {
return DEFAULT_UNIX_ENDPOINT;
} else if (System.getProperty("os.name").equalsIgnoreCase("Windows 10")) {
//from Docker doc: Windows 10 64bit: Pro, Enterprise or Education
return DEFAULT_WINDOWS_ENDPOINT;
} else {
return DEFAULT_ADDRESS + ":" + defaultPort();
}
Expand All @@ -200,6 +204,10 @@ public static String defaultUnixEndpoint() {
return DEFAULT_UNIX_ENDPOINT;
}

public static String defaultWindowsEndpoint() {
return DEFAULT_WINDOWS_ENDPOINT;
}

public static String defaultAddress() {
return DEFAULT_ADDRESS;
}
Expand Down
Loading

0 comments on commit e2b4fb6

Please sign in to comment.