You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/09/20 09:11:11 UTC
[4/5] camel git commit: CAMEL-10307,
docker library upgrade (async test incomplete)
CAMEL-10307, docker library upgrade (async test incomplete)
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a9304c53
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a9304c53
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a9304c53
Branch: refs/heads/master
Commit: a9304c5335aef74433e1ba3ccd59f359bd0f55b2
Parents: 9d43d77
Author: Fabrizio Spataro <fa...@bizmate.it>
Authored: Mon Sep 19 18:28:43 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Tue Sep 20 11:07:34 2016 +0200
----------------------------------------------------------------------
.../component/docker/DockerClientFactory.java | 61 +--
.../component/docker/DockerClientProfile.java | 38 +-
.../component/docker/DockerConfiguration.java | 16 +-
.../camel/component/docker/DockerConstants.java | 1 +
.../camel/component/docker/DockerEndpoint.java | 30 +-
.../camel/component/docker/DockerHelper.java | 4 +-
.../camel/component/docker/DockerOperation.java | 78 ++--
.../docker/consumer/DockerEventsConsumer.java | 155 -------
.../docker/consumer/DockerStatsConsumer.java | 138 ------
.../docker/producer/AsyncDockerProducer.java | 461 +++++++++++++++++++
.../docker/producer/DockerProducer.java | 400 ++--------------
.../docker/DockerEventsConsumerTest.java | 107 -----
.../docker/DockerStatsConsumerTest.java | 109 -----
.../component/docker/RemoveImageCmdUriTest.java | 4 +-
.../headers/AttachContainerCmdHeaderTest.java | 12 +-
.../docker/headers/AuthCmdHeaderTest.java | 1 +
.../docker/headers/BaseDockerHeaderTest.java | 2 +
.../headers/CreateContainerCmdHeaderTest.java | 2 +-
.../docker/headers/ListImagesCmdHeaderTest.java | 2 +-
.../headers/RemoveImageCmdHeaderTest.java | 4 +-
.../src/test/resources/log4j2.properties | 2 +-
parent/pom.xml | 2 +-
22 files changed, 641 insertions(+), 988 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientFactory.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientFactory.java
index fd1994f..f6664b4 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientFactory.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientFactory.java
@@ -16,17 +16,18 @@
*/
package org.apache.camel.component.docker;
+import org.apache.camel.Message;
+import org.apache.camel.component.docker.exception.DockerException;
+import org.apache.camel.component.docker.ssl.NoImplSslConfig;
+import org.apache.camel.util.ObjectHelper;
+
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.DockerCmdExecFactory;
+import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientBuilder;
-import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.LocalDirectorySSLConfig;
import com.github.dockerjava.core.SSLConfig;
-import com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl;
-import org.apache.camel.Message;
-import org.apache.camel.component.docker.exception.DockerException;
-import org.apache.camel.component.docker.ssl.NoImplSslConfig;
-import org.apache.camel.util.ObjectHelper;
+import com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory;
/**
* Methods for communicating with Docker
@@ -40,6 +41,7 @@ public final class DockerClientFactory {
/**
* Produces a {@link DockerClient} to communicate with Docker
*/
+ @SuppressWarnings("resource")
public static DockerClient getDockerClient(DockerComponent dockerComponent, DockerConfiguration dockerConfiguration, Message message) throws DockerException {
ObjectHelper.notNull(dockerConfiguration, "dockerConfiguration");
@@ -62,10 +64,12 @@ public final class DockerClientFactory {
String serverAddress = DockerHelper.getProperty(DockerConstants.DOCKER_SERVER_ADDRESS, dockerConfiguration, message, String.class, dockerConfiguration.getServerAddress());
String certPath = DockerHelper.getProperty(DockerConstants.DOCKER_CERT_PATH, dockerConfiguration, message, String.class, dockerConfiguration.getCertPath());
Boolean secure = DockerHelper.getProperty(DockerConstants.DOCKER_SECURE, dockerConfiguration, message, Boolean.class, dockerConfiguration.isSecure());
- Boolean loggingFilter = DockerHelper.getProperty(DockerConstants.DOCKER_LOGGING_FILTER, dockerConfiguration, message, Boolean.class, dockerConfiguration.isLoggingFilterEnabled());
- Boolean followRedirectFilter = DockerHelper.getProperty(DockerConstants.DOCKER_FOLLOW_REDIRECT_FILTER, dockerConfiguration, message,
- Boolean.class, dockerConfiguration.isFollowRedirectFilterEnabled());
-
+ Boolean loggingFilter = DockerHelper.getProperty(DockerConstants.DOCKER_LOGGING_FILTER, dockerConfiguration, message, Boolean.class,
+ dockerConfiguration.isLoggingFilterEnabled());
+ Boolean followRedirectFilter = DockerHelper.getProperty(DockerConstants.DOCKER_FOLLOW_REDIRECT_FILTER, dockerConfiguration, message, Boolean.class,
+ dockerConfiguration.isFollowRedirectFilterEnabled());
+ Boolean tlsVerify = DockerHelper.getProperty(DockerConstants.DOCKER_TLSVERIFY, dockerConfiguration, message, Boolean.class, dockerConfiguration.isTlsVerify());
+
clientProfile.setHost(host);
clientProfile.setPort(port);
clientProfile.setEmail(email);
@@ -79,11 +83,12 @@ public final class DockerClientFactory {
clientProfile.setSecure(secure);
clientProfile.setFollowRedirectFilter(followRedirectFilter);
clientProfile.setLoggingFilter(loggingFilter);
+ clientProfile.setTlsVerify(tlsVerify);
- DockerClient client = dockerComponent.getClient(clientProfile);
+ DockerClient dockerClient = dockerComponent.getClient(clientProfile);
- if (client != null) {
- return client;
+ if (dockerClient != null) {
+ return dockerClient;
}
SSLConfig sslConfig;
@@ -96,29 +101,25 @@ public final class DockerClientFactory {
sslConfig = new NoImplSslConfig();
}
- DockerClientConfig.DockerClientConfigBuilder configBuilder = new DockerClientConfig.DockerClientConfigBuilder().withUsername(clientProfile.getUsername())
- .withPassword(clientProfile.getPassword()).withEmail(clientProfile.getEmail()).withReadTimeout(clientProfile.getRequestTimeout()).withUri(clientProfile.toUrl())
- .withMaxPerRouteConnections(clientProfile.getMaxPerRouteConnections()).withMaxTotalConnections(clientProfile.getMaxTotalConnections()).withSSLConfig(sslConfig)
- .withServerAddress(clientProfile.getServerAddress());
+ DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost(clientProfile.toUrl())
+ .withDockerTlsVerify(clientProfile.isTlsVerify()).withRegistryUsername(clientProfile.getUsername()).withRegistryPassword(clientProfile.getPassword())
+ .withRegistryEmail(clientProfile.getEmail()).withRegistryUrl(clientProfile.getServerAddress()).withCustomSslConfig(sslConfig);
if (clientProfile.getCertPath() != null) {
configBuilder.withDockerCertPath(clientProfile.getCertPath());
}
-
- if (clientProfile.isFollowRedirectFilterEnabled() != null && clientProfile.isFollowRedirectFilterEnabled()) {
- configBuilder.withFollowRedirectsFilter(clientProfile.isFollowRedirectFilterEnabled());
- }
- if (clientProfile.isLoggingFilterEnabled() != null && clientProfile.isLoggingFilterEnabled()) {
- configBuilder.withLoggingFilter(clientProfile.isLoggingFilterEnabled());
- }
-
- DockerClientConfig config = configBuilder.build();
- DockerCmdExecFactory dockerClientFactory = new DockerCmdExecFactoryImpl();
- client = DockerClientBuilder.getInstance(config).withDockerCmdExecFactory(dockerClientFactory).build();
- dockerComponent.setClient(clientProfile, client);
+ // @Deprecated: isFollowRedirectFilterEnabled, isLoggingFilterEnabled
+
+ DockerCmdExecFactory dockerCmdExecFactory = new JerseyDockerCmdExecFactory().withReadTimeout(clientProfile.getRequestTimeout())
+ .withConnectTimeout(clientProfile.getRequestTimeout()).withMaxTotalConnections(clientProfile.getMaxTotalConnections())
+ .withMaxPerRouteConnections(clientProfile.getMaxPerRouteConnections());
+
+ dockerClient = DockerClientBuilder.getInstance(configBuilder).withDockerCmdExecFactory(dockerCmdExecFactory).build();
+
+ dockerComponent.setClient(clientProfile, dockerClient);
- return client;
+ return dockerClient;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientProfile.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientProfile.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientProfile.java
index 5d7d3fc..9d5b7df 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientProfile.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerClientProfile.java
@@ -16,9 +16,6 @@
*/
package org.apache.camel.component.docker;
-import java.net.MalformedURLException;
-import java.net.URL;
-
import org.apache.camel.component.docker.exception.DockerException;
import org.apache.camel.util.ObjectHelper;
@@ -53,6 +50,10 @@ public class DockerClientProfile {
private Boolean followRedirectFilterEnabled;
+ private Boolean tlsVerify;
+
+ private Boolean socket;
+
public String getHost() {
return host;
}
@@ -145,16 +146,7 @@ public class DockerClientProfile {
ObjectHelper.notNull(this.host, "host");
ObjectHelper.notNull(this.port, "port");
- URL uri;
- String secure = this.secure != null && this.secure ? "https" : "http";
- try {
- uri = new URL(secure, this.host, this.port, "");
- } catch (MalformedURLException e) {
- throw new DockerException(e);
- }
-
- return uri.toString();
-
+ return ((this.socket) ? "unix" : "tcp") + "://" + host + ":" + port;
}
public Boolean isLoggingFilterEnabled() {
@@ -173,7 +165,23 @@ public class DockerClientProfile {
this.followRedirectFilterEnabled = followRedirectFilterEnabled;
}
- @Override
+ public Boolean isTlsVerify() {
+ return tlsVerify;
+ }
+
+ public void setTlsVerify(Boolean tlsVerify) {
+ this.tlsVerify = tlsVerify;
+ }
+
+ public Boolean isSocket() {
+ return socket;
+ }
+
+ public void setSocket(Boolean socket) {
+ this.socket = socket;
+ }
+
+ @Override
public int hashCode() {
final int prime = 31;
int result = 1;
@@ -297,6 +305,6 @@ public class DockerClientProfile {
return false;
}
return true;
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java
index 2a9ec62..081ca0b 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java
@@ -59,7 +59,9 @@ public class DockerConfiguration implements Cloneable {
private boolean loggingFilter;
@UriParam
private boolean followRedirectFilter;
-
+ @UriParam
+ private boolean tlsVerify;
+
private Map<String, Object> parameters = new HashMap<String, Object>();
public String getHost() {
@@ -227,6 +229,17 @@ public class DockerConfiguration implements Cloneable {
this.operation = operation;
}
+ public boolean isTlsVerify() {
+ return tlsVerify;
+ }
+
+ /**
+ * Check TLS
+ */
+ public void setTlsVerify(boolean tlsVerify) {
+ this.tlsVerify = tlsVerify;
+ }
+
public DockerConfiguration copy() {
try {
return (DockerConfiguration) clone();
@@ -235,4 +248,5 @@ public class DockerConfiguration implements Cloneable {
}
}
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConstants.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConstants.java
index b938eed..34c2ad6 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConstants.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConstants.java
@@ -45,6 +45,7 @@ public final class DockerConstants {
public static final String DOCKER_SECURE = "CamelDockerSecure";
public static final String DOCKER_FOLLOW_REDIRECT_FILTER = "CamelDockerFollowRedirectFilter";
public static final String DOCKER_LOGGING_FILTER = "CamelDockerLoggingFilter";
+ public static final String DOCKER_TLSVERIFY = "CamelDockerTlsVerify";
/**
* List Images *
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerEndpoint.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerEndpoint.java
index b62c994..4123d16 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerEndpoint.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerEndpoint.java
@@ -16,12 +16,12 @@
*/
package org.apache.camel.component.docker;
+import org.apache.camel.CamelException;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.component.docker.consumer.DockerEventsConsumer;
-import org.apache.camel.component.docker.consumer.DockerStatsConsumer;
import org.apache.camel.component.docker.exception.DockerException;
+import org.apache.camel.component.docker.producer.AsyncDockerProducer;
import org.apache.camel.component.docker.producer.DockerProducer;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.UriEndpoint;
@@ -30,7 +30,7 @@ import org.apache.camel.spi.UriParam;
/**
* The docker component is used for managing Docker containers.
*/
-@UriEndpoint(scheme = "docker", title = "Docker", syntax = "docker:operation", consumerClass = DockerEventsConsumer.class,
+@UriEndpoint(scheme = "docker", title = "Docker", syntax = "docker:operation",
label = "container,cloud,paas", lenientProperties = true)
public class DockerEndpoint extends DefaultEndpoint {
@@ -49,30 +49,27 @@ public class DockerEndpoint extends DefaultEndpoint {
super(endpointUri);
}
+ @Override
public Producer createProducer() throws Exception {
DockerOperation operation = configuration.getOperation();
if (operation != null && operation.canProduce()) {
- return new DockerProducer(this);
+ if (operation.isAsync()) {
+ return new AsyncDockerProducer(this);
+ } else {
+ return new DockerProducer(this);
+ }
} else {
throw new DockerException(operation + " is not a valid producer operation");
}
}
+ @Override
public Consumer createConsumer(Processor processor) throws Exception {
-
- DockerOperation operation = configuration.getOperation();
-
- switch (operation) {
- case EVENTS:
- return new DockerEventsConsumer(this, processor);
- case STATS:
- return new DockerStatsConsumer(this, processor);
- default:
- throw new DockerException(operation + " is not a valid consumer operation");
- }
+ throw new CamelException();
}
-
+
+ @Override
public boolean isSingleton() {
return true;
}
@@ -87,4 +84,5 @@ public class DockerEndpoint extends DefaultEndpoint {
}
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerHelper.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerHelper.java
index 8003a6d..37edee7 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerHelper.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerHelper.java
@@ -20,11 +20,13 @@ import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.Map;
-import com.github.dockerjava.api.DockerClientException;
import org.apache.camel.Message;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.lang.BooleanUtils;
+import com.github.dockerjava.api.exception.DockerClientException;
+
+
/**
* Utility methods for Docker Component
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerOperation.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerOperation.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerOperation.java
index 36ae1e3..3ce04b8 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerOperation.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerOperation.java
@@ -28,57 +28,57 @@ public enum DockerOperation {
/**
* Events *
*/
- EVENTS("events", false, true,
+ EVENTS("events", false, true, false,
DockerConstants.DOCKER_INITIAL_RANGE, Long.class),
/**
* Stats *
*/
- STATS("stats", false, true,
+ STATS("stats", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, Long.class),
/**
* General *
*/
- AUTH("auth", false, true,
+ AUTH("auth", false, true, false,
DockerConstants.DOCKER_USERNAME, String.class,
DockerConstants.DOCKER_PASSWORD, String.class,
DockerConstants.DOCKER_EMAIL, String.class,
DockerConstants.DOCKER_SERVER_ADDRESS, String.class),
- INFO("info", false, true),
- PING("ping", false, true),
- VERSION("version", false, true),
+ INFO("info", false, true, false),
+ PING("ping", false, true, false),
+ VERSION("version", false, true, false),
/**
* Images *
*/
- BUILD_IMAGE("imagebuild", false, true,
+ BUILD_IMAGE("imagebuild", false, true, true,
DockerConstants.DOCKER_NO_CACHE, Boolean.class,
DockerConstants.DOCKER_REMOVE, Boolean.class,
DockerConstants.DOCKER_QUIET, Boolean.class),
- CREATE_IMAGE("imagecreate", false, true,
+ CREATE_IMAGE("imagecreate", false, true, false,
DockerConstants.DOCKER_REPOSITORY, String.class),
- INSPECT_IMAGE("imageinspect", false, true,
+ INSPECT_IMAGE("imageinspect", false, true, false,
DockerConstants.DOCKER_IMAGE_ID, String.class,
DockerConstants.DOCKER_NO_PRUNE, Boolean.class,
DockerConstants.DOCKER_FORCE, Boolean.class),
- LIST_IMAGES("imagelist", false, true,
+ LIST_IMAGES("imagelist", false, true, false,
DockerConstants.DOCKER_FILTER, String.class,
DockerConstants.DOCKER_SHOW_ALL, Boolean.class),
- PULL_IMAGE("imagepull", false, true,
+ PULL_IMAGE("imagepull", false, true, true,
DockerConstants.DOCKER_REGISTRY, String.class,
DockerConstants.DOCKER_TAG, String.class,
DockerConstants.DOCKER_REPOSITORY, String.class),
- PUSH_IMAGE("imagepush", false, true,
+ PUSH_IMAGE("imagepush", false, true, true,
DockerConstants.DOCKER_NAME, String.class,
DockerConstants.DOCKER_TAG, String.class),
- REMOVE_IMAGE("imageremove", false, true,
+ REMOVE_IMAGE("imageremove", false, true, false,
DockerConstants.DOCKER_IMAGE_ID, String.class,
DockerConstants.DOCKER_FORCE, Boolean.class,
DockerConstants.DOCKER_NO_PRUNE, String.class),
- SEARCH_IMAGES("imagesearch", false, true,
+ SEARCH_IMAGES("imagesearch", false, true, false,
DockerConstants.DOCKER_TERM, String.class),
- TAG_IMAGE("imagetag", false, true,
+ TAG_IMAGE("imagetag", false, true, false,
DockerConstants.DOCKER_FORCE, Boolean.class,
DockerConstants.DOCKER_IMAGE_ID, String.class,
DockerConstants.DOCKER_REPOSITORY, String.class),
@@ -86,14 +86,14 @@ public enum DockerOperation {
/**
* Container *
*/
- ATTACH_CONTAINER("containerattach", false, true,
+ ATTACH_CONTAINER("containerattach", false, true, true,
DockerConstants.DOCKER_CONTAINER_ID, String.class,
DockerConstants.DOCKER_FOLLOW_STREAM, Boolean.class,
DockerConstants.DOCKER_LOGS, Boolean.class,
DockerConstants.DOCKER_STD_OUT, Boolean.class,
DockerConstants.DOCKER_STD_ERR, Boolean.class,
DockerConstants.DOCKER_TIMESTAMPS, Boolean.class),
- COMMIT_CONTAINER("containercommit", false, true,
+ COMMIT_CONTAINER("containercommit", false, true, false,
DockerConstants.DOCKER_ATTACH_STD_ERR, Boolean.class,
DockerConstants.DOCKER_ATTACH_STD_IN, Boolean.class,
DockerConstants.DOCKER_ATTACH_STD_OUT, Boolean.class,
@@ -117,11 +117,11 @@ public enum DockerOperation {
DockerConstants.DOCKER_USER, String.class,
DockerConstants.DOCKER_VOLUMES, String.class,
DockerConstants.DOCKER_WORKING_DIR, String.class),
- COPY_FILE_CONTAINER("containercopyfile", false, true,
+ COPY_FILE_CONTAINER("containercopyfile", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class,
DockerConstants.DOCKER_HOST_PATH, String.class,
DockerConstants.DOCKER_RESOURCE, String.class),
- CREATE_CONTAINER("containercreate", false, true,
+ CREATE_CONTAINER("containercreate", false, true, false,
DockerConstants.DOCKER_ATTACH_STD_ERR, Boolean.class,
DockerConstants.DOCKER_ATTACH_STD_IN, Boolean.class,
DockerConstants.DOCKER_ATTACH_STD_OUT, Boolean.class,
@@ -147,20 +147,20 @@ public enum DockerOperation {
DockerConstants.DOCKER_VOLUMES, String.class,
DockerConstants.DOCKER_VOLUMES_FROM, String.class,
DockerConstants.DOCKER_WORKING_DIR, String.class),
- DIFF_CONTAINER("containerdiff", false, true,
+ DIFF_CONTAINER("containerdiff", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class),
- INSPECT_CONTAINER("inspectcontainer", false, true,
+ INSPECT_CONTAINER("inspectcontainer", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class),
- KILL_CONTAINER("containerkill", false, true,
+ KILL_CONTAINER("containerkill", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class,
DockerConstants.DOCKER_SIGNAL, String.class),
- LIST_CONTAINERS("containerlist", false, true,
+ LIST_CONTAINERS("containerlist", false, true, false,
DockerConstants.DOCKER_BEFORE, String.class,
DockerConstants.DOCKER_LIMIT, String.class,
DockerConstants.DOCKER_SHOW_ALL, Boolean.class,
DockerConstants.DOCKER_SHOW_SIZE, Boolean.class,
DockerConstants.DOCKER_SINCE, String.class),
- LOG_CONTAINER("containerlog", false, true,
+ LOG_CONTAINER("containerlog", false, true, true,
DockerConstants.DOCKER_CONTAINER_ID, String.class,
DockerConstants.DOCKER_FOLLOW_STREAM, Boolean.class,
DockerConstants.DOCKER_STD_ERR, Boolean.class,
@@ -168,38 +168,38 @@ public enum DockerOperation {
DockerConstants.DOCKER_TAIL, Integer.class,
DockerConstants.DOCKER_TAIL_ALL, Boolean.class,
DockerConstants.DOCKER_TIMESTAMPS, Boolean.class),
- PAUSE_CONTAINER("containerpause", false, true,
+ PAUSE_CONTAINER("containerpause", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class),
- RESTART_CONTAINER("containerrestart", false, true,
+ RESTART_CONTAINER("containerrestart", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class,
DockerConstants.DOCKER_TIMEOUT, Integer.class),
- REMOVE_CONTAINER("containerremove", false, true,
+ REMOVE_CONTAINER("containerremove", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class,
DockerConstants.DOCKER_FORCE, Boolean.class,
DockerConstants.DOCKER_REMOVE_VOLUMES, Boolean.class),
- START_CONTAINER("containerstart", false, true,
+ START_CONTAINER("containerstart", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class),
- STOP_CONTAINER("containerstop", false, true,
+ STOP_CONTAINER("containerstop", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class,
DockerConstants.DOCKER_TIMEOUT, Integer.class),
- TOP_CONTAINER("containertop", false, true,
+ TOP_CONTAINER("containertop", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class,
DockerConstants.DOCKER_PS_ARGS, String.class),
- UNPAUSE_CONTAINER("containerunpause", false, true,
+ UNPAUSE_CONTAINER("containerunpause", false, true, false,
DockerConstants.DOCKER_CONTAINER_ID, String.class),
- WAIT_CONTAINER("containerwait", false, true,
+ WAIT_CONTAINER("containerwait", false, true, true,
DockerConstants.DOCKER_CONTAINER_ID, String.class),
/**
* Exec *
*/
- EXEC_CREATE("execcreate", false, true,
+ EXEC_CREATE("execcreate", false, true, false,
DockerConstants.DOCKER_ATTACH_STD_ERR, Boolean.class,
DockerConstants.DOCKER_ATTACH_STD_IN, Boolean.class,
DockerConstants.DOCKER_ATTACH_STD_OUT, Boolean.class,
DockerConstants.DOCKER_TTY, Boolean.class),
- EXEC_START("execstart", false, true,
+ EXEC_START("execstart", false, true, true,
DockerConstants.DOCKER_DETACH, Boolean.class,
DockerConstants.DOCKER_EXEC_ID, String.class,
DockerConstants.DOCKER_TTY, Boolean.class);
@@ -208,14 +208,16 @@ public enum DockerOperation {
private String text;
private boolean canConsume;
private boolean canProduce;
+ private boolean async;
private Map<String, Class<?>> parameters;
- DockerOperation(String text, boolean canConsume, boolean canProduce, Object... params) {
+ DockerOperation(String text, boolean canConsume, boolean canProduce, boolean async, Object... params) {
this.text = text;
this.canConsume = canConsume;
this.canProduce = canProduce;
+ this.async = async;
parameters = new HashMap<String, Class<?>>();
@@ -248,6 +250,10 @@ public enum DockerOperation {
return canProduce;
}
+ public boolean isAsync() {
+ return async;
+ }
+
public Map<String, Class<?>> getParameters() {
return parameters;
}
@@ -262,4 +268,4 @@ public enum DockerOperation {
return null;
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/consumer/DockerEventsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/consumer/DockerEventsConsumer.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/consumer/DockerEventsConsumer.java
deleted file mode 100644
index 7895c44..0000000
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/consumer/DockerEventsConsumer.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.docker.consumer;
-
-import java.util.Date;
-import java.util.concurrent.ExecutorService;
-
-import com.github.dockerjava.api.command.EventCallback;
-import com.github.dockerjava.api.command.EventsCmd;
-import com.github.dockerjava.api.model.Event;
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.component.docker.DockerClientFactory;
-import org.apache.camel.component.docker.DockerComponent;
-import org.apache.camel.component.docker.DockerConstants;
-import org.apache.camel.component.docker.DockerEndpoint;
-import org.apache.camel.component.docker.DockerHelper;
-import org.apache.camel.impl.DefaultConsumer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Docker Consumer for streaming events
- */
-public class DockerEventsConsumer extends DefaultConsumer implements EventCallback {
-
- private static final transient Logger LOGGER = LoggerFactory.getLogger(DockerEventsConsumer.class);
-
- private DockerEndpoint endpoint;
-
- private DockerComponent component;
-
- private EventsCmd eventsCmd;
-
- private ExecutorService eventsExecutorService;
-
- public DockerEventsConsumer(DockerEndpoint endpoint, Processor processor) throws Exception {
- super(endpoint, processor);
- this.endpoint = endpoint;
- this.component = (DockerComponent) endpoint.getComponent();
-
- }
-
- @Override
- public DockerEndpoint getEndpoint() {
- return (DockerEndpoint) super.getEndpoint();
- }
-
-
- /**
- * Determine the point in time to begin streaming events
- */
- private long processInitialEvent() {
-
- long currentTime = new Date().getTime();
-
- Long initialRange = DockerHelper.getProperty(DockerConstants.DOCKER_INITIAL_RANGE, endpoint.getConfiguration(), null, Long.class);
-
- if (initialRange != null) {
- currentTime = currentTime - initialRange;
- }
-
- return currentTime;
-
-
- }
-
- @Override
- protected void doStart() throws Exception {
-
- eventsCmd = DockerClientFactory.getDockerClient(component, endpoint.getConfiguration(), null).eventsCmd(this);
-
- eventsCmd.withSince(String.valueOf(processInitialEvent()));
- eventsExecutorService = eventsCmd.exec();
-
- super.doStart();
- }
-
- @Override
- protected void doStop() throws Exception {
-
- if (eventsExecutorService != null && !eventsExecutorService.isTerminated()) {
- LOGGER.trace("Stopping Docker events Executor Service");
-
- eventsExecutorService.shutdown();
- }
-
- super.doStop();
- }
-
-
- @Override
- public void onEvent(Event event) {
-
- LOGGER.debug("Received Docker Event: " + event);
-
- final Exchange exchange = getEndpoint().createExchange();
- Message message = exchange.getIn();
- message.setBody(event);
-
- try {
- LOGGER.trace("Processing exchange [{}]...", exchange);
- getAsyncProcessor().process(exchange, new AsyncCallback() {
- @Override
- public void done(boolean doneSync) {
- LOGGER.trace("Done processing exchange [{}]...", exchange);
- }
- });
- } catch (Exception e) {
- exchange.setException(e);
- }
- if (exchange.getException() != null) {
- getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
- }
-
- }
-
- @Override
- public void onException(Throwable throwable) {
- LOGGER.error("Error Consuming from Docker Events: {}", throwable.getMessage());
- }
-
- @Override
- public void onCompletion(int numEvents) {
-
- LOGGER.debug("Docker events connection completed. Events processed : {}", numEvents);
-
- eventsCmd.withSince(null);
-
- LOGGER.debug("Reestablishing connection with Docker");
- eventsCmd.exec();
-
- }
-
- @Override
- public boolean isReceiving() {
- return isRunAllowed();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/consumer/DockerStatsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/consumer/DockerStatsConsumer.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/consumer/DockerStatsConsumer.java
deleted file mode 100644
index 1ae10bb..0000000
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/consumer/DockerStatsConsumer.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.docker.consumer;
-
-import java.util.concurrent.ExecutorService;
-
-import com.github.dockerjava.api.command.StatsCallback;
-import com.github.dockerjava.api.command.StatsCmd;
-import com.github.dockerjava.api.model.Statistics;
-
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.Exchange;
-import org.apache.camel.Message;
-import org.apache.camel.Processor;
-import org.apache.camel.component.docker.DockerClientFactory;
-import org.apache.camel.component.docker.DockerComponent;
-import org.apache.camel.component.docker.DockerConstants;
-import org.apache.camel.component.docker.DockerEndpoint;
-import org.apache.camel.component.docker.DockerHelper;
-import org.apache.camel.impl.DefaultConsumer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Docker Consumer for streaming statistical events
- */
-public class DockerStatsConsumer extends DefaultConsumer implements StatsCallback {
-
- private static final transient Logger LOGGER = LoggerFactory.getLogger(DockerStatsConsumer.class);
-
- private DockerEndpoint endpoint;
-
- private DockerComponent component;
-
- private StatsCmd statsCmd;
-
- private ExecutorService eventsExecutorService;
-
- public DockerStatsConsumer(DockerEndpoint endpoint, Processor processor) throws Exception {
- super(endpoint, processor);
- this.endpoint = endpoint;
- this.component = (DockerComponent) endpoint.getComponent();
-
- }
-
- @Override
- public DockerEndpoint getEndpoint() {
- return (DockerEndpoint) super.getEndpoint();
- }
-
-
-
- @Override
- protected void doStart() throws Exception {
-
- statsCmd = DockerClientFactory.getDockerClient(component, endpoint.getConfiguration(), null).statsCmd(this);
-
- String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, endpoint.getConfiguration(), null, String.class);
-
- statsCmd.withContainerId(containerId);
-
- eventsExecutorService = statsCmd.exec();
-
- super.doStart();
- }
-
- @Override
- protected void doStop() throws Exception {
-
- if (eventsExecutorService != null && !eventsExecutorService.isTerminated()) {
- LOGGER.trace("Stopping Docker statistics Executor Service");
-
- eventsExecutorService.shutdown();
- }
-
- super.doStop();
- }
-
-
- @Override
- public void onStats(Statistics statistics) {
-
- LOGGER.debug("Received Docker Statistics Event: " + statistics);
-
- final Exchange exchange = getEndpoint().createExchange();
- Message message = exchange.getIn();
- message.setBody(statistics);
-
- try {
- LOGGER.trace("Processing exchange [{}]...", exchange);
- getAsyncProcessor().process(exchange, new AsyncCallback() {
- @Override
- public void done(boolean doneSync) {
- LOGGER.trace("Done processing exchange [{}]...", exchange);
- }
- });
- } catch (Exception e) {
- exchange.setException(e);
- }
- if (exchange.getException() != null) {
- getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
- }
-
- }
-
- @Override
- public void onException(Throwable throwable) {
- LOGGER.error("Error Consuming from Docker Statistics: {}", throwable.getMessage());
- }
-
- @Override
- public void onCompletion(int numEvents) {
-
- LOGGER.debug("Docker statistics connection completed. Events processed : {}", numEvents);
-
- statsCmd.exec();
-
- }
-
- @Override
- public boolean isReceiving() {
- return isRunAllowed();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/AsyncDockerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/AsyncDockerProducer.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/AsyncDockerProducer.java
new file mode 100644
index 0000000..aacce33
--- /dev/null
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/AsyncDockerProducer.java
@@ -0,0 +1,461 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.docker.producer;
+
+import java.io.File;
+import java.io.InputStream;
+
+import com.github.dockerjava.api.DockerClient;
+import com.github.dockerjava.api.command.AttachContainerCmd;
+import com.github.dockerjava.api.command.BuildImageCmd;
+import com.github.dockerjava.api.command.ExecStartCmd;
+import com.github.dockerjava.api.command.LogContainerCmd;
+import com.github.dockerjava.api.command.PullImageCmd;
+import com.github.dockerjava.api.command.PushImageCmd;
+import com.github.dockerjava.api.command.WaitContainerCmd;
+import com.github.dockerjava.api.model.AuthConfig;
+import com.github.dockerjava.api.model.BuildResponseItem;
+import com.github.dockerjava.api.model.Frame;
+import com.github.dockerjava.api.model.PullResponseItem;
+import com.github.dockerjava.api.model.PushResponseItem;
+import com.github.dockerjava.api.model.WaitResponse;
+import com.github.dockerjava.core.command.AttachContainerResultCallback;
+import com.github.dockerjava.core.command.BuildImageResultCallback;
+import com.github.dockerjava.core.command.ExecStartResultCallback;
+import com.github.dockerjava.core.command.LogContainerResultCallback;
+import com.github.dockerjava.core.command.PullImageResultCallback;
+import com.github.dockerjava.core.command.PushImageResultCallback;
+import com.github.dockerjava.core.command.WaitContainerResultCallback;
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.docker.DockerClientFactory;
+import org.apache.camel.component.docker.DockerComponent;
+import org.apache.camel.component.docker.DockerConfiguration;
+import org.apache.camel.component.docker.DockerConstants;
+import org.apache.camel.component.docker.DockerEndpoint;
+import org.apache.camel.component.docker.DockerHelper;
+import org.apache.camel.component.docker.DockerOperation;
+import org.apache.camel.component.docker.exception.DockerException;
+import org.apache.camel.impl.DefaultAsyncProducer;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Docker producer.
+ */
+public class AsyncDockerProducer extends DefaultAsyncProducer {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AsyncDockerProducer.class);
+ private DockerConfiguration configuration;
+ private DockerComponent component;
+
+ public AsyncDockerProducer(DockerEndpoint endpoint) {
+ super(endpoint);
+ this.configuration = endpoint.getConfiguration();
+ this.component = (DockerComponent)endpoint.getComponent();
+ }
+
+ @Override
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ try {
+
+ Message message = exchange.getIn();
+ DockerClient client = DockerClientFactory.getDockerClient(component, configuration, message);
+
+ DockerOperation operation = configuration.getOperation();
+
+ Object result = null;
+
+ switch (operation) {
+
+ /** Images **/
+ case BUILD_IMAGE:
+ // result contain an image id value
+ result = executeBuildImageRequest(client, message).exec(new BuildImageResultCallback() {
+ @Override
+ public void onNext(BuildResponseItem item) {
+ log.trace("build image callback {}", item);
+ super.onNext(item);
+ }
+ }).awaitImageId();
+ break;
+ case PULL_IMAGE:
+ result = executePullImageRequest(client, message).exec(new PullImageResultCallback() {
+ @Override
+ public void onNext(PullResponseItem item) {
+ log.trace("pull image callback {}", item);
+ super.onNext(item);
+ }
+ });
+ break;
+ case PUSH_IMAGE:
+ result = executePushImageRequest(client, message).exec(new PushImageResultCallback() {
+ @Override
+ public void onNext(PushResponseItem item) {
+ log.trace("push image callback {}", item);
+ super.onNext(item);
+ }
+ }).awaitCompletion();
+ break;
+ /** Containers **/
+ case ATTACH_CONTAINER:
+ result = executeAttachContainerRequest(client, message).exec(new AttachContainerResultCallback() {
+ @Override
+ public void onNext(Frame item) {
+ log.trace("attach container callback {}", item);
+ super.onNext(item);
+ }
+
+ }).awaitCompletion();
+
+ break;
+ case LOG_CONTAINER:
+ result = executeLogContainerRequest(client, message).exec(new LogContainerResultCallback() {
+ @Override
+ public void onNext(Frame item) {
+ log.trace("log container callback {}", item);
+ super.onNext(item);
+ }
+
+ }).awaitCompletion();
+
+ break;
+ case WAIT_CONTAINER:
+ // result contain a status code value
+ result = executeWaitContainerRequest(client, message).exec(new WaitContainerResultCallback() {
+ @Override
+ public void onNext(WaitResponse item) {
+ log.trace("wait contanier callback {}", item);
+ super.onNext(item);
+ }
+
+ }).awaitStatusCode();
+ break;
+ case EXEC_START:
+ result = executeExecStartRequest(client, message).exec(new ExecStartResultCallback() {
+ @Override
+ public void onNext(Frame item) {
+ log.trace("exec start callback {}", item);
+ super.onNext(item);
+ }
+
+ }).awaitCompletion();
+ break;
+ default:
+ throw new DockerException("Invalid operation: " + operation);
+ }
+
+ // If request included a response, set as body
+ if (result != null) {
+ exchange.getIn().setBody(result);
+
+ return true;
+ }
+ } catch (DockerException | InterruptedException e) {
+ log.error(e.getMessage(), e);
+
+ return false;
+ }
+
+ return false;
+ }
+
+ /**
+ * Produces a build image request
+ *
+ * @param client
+ * @param message
+ * @return
+ * @throws DockerException
+ */
+ private BuildImageCmd executeBuildImageRequest(DockerClient client, Message message) throws DockerException {
+
+ LOGGER.debug("Executing Docker Build Image Request");
+
+ Object body = message.getBody();
+
+ BuildImageCmd buildImageCmd;
+
+ if (body != null && body instanceof InputStream) {
+ buildImageCmd = client.buildImageCmd((InputStream)body);
+ } else if (body != null && body instanceof File) {
+ buildImageCmd = client.buildImageCmd((File)body);
+ } else {
+ throw new DockerException("Unable to location source Image");
+ }
+
+ Boolean noCache = DockerHelper.getProperty(DockerConstants.DOCKER_NO_CACHE, configuration, message, Boolean.class);
+
+ if (noCache != null) {
+ buildImageCmd.withNoCache(noCache);
+ }
+
+ Boolean quiet = DockerHelper.getProperty(DockerConstants.DOCKER_QUIET, configuration, message, Boolean.class);
+
+ if (quiet != null) {
+ buildImageCmd.withQuiet(quiet);
+ }
+
+ Boolean remove = DockerHelper.getProperty(DockerConstants.DOCKER_REMOVE, configuration, message, Boolean.class);
+
+ if (remove != null) {
+ buildImageCmd.withRemove(remove);
+ }
+
+ String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
+
+ if (tag != null) {
+ buildImageCmd.withTag(tag);
+ }
+
+ return buildImageCmd;
+
+ }
+
+ /**
+ * Produces a pull image request
+ *
+ * @param client
+ * @param message
+ * @return
+ */
+ private PullImageCmd executePullImageRequest(DockerClient client, Message message) {
+
+ LOGGER.debug("Executing Docker Pull Image Request");
+
+ String repository = DockerHelper.getProperty(DockerConstants.DOCKER_REPOSITORY, configuration, message, String.class);
+
+ ObjectHelper.notNull(repository, "Repository must be specified");
+
+ PullImageCmd pullImageCmd = client.pullImageCmd(repository);
+
+ String registry = DockerHelper.getProperty(DockerConstants.DOCKER_REGISTRY, configuration, message, String.class);
+ if (registry != null) {
+ pullImageCmd.withRegistry(registry);
+ }
+
+ String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
+ if (tag != null) {
+ pullImageCmd.withTag(tag);
+ }
+
+ AuthConfig authConfig = client.authConfig();
+
+ if (authConfig != null) {
+ pullImageCmd.withAuthConfig(authConfig);
+ }
+
+ return pullImageCmd;
+
+ }
+
+ /**
+ * Produces a push image request
+ *
+ * @param client
+ * @param message
+ * @return
+ */
+ private PushImageCmd executePushImageRequest(DockerClient client, Message message) {
+
+ LOGGER.debug("Executing Docker Push Image Request");
+
+ String name = DockerHelper.getProperty(DockerConstants.DOCKER_NAME, configuration, message, String.class);
+
+ ObjectHelper.notNull(name, "Image name must be specified");
+
+ PushImageCmd pushImageCmd = client.pushImageCmd(name);
+
+ String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
+
+ if (tag != null) {
+ pushImageCmd.withTag(tag);
+ }
+
+ AuthConfig authConfig = client.authConfig();
+
+ if (authConfig != null) {
+ pushImageCmd.withAuthConfig(authConfig);
+ }
+
+ return pushImageCmd;
+
+ }
+
+ /**
+ * Produce a attach container request
+ *
+ * @param client
+ * @param message
+ * @return
+ */
+ private AttachContainerCmd executeAttachContainerRequest(DockerClient client, Message message) {
+
+ LOGGER.debug("Executing Docker Attach Container Request");
+
+ String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class);
+
+ ObjectHelper.notNull(containerId, "Container ID must be specified");
+
+ AttachContainerCmd attachContainerCmd = client.attachContainerCmd(containerId);
+
+ Boolean followStream = DockerHelper.getProperty(DockerConstants.DOCKER_FOLLOW_STREAM, configuration, message, Boolean.class);
+
+ if (followStream != null) {
+ attachContainerCmd.withFollowStream(followStream);
+ }
+
+ Boolean logs = DockerHelper.getProperty(DockerConstants.DOCKER_LOGS, configuration, message, Boolean.class);
+
+ if (logs != null) {
+ attachContainerCmd.withLogs(logs);
+ }
+
+ Boolean stdErr = DockerHelper.getProperty(DockerConstants.DOCKER_STD_ERR, configuration, message, Boolean.class);
+
+ if (stdErr != null) {
+ attachContainerCmd.withStdErr(stdErr);
+ }
+
+ Boolean stdOut = DockerHelper.getProperty(DockerConstants.DOCKER_STD_OUT, configuration, message, Boolean.class);
+
+ if (stdOut != null) {
+ attachContainerCmd.withStdOut(stdOut);
+ }
+
+ Boolean timestamps = DockerHelper.getProperty(DockerConstants.DOCKER_TIMESTAMPS, configuration, message, Boolean.class);
+
+ if (timestamps != null) {
+ attachContainerCmd.withTimestamps(timestamps);
+ }
+
+ return attachContainerCmd;
+
+ }
+
+ /**
+ * Produce a log container request
+ *
+ * @param client
+ * @param message
+ * @return
+ */
+ private LogContainerCmd executeLogContainerRequest(DockerClient client, Message message) {
+
+ LOGGER.debug("Executing Docker Log Container Request");
+
+ String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class);
+
+ ObjectHelper.notNull(containerId, "Container ID must be specified");
+
+ LogContainerCmd logContainerCmd = client.logContainerCmd(containerId);
+
+ Boolean followStream = DockerHelper.getProperty(DockerConstants.DOCKER_FOLLOW_STREAM, configuration, message, Boolean.class);
+
+ if (followStream != null) {
+ logContainerCmd.withFollowStream(followStream);
+ }
+
+ Boolean stdErr = DockerHelper.getProperty(DockerConstants.DOCKER_STD_ERR, configuration, message, Boolean.class);
+
+ if (stdErr != null) {
+ logContainerCmd.withStdErr(stdErr);
+ }
+
+ Boolean stdOut = DockerHelper.getProperty(DockerConstants.DOCKER_STD_OUT, configuration, message, Boolean.class);
+
+ if (stdOut != null) {
+ logContainerCmd.withStdOut(stdOut);
+ }
+
+ Integer tail = DockerHelper.getProperty(DockerConstants.DOCKER_TAIL, configuration, message, Integer.class);
+
+ if (tail != null) {
+ logContainerCmd.withTail(tail);
+ }
+
+ Boolean tailAll = DockerHelper.getProperty(DockerConstants.DOCKER_TAIL_ALL, configuration, message, Boolean.class);
+
+ if (tailAll != null && tailAll) {
+ logContainerCmd.withTailAll();
+ }
+
+ Boolean timestamps = DockerHelper.getProperty(DockerConstants.DOCKER_TIMESTAMPS, configuration, message, Boolean.class);
+
+ if (timestamps != null) {
+ logContainerCmd.withTimestamps(timestamps);
+ }
+
+ return logContainerCmd;
+
+ }
+
+ /**
+ * Produce a wait container request
+ *
+ * @param client
+ * @param message
+ * @return
+ */
+ private WaitContainerCmd executeWaitContainerRequest(DockerClient client, Message message) {
+
+ LOGGER.debug("Executing Docker Wait Container Request");
+
+ String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class);
+
+ ObjectHelper.notNull(containerId, "Container ID must be specified");
+
+ WaitContainerCmd waitContainerCmd = client.waitContainerCmd(containerId);
+
+ return waitContainerCmd;
+
+ }
+
+ /**
+ * Produces a exec start request
+ *
+ * @param client
+ * @param message
+ * @return
+ */
+ private ExecStartCmd executeExecStartRequest(DockerClient client, Message message) {
+
+ LOGGER.debug("Executing Docker Exec Create Request");
+
+ String execId = DockerHelper.getProperty(DockerConstants.DOCKER_EXEC_ID, configuration, message, String.class);
+
+ ObjectHelper.notNull(execId, "Exec ID must be specified");
+
+ ExecStartCmd execStartCmd = client.execStartCmd(execId);
+
+ Boolean detach = DockerHelper.getProperty(DockerConstants.DOCKER_DETACH, configuration, message, Boolean.class);
+
+ if (detach != null) {
+ execStartCmd.withDetach(detach);
+ }
+
+ Boolean tty = DockerHelper.getProperty(DockerConstants.DOCKER_TTY, configuration, message, Boolean.class);
+
+ if (tty != null) {
+ execStartCmd.withTty(tty);
+ }
+
+ return execStartCmd;
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/DockerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/DockerProducer.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/DockerProducer.java
index a76df1c..e76cee0 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/DockerProducer.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/producer/DockerProducer.java
@@ -16,32 +16,24 @@
*/
package org.apache.camel.component.docker.producer;
-import java.io.File;
import java.io.InputStream;
import com.github.dockerjava.api.DockerClient;
-import com.github.dockerjava.api.command.AttachContainerCmd;
import com.github.dockerjava.api.command.AuthCmd;
-import com.github.dockerjava.api.command.BuildImageCmd;
import com.github.dockerjava.api.command.CommitCmd;
import com.github.dockerjava.api.command.ContainerDiffCmd;
import com.github.dockerjava.api.command.CopyFileFromContainerCmd;
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.command.CreateImageCmd;
-import com.github.dockerjava.api.command.DockerCmd;
import com.github.dockerjava.api.command.ExecCreateCmd;
-import com.github.dockerjava.api.command.ExecStartCmd;
import com.github.dockerjava.api.command.InfoCmd;
import com.github.dockerjava.api.command.InspectContainerCmd;
import com.github.dockerjava.api.command.InspectImageCmd;
import com.github.dockerjava.api.command.KillContainerCmd;
import com.github.dockerjava.api.command.ListContainersCmd;
import com.github.dockerjava.api.command.ListImagesCmd;
-import com.github.dockerjava.api.command.LogContainerCmd;
import com.github.dockerjava.api.command.PauseContainerCmd;
import com.github.dockerjava.api.command.PingCmd;
-import com.github.dockerjava.api.command.PullImageCmd;
-import com.github.dockerjava.api.command.PushImageCmd;
import com.github.dockerjava.api.command.RemoveContainerCmd;
import com.github.dockerjava.api.command.RemoveImageCmd;
import com.github.dockerjava.api.command.RestartContainerCmd;
@@ -52,7 +44,6 @@ import com.github.dockerjava.api.command.TagImageCmd;
import com.github.dockerjava.api.command.TopContainerCmd;
import com.github.dockerjava.api.command.UnpauseContainerCmd;
import com.github.dockerjava.api.command.VersionCmd;
-import com.github.dockerjava.api.command.WaitContainerCmd;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.Capability;
import com.github.dockerjava.api.model.ExposedPort;
@@ -61,7 +52,6 @@ import com.github.dockerjava.api.model.HostConfig;
import com.github.dockerjava.api.model.Volume;
import com.github.dockerjava.api.model.Volumes;
import com.github.dockerjava.api.model.VolumesFrom;
-
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.docker.DockerClientFactory;
@@ -88,135 +78,105 @@ public class DockerProducer extends DefaultProducer {
public DockerProducer(DockerEndpoint endpoint) {
super(endpoint);
this.configuration = endpoint.getConfiguration();
- this.component = (DockerComponent) endpoint.getComponent();
+ this.component = (DockerComponent)endpoint.getComponent();
}
public void process(Exchange exchange) throws Exception {
- DockerCmd<?> dockerCmd = null;
-
Message message = exchange.getIn();
DockerClient client = DockerClientFactory.getDockerClient(component, configuration, message);
DockerOperation operation = configuration.getOperation();
+ Object result = null;
+
switch (operation) {
/** General **/
case AUTH:
- dockerCmd = executeAuthRequest(client, message);
+ result = executeAuthRequest(client, message).exec();
break;
case INFO:
- dockerCmd = executeInfoRequest(client, message);
+ result = executeInfoRequest(client, message).exec();
break;
case PING:
- dockerCmd = executePingRequest(client, message);
+ result = executePingRequest(client, message).exec();
break;
case VERSION:
- dockerCmd = executeVersionRequest(client, message);
- break;
-
- /** Images **/
- case BUILD_IMAGE:
- dockerCmd = executeBuildImageRequest(client, message);
+ result = executeVersionRequest(client, message).exec();
break;
case CREATE_IMAGE:
- dockerCmd = executeCreateImageRequest(client, message);
+ result = executeCreateImageRequest(client, message).exec();
break;
case INSPECT_IMAGE:
- dockerCmd = executeInspectImageRequest(client, message);
+ result = executeInspectImageRequest(client, message).exec();
break;
case LIST_IMAGES:
- dockerCmd = executeListImagesRequest(client, message);
- break;
- case PULL_IMAGE:
- dockerCmd = executePullImageRequest(client, message);
- break;
- case PUSH_IMAGE:
- dockerCmd = executePushImageRequest(client, message);
+ result = executeListImagesRequest(client, message).exec();
break;
case REMOVE_IMAGE:
- dockerCmd = executeRemoveImageRequest(client, message);
+ result = executeRemoveImageRequest(client, message).exec();
break;
case SEARCH_IMAGES:
- dockerCmd = executeSearchImageRequest(client, message);
+ result = executeSearchImageRequest(client, message).exec();
break;
case TAG_IMAGE:
- dockerCmd = executeTagImageRequest(client, message);
- break;
-
- /** Containers **/
- case ATTACH_CONTAINER:
- dockerCmd = executeAttachContainerRequest(client, message);
+ result = executeTagImageRequest(client, message).exec();
break;
case COMMIT_CONTAINER:
- dockerCmd = executeCommitContainerRequest(client, message);
+ result = executeCommitContainerRequest(client, message).exec();
break;
case COPY_FILE_CONTAINER:
- dockerCmd = executeCopyFileContainerRequest(client, message);
+ result = executeCopyFileContainerRequest(client, message).exec();
break;
case CREATE_CONTAINER:
- dockerCmd = executeCreateContainerRequest(client, message);
+ result = executeCreateContainerRequest(client, message).exec();
break;
case DIFF_CONTAINER:
- dockerCmd = executeDiffContainerRequest(client, message);
+ result = executeDiffContainerRequest(client, message).exec();
break;
case INSPECT_CONTAINER:
- dockerCmd = executeInspectContainerRequest(client, message);
+ result = executeInspectContainerRequest(client, message).exec();
break;
case LIST_CONTAINERS:
- dockerCmd = executeListContainersRequest(client, message);
- break;
- case LOG_CONTAINER:
- dockerCmd = executeLogContainerRequest(client, message);
+ result = executeListContainersRequest(client, message).exec();
break;
case KILL_CONTAINER:
- dockerCmd = executeKillContainerRequest(client, message);
+ result = executeKillContainerRequest(client, message).exec();
break;
case PAUSE_CONTAINER:
- dockerCmd = executePauseContainerRequest(client, message);
+ result = executePauseContainerRequest(client, message).exec();
break;
case REMOVE_CONTAINER:
- dockerCmd = executeRemoveContainerRequest(client, message);
+ result = executeRemoveContainerRequest(client, message).exec();
break;
case RESTART_CONTAINER:
- dockerCmd = executeRestartContainerRequest(client, message);
+ result = executeRestartContainerRequest(client, message).exec();
break;
case START_CONTAINER:
- dockerCmd = executeStartContainerRequest(client, message);
+ result = executeStartContainerRequest(client, message).exec();
break;
case STOP_CONTAINER:
- dockerCmd = executeStopContainerRequest(client, message);
+ result = executeStopContainerRequest(client, message).exec();
break;
case TOP_CONTAINER:
- dockerCmd = executeTopContainerRequest(client, message);
+ result = executeTopContainerRequest(client, message).exec();
break;
case UNPAUSE_CONTAINER:
- dockerCmd = executeUnpauseContainerRequest(client, message);
- break;
- case WAIT_CONTAINER:
- dockerCmd = executeWaitContainerRequest(client, message);
+ result = executeUnpauseContainerRequest(client, message).exec();
break;
-
- /** Exec **/
case EXEC_CREATE:
- dockerCmd = executeExecCreateRequest(client, message);
- break;
- case EXEC_START:
- dockerCmd = executeExecStartRequest(client, message);
+ result = executeExecCreateRequest(client, message).exec();
break;
default:
throw new DockerException("Invalid operation: " + operation);
}
- Object result = dockerCmd.exec();
-
// If request included a response, set as body
if (result != null) {
exchange.getIn().setBody(result);
}
-
}
/*********************
@@ -301,59 +261,6 @@ public class DockerProducer extends DefaultProducer {
********************/
/**
- * Produces a build image request
- *
- * @param client
- * @param message
- * @return
- * @throws DockerException
- */
- private BuildImageCmd executeBuildImageRequest(DockerClient client, Message message) throws DockerException {
-
- LOGGER.debug("Executing Docker Build Image Request");
-
- Object body = message.getBody();
-
- BuildImageCmd buildImageCmd;
-
- if (body != null && body instanceof InputStream) {
- buildImageCmd = client.buildImageCmd((InputStream) body);
- } else if (body != null && body instanceof File) {
- buildImageCmd = client.buildImageCmd((File) body);
- } else {
- throw new DockerException("Unable to location source Image");
- }
-
- Boolean noCache = DockerHelper.getProperty(DockerConstants.DOCKER_NO_CACHE, configuration, message, Boolean.class);
-
- if (noCache != null) {
- buildImageCmd.withNoCache(noCache);
- }
-
- Boolean quiet = DockerHelper.getProperty(DockerConstants.DOCKER_QUIET, configuration, message, Boolean.class);
-
- if (quiet != null) {
- buildImageCmd.withQuiet(quiet);
- }
-
- Boolean remove = DockerHelper.getProperty(DockerConstants.DOCKER_REMOVE, configuration, message, Boolean.class);
-
- if (remove != null) {
- buildImageCmd.withRemove(remove);
- }
-
- String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
-
- if (tag != null) {
- buildImageCmd.withTag(tag);
- }
-
- return buildImageCmd;
-
- }
-
-
- /**
* Performs a create image request
*
* @param client
@@ -399,7 +306,6 @@ public class DockerProducer extends DefaultProducer {
}
-
/**
* Performs a list images request
*
@@ -416,7 +322,7 @@ public class DockerProducer extends DefaultProducer {
String filter = DockerHelper.getProperty(DockerConstants.DOCKER_FILTER, configuration, message, String.class);
if (filter != null) {
- listImagesCmd.withFilters(filter);
+ listImagesCmd.withLabelFilter(filter);
}
Boolean showAll = DockerHelper.getProperty(DockerConstants.DOCKER_SHOW_ALL, configuration, message, Boolean.class);
@@ -429,78 +335,6 @@ public class DockerProducer extends DefaultProducer {
}
-
- /**
- * Produces a pull image request
- *
- * @param client
- * @param message
- * @return
- */
- private PullImageCmd executePullImageRequest(DockerClient client, Message message) {
-
- LOGGER.debug("Executing Docker Pull Image Request");
-
- String repository = DockerHelper.getProperty(DockerConstants.DOCKER_REPOSITORY, configuration, message, String.class);
-
- ObjectHelper.notNull(repository, "Repository must be specified");
-
- PullImageCmd pullImageCmd = client.pullImageCmd(repository);
-
- String registry = DockerHelper.getProperty(DockerConstants.DOCKER_REGISTRY, configuration, message, String.class);
- if (registry != null) {
- pullImageCmd.withRegistry(registry);
- }
-
- String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
- if (tag != null) {
- pullImageCmd.withTag(tag);
- }
-
- AuthConfig authConfig = client.authConfig();
-
- if (authConfig != null) {
- pullImageCmd.withAuthConfig(authConfig);
- }
-
- return pullImageCmd;
-
- }
-
-
- /**
- * Produces a push image request
- *
- * @param client
- * @param message
- * @return
- */
- private PushImageCmd executePushImageRequest(DockerClient client, Message message) {
-
- LOGGER.debug("Executing Docker Push Image Request");
-
- String name = DockerHelper.getProperty(DockerConstants.DOCKER_NAME, configuration, message, String.class);
-
- ObjectHelper.notNull(name, "Image name must be specified");
-
- PushImageCmd pushImageCmd = client.pushImageCmd(name);
-
- String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
-
- if (tag != null) {
- pushImageCmd.withTag(tag);
- }
-
- AuthConfig authConfig = client.authConfig();
-
- if (authConfig != null) {
- pushImageCmd.withAuthConfig(authConfig);
- }
-
- return pushImageCmd;
-
- }
-
/**
* Produces a remove image request
*
@@ -521,7 +355,7 @@ public class DockerProducer extends DefaultProducer {
Boolean force = DockerHelper.getProperty(DockerConstants.DOCKER_FORCE, configuration, message, Boolean.class);
if (force != null) {
- removeImagesCmd.withForce();
+ removeImagesCmd.withForce(force);
}
Boolean noPrune = DockerHelper.getProperty(DockerConstants.DOCKER_NO_PRUNE, configuration, message, Boolean.class);
@@ -534,7 +368,6 @@ public class DockerProducer extends DefaultProducer {
}
-
/**
* Produces a search image request
*
@@ -556,7 +389,6 @@ public class DockerProducer extends DefaultProducer {
}
-
/**
* Produces a tag image request
*
@@ -590,64 +422,11 @@ public class DockerProducer extends DefaultProducer {
}
-
/*********************
* Container Requests
********************/
/**
- * Produce a attach container request
- *
- * @param client
- * @param message
- * @return
- */
- private AttachContainerCmd executeAttachContainerRequest(DockerClient client, Message message) {
-
- LOGGER.debug("Executing Docker Attach Container Request");
-
- String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class);
-
- ObjectHelper.notNull(containerId, "Container ID must be specified");
-
- AttachContainerCmd attachContainerCmd = client.attachContainerCmd(containerId);
-
- Boolean followStream = DockerHelper.getProperty(DockerConstants.DOCKER_FOLLOW_STREAM, configuration, message, Boolean.class);
-
- if (followStream != null) {
- attachContainerCmd.withFollowStream(followStream);
- }
-
- Boolean logs = DockerHelper.getProperty(DockerConstants.DOCKER_LOGS, configuration, message, Boolean.class);
-
- if (logs != null) {
- attachContainerCmd.withLogs(logs);
- }
-
- Boolean stdErr = DockerHelper.getProperty(DockerConstants.DOCKER_STD_ERR, configuration, message, Boolean.class);
-
- if (stdErr != null) {
- attachContainerCmd.withStdErr(stdErr);
- }
-
- Boolean stdOut = DockerHelper.getProperty(DockerConstants.DOCKER_STD_OUT, configuration, message, Boolean.class);
-
- if (stdOut != null) {
- attachContainerCmd.withStdOut(stdOut);
- }
-
-
- Boolean timestamps = DockerHelper.getProperty(DockerConstants.DOCKER_TIMESTAMPS, configuration, message, Boolean.class);
-
- if (timestamps != null) {
- attachContainerCmd.withTimestamps(timestamps);
- }
-
- return attachContainerCmd;
-
- }
-
- /**
* Produces a commit container request
*
* @param client
@@ -901,7 +680,7 @@ public class DockerProducer extends DefaultProducer {
if (dns != null) {
createContainerCmd.withDns(dns);
}
-
+
String domainName = DockerHelper.getProperty(DockerConstants.DOCKER_DOMAIN_NAME, configuration, message, String.class);
if (domainName != null) {
@@ -941,7 +720,7 @@ public class DockerProducer extends DefaultProducer {
Long memoryLimit = DockerHelper.getProperty(DockerConstants.DOCKER_MEMORY_LIMIT, configuration, message, Long.class);
if (memoryLimit != null) {
- createContainerCmd.withMemoryLimit(memoryLimit);
+ createContainerCmd.withMemory(memoryLimit);
}
Long memorySwap = DockerHelper.getProperty(DockerConstants.DOCKER_MEMORY_SWAP, configuration, message, Long.class);
@@ -1120,7 +899,6 @@ public class DockerProducer extends DefaultProducer {
listContainersCmd.withShowSize(showSize);
}
-
String since = DockerHelper.getProperty(DockerConstants.DOCKER_SINCE, configuration, message, String.class);
if (since != null) {
@@ -1132,63 +910,6 @@ public class DockerProducer extends DefaultProducer {
}
/**
- * Produce a log container request
- *
- * @param client
- * @param message
- * @return
- */
- private LogContainerCmd executeLogContainerRequest(DockerClient client, Message message) {
-
- LOGGER.debug("Executing Docker Log Container Request");
-
- String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class);
-
- ObjectHelper.notNull(containerId, "Container ID must be specified");
-
- LogContainerCmd logContainerCmd = client.logContainerCmd(containerId);
-
- Boolean followStream = DockerHelper.getProperty(DockerConstants.DOCKER_FOLLOW_STREAM, configuration, message, Boolean.class);
-
- if (followStream != null) {
- logContainerCmd.withFollowStream(followStream);
- }
-
- Boolean stdErr = DockerHelper.getProperty(DockerConstants.DOCKER_STD_ERR, configuration, message, Boolean.class);
-
- if (stdErr != null) {
- logContainerCmd.withStdErr(stdErr);
- }
-
- Boolean stdOut = DockerHelper.getProperty(DockerConstants.DOCKER_STD_OUT, configuration, message, Boolean.class);
-
- if (stdOut != null) {
- logContainerCmd.withStdOut(stdOut);
- }
-
- Integer tail = DockerHelper.getProperty(DockerConstants.DOCKER_TAIL, configuration, message, Integer.class);
-
- if (tail != null) {
- logContainerCmd.withTail(tail);
- }
-
- Boolean tailAll = DockerHelper.getProperty(DockerConstants.DOCKER_TAIL_ALL, configuration, message, Boolean.class);
-
- if (tailAll != null && tailAll) {
- logContainerCmd.withTailAll();
- }
-
- Boolean timestamps = DockerHelper.getProperty(DockerConstants.DOCKER_TIMESTAMPS, configuration, message, Boolean.class);
-
- if (timestamps != null) {
- logContainerCmd.withTimestamps(timestamps);
- }
-
- return logContainerCmd;
-
- }
-
- /**
* Produces a pause container request
*
* @param client
@@ -1362,34 +1083,10 @@ public class DockerProducer extends DefaultProducer {
}
-
- /**
- * Produce a wait container request
- *
- * @param client
- * @param message
- * @return
- */
- private WaitContainerCmd executeWaitContainerRequest(DockerClient client, Message message) {
-
- LOGGER.debug("Executing Docker Wait Container Request");
-
- String containerId = DockerHelper.getProperty(DockerConstants.DOCKER_CONTAINER_ID, configuration, message, String.class);
-
- ObjectHelper.notNull(containerId, "Container ID must be specified");
-
- WaitContainerCmd waitContainerCmd = client.waitContainerCmd(containerId);
-
- return waitContainerCmd;
-
- }
-
-
/*********************
* Exec Requests
********************/
-
/**
* Produces a exec create request
*
@@ -1441,39 +1138,6 @@ public class DockerProducer extends DefaultProducer {
}
- /**
- * Produces a exec start request
- *
- * @param client
- * @param message
- * @return
- */
- private ExecStartCmd executeExecStartRequest(DockerClient client, Message message) {
-
- LOGGER.debug("Executing Docker Exec Create Request");
-
- String execId = DockerHelper.getProperty(DockerConstants.DOCKER_EXEC_ID, configuration, message, String.class);
-
- ObjectHelper.notNull(execId, "Exec ID must be specified");
-
- ExecStartCmd execStartCmd = client.execStartCmd(execId);
-
- Boolean detach = DockerHelper.getProperty(DockerConstants.DOCKER_DETACH, configuration, message, Boolean.class);
-
- if (detach != null) {
- execStartCmd.withDetach(detach);
- }
-
- Boolean tty = DockerHelper.getProperty(DockerConstants.DOCKER_TTY, configuration, message, Boolean.class);
-
- if (tty != null) {
- execStartCmd.withTty(tty);
- }
-
- return execStartCmd;
-
- }
-
@Override
protected void doStop() throws Exception {
super.doStop();
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerEventsConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerEventsConsumerTest.java b/components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerEventsConsumerTest.java
deleted file mode 100644
index 314a025..0000000
--- a/components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerEventsConsumerTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.docker;
-
-import java.util.concurrent.TimeUnit;
-
-import com.github.dockerjava.api.DockerClient;
-import com.github.dockerjava.api.command.EventCallback;
-import com.github.dockerjava.api.command.EventsCmd;
-import com.github.dockerjava.api.model.Event;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.docker.util.DockerTestUtils;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Matchers;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-/**
- * Consumer test for events on Docker Platform
- */
-@RunWith(PowerMockRunner.class)
-public class DockerEventsConsumerTest extends CamelTestSupport {
-
- private String host = "localhost";
- private Integer port = 2375;
- private EventCallback callback;
-
- private DockerConfiguration dockerConfiguration;
-
- @Mock
- private EventsCmd eventsCmd;
-
- @Mock
- private DockerClient dockerClient;
-
- public void setupMocks() {
- Mockito.when(dockerClient.eventsCmd(Matchers.any(EventCallback.class))).thenAnswer(new Answer<EventsCmd>() {
- public EventsCmd answer(InvocationOnMock invocation) {
- Object[] args = invocation.getArguments();
- callback = (EventCallback)args[0];
- return eventsCmd;
- }
- });
-
-
- }
-
- @Test
- public void testEvent() throws Exception {
-
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(1);
-
- callback.onEvent(new Event());
-
- assertMockEndpointsSatisfied(10, TimeUnit.SECONDS);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() {
- from("docker://events?host=" + host + "&port=" + port)
- .log("${body}")
- .to("mock:result");
- }
- };
- }
-
- @Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext camelContext = super.createCamelContext();
- dockerConfiguration = new DockerConfiguration();
- dockerConfiguration.setParameters(DockerTestUtils.getDefaultParameters(host, port, dockerConfiguration));
-
- DockerComponent dockerComponent = new DockerComponent(dockerConfiguration);
- dockerComponent.setClient(DockerTestUtils.getClientProfile(host, port, dockerConfiguration), dockerClient);
- camelContext.addComponent("docker", dockerComponent);
-
- setupMocks();
-
- return camelContext;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9304c53/components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerStatsConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerStatsConsumerTest.java b/components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerStatsConsumerTest.java
deleted file mode 100644
index 9eb1a94..0000000
--- a/components/camel-docker/src/test/java/org/apache/camel/component/docker/DockerStatsConsumerTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.docker;
-
-import java.util.concurrent.TimeUnit;
-
-import com.github.dockerjava.api.DockerClient;
-import com.github.dockerjava.api.command.StatsCallback;
-import com.github.dockerjava.api.command.StatsCmd;
-import com.github.dockerjava.api.model.Statistics;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.docker.util.DockerTestUtils;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Matchers;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-
-/**
- * Consumer test for statistics on Docker Platform
- */
-@RunWith(PowerMockRunner.class)
-public class DockerStatsConsumerTest extends CamelTestSupport {
-
- private String host = "localhost";
- private Integer port = 2375;
- private String containerId = "470b9b823e6c";
- private StatsCallback callback;
-
- private DockerConfiguration dockerConfiguration;
-
- @Mock
- private StatsCmd statsCmd;
-
- @Mock
- private DockerClient dockerClient;
-
- public void setupMocks() {
- Mockito.when(dockerClient.statsCmd(Matchers.any(StatsCallback.class))).thenAnswer(new Answer<StatsCmd>() {
- public StatsCmd answer(InvocationOnMock invocation) {
- Object[] args = invocation.getArguments();
- callback = (StatsCallback)args[0];
- return statsCmd;
- }
- });
-
-
- }
-
- @Test
- public void testStats() throws Exception {
-
- MockEndpoint mock = getMockEndpoint("mock:result");
- mock.expectedMinimumMessageCount(1);
-
- callback.onStats(new Statistics());
-
- assertMockEndpointsSatisfied(10, TimeUnit.SECONDS);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() {
- from("docker://stats?host=" + host + "&port=" + port + "&containerId=" + containerId)
- .log("${body}")
- .to("mock:result");
- }
- };
- }
-
- @Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext camelContext = super.createCamelContext();
- dockerConfiguration = new DockerConfiguration();
- dockerConfiguration.setParameters(DockerTestUtils.getDefaultParameters(host, port, dockerConfiguration));
-
- DockerComponent dockerComponent = new DockerComponent(dockerConfiguration);
- dockerComponent.setClient(DockerTestUtils.getClientProfile(host, port, dockerConfiguration), dockerClient);
- camelContext.addComponent("docker", dockerComponent);
-
- setupMocks();
-
- return camelContext;
- }
-
-}