cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [3/3] git commit: updated refs/heads/docker to edd3fca
Date Tue, 25 Mar 2014 19:47:11 GMT
add docker client


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/edd3fcaf
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/edd3fcaf
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/edd3fcaf

Branch: refs/heads/docker
Commit: edd3fcaff6405b599327f84002d1d48769642940
Parents: 2a48050
Author: tuna <ng.tuna@gmail.com>
Authored: Wed Mar 26 02:45:37 2014 +0700
Committer: tuna <ng.tuna@gmail.com>
Committed: Wed Mar 26 02:45:37 2014 +0700

----------------------------------------------------------------------
 docker-java/.gitignore                          |  21 +
 docker-java/LICENSE                             | 202 +++++
 docker-java/README.md                           | 114 +++
 docker-java/pom.xml                             | 292 +++++++
 .../com/google/common/base/Preconditions.java   | 443 +++++++++++
 .../com/kpelykh/docker/client/DockerClient.java | 767 ++++++++++++++++++
 .../kpelykh/docker/client/DockerException.java  |  25 +
 .../docker/client/NotFoundException.java        |  20 +
 .../kpelykh/docker/client/UnixSocketClient.java |  12 +
 .../docker/client/UnixSocketClientHandler.java  | 213 +++++
 .../client/UnixSocketSessionInputBuffer.java    |  23 +
 .../client/UnixSocketSessionOutputBuffer.java   |  17 +
 .../docker/client/model/BoundHostVolumes.java   |  93 +++
 .../kpelykh/docker/client/model/ChangeLog.java  |  33 +
 .../docker/client/model/CommitConfig.java       |  85 ++
 .../kpelykh/docker/client/model/Container.java  | 140 ++++
 .../docker/client/model/ContainerConfig.java    | 282 +++++++
 .../client/model/ContainerCreateResponse.java   |  43 +
 .../client/model/ContainerInspectResponse.java  | 247 ++++++
 .../kpelykh/docker/client/model/CopyConfig.java |  61 ++
 .../docker/client/model/DriverStatus.java       |  31 +
 .../kpelykh/docker/client/model/HostConfig.java | 148 ++++
 .../kpelykh/docker/client/model/IBuilder.java   |   9 +
 .../com/kpelykh/docker/client/model/Image.java  | 116 +++
 .../client/model/ImageCreateResponse.java       |  30 +
 .../client/model/ImageInspectResponse.java      | 150 ++++
 .../com/kpelykh/docker/client/model/Info.java   | 225 ++++++
 .../com/kpelykh/docker/client/model/Port.java   |  52 ++
 .../com/kpelykh/docker/client/model/Ports.java  | 131 +++
 .../kpelykh/docker/client/model/SearchItem.java |  52 ++
 .../kpelykh/docker/client/model/Version.java    |  91 +++
 .../client/utils/CompressArchiveUtil.java       |  59 ++
 .../docker/client/utils/JsonClientFilter.java   |  26 +
 .../docker/client/test/DockerClientTest.java    | 791 +++++++++++++++++++
 docker-java/src/test/resources/logback.xml      |  16 +
 .../src/test/resources/netcat/Dockerfile        |  11 +
 docker-java/src/test/resources/nginx/Dockerfile |  12 +
 .../src/test/resources/testAddFile/Dockerfile   |   9 +
 .../src/test/resources/testAddFile/testrun.sh   |   3 +
 .../src/test/resources/testAddFolder/Dockerfile |  11 +
 .../testAddFolder/folderA/testAddFolder.sh      |   3 +
 .../resources/testImportImageFromTar/empty.tar  | Bin 0 -> 10240 bytes
 pom.xml                                         |   5 +
 43 files changed, 5114 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/.gitignore
----------------------------------------------------------------------
diff --git a/docker-java/.gitignore b/docker-java/.gitignore
new file mode 100644
index 0000000..8613949
--- /dev/null
+++ b/docker-java/.gitignore
@@ -0,0 +1,21 @@
+#Ignore Mac OS X DS Store
+.DS_Store
+
+*~
+*.swp
+.project
+.settings
+.classpath
+
+# Ignore all build/dist directories
+target
+
+# Ignore InteliJ Idea project files
+.idea
+.idea/*
+*.iml
+*.iws
+*.ipr
+
+# Ignore all log files
+*.log

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/LICENSE
----------------------------------------------------------------------
diff --git a/docker-java/LICENSE b/docker-java/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/docker-java/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/README.md
----------------------------------------------------------------------
diff --git a/docker-java/README.md b/docker-java/README.md
new file mode 100644
index 0000000..2dd43ec
--- /dev/null
+++ b/docker-java/README.md
@@ -0,0 +1,114 @@
+# docker-java
+
+Java API client for [Docker](http://docs.docker.io/ "Docker")
+
+Supports a subset of the Docker Client API v1.8, Docker Server version 0.8.1
+
+## Build with Maven
+
+###### Prerequisites:
+
+* Java 1.6+
+* Maven 3.0.5
+* Docker daemon running
+
+Maven will run tests during build process. Tests are using localhost instance of Docker, make sure that
+you have Docker running for tests to work or just turn off tests.
+
+If you don't have Docker running locally, you can skip tests with -DskipTests flag set to true:
+
+    $ mvn clean install -DskipTests=true
+
+
+By default Docker server is using UNIX sockets for communication with the Docker client, however docker-java
+client uses TCP/IP to connect to the Docker server, so you will need to make sure that your Docker server is
+listening on TCP port. To allow Docker server to use TCP add the following line to /etc/default/docker
+
+    DOCKER_OPTS="-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock"
+
+More details setting up docket server can be found in official documentation: http://docs.docker.io/en/latest/use/basics/
+
+Now make sure that docker is up:
+    
+    $ docker -H tcp://127.0.0.1:4243 version
+
+    Client version: 0.8.1
+    Go version (client): go1.2
+    Git commit (client): a1598d1
+    Server version: 0.8.1
+    Git commit (server): a1598d1
+    Go version (server): go1.2
+    Last stable version: 0.8.1
+
+Run build with tests:
+
+    $ mvn clean install
+
+## Docker-Java maven dependency:
+
+    <dependency>
+          <groupId>com.kpelykh</groupId>
+          <artifactId>docker-java</artifactId>
+          <version>0.8.1</version>
+    </dependency>
+
+
+## Example code snippets:
+
+    DockerClient dockerClient = new DockerClient("http://localhost:4243");
+
+###### Get Docker info:
+
+    Info info = dockerClient.info();
+    System.out.print(info);
+    
+###### Search Docker repository:
+
+    List<SearchItem> dockerSearch = dockerClient.search("busybox");
+    System.out.println("Search returned" + dockerSearch.toString());
+      
+###### Create new Docker container, wait for its start and stop it:
+
+    ContainerConfig containerConfig = new ContainerConfig();
+    containerConfig.setImage("busybox");
+    containerConfig.setCmd(new String[] {"touch", "/test"});
+    ContainerCreateResponse container = dockerClient.createContainer(containerConfig);
+
+    dockerClient.startContainer(container.id);
+
+    dockerClient.waitContainer(container.id);
+
+    dockerClient.stopContainer(container.id);
+    
+
+##### Support for UNIX sockets:
+
+    Support for UNIX socket should appear in docker-java pretty soon. I'm working on its integration.
+
+##### Docker Builder:
+
+To use Docker Builder, as described on page http://docs.docker.io/en/latest/use/builder/,
+user dockerClient.build(baseDir), where baseDir is a path to folder containing Dockerfile.
+
+
+    File baseDir = new File("~/kpelykh/docker/netcat");
+
+    ClientResponse response = dockerClient.build(baseDir);
+
+    StringWriter logwriter = new StringWriter();
+
+    try {
+        LineIterator itr = IOUtils.lineIterator(response.getEntityInputStream(), "UTF-8");
+        while (itr.hasNext()) {
+            String line = itr.next();
+            logwriter.write(line);
+            LOG.info(line);
+        }
+    } finally {
+        IOUtils.closeQuietly(response.getEntityInputStream());
+    }
+
+
+
+For additional examples, please look at [DockerClientTest.java](https://github.com/kpelykh/docker-java/blob/master/src/test/java/com/kpelykh/docker/client/test/DockerClientTest.java "DockerClientTest.java")
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/pom.xml
----------------------------------------------------------------------
diff --git a/docker-java/pom.xml b/docker-java/pom.xml
new file mode 100644
index 0000000..03125eb
--- /dev/null
+++ b/docker-java/pom.xml
@@ -0,0 +1,292 @@
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+   <parent>
+    <groupId>org.apache.cloudstack</groupId>
+    <artifactId>cloudstack</artifactId>
+    <version>4.4.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+   </parent>
+
+    <groupId>com.kpelykh</groupId>
+    <artifactId>docker-java</artifactId>
+    <packaging>jar</packaging>
+    <version>0.8.2-SNAPSHOT</version>
+
+    <name>docker-java</name>
+    <url>https://github.com/kpelykh/docker-java</url>
+    <description>Java API Client for Docker</description>
+
+    <scm>
+        <connection>scm:git:git@github.com:kpelykh/docker-java.git</connection>
+        <url>git@github.com:kpelykh/docker-java.git</url>
+        <developerConnection>scm:git:git@github.com:kpelykh/docker-java.git</developerConnection>
+    <tag>HEAD</tag>
+  </scm>
+
+    <developers>
+        <developer>
+            <id>kpelykh</id>
+            <name>Konstantin Pelykh</name>
+            <email>kpelykh@gmail.com</email>
+        </developer>
+    </developers>
+
+    <properties>
+        <skipTests>true</skipTests>
+
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <jdk.debug>true</jdk.debug>
+        <jdk.optimize>false</jdk.optimize>
+        <jdk.source>1.6</jdk.source>
+        <jdk.target>1.6</jdk.target>
+
+        <version.slf4j>1.6.1</version.slf4j>
+
+        <jersey.version>1.18</jersey.version>
+        <jersey-apache-client4.version>1.9</jersey-apache-client4.version>
+
+        <httpclient.version>4.2.5</httpclient.version>
+        <commons-compress.version>1.5</commons-compress.version>
+        <commons-io.version>2.3</commons-io.version>
+        <commons-lang.version>2.6</commons-lang.version>
+        <slf4j-api.version>1.7.5</slf4j-api.version>
+        <jsr305.version>1.3.9</jsr305.version>
+        <jnr.unixsocket.version>0.3</jnr.unixsocket.version>
+
+        <!--test dependencies -->
+        <version.logback>1.0.1</version.logback>
+        <version.testng>5.12.1</version.testng>
+        <hamcrest.library.version>1.3</hamcrest.library.version>
+        <hamcrest.jpa-matchers>1.6</hamcrest.jpa-matchers>
+        <lambdaj.version>2.3.3</lambdaj.version>
+
+
+        <maven-jar-plugin.version>2.2</maven-jar-plugin.version>
+        <maven-compiler-plugin.version>2.3.1</maven-compiler-plugin.version>
+        <maven-release-plugin.version>2.3.1</maven-release-plugin.version>
+        <maven-surefire-plugin.version>2.8.1</maven-surefire-plugin.version>
+        <cobertura-maven-plugin.version>2.5.1</cobertura-maven-plugin.version>
+        <maven-antrun-plugin.version>1.7</maven-antrun-plugin.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-core</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-client</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.jersey</groupId>
+            <artifactId>jersey-json</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.jersey.contribs</groupId>
+            <artifactId>jersey-multipart</artifactId>
+            <version>${jersey.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.sun.jersey.contribs</groupId>
+            <artifactId>jersey-apache-client4</artifactId>
+            <version>${jersey-apache-client4.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>${httpclient.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+            <version>${commons-compress.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>${commons-lang.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>${commons-io.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.github.jnr</groupId>
+            <artifactId>jnr-unixsocket</artifactId>
+            <version>${jnr.unixsocket.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>${slf4j-api.version}</version>
+        </dependency>
+
+        <!-- /// Test /////////////////////////// -->
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-core</artifactId>
+            <version>${version.logback}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>${version.logback}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <version>${version.testng}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-library</artifactId>
+            <version>${hamcrest.library.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.googlecode.lambdaj</groupId>
+            <artifactId>lambdaj</artifactId>
+            <version>${lambdaj.version}</version>
+            <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.hamcrest</groupId>
+                    <artifactId>hamcrest-all</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>org.testinfected.hamcrest-matchers</groupId>
+            <artifactId>jpa-matchers</artifactId>
+            <version>${hamcrest.jpa-matchers}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+
+    <build>
+	  <pluginManagement>
+        <plugins>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-release-plugin</artifactId>
+                <version>${maven-release-plugin.version}</version>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>${maven-compiler-plugin.version}</version>
+                <configuration>
+                    <source>${jdk.source}</source>
+                    <target>${jdk.target}</target>
+                    <encoding>ISO-8859-1</encoding>
+                    <debug>${jdk.debug}</debug>
+                    <optimize>${jdk.optimize}</optimize>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>${maven-jar-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>${maven-surefire-plugin.version}</version>
+                <configuration>
+                    <skipTests>${skipTests}</skipTests>
+                </configuration>
+            </plugin>
+
+
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>cobertura-maven-plugin</artifactId>
+                <version>${cobertura-maven-plugin.version}</version>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <version>${maven-antrun-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <phase>validate</phase>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                        <configuration>
+                            <tasks>
+                                <echo>*******************************************************************</echo>
+                                <echo>*******************************************************************</echo>
+                                <echo>[project.name] : ${project.name}</echo>
+                                <echo>[project.basedir] : ${project.basedir}</echo>
+                                <echo>[project.version] : ${project.version}</echo>
+                                <echo>[project.artifactId] ${project.artifactId}</echo>
+                                <echo>[project.build.directory] ${project.build.directory}</echo>
+                                <echo>[jdk.source] : ${jdk.source}</echo>
+                                <echo>[jdk.target] : ${jdk.target}</echo>
+                                <echo>[jdk.debug] : ${jdk.debug}</echo>
+                                <echo>[jdk.optimize] : ${jdk.optimize}</echo>
+                                <echo>[source encoding]: ${project.build.sourceEncoding}</echo>
+                                <echo>[M2_HOME] : ${env.M2_HOME}</echo>
+                                <echo>[LocalRepository] : ${settings.localRepository}</echo>
+                                <echo>*******************************************************************</echo>
+                                <echo>*******************************************************************</echo>
+                            </tasks>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+        </plugins>
+      </pluginManagement>
+    </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/src/main/java/com/google/common/base/Preconditions.java
----------------------------------------------------------------------
diff --git a/docker-java/src/main/java/com/google/common/base/Preconditions.java b/docker-java/src/main/java/com/google/common/base/Preconditions.java
new file mode 100644
index 0000000..6a15fb4
--- /dev/null
+++ b/docker-java/src/main/java/com/google/common/base/Preconditions.java
@@ -0,0 +1,443 @@
+/*
+ * Copyright (C) 2007 The Guava Authors
+ *
+ * Licensed 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 com.google.common.base;
+
+
+import java.util.NoSuchElementException;
+
+/**
+ * Simple static methods to be called at the start of your own methods to verify
+ * correct arguments and state. This allows constructs such as
+ * <pre>
+ *     if (count <= 0) {
+ *       throw new IllegalArgumentException("must be positive: " + count);
+ *     }</pre>
+ *
+ * to be replaced with the more compact
+ * <pre>
+ *     checkArgument(count > 0, "must be positive: %s", count);</pre>
+ *
+ * Note that the sense of the expression is inverted; with {@code Preconditions}
+ * you declare what you expect to be <i>true</i>, just as you do with an
+ * <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/assert.html">
+ * {@code assert}</a> or a JUnit {@code assertTrue} call.
+ *
+ * <p><b>Warning:</b> only the {@code "%s"} specifier is recognized as a
+ * placeholder in these messages, not the full range of {@link
+ * String#format(String, Object[])} specifiers.
+ *
+ * <p>Take care not to confuse precondition checking with other similar types
+ * of checks! Precondition exceptions -- including those provided here, but also
+ * {@link IndexOutOfBoundsException}, {@link NoSuchElementException}, {@link
+ * UnsupportedOperationException} and others -- are used to signal that the
+ * <i>calling method</i> has made an error. This tells the caller that it should
+ * not have invoked the method when it did, with the arguments it did, or
+ * perhaps ever. Postcondition or other invariant failures should not throw
+ * these types of exceptions.
+ *
+ * <p>See the Guava User Guide on <a href=
+ * "http://code.google.com/p/guava-libraries/wiki/PreconditionsExplained">
+ * using {@code Preconditions}</a>.
+ *
+ * @author Kevin Bourrillion
+ * @since 2.0 (imported from Google Collections Library)
+ */
+public final class Preconditions {
+    private Preconditions() {}
+
+    /**
+     * Ensures the truth of an expression involving one or more parameters to the
+     * calling method.
+     *
+     * @param expression a boolean expression
+     * @throws IllegalArgumentException if {@code expression} is false
+     */
+    public static void checkArgument(boolean expression) {
+        if (!expression) {
+            throw new IllegalArgumentException();
+        }
+    }
+
+    /**
+     * Ensures the truth of an expression involving one or more parameters to the
+     * calling method.
+     *
+     * @param expression a boolean expression
+     * @param errorMessage the exception message to use if the check fails; will
+     *     be converted to a string using {@link String#valueOf(Object)}
+     * @throws IllegalArgumentException if {@code expression} is false
+     */
+    public static void checkArgument(
+            boolean expression, Object errorMessage) {
+        if (!expression) {
+            throw new IllegalArgumentException(String.valueOf(errorMessage));
+        }
+    }
+
+    /**
+     * Ensures the truth of an expression involving one or more parameters to the
+     * calling method.
+     *
+     * @param expression a boolean expression
+     * @param errorMessageTemplate a template for the exception message should the
+     *     check fail. The message is formed by replacing each {@code %s}
+     *     placeholder in the template with an argument. These are matched by
+     *     position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc.
+     *     Unmatched arguments will be appended to the formatted message in square
+     *     braces. Unmatched placeholders will be left as-is.
+     * @param errorMessageArgs the arguments to be substituted into the message
+     *     template. Arguments are converted to strings using
+     *     {@link String#valueOf(Object)}.
+     * @throws IllegalArgumentException if {@code expression} is false
+     * @throws NullPointerException if the check fails and either {@code
+     *     errorMessageTemplate} or {@code errorMessageArgs} is null (don't let
+     *     this happen)
+     */
+    public static void checkArgument(boolean expression,
+                                     String errorMessageTemplate,
+                                     Object... errorMessageArgs) {
+        if (!expression) {
+            throw new IllegalArgumentException(
+                    format(errorMessageTemplate, errorMessageArgs));
+        }
+    }
+
+    /**
+     * Ensures the truth of an expression involving the state of the calling
+     * instance, but not involving any parameters to the calling method.
+     *
+     * @param expression a boolean expression
+     * @throws IllegalStateException if {@code expression} is false
+     */
+    public static void checkState(boolean expression) {
+        if (!expression) {
+            throw new IllegalStateException();
+        }
+    }
+
+    /**
+     * Ensures the truth of an expression involving the state of the calling
+     * instance, but not involving any parameters to the calling method.
+     *
+     * @param expression a boolean expression
+     * @param errorMessage the exception message to use if the check fails; will
+     *     be converted to a string using {@link String#valueOf(Object)}
+     * @throws IllegalStateException if {@code expression} is false
+     */
+    public static void checkState(
+            boolean expression, Object errorMessage) {
+        if (!expression) {
+            throw new IllegalStateException(String.valueOf(errorMessage));
+        }
+    }
+
+    /**
+     * Ensures the truth of an expression involving the state of the calling
+     * instance, but not involving any parameters to the calling method.
+     *
+     * @param expression a boolean expression
+     * @param errorMessageTemplate a template for the exception message should the
+     *     check fail. The message is formed by replacing each {@code %s}
+     *     placeholder in the template with an argument. These are matched by
+     *     position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc.
+     *     Unmatched arguments will be appended to the formatted message in square
+     *     braces. Unmatched placeholders will be left as-is.
+     * @param errorMessageArgs the arguments to be substituted into the message
+     *     template. Arguments are converted to strings using
+     *     {@link String#valueOf(Object)}.
+     * @throws IllegalStateException if {@code expression} is false
+     * @throws NullPointerException if the check fails and either {@code
+     *     errorMessageTemplate} or {@code errorMessageArgs} is null (don't let
+     *     this happen)
+     */
+    public static void checkState(boolean expression,
+                                  String errorMessageTemplate,
+                                  Object... errorMessageArgs) {
+        if (!expression) {
+            throw new IllegalStateException(
+                    format(errorMessageTemplate, errorMessageArgs));
+        }
+    }
+
+    /**
+     * Ensures that an object reference passed as a parameter to the calling
+     * method is not null.
+     *
+     * @param reference an object reference
+     * @return the non-null reference that was validated
+     * @throws NullPointerException if {@code reference} is null
+     */
+    public static <T> T checkNotNull(T reference) {
+        if (reference == null) {
+            throw new NullPointerException();
+        }
+        return reference;
+    }
+
+    /**
+     * Ensures that an object reference passed as a parameter to the calling
+     * method is not null.
+     *
+     * @param reference an object reference
+     * @param errorMessage the exception message to use if the check fails; will
+     *     be converted to a string using {@link String#valueOf(Object)}
+     * @return the non-null reference that was validated
+     * @throws NullPointerException if {@code reference} is null
+     */
+    public static <T> T checkNotNull(T reference, Object errorMessage) {
+        if (reference == null) {
+            throw new NullPointerException(String.valueOf(errorMessage));
+        }
+        return reference;
+    }
+
+    /**
+     * Ensures that an object reference passed as a parameter to the calling
+     * method is not null.
+     *
+     * @param reference an object reference
+     * @param errorMessageTemplate a template for the exception message should the
+     *     check fail. The message is formed by replacing each {@code %s}
+     *     placeholder in the template with an argument. These are matched by
+     *     position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc.
+     *     Unmatched arguments will be appended to the formatted message in square
+     *     braces. Unmatched placeholders will be left as-is.
+     * @param errorMessageArgs the arguments to be substituted into the message
+     *     template. Arguments are converted to strings using
+     *     {@link String#valueOf(Object)}.
+     * @return the non-null reference that was validated
+     * @throws NullPointerException if {@code reference} is null
+     */
+    public static <T> T checkNotNull(T reference,
+                                     String errorMessageTemplate,
+                                     Object... errorMessageArgs) {
+        if (reference == null) {
+            // If either of these parameters is null, the right thing happens anyway
+            throw new NullPointerException(
+                    format(errorMessageTemplate, errorMessageArgs));
+        }
+        return reference;
+    }
+
+  /*
+   * All recent hotspots (as of 2009) *really* like to have the natural code
+   *
+   * if (guardExpression) {
+   *    throw new BadException(messageExpression);
+   * }
+   *
+   * refactored so that messageExpression is moved to a separate
+   * String-returning method.
+   *
+   * if (guardExpression) {
+   *    throw new BadException(badMsg(...));
+   * }
+   *
+   * The alternative natural refactorings into void or Exception-returning
+   * methods are much slower.  This is a big deal - we're talking factors of
+   * 2-8 in microbenchmarks, not just 10-20%.  (This is a hotspot optimizer
+   * bug, which should be fixed, but that's a separate, big project).
+   *
+   * The coding pattern above is heavily used in java.util, e.g. in ArrayList.
+   * There is a RangeCheckMicroBenchmark in the JDK that was used to test this.
+   *
+   * But the methods in this class want to throw different exceptions,
+   * depending on the args, so it appears that this pattern is not directly
+   * applicable.  But we can use the ridiculous, devious trick of throwing an
+   * exception in the middle of the construction of another exception.
+   * Hotspot is fine with that.
+   */
+
+    /**
+     * Ensures that {@code index} specifies a valid <i>element</i> in an array,
+     * list or string of size {@code size}. An element index may range from zero,
+     * inclusive, to {@code size}, exclusive.
+     *
+     * @param index a user-supplied index identifying an element of an array, list
+     *     or string
+     * @param size the size of that array, list or string
+     * @return the value of {@code index}
+     * @throws IndexOutOfBoundsException if {@code index} is negative or is not
+     *     less than {@code size}
+     * @throws IllegalArgumentException if {@code size} is negative
+     */
+    public static int checkElementIndex(int index, int size) {
+        return checkElementIndex(index, size, "index");
+    }
+
+    /**
+     * Ensures that {@code index} specifies a valid <i>element</i> in an array,
+     * list or string of size {@code size}. An element index may range from zero,
+     * inclusive, to {@code size}, exclusive.
+     *
+     * @param index a user-supplied index identifying an element of an array, list
+     *     or string
+     * @param size the size of that array, list or string
+     * @param desc the text to use to describe this index in an error message
+     * @return the value of {@code index}
+     * @throws IndexOutOfBoundsException if {@code index} is negative or is not
+     *     less than {@code size}
+     * @throws IllegalArgumentException if {@code size} is negative
+     */
+    public static int checkElementIndex(
+            int index, int size, String desc) {
+        // Carefully optimized for execution by hotspot (explanatory comment above)
+        if (index < 0 || index >= size) {
+            throw new IndexOutOfBoundsException(badElementIndex(index, size, desc));
+        }
+        return index;
+    }
+
+    private static String badElementIndex(int index, int size, String desc) {
+        if (index < 0) {
+            return format("%s (%s) must not be negative", desc, index);
+        } else if (size < 0) {
+            throw new IllegalArgumentException("negative size: " + size);
+        } else { // index >= size
+            return format("%s (%s) must be less than size (%s)", desc, index, size);
+        }
+    }
+
+    /**
+     * Ensures that {@code index} specifies a valid <i>position</i> in an array,
+     * list or string of size {@code size}. A position index may range from zero
+     * to {@code size}, inclusive.
+     *
+     * @param index a user-supplied index identifying a position in an array, list
+     *     or string
+     * @param size the size of that array, list or string
+     * @return the value of {@code index}
+     * @throws IndexOutOfBoundsException if {@code index} is negative or is
+     *     greater than {@code size}
+     * @throws IllegalArgumentException if {@code size} is negative
+     */
+    public static int checkPositionIndex(int index, int size) {
+        return checkPositionIndex(index, size, "index");
+    }
+
+    /**
+     * Ensures that {@code index} specifies a valid <i>position</i> in an array,
+     * list or string of size {@code size}. A position index may range from zero
+     * to {@code size}, inclusive.
+     *
+     * @param index a user-supplied index identifying a position in an array, list
+     *     or string
+     * @param size the size of that array, list or string
+     * @param desc the text to use to describe this index in an error message
+     * @return the value of {@code index}
+     * @throws IndexOutOfBoundsException if {@code index} is negative or is
+     *     greater than {@code size}
+     * @throws IllegalArgumentException if {@code size} is negative
+     */
+    public static int checkPositionIndex(
+            int index, int size, String desc) {
+        // Carefully optimized for execution by hotspot (explanatory comment above)
+        if (index < 0 || index > size) {
+            throw new IndexOutOfBoundsException(badPositionIndex(index, size, desc));
+        }
+        return index;
+    }
+
+    private static String badPositionIndex(int index, int size, String desc) {
+        if (index < 0) {
+            return format("%s (%s) must not be negative", desc, index);
+        } else if (size < 0) {
+            throw new IllegalArgumentException("negative size: " + size);
+        } else { // index > size
+            return format("%s (%s) must not be greater than size (%s)",
+                    desc, index, size);
+        }
+    }
+
+    /**
+     * Ensures that {@code start} and {@code end} specify a valid <i>positions</i>
+     * in an array, list or string of size {@code size}, and are in order. A
+     * position index may range from zero to {@code size}, inclusive.
+     *
+     * @param start a user-supplied index identifying a starting position in an
+     *     array, list or string
+     * @param end a user-supplied index identifying a ending position in an array,
+     *     list or string
+     * @param size the size of that array, list or string
+     * @throws IndexOutOfBoundsException if either index is negative or is
+     *     greater than {@code size}, or if {@code end} is less than {@code start}
+     * @throws IllegalArgumentException if {@code size} is negative
+     */
+    public static void checkPositionIndexes(int start, int end, int size) {
+        // Carefully optimized for execution by hotspot (explanatory comment above)
+        if (start < 0 || end < start || end > size) {
+            throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size));
+        }
+    }
+
+    private static String badPositionIndexes(int start, int end, int size) {
+        if (start < 0 || start > size) {
+            return badPositionIndex(start, size, "start index");
+        }
+        if (end < 0 || end > size) {
+            return badPositionIndex(end, size, "end index");
+        }
+        // end < start
+        return format("end index (%s) must not be less than start index (%s)",
+                end, start);
+    }
+
+    /**
+     * Substitutes each {@code %s} in {@code template} with an argument. These
+     * are matched by position - the first {@code %s} gets {@code args[0]}, etc.
+     * If there are more arguments than placeholders, the unmatched arguments will
+     * be appended to the end of the formatted message in square braces.
+     *
+     * @param template a non-null string containing 0 or more {@code %s}
+     *     placeholders.
+     * @param args the arguments to be substituted into the message
+     *     template. Arguments are converted to strings using
+     *     {@link String#valueOf(Object)}. Arguments can be null.
+     */
+    static String format(String template, Object... args) {
+        template = String.valueOf(template); // null -> "null"
+
+        // start substituting the arguments into the '%s' placeholders
+        StringBuilder builder = new StringBuilder(
+                template.length() + 16 * args.length);
+        int templateStart = 0;
+        int i = 0;
+        while (i < args.length) {
+            int placeholderStart = template.indexOf("%s", templateStart);
+            if (placeholderStart == -1) {
+                break;
+            }
+            builder.append(template.substring(templateStart, placeholderStart));
+            builder.append(args[i++]);
+            templateStart = placeholderStart + 2;
+        }
+        builder.append(template.substring(templateStart));
+
+        // if we run out of placeholders, append the extra args in square braces
+        if (i < args.length) {
+            builder.append(" [");
+            builder.append(args[i++]);
+            while (i < args.length) {
+                builder.append(", ");
+                builder.append(args[i++]);
+            }
+            builder.append(']');
+        }
+
+        return builder.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/src/main/java/com/kpelykh/docker/client/DockerClient.java
----------------------------------------------------------------------
diff --git a/docker-java/src/main/java/com/kpelykh/docker/client/DockerClient.java b/docker-java/src/main/java/com/kpelykh/docker/client/DockerClient.java
new file mode 100644
index 0000000..d29d28e
--- /dev/null
+++ b/docker-java/src/main/java/com/kpelykh/docker/client/DockerClient.java
@@ -0,0 +1,767 @@
+package com.kpelykh.docker.client;
+
+import com.google.common.base.Preconditions;
+import com.kpelykh.docker.client.model.*;
+import com.kpelykh.docker.client.utils.CompressArchiveUtil;
+import com.kpelykh.docker.client.utils.JsonClientFilter;
+import com.sun.jersey.api.client.*;
+import com.sun.jersey.api.client.WebResource.Builder;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.client.filter.LoggingFilter;
+import com.sun.jersey.api.json.JSONConfiguration;
+import com.sun.jersey.client.apache4.ApacheHttpClient4;
+import com.sun.jersey.client.apache4.ApacheHttpClient4Handler;
+import com.sun.jersey.core.util.MultivaluedMapImpl;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ *
+ * @author Konstantin Pelykh (kpelykh@gmail.com)
+ *
+ */
+public class DockerClient
+{
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(DockerClient.class);
+
+    private static DockerClient instance;
+    private Client client;
+    private String restEndpointUrl;
+
+    public DockerClient(String serverUrl) {
+        restEndpointUrl = serverUrl + "/v1.8";
+        ClientConfig clientConfig = new DefaultClientConfig();
+        clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
+
+        SchemeRegistry schemeRegistry = new SchemeRegistry();
+        schemeRegistry.register(new Scheme("http", 4243, PlainSocketFactory.getSocketFactory()));
+
+        PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry);
+        // Increase max total connection
+        cm.setMaxTotal(1000);
+        // Increase default max connection per route
+        cm.setDefaultMaxPerRoute(1000);
+
+        HttpClient httpClient = new DefaultHttpClient(cm);
+        client = new ApacheHttpClient4(new ApacheHttpClient4Handler(httpClient, null, false), clientConfig);
+
+        //Experimental support for unix sockets:
+        //client = new UnixSocketClient(clientConfig);
+
+        client.addFilter(new JsonClientFilter());        
+        client.addFilter(new LoggingFilter());
+    }
+
+    /**
+     ** MISC API
+     **
+     **/
+
+    public Info info() throws DockerException {
+        WebResource webResource = client.resource(restEndpointUrl + "/info");
+
+        try {
+            LOGGER.trace("GET: {}", webResource);
+            return webResource.accept(MediaType.APPLICATION_JSON).get(Info.class);
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error.", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+
+    public Version version() throws DockerException {
+        WebResource webResource = client.resource(restEndpointUrl + "/version");
+
+        try {
+            LOGGER.trace("GET: {}", webResource);
+            return webResource.accept(MediaType.APPLICATION_JSON).get(Version.class);
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error.", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+
+    /**
+     ** IMAGE API
+     **
+     **/
+
+    public ClientResponse pull(String repository) throws DockerException {
+        return this.pull(repository, null, null);
+    }
+
+    public ClientResponse pull(String repository, String tag) throws DockerException {
+        return this.pull(repository, tag, null);
+    }
+
+    public ClientResponse pull(String repository, String tag, String registry) throws DockerException {
+        Preconditions.checkNotNull(repository, "Repository was not specified");
+
+        if (StringUtils.countMatches(repository, ":") == 1) {
+            String repositoryTag[] = StringUtils.split(repository);
+            repository = repositoryTag[0];
+            tag = repositoryTag[1];
+
+        }
+
+        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
+        params.add("tag", tag);
+        params.add("fromImage", repository);
+        params.add("registry", registry);
+
+        WebResource webResource = client.resource(restEndpointUrl + "/images/create").queryParams(params);
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            return webResource.accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).post(ClientResponse.class);
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error.", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    /**
+     * Create an image by importing the given stream of a tar file.
+     *
+     * @param repository the repository to import to
+     * @param tag any tag for this image
+     * @param imageStream the InputStream of the tar file
+     * @return an {@link ImageCreateResponse} containing the id of the imported image
+     * @throws DockerException if the import fails for some reason.
+     */
+    public ImageCreateResponse importImage(String repository, String tag, InputStream imageStream) throws DockerException {
+        Preconditions.checkNotNull(repository, "Repository was not specified");
+        Preconditions.checkNotNull(imageStream, "imageStream was not provided");
+
+        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
+        params.add("repo", repository);
+        params.add("tag", tag);
+        params.add("fromSrc","-");
+
+        WebResource webResource = client.resource(restEndpointUrl + "/images/create").queryParams(params);
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            return webResource.accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).post(ImageCreateResponse.class,imageStream);
+
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error.", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    public List<SearchItem> search(String search) throws DockerException {
+        WebResource webResource = client.resource(restEndpointUrl + "/images/search").queryParam("term", search);
+        try {
+            return webResource.accept(MediaType.APPLICATION_JSON).get(new GenericType<List<SearchItem>>() {});
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error.", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+
+    }
+
+    public void removeImage(String imageId) throws DockerException {
+        Preconditions.checkState(!StringUtils.isEmpty(imageId), "Image ID can't be empty");
+
+        try {
+            WebResource webResource = client.resource(restEndpointUrl + "/images/" + imageId);
+            LOGGER.trace("DELETE: {}", webResource);
+            webResource.delete();
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 204) {
+                //no error
+                LOGGER.trace("Successfully removed image " + imageId);
+            } else if (exception.getResponse().getStatus() == 404) {
+                LOGGER.warn("{} no such image", imageId);
+            } else if (exception.getResponse().getStatus() == 409) {
+                throw new DockerException("Conflict");
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error.", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+
+    }
+
+    public void removeImages(List<String> images) throws DockerException {
+        Preconditions.checkNotNull(images, "List of images can't be null");
+
+        for (String imageId : images) {
+            removeImage(imageId);
+        }
+    }
+
+    public String getVizImages() throws DockerException {
+        WebResource webResource = client.resource(restEndpointUrl + "/images/viz");
+
+        try {
+            LOGGER.trace("GET: {}", webResource);
+            String response = webResource.get(String.class);
+            LOGGER.trace("Response: {}", response);
+
+            return response;
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 400) {
+                throw new DockerException("bad parameter");
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+
+    public List<Image> getImages() throws DockerException {
+        return this.getImages(null, false);
+    }
+
+    public List<Image> getImages(boolean allContainers) throws DockerException {
+        return this.getImages(null, allContainers);
+    }
+
+    public List<Image> getImages(String name) throws DockerException {
+        return this.getImages(name, false);
+    }
+
+    public List<Image> getImages(String name, boolean allImages) throws DockerException {
+
+        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
+        params.add("filter", name);
+        params.add("all", allImages ? "1" : "0");
+
+        WebResource webResource = client.resource(restEndpointUrl + "/images/json").queryParams(params);
+
+        try {
+            LOGGER.trace("GET: {}", webResource);
+            List<Image> images = webResource.accept(MediaType.APPLICATION_JSON).get(new GenericType<List<Image>>() {});
+            LOGGER.trace("Response: {}", images);
+            return images;
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 400) {
+                throw new DockerException("bad parameter");
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException();
+            }
+        }
+
+    }
+
+    public ImageInspectResponse inspectImage(String imageId) throws DockerException, NotFoundException {
+
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/images/%s/json", imageId));
+
+        try {
+            LOGGER.trace("GET: {}", webResource);
+            return webResource.accept(MediaType.APPLICATION_JSON).get(ImageInspectResponse.class);
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("No such image %s", imageId));
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    /**
+     ** CONTAINER API
+     **
+     **/
+
+    public List<Container> listContainers(boolean allContainers) {
+        return this.listContainers(allContainers, false, -1, false, null, null);
+    }
+
+    public List<Container> listContainers(boolean allContainers, boolean latest) {
+        return this.listContainers(allContainers, latest, -1, false, null, null);
+    }
+
+    public List<Container> listContainers(boolean allContainers, boolean latest, int limit) {
+        return this.listContainers(allContainers, latest, limit, false, null, null);
+    }
+
+    public List<Container> listContainers(boolean allContainers, boolean latest, int limit, boolean showSize) {
+        return this.listContainers(allContainers, latest, limit, showSize, null, null);
+    }
+
+    public List<Container> listContainers(boolean allContainers, boolean latest, int limit, boolean showSize, String since) {
+        return this.listContainers(allContainers, latest, limit, false, since, null);
+    }
+
+    public List<Container> listContainers(boolean allContainers, boolean latest, int limit, boolean showSize, String since, String before) {
+
+        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
+        params.add("limit", latest ? "1" : String.valueOf(limit));
+        params.add("all", allContainers ? "1" : "0");
+        params.add("since", since);
+        params.add("before", before);
+        params.add("size", showSize ? "1" : "0");
+
+        WebResource webResource = client.resource(restEndpointUrl + "/containers/json").queryParams(params);
+        LOGGER.trace("GET: {}", webResource);
+        List<Container> containers = webResource.accept(MediaType.APPLICATION_JSON).get(new GenericType<List<Container>>() {});
+        LOGGER.trace("Response: {}", containers);
+
+        return containers;
+    }
+
+    public ContainerCreateResponse createContainer(ContainerConfig config) throws DockerException{
+        return createContainer(config, null);
+    }
+
+    public ContainerCreateResponse createContainer(ContainerConfig config,String name) throws DockerException, NotFoundException {
+
+        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
+        if(name != null){
+            params.add("name", name);
+        }
+        WebResource webResource = client.resource(restEndpointUrl + "/containers/create").queryParams(params);
+
+        try {
+            LOGGER.trace("POST: {} ", webResource);
+            return webResource.accept(MediaType.APPLICATION_JSON)
+                    .type(MediaType.APPLICATION_JSON)
+                    .post(ContainerCreateResponse.class, config);
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("%s is an unrecognized image. Please pull the image first.", config.getImage()));
+            } else if (exception.getResponse().getStatus() == 406) {
+                throw new DockerException("impossible to attach (container not running)");
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+
+    }
+
+    public void startContainer(String containerId) throws DockerException {
+        this.startContainer(containerId, null);
+    }
+
+    public void startContainer(String containerId, HostConfig hostConfig) throws DockerException, NotFoundException {
+
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/start", containerId));
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            Builder builder = webResource.accept(MediaType.TEXT_PLAIN);
+            if (hostConfig != null) {
+                builder.type(MediaType.APPLICATION_JSON).post(hostConfig);
+            } else {
+                builder.post((HostConfig) null);
+            }
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("No such container %s", containerId));
+            } else if (exception.getResponse().getStatus() == 204) {
+                //no error
+                LOGGER.trace("Successfully started container {}", containerId);
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    public ContainerInspectResponse inspectContainer(String containerId) throws DockerException, NotFoundException {
+
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/json", containerId));
+
+        try {
+            LOGGER.trace("GET: {}", webResource);
+            return webResource.accept(MediaType.APPLICATION_JSON).get(ContainerInspectResponse.class);
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("No such container %s", containerId));
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+
+    public void removeContainer(String container) throws DockerException {
+        this.removeContainer(container, false);
+    }
+
+    public void removeContainer(String containerId, boolean removeVolumes) throws DockerException {
+        Preconditions.checkState(!StringUtils.isEmpty(containerId), "Container ID can't be empty");
+
+        WebResource webResource = client.resource(restEndpointUrl + "/containers/" + containerId).queryParam("v", removeVolumes ? "1" : "0");
+
+        try {
+            LOGGER.trace("DELETE: {}", webResource);
+            String response = webResource.accept(MediaType.APPLICATION_JSON).delete(String.class);
+            LOGGER.trace("Response: {}", response);
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 204) {
+                //no error
+                LOGGER.trace("Successfully removed container " + containerId);
+            } else if (exception.getResponse().getStatus() == 400) {
+                throw new DockerException("bad parameter");
+            } else if (exception.getResponse().getStatus() == 404) {
+                // should really throw a NotFoundException instead of silently ignoring the problem
+                LOGGER.warn(String.format("%s is an unrecognized container.", containerId));
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+
+    public void removeContainers(List<String> containers, boolean removeVolumes) throws DockerException {
+        Preconditions.checkNotNull(containers, "List of containers can't be null");
+
+        for (String containerId : containers) {
+            removeContainer(containerId, removeVolumes);
+        }
+    }
+
+    public int waitContainer(String containerId) throws DockerException, NotFoundException {
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/wait", containerId));
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            JSONObject jsonObject = webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post(JSONObject.class);
+            return jsonObject.getInt("StatusCode");
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("No such container %s", containerId));
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        } catch (JSONException e) {
+            throw new DockerException(e);
+        }
+    }
+
+
+    public ClientResponse logContainer(String containerId) throws DockerException {
+        return logContainer(containerId, false);
+    }
+
+    public ClientResponse logContainerStream(String containerId) throws DockerException {
+        return logContainer(containerId, true);
+    }
+
+    private ClientResponse logContainer(String containerId, boolean stream) throws DockerException, NotFoundException {
+        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
+        params.add("logs", "1");
+        params.add("stdout", "1");
+        params.add("stderr", "1");
+        if (stream) {
+            params.add("stream", "1"); // this parameter keeps stream open indefinitely
+        }
+
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/attach", containerId))
+                .queryParams(params);
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            return webResource.accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).post(ClientResponse.class, params);
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 400) {
+                throw new DockerException("bad parameter");
+            } else if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("No such container %s", containerId));
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    public ClientResponse copyFile(String containerId, String resource) throws DockerException {
+        CopyConfig copyConfig = new CopyConfig();
+        copyConfig.setResource(resource);
+
+        WebResource webResource =
+            client.resource(restEndpointUrl + String.format("/containers/%s/copy", containerId));
+
+        try {
+            LOGGER.trace("POST: " + webResource.toString());
+            WebResource.Builder builder =
+                webResource.accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).type("application/json");
+
+            return builder.post(ClientResponse.class, copyConfig.toString());
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 400) {
+                throw new DockerException("bad parameter");
+            } else if (exception.getResponse().getStatus() == 404) {
+                throw new DockerException(String.format("No such container %s", containerId));
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    public List<ChangeLog> containterDiff(String containerId) throws DockerException, NotFoundException {
+
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/changes", containerId));
+
+        try {
+            LOGGER.trace("GET: {}", webResource);
+            return webResource.accept(MediaType.APPLICATION_JSON).get(new GenericType<List<ChangeLog>>() {});
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("No such container %s", containerId));
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+
+
+
+    public void stopContainer(String containerId) throws DockerException {
+        this.stopContainer(containerId, 10);
+    }
+
+    public void stopContainer(String containerId, int timeout) throws DockerException {
+
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/stop", containerId))
+                .queryParam("t", String.valueOf(timeout));
+
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post();
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                LOGGER.warn("No such container {}", containerId);
+            } else if (exception.getResponse().getStatus() == 204) {
+                //no error
+                LOGGER.trace("Successfully stopped container {}", containerId);
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    public void kill(String containerId) throws DockerException {
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/kill", containerId));
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post();
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                LOGGER.warn("No such container {}", containerId);
+            } else if (exception.getResponse().getStatus() == 204) {
+                //no error
+                LOGGER.trace("Successfully killed container {}", containerId);
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    public void restart(String containerId, int timeout) throws DockerException, NotFoundException {
+        WebResource webResource = client.resource(restEndpointUrl + String.format("/containers/%s/restart", containerId));
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).post();
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("No such container %s", containerId));
+            } else if (exception.getResponse().getStatus() == 204) {
+                //no error
+                LOGGER.trace("Successfully restarted container {}", containerId);
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        }
+    }
+
+    public String commit(CommitConfig commitConfig) throws DockerException, NotFoundException {
+        Preconditions.checkNotNull(commitConfig.getContainer(), "Container ID was not specified");
+
+        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
+        params.add("container", commitConfig.getContainer());
+        params.add("repo", commitConfig.getRepo());
+        params.add("tag", commitConfig.getTag());
+        params.add("m", commitConfig.getMessage());
+        params.add("author", commitConfig.getAuthor());
+        params.add("run", commitConfig.getRun());
+
+        WebResource webResource = client.resource(restEndpointUrl + "/commit").queryParams(params);
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            JSONObject jsonObject = webResource.accept("application/vnd.docker.raw-stream").post(JSONObject.class, params);
+            return jsonObject.getString("Id");
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 404) {
+                throw new NotFoundException(String.format("No such container %s", commitConfig.getContainer()));
+            } else if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        } catch (JSONException e) {
+            throw new DockerException(e);
+        }
+    }
+
+
+    public ClientResponse build(File dockerFolder) throws DockerException {
+        return this.build(dockerFolder, null);
+    }
+    
+    public ClientResponse build(File dockerFolder, String tag) throws DockerException {
+    	return this.build(dockerFolder, null, false);
+    }
+
+    public ClientResponse build(File dockerFolder, String tag, boolean noCache) throws DockerException {
+        Preconditions.checkNotNull(dockerFolder, "Folder is null");
+        Preconditions.checkArgument(dockerFolder.exists(), "Folder %s doesn't exist", dockerFolder);
+        Preconditions.checkState(new File(dockerFolder, "Dockerfile").exists(), "Dockerfile doesn't exist in " + dockerFolder);
+
+        //We need to use Jersey HttpClient here, since ApacheHttpClient4 will not add boundary filed to
+        //Content-Type: multipart/form-data; boundary=Boundary_1_372491238_1372806136625
+
+        MultivaluedMap<String,String> params = new MultivaluedMapImpl();
+        params.add("t", tag);
+        if(noCache) {
+        	params.add("nocache", "true");
+        }
+
+        // ARCHIVE TAR
+        String archiveNameWithOutExtension = UUID.randomUUID().toString();
+
+        File dockerFolderTar = null;
+        File tmpDockerContextFolder = null;
+
+        try {
+            File dockerFile = new File(dockerFolder, "Dockerfile");
+            List<String> dockerFileContent = FileUtils.readLines(dockerFile);
+
+            if (dockerFileContent.size() <= 0) {
+                throw new DockerException(String.format("Dockerfile %s is empty", dockerFile));
+            }
+
+            //Create tmp docker context folder
+            tmpDockerContextFolder = new File(FileUtils.getTempDirectoryPath(), "docker-java-build" + archiveNameWithOutExtension);
+
+            FileUtils.copyFileToDirectory(dockerFile, tmpDockerContextFolder);
+
+            for (String cmd : dockerFileContent) {
+                if (StringUtils.startsWithIgnoreCase(cmd.trim(), "ADD ")) {
+                    String addArgs[] = StringUtils.split(cmd, " \t");
+                    if (addArgs.length != 3) {
+                        throw new DockerException(String.format("Wrong format on line [%s]", cmd));
+                    }
+
+                    File src = new File(addArgs[1]);
+                    if (!src.isAbsolute()) {
+                        src = new File(dockerFolder, addArgs[1]).getCanonicalFile();
+                    }
+
+                    if (!src.exists()) {
+                        throw new DockerException(String.format("Source file %s doesnt' exist", src));
+                    }
+                    if (src.isDirectory()) {
+                        FileUtils.copyDirectory(src, tmpDockerContextFolder);
+                    } else {
+                        FileUtils.copyFileToDirectory(src, tmpDockerContextFolder);
+                    }
+                }
+            }
+
+            dockerFolderTar = CompressArchiveUtil.archiveTARFiles(tmpDockerContextFolder, archiveNameWithOutExtension);
+
+        } catch (IOException ex) {
+            FileUtils.deleteQuietly(dockerFolderTar);
+            FileUtils.deleteQuietly(tmpDockerContextFolder);
+            throw new DockerException("Error occurred while preparing Docker context folder.", ex);
+        }
+
+        WebResource webResource = client.resource(restEndpointUrl + "/build").queryParams(params);
+
+        try {
+            LOGGER.trace("POST: {}", webResource);
+            return webResource
+                    .type("application/tar")
+                    .accept(MediaType.TEXT_PLAIN)
+                    .post(ClientResponse.class, FileUtils.openInputStream(dockerFolderTar));
+        } catch (UniformInterfaceException exception) {
+            if (exception.getResponse().getStatus() == 500) {
+                throw new DockerException("Server error", exception);
+            } else {
+                throw new DockerException(exception);
+            }
+        } catch (IOException e) {
+            throw new DockerException(e);
+        } finally {
+            FileUtils.deleteQuietly(dockerFolderTar);
+            FileUtils.deleteQuietly(tmpDockerContextFolder);
+        }
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/src/main/java/com/kpelykh/docker/client/DockerException.java
----------------------------------------------------------------------
diff --git a/docker-java/src/main/java/com/kpelykh/docker/client/DockerException.java b/docker-java/src/main/java/com/kpelykh/docker/client/DockerException.java
new file mode 100644
index 0000000..aa3df66
--- /dev/null
+++ b/docker-java/src/main/java/com/kpelykh/docker/client/DockerException.java
@@ -0,0 +1,25 @@
+package com.kpelykh.docker.client;
+
+/**
+ *
+ * @author Konstantin Pelykh (kpelykh@gmail.com)
+ *
+ */
+
+public class DockerException extends Exception {
+
+    public DockerException() {
+    }
+
+    public DockerException(String message) {
+        super(message);
+    }
+
+    public DockerException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public DockerException(Throwable cause) {
+        super(cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/src/main/java/com/kpelykh/docker/client/NotFoundException.java
----------------------------------------------------------------------
diff --git a/docker-java/src/main/java/com/kpelykh/docker/client/NotFoundException.java b/docker-java/src/main/java/com/kpelykh/docker/client/NotFoundException.java
new file mode 100644
index 0000000..f6c8fe5
--- /dev/null
+++ b/docker-java/src/main/java/com/kpelykh/docker/client/NotFoundException.java
@@ -0,0 +1,20 @@
+package com.kpelykh.docker.client;
+
+/**
+ * Indicates that the given entity does not exist.
+ *
+ * @author Ryan Campbell ryan.campbell@gmail.com
+ */
+public class NotFoundException extends DockerException {
+    public NotFoundException() {
+
+    }
+
+    public NotFoundException(String message) {
+        super(message);
+    }
+
+    public NotFoundException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/edd3fcaf/docker-java/src/main/java/com/kpelykh/docker/client/UnixSocketClient.java
----------------------------------------------------------------------
diff --git a/docker-java/src/main/java/com/kpelykh/docker/client/UnixSocketClient.java b/docker-java/src/main/java/com/kpelykh/docker/client/UnixSocketClient.java
new file mode 100644
index 0000000..7558203
--- /dev/null
+++ b/docker-java/src/main/java/com/kpelykh/docker/client/UnixSocketClient.java
@@ -0,0 +1,12 @@
+package com.kpelykh.docker.client;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.config.ClientConfig;
+
+
+public class UnixSocketClient extends Client {
+
+  public UnixSocketClient(ClientConfig clientConfig) {
+    super(new UnixSocketClientHandler(), clientConfig);
+  }
+}


Mime
View raw message