@Override protected boolean isApplicable() { return "tcp".equalsIgnoreCase(config.getDockerHost().getScheme()) || SystemUtils.IS_OS_LINUX; }
public static String getDockerHostIpAddress(DockerClientConfig config) { switch (config.getDockerHost().getScheme()) { case "http": case "https": case "tcp": return config.getDockerHost().getHost(); case "unix": case "npipe": if (IN_A_CONTAINER) { return getDefaultGateway().orElse("localhost"); } return "localhost"; default: return null; } } }
@Override public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException { String socketPath = getDockerClientConfig().getDockerHost().getPath(); return (DuplexChannel) bootstrap.connect(new DomainSocketAddress(socketPath)).sync().channel(); } }
@Override public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException { DockerClientConfig dockerClientConfig = getDockerClientConfig(); String path = dockerClientConfig.getDockerHost().getPath(); return (DuplexChannel) bootstrap.connect(new DomainSocketAddress(path)).sync().channel(); } }
@Override public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException { DockerClientConfig dockerClientConfig = getDockerClientConfig(); String host = dockerClientConfig.getDockerHost().getHost(); int port = dockerClientConfig.getDockerHost().getPort(); if (port == -1) { throw new RuntimeException("no port configured for " + host); } DuplexChannel channel = (DuplexChannel) bootstrap.connect(host, port).sync().channel(); final SslHandler ssl = initSsl(dockerClientConfig); if (ssl != null) { channel.pipeline().addFirst(ssl); } return channel; }
@Override public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException { DockerClientConfig dockerClientConfig = getDockerClientConfig(); String host = dockerClientConfig.getDockerHost().getHost(); int port = dockerClientConfig.getDockerHost().getPort(); if (port == -1) { throw new RuntimeException("no port configured for " + host); } DuplexChannel channel = (DuplexChannel) bootstrap.connect(host, port).sync().channel(); final SslHandler ssl = initSsl(dockerClientConfig); if (ssl != null) { channel.pipeline().addFirst(ssl); } return channel; }
/** * Called when a read timeout was detected. */ @Override protected synchronized void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception { assert evt.state() == IdleState.READER_IDLE; final Channel channel = ctx.channel(); if (channel == null || !channel.isActive() || alreadyTimedOut) { return; } DockerClientConfig dockerClientConfig = getDockerClientConfig(); final Object dockerAPIEndpoint = dockerClientConfig.getDockerHost(); final String msg = "Read timed out: No data received within " + readTimeout + "ms. Perhaps the docker API (" + dockerAPIEndpoint + ") is not responding normally, or perhaps you need to increase the readTimeout value."; final Exception ex = new SocketTimeoutException(msg); ctx.fireExceptionCaught(ex); alreadyTimedOut = true; } }
/** * Called when a read timeout was detected. */ @Override protected synchronized void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt) throws Exception { assert evt.state() == IdleState.READER_IDLE; final Channel channel = ctx.channel(); if (channel == null || !channel.isActive() || alreadyTimedOut) { return; } DockerClientConfig dockerClientConfig = getDockerClientConfig(); final Object dockerAPIEndpoint = dockerClientConfig.getDockerHost(); final String msg = "Read timed out: No data received within " + readTimeout + "ms. Perhaps the docker API (" + dockerAPIEndpoint + ") is not responding normally, or perhaps you need to increase the readTimeout value."; final Exception ex = new SocketTimeoutException(msg); ctx.fireExceptionCaught(ex); alreadyTimedOut = true; } }
@Override public void init(DockerClientConfig dockerClientConfig) { super.init(dockerClientConfig); bootstrap = new Bootstrap(); String scheme = dockerClientConfig.getDockerHost().getScheme(); String host = ""; if ("unix".equals(scheme)) { nettyInitializer = new UnixDomainSocketInitializer(); host = "DUMMY"; } else if ("tcp".equals(scheme)) { nettyInitializer = new InetSocketInitializer(); host = dockerClientConfig.getDockerHost().getHost() + ":" + Integer.toString(dockerClientConfig.getDockerHost().getPort()); } eventLoopGroup = nettyInitializer.init(bootstrap, dockerClientConfig); baseResource = new NettyWebTarget(this::connect, host) .path(dockerClientConfig.getApiVersion().asWebPathPart()); }
@Override public void init(DockerClientConfig dockerClientConfig) { super.init(dockerClientConfig); bootstrap = new Bootstrap(); String scheme = dockerClientConfig.getDockerHost().getScheme(); String host = ""; if ("unix".equals(scheme)) { nettyInitializer = new UnixDomainSocketInitializer(); host = "DUMMY"; } else if ("tcp".equals(scheme)) { nettyInitializer = new InetSocketInitializer(); host = dockerClientConfig.getDockerHost().getHost() + ":" + Integer.toString(dockerClientConfig.getDockerHost().getPort()); } eventLoopGroup = nettyInitializer.init(bootstrap, dockerClientConfig); baseResource = new NettyWebTarget(channelProvider, host).path(dockerClientConfig.getApiVersion().asWebPathPart()); }
private SslHandler initSsl(DockerClientConfig dockerClientConfig) { SslHandler ssl = null; try { String host = dockerClientConfig.getDockerHost().getHost(); int port = dockerClientConfig.getDockerHost().getPort(); final SSLConfig sslConfig = dockerClientConfig.getSSLConfig(); if (sslConfig != null && sslConfig.getSSLContext() != null) { SSLEngine engine = sslConfig.getSSLContext().createSSLEngine(host, port); engine.setUseClientMode(true); engine.setSSLParameters(enableHostNameVerification(engine.getSSLParameters())); // in the future we may use HostnameVerifier like here: // https://github.com/AsyncHttpClient/async-http-client/blob/1.8.x/src/main/java/com/ning/http/client/providers/netty/NettyConnectListener.java#L76 ssl = new SslHandler(engine); } } catch (Exception e) { throw new RuntimeException(e); } return ssl; } }
private SslHandler initSsl(DockerClientConfig dockerClientConfig) { SslHandler ssl = null; try { String host = dockerClientConfig.getDockerHost().getHost(); int port = dockerClientConfig.getDockerHost().getPort(); final SSLConfig sslConfig = dockerClientConfig.getSSLConfig(); if (sslConfig != null && sslConfig.getSSLContext() != null) { SSLEngine engine = sslConfig.getSSLContext().createSSLEngine(host, port); engine.setUseClientMode(true); engine.setSSLParameters(enableHostNameVerification(engine.getSSLParameters())); // in the future we may use HostnameVerifier like here: // https://github.com/AsyncHttpClient/async-http-client/blob/1.8.x/src/main/java/com/ning/http/client/providers/netty/NettyConnectListener.java#L76 ssl = new SslHandler(engine); } } catch (Exception e) { throw new RuntimeException(e); } return ssl; } }
private String stringRepresentation(DockerClientConfig config) { if (config == null) { return ""; } return " dockerHost=" + config.getDockerHost() + "\n" + " apiVersion='" + config.getApiVersion() + "'\n" + " registryUrl='" + config.getRegistryUrl() + "'\n" + " registryUsername='" + config.getRegistryUsername() + "'\n" + " registryPassword='" + config.getRegistryPassword() + "'\n" + " registryEmail='" + config.getRegistryEmail() + "'\n" + " dockerConfig='" + config.toString() + "'\n"; } }
.retryOnConnectionFailure(true); URI dockerHost = dockerClientConfig.getDockerHost(); switch (dockerHost.getScheme()) { case "unix":
URI originalUri = dockerClientConfig.getDockerHost();
@java.lang.SuppressWarnings("all") public java.net.URI getDockerHost() { return this.delegate.getDockerHost(); }
@Override protected boolean isApplicable() { return "tcp".equalsIgnoreCase(config.getDockerHost().getScheme()) || SystemUtils.IS_OS_LINUX; }
@Override public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException { DockerClientConfig dockerClientConfig = getDockerClientConfig(); String path = dockerClientConfig.getDockerHost().getPath(); return (DuplexChannel) bootstrap.connect(new DomainSocketAddress(path)).sync().channel(); } }
@Override public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException { String socketPath = getDockerClientConfig().getDockerHost().getPath(); return (DuplexChannel) bootstrap.connect(new DomainSocketAddress(socketPath)).sync().channel(); } }
private String stringRepresentation(DockerClientConfig config) { if (config == null) { return ""; } return " dockerHost=" + config.getDockerHost() + "\n apiVersion=\'" + config.getApiVersion() + "\'\n registryUrl=\'" + config.getRegistryUrl() + "\'\n registryUsername=\'" + config.getRegistryUsername() + "\'\n registryPassword=\'" + config.getRegistryPassword() + "\'\n registryEmail=\'" + config.getRegistryEmail() + "\'\n dockerConfig=\'" + config.toString() + "\'\n"; } }