diff --git a/pom.xml b/pom.xml index 8933bad62f..c56aa2d7c0 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 @@ -10,7 +11,7 @@ com.github.docker-java docker-java jar - 3.0.10-SNAPSHOT + 3.0.10-ALIEN2 docker-java https://github.com/docker-java/docker-java @@ -73,7 +74,7 @@ 1.1.7 6.9.10 - 4.1.3.Final + 4.1.11.Final-ALIEN1 1.3 1.8 2.3.3 @@ -258,6 +259,12 @@ ${netty.version} linux-x86_64 + + io.netty + netty-transport-native-kqueue + ${netty.version} + osx-x86_64 + junit junit @@ -267,14 +274,14 @@ - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ + repo.opensource.fastconnect.org + https://fastconnect.org/maven/content/repositories/opensource + + repo.opensource.snapshot.fastconnect.org + https://fastconnect.org/maven/content/repositories/opensource-snapshot + @@ -394,18 +401,6 @@ - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://oss.sonatype.org/ - true - - - org.apache.maven.plugins maven-release-plugin @@ -539,8 +534,8 @@ true true false - + src/test/resources/checkstyle/checkstyle-config.xml diff --git a/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java b/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java index 497aaad2b5..9a61878cf5 100644 --- a/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java +++ b/src/main/java/com/github/dockerjava/api/command/InspectContainerResponse.java @@ -14,6 +14,7 @@ import com.github.dockerjava.api.model.ContainerConfig; import com.github.dockerjava.api.model.HostConfig; import com.github.dockerjava.api.model.NetworkSettings; +import com.github.dockerjava.api.model.Node; import com.github.dockerjava.api.model.Volume; import com.github.dockerjava.api.model.VolumeBind; import com.github.dockerjava.api.model.VolumeBinds; @@ -83,6 +84,9 @@ public class InspectContainerResponse { @JsonProperty("NetworkSettings") private NetworkSettings networkSettings; + @JsonProperty("Node") + private Node node; + @JsonProperty("Path") private String path; @@ -147,6 +151,10 @@ public NetworkSettings getNetworkSettings() { return networkSettings; } + public Node getNode() { + return node; + } + public String getResolvConfPath() { return resolvConfPath; } diff --git a/src/main/java/com/github/dockerjava/api/model/Node.java b/src/main/java/com/github/dockerjava/api/model/Node.java index 89b391c0a7..825fad4405 100644 --- a/src/main/java/com/github/dockerjava/api/model/Node.java +++ b/src/main/java/com/github/dockerjava/api/model/Node.java @@ -1,8 +1,12 @@ package com.github.dockerjava.api.model; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang.builder.ToStringBuilder; + +import java.util.Map; import java.io.Serializable; @@ -10,21 +14,37 @@ * A node as returned by the /events API, for instance, when Swarm is used. */ @JsonInclude(Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) public class Node implements Serializable { private static final long serialVersionUID = 1L; @JsonProperty("Name") private String name; - @JsonProperty("Id") + @JsonProperty("ID") private String id; @JsonProperty("Addr") private String addr; - @JsonProperty("Ip") + @JsonProperty("IP") private String ip; + @JsonProperty("Cpus") + private Integer cpus; + + @JsonProperty("Memory") + private Long memory; + + @JsonProperty("Labels") + private Map labels; + + @JsonProperty("Version") + private String version; + + @JsonProperty("DeltaDuration") + private Long deltaDuration; + public String getName() { return name; } @@ -40,4 +60,29 @@ public String getAddr() { public String getIp() { return ip; } + + public Integer getCpus() { + return cpus; + } + + public Long getMemory() { + return memory; + } + + public Map getLabels() { + return labels; + } + + public String getVersion() { + return version; + } + + public Long getDeltaDuration() { + return deltaDuration; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } } diff --git a/src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java b/src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java index 2238dfcea7..841976ad50 100644 --- a/src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java +++ b/src/main/java/com/github/dockerjava/core/async/ResultCallbackTemplate.java @@ -3,24 +3,21 @@ */ package com.github.dockerjava.core.async; +import com.github.dockerjava.api.async.ResultCallback; +import com.google.common.base.Throwables; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.CheckForNull; import java.io.Closeable; import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import javax.annotation.CheckForNull; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.github.dockerjava.api.async.ResultCallback; -import com.google.common.base.Throwables; - /** * Abstract template implementation of {@link ResultCallback} * * @author Marcus Linke - * */ public abstract class ResultCallbackTemplate, A_RES_T> implements ResultCallback { @@ -54,13 +51,9 @@ public void onError(Throwable throwable) { } try { - LOGGER.error("Error during callback", throwable); - } finally { - try { - close(); - } catch (IOException e) { - throw new RuntimeException(e); - } + close(); + } catch (IOException e) { + throw new RuntimeException(e); } } @@ -76,11 +69,11 @@ public void onComplete() { @Override public void close() throws IOException { if (!closed) { - closed = true; - if (stream != null) { - stream.close(); - } - completed.countDown(); + closed = true; + if (stream != null) { + stream.close(); + } + completed.countDown(); } } @@ -97,8 +90,9 @@ public RC_T awaitCompletion() throws InterruptedException { /** * Blocks until {@link ResultCallback#onComplete()} was called or the given timeout occurs + * * @return {@code true} if completed and {@code false} if the waiting time elapsed - * before {@link ResultCallback#onComplete()} was called. + * before {@link ResultCallback#onComplete()} was called. */ public boolean awaitCompletion(long timeout, TimeUnit timeUnit) throws InterruptedException { boolean result = completed.await(timeout, timeUnit); @@ -119,8 +113,9 @@ public RC_T awaitStarted() throws InterruptedException { /** * Blocks until {@link ResultCallback#onStart()} was called or the given timeout occurs. {@link ResultCallback#onStart()} is called when * the request was processed on the server side and the response is incoming. + * * @return {@code true} if started and {@code false} if the waiting time elapsed - * before {@link ResultCallback#onStart()} was called. + * before {@link ResultCallback#onStart()} was called. */ public boolean awaitStarted(long timeout, TimeUnit timeUnit) throws InterruptedException { return started.await(timeout, timeUnit); diff --git a/src/main/java/com/github/dockerjava/netty/NettyDockerCmdExecFactory.java b/src/main/java/com/github/dockerjava/netty/NettyDockerCmdExecFactory.java index 2c8a83b0ea..f6a0f54adc 100644 --- a/src/main/java/com/github/dockerjava/netty/NettyDockerCmdExecFactory.java +++ b/src/main/java/com/github/dockerjava/netty/NettyDockerCmdExecFactory.java @@ -115,6 +115,8 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.epoll.EpollDomainSocketChannel; import io.netty.channel.epoll.EpollEventLoopGroup; +import io.netty.channel.kqueue.KQueueDomainSocketChannel; +import io.netty.channel.kqueue.KQueueEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.DuplexChannel; import io.netty.channel.socket.SocketChannel; @@ -195,7 +197,12 @@ public void init(DockerClientConfig dockerClientConfig) { String scheme = dockerClientConfig.getDockerHost().getScheme(); if ("unix".equals(scheme)) { - nettyInitializer = new UnixDomainSocketInitializer(); + String osName = System.getProperty("os.name"); + if (osName.startsWith("Mac")) { + nettyInitializer = new KQueueDomainSocketInitializer(); + } else { + nettyInitializer = new UnixDomainSocketInitializer(); + } } else if ("tcp".equals(scheme)) { nettyInitializer = new InetSocketInitializer(); } @@ -235,13 +242,12 @@ public EpollDomainSocketChannel newChannel() { } }; - bootstrap.group(epollEventLoopGroup).channelFactory(factory) - .handler(new ChannelInitializer() { - @Override - protected void initChannel(final UnixChannel channel) throws Exception { - channel.pipeline().addLast(new HttpClientCodec()); - } - }); + bootstrap.group(epollEventLoopGroup).channelFactory(factory).handler(new ChannelInitializer() { + @Override + protected void initChannel(final UnixChannel channel) throws Exception { + channel.pipeline().addLast(new HttpClientCodec()); + } + }); return epollEventLoopGroup; } @@ -251,6 +257,34 @@ public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException { } } + private class KQueueDomainSocketInitializer implements NettyInitializer { + @Override + public EventLoopGroup init(Bootstrap bootstrap, DockerClientConfig dockerClientConfig) { + + EventLoopGroup kQueueEventLoopGroup = new KQueueEventLoopGroup(0, new DefaultThreadFactory(threadPrefix)); + + ChannelFactory factory = new ChannelFactory() { + @Override + public KQueueDomainSocketChannel newChannel() { + return configure(new KQueueDomainSocketChannel()); + } + }; + + bootstrap.group(kQueueEventLoopGroup).channelFactory(factory).handler(new ChannelInitializer() { + @Override + protected void initChannel(final UnixChannel channel) throws Exception { + channel.pipeline().addLast(new HttpClientCodec()); + } + }); + return kQueueEventLoopGroup; + } + + @Override + public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException { + return (DuplexChannel) bootstrap.connect(new DomainSocketAddress("/var/run/docker.sock")).sync().channel(); + } + } + private class InetSocketInitializer implements NettyInitializer { @Override public EventLoopGroup init(Bootstrap bootstrap, final DockerClientConfig dockerClientConfig) { @@ -269,15 +303,14 @@ public NioSocketChannel newChannel() { } }; - bootstrap.group(nioEventLoopGroup).channelFactory(factory) - .handler(new ChannelInitializer() { - @Override - protected void initChannel(final SocketChannel channel) throws Exception { - // channel.pipeline().addLast(new - // HttpProxyHandler(proxyAddress)); - channel.pipeline().addLast(new HttpClientCodec()); - } - }); + bootstrap.group(nioEventLoopGroup).channelFactory(factory).handler(new ChannelInitializer() { + @Override + protected void initChannel(final SocketChannel channel) throws Exception { + // channel.pipeline().addLast(new + // HttpProxyHandler(proxyAddress)); + channel.pipeline().addLast(new HttpClientCodec()); + } + }); return nioEventLoopGroup; } @@ -332,8 +365,7 @@ private SslHandler initSsl(DockerClientConfig dockerClientConfig) { } protected DockerClientConfig getDockerClientConfig() { - checkNotNull(dockerClientConfig, - "Factor not initialized, dockerClientConfig not set. You probably forgot to call init()!"); + checkNotNull(dockerClientConfig, "Factor not initialized, dockerClientConfig not set. You probably forgot to call init()!"); return dockerClientConfig; }