You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/10/31 05:20:33 UTC

[1/3] git commit: Remove tar creation responsibility from docker, avoiding filesystem bias.

Repository: jclouds-labs
Updated Branches:
  refs/heads/1.8.x 8798b4d51 -> 0c6c12962


Remove tar creation responsibility from docker, avoiding filesystem bias.


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

Branch: refs/heads/1.8.x
Commit: a1ce199c5b9ef9eaddc3754ddf75c062b4bab768
Parents: 8798b4d
Author: Adrian Cole <ac...@twitter.com>
Authored: Tue Oct 28 16:51:19 2014 -0700
Committer: Adrian Cole <ad...@apache.org>
Committed: Thu Oct 30 21:19:56 2014 -0700

----------------------------------------------------------------------
 docker/pom.xml                                  |  12 +-
 .../binders/BindInputStreamToRequest.java       |  68 -----------
 .../org/jclouds/docker/features/RemoteApi.java  |  16 ---
 .../docker/features/internal/Archives.java      |  60 ----------
 .../binders/BindInputStreamToRequestTest.java   |  66 -----------
 .../docker/compute/BaseDockerApiLiveTest.java   |  52 ++++-----
 .../docker/features/RemoteApiLiveTest.java      |  30 +++--
 .../docker/features/RemoteApiMockTest.java      |  39 -------
 .../docker/features/internal/ArchivesTest.java  | 112 -------------------
 9 files changed, 43 insertions(+), 412 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/pom.xml
----------------------------------------------------------------------
diff --git a/docker/pom.xml b/docker/pom.xml
index f506ef5..e44114b 100644
--- a/docker/pom.xml
+++ b/docker/pom.xml
@@ -58,11 +58,6 @@
       <version>1.8.2-SNAPSHOT</version>
     </dependency>
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-compress</artifactId>
-      <version>1.5</version>
-    </dependency>
-    <dependency>
       <groupId>com.google.auto.value</groupId>
       <artifactId>auto-value</artifactId>
       <version>1.0-rc2</version>
@@ -111,6 +106,13 @@
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-depchain</artifactId>
+      <version>1.2.2</version>
+      <type>pom</type>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/src/main/java/org/jclouds/docker/binders/BindInputStreamToRequest.java
----------------------------------------------------------------------
diff --git a/docker/src/main/java/org/jclouds/docker/binders/BindInputStreamToRequest.java b/docker/src/main/java/org/jclouds/docker/binders/BindInputStreamToRequest.java
deleted file mode 100644
index 855a2e5..0000000
--- a/docker/src/main/java/org/jclouds/docker/binders/BindInputStreamToRequest.java
+++ /dev/null
@@ -1,68 +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.jclouds.docker.binders;
-
-import com.google.common.base.Throwables;
-import com.google.common.io.Files;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.docker.features.internal.Archives;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.io.Payload;
-import org.jclouds.io.Payloads;
-import org.jclouds.logging.Logger;
-import org.jclouds.rest.Binder;
-
-import javax.annotation.Resource;
-import javax.inject.Named;
-import javax.inject.Singleton;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-@Singleton
-public class BindInputStreamToRequest implements Binder {
-
-   @Resource
-   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
-   protected Logger logger = Logger.NULL;
-
-   @Override
-   public <R extends HttpRequest> R bindToRequest(R request, Object input) {
-      checkArgument(checkNotNull(input, "input") instanceof File, "this binder is only valid for File!");
-      checkNotNull(request, "request");
-
-      File dockerFile = (File) input;
-      File tmpDir = Files.createTempDir();
-      final File targetFile = new File(tmpDir + File.separator + "Dockerfile");
-      try {
-         Files.copy(dockerFile, targetFile);
-         File archive = Archives.tar(tmpDir, File.createTempFile("archive", ".tar"));
-         FileInputStream data = new FileInputStream(archive);
-         Payload payload = Payloads.newInputStreamPayload(data);
-         payload.getContentMetadata().setContentLength(data.getChannel().size());
-         payload.getContentMetadata().setContentType("application/tar");
-         request.setPayload(payload);
-      } catch (IOException e) {
-         logger.error(e, "Couldn't create a tarball for %s", targetFile);
-         throw Throwables.propagate(e);
-      }
-      return request;
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/src/main/java/org/jclouds/docker/features/RemoteApi.java
----------------------------------------------------------------------
diff --git a/docker/src/main/java/org/jclouds/docker/features/RemoteApi.java b/docker/src/main/java/org/jclouds/docker/features/RemoteApi.java
index 96b0228..785eb20 100644
--- a/docker/src/main/java/org/jclouds/docker/features/RemoteApi.java
+++ b/docker/src/main/java/org/jclouds/docker/features/RemoteApi.java
@@ -17,7 +17,6 @@
 package org.jclouds.docker.features;
 
 import java.io.Closeable;
-import java.io.File;
 import java.io.InputStream;
 import java.util.Set;
 
@@ -32,7 +31,6 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 
 import org.jclouds.Fallbacks;
-import org.jclouds.docker.binders.BindInputStreamToRequest;
 import org.jclouds.docker.domain.Config;
 import org.jclouds.docker.domain.Container;
 import org.jclouds.docker.domain.HostConfig;
@@ -255,18 +253,4 @@ public interface RemoteApi extends Closeable {
    @Path("/build")
    @Headers(keys = "Content-Type", values = "application/tar")
    InputStream build(Payload inputStream, BuildOptions options);
-
-   /**
-    * Build an image from Dockerfile via stdin
-    *
-    * @param dockerFile The file to be compressed with one of the following algorithms: identity, gzip, bzip2, xz.*
-    * @param options the image build's options (@see BuildOptions)
-    * @return a stream of the build execution
-    */
-   @Named("image:build")
-   @POST
-   @Path("/build")
-   @Headers(keys = "Content-Type", values = "application/tar")
-   InputStream build(@BinderParam(BindInputStreamToRequest.class) File dockerFile, BuildOptions options);
-
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/src/main/java/org/jclouds/docker/features/internal/Archives.java
----------------------------------------------------------------------
diff --git a/docker/src/main/java/org/jclouds/docker/features/internal/Archives.java b/docker/src/main/java/org/jclouds/docker/features/internal/Archives.java
deleted file mode 100644
index 43b69c3..0000000
--- a/docker/src/main/java/org/jclouds/docker/features/internal/Archives.java
+++ /dev/null
@@ -1,60 +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.jclouds.docker.features.internal;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.collect.Iterables.getLast;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
-import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
-
-import com.google.common.base.Splitter;
-import com.google.common.io.Files;
-
-public class Archives {
-
-   public static File tar(File baseDir, String archivePath) throws IOException {
-      return tar(baseDir, new File(archivePath));
-   }
-
-   public static File tar(File baseDir, File tarFile) throws IOException {
-      // Check that the directory is a directory, and get its contents
-      checkArgument(baseDir.isDirectory(), "%s is not a directory", baseDir);
-      File[] files = baseDir.listFiles();
-      String token = getLast(Splitter.on("/").split(baseDir.getAbsolutePath()));
-      TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile));
-      tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
-      try {
-         for (File file : files) {
-            TarArchiveEntry tarEntry = new TarArchiveEntry(file);
-            tarEntry.setName("/" + getLast(Splitter.on(token).split(file.toString())));
-            tos.putArchiveEntry(tarEntry);
-            if (!file.isDirectory()) {
-               Files.asByteSource(file).copyTo(tos);
-            }
-            tos.closeArchiveEntry();
-         }
-      } finally {
-         tos.close();
-      }
-      return tarFile;
-   }
-
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/src/test/java/org/jclouds/docker/binders/BindInputStreamToRequestTest.java
----------------------------------------------------------------------
diff --git a/docker/src/test/java/org/jclouds/docker/binders/BindInputStreamToRequestTest.java b/docker/src/test/java/org/jclouds/docker/binders/BindInputStreamToRequestTest.java
deleted file mode 100644
index a21999c..0000000
--- a/docker/src/test/java/org/jclouds/docker/binders/BindInputStreamToRequestTest.java
+++ /dev/null
@@ -1,66 +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.jclouds.docker.binders;
-
-import com.google.common.io.CharStreams;
-import org.jclouds.http.HttpRequest;
-import org.testng.annotations.Test;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.AssertJUnit.assertTrue;
-
-@Test(groups = "unit", testName = "BindInputStreamToRequestTest")
-public class BindInputStreamToRequestTest {
-
-   @Test
-   public void testBindInputStreamToRequest() throws IOException {
-      BindInputStreamToRequest binder = new BindInputStreamToRequest();
-
-      HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://test").build();
-      request = binder.bindToRequest(request, File.createTempFile("dockerfile", ""));
-      String rawContent = CharStreams.toString(new InputStreamReader((FileInputStream) request.getPayload().getRawContent(), "UTF-8"));
-      assertTrue(rawContent.startsWith("Dockerfile"));
-      assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/tar");
-   }
-
-   @Test(expectedExceptions = IllegalArgumentException.class)
-   public void testBindInputStreamToRequestWithObjectAsInput() throws IOException {
-      BindInputStreamToRequest binder = new BindInputStreamToRequest();
-
-      HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://test").build();
-      request = binder.bindToRequest(request, new Object());
-      String rawContent = CharStreams.toString(new InputStreamReader((FileInputStream) request.getPayload().getRawContent(), "UTF-8"));
-      assertTrue(rawContent.startsWith("Dockerfile"));
-      assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/tar");
-   }
-
-   @Test(expectedExceptions = NullPointerException.class)
-   public void testBindInputStreamToRequestWithNullInput() throws IOException {
-      BindInputStreamToRequest binder = new BindInputStreamToRequest();
-
-      HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://test").build();
-      request = binder.bindToRequest(request, null);
-      String rawContent = CharStreams.toString(new InputStreamReader((FileInputStream) request.getPayload().getRawContent(), "UTF-8"));
-      assertTrue(rawContent.startsWith("Dockerfile"));
-      assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/tar");
-   }
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
----------------------------------------------------------------------
diff --git a/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java b/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
index db835f8..3e25dde 100644
--- a/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
+++ b/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
@@ -16,30 +16,30 @@
  */
 package org.jclouds.docker.compute;
 
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.io.CharStreams;
-import com.google.common.io.Closeables;
-import com.google.common.io.Files;
-import com.google.common.io.Resources;
-import com.google.inject.Module;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
+import org.jboss.shrinkwrap.api.GenericArchive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
+import org.jboss.shrinkwrap.api.exporter.TarExporter;
 import org.jclouds.Constants;
 import org.jclouds.apis.BaseApiLiveTest;
 import org.jclouds.docker.DockerApi;
-import org.jclouds.docker.features.internal.Archives;
 import org.jclouds.io.Payload;
 import org.jclouds.io.Payloads;
 import org.jclouds.sshj.config.SshjSshClientModule;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.Properties;
+import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.io.CharStreams;
+import com.google.common.io.Closeables;
+import com.google.inject.Module;
 
 @Test(groups = "live")
 public class BaseDockerApiLiveTest extends BaseApiLiveTest<DockerApi> {
@@ -80,20 +80,12 @@ public class BaseDockerApiLiveTest extends BaseApiLiveTest<DockerApi> {
       return result;
    }
 
-   protected Payload createPayload() throws IOException {
-      String folderPath = System.getProperty("user.dir") + "/docker/src/test/resources";
-      File parentDir = new File(folderPath + "/archive");
-      parentDir.mkdirs();
-      URL url = Resources.getResource("Dockerfile");
-      String content = Resources.toString(url, Charsets.UTF_8);
-      final File dockerfile = new File(parentDir.getAbsolutePath() + File.separator + "Dockerfile");
-      Files.write(content.getBytes(), dockerfile);
-      File archive = Archives.tar(parentDir, folderPath + "/archive/archive.tar");
-      FileInputStream data = new FileInputStream(archive);
-      Payload payload = Payloads.newInputStreamPayload(data);
-      payload.getContentMetadata().setContentLength(data.getChannel().size());
-      payload.getContentMetadata().setContentType("application/tar");
-      return payload;
-   }
+   public static Payload tarredDockerfile() throws IOException {
+      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+      ShrinkWrap.create(GenericArchive.class, "archive.tar")
+            .add(new ClassLoaderAsset("Dockerfile"), "Dockerfile")
+            .as(TarExporter.class).exportTo(bytes);
 
+      return Payloads.newByteArrayPayload(bytes.toByteArray());
+   }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java
----------------------------------------------------------------------
diff --git a/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java b/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java
index 30fd171..a489ac3 100644
--- a/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java
+++ b/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java
@@ -16,10 +16,16 @@
  */
 package org.jclouds.docker.features;
 
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.io.Resources;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+
 import org.jclouds.docker.compute.BaseDockerApiLiveTest;
 import org.jclouds.docker.domain.Config;
 import org.jclouds.docker.domain.Container;
@@ -30,16 +36,9 @@ import org.jclouds.docker.options.DeleteImageOptions;
 import org.jclouds.rest.ResourceNotFoundException;
 import org.testng.annotations.Test;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
 
 @Test(groups = "live", testName = "RemoteApiLiveTest", singleThreaded = true)
 public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
@@ -104,7 +103,7 @@ public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
 
    public void testBuildImage() throws IOException, InterruptedException, URISyntaxException {
       BuildOptions options = BuildOptions.Builder.tag("testBuildImage").verbose(false).nocache(false);
-      InputStream buildImageStream = api().build(new File(Resources.getResource("Dockerfile").toURI()), options);
+      InputStream buildImageStream = api().build(tarredDockerfile(), options);
       String buildStream = consumeStream(buildImageStream, false);
       Iterable<String> splitted = Splitter.on("\n").split(buildStream.replace("\r", "").trim());
       String lastStreamedLine = Iterables.getLast(splitted).trim();
@@ -117,5 +116,4 @@ public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
    private RemoteApi api() {
       return api.getRemoteApi();
    }
-
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java
----------------------------------------------------------------------
diff --git a/docker/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java b/docker/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java
index 515d98d..b164c7b 100644
--- a/docker/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java
+++ b/docker/src/test/java/org/jclouds/docker/features/RemoteApiMockTest.java
@@ -315,22 +315,6 @@ public class RemoteApiMockTest extends BaseDockerMockTest {
       }
    }
 
-   public void testBuildContainer() throws Exception {
-      MockWebServer server = mockWebServer();
-      server.enqueue(new MockResponse().setResponseCode(200));
-      DockerApi api = api(server.getUrl("/"));
-      RemoteApi remoteApi = api.getRemoteApi();
-      File dockerFile = File.createTempFile("docker", "tmp");
-      try {
-         remoteApi.build(dockerFile, BuildOptions.NONE);
-         assertRequestHasCommonFields(server.takeRequest(), "POST", "/build");
-      } finally {
-         dockerFile.delete();
-         api.close();
-         server.shutdown();
-      }
-   }
-
    public void testBuildContainerUsingPayload() throws Exception {
       MockWebServer server = mockWebServer();
       server.enqueue(new MockResponse().setResponseCode(200));
@@ -350,27 +334,4 @@ public class RemoteApiMockTest extends BaseDockerMockTest {
          server.shutdown();
       }
    }
-
-   public void testBuildNonexistentContainer() throws Exception {
-      MockWebServer server = mockWebServer();
-      server.enqueue(new MockResponse().setResponseCode(404));
-
-      DockerApi api = api(server.getUrl("/"));
-      RemoteApi remoteApi = api.getRemoteApi();
-
-      File dockerFile = File.createTempFile("docker", "tmp");
-      try {
-         try {
-            remoteApi.build(dockerFile, BuildOptions.NONE);
-            fail("Build container must fail on 404");
-         } catch (ResourceNotFoundException ex) {
-            // Expected exception
-         }
-      } finally {
-         dockerFile.delete();
-         api.close();
-         server.shutdown();
-      }
-   }
-
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/a1ce199c/docker/src/test/java/org/jclouds/docker/features/internal/ArchivesTest.java
----------------------------------------------------------------------
diff --git a/docker/src/test/java/org/jclouds/docker/features/internal/ArchivesTest.java b/docker/src/test/java/org/jclouds/docker/features/internal/ArchivesTest.java
deleted file mode 100644
index 15eb3ff..0000000
--- a/docker/src/test/java/org/jclouds/docker/features/internal/ArchivesTest.java
+++ /dev/null
@@ -1,112 +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.jclouds.docker.features.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-
-import javax.annotation.Resource;
-import javax.inject.Named;
-
-import org.apache.commons.compress.archivers.ArchiveStreamFactory;
-import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
-import org.apache.commons.compress.archivers.tar.TarUtils;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.logging.Logger;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import com.beust.jcommander.internal.Lists;
-import com.google.common.io.ByteStreams;
-import com.google.common.io.Files;
-
-@Test(groups = "unit", testName = "ArchivesTest")
-public class ArchivesTest {
-
-   @Resource
-   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
-   protected Logger logger = Logger.NULL;
-
-   private File tmpDir;
-   private File outputDir;
-   private long checkSum;
-
-   @BeforeClass
-   private void init() throws IOException {
-      tmpDir = Files.createTempDir();
-      outputDir = Files.createTempDir();
-      File sampleFile = writeSampleFile("test", "this is a test to tar a hierarchy of folders and files\n");
-      checkSum = TarUtils.computeCheckSum(Files.asByteSource(sampleFile).read());
-   }
-
-   public void testTarSingleFile() throws Exception {
-      File archive = Archives.tar(tmpDir, new File(outputDir + File.separator + "test.tar.gz"));
-      List<File> untarredFiles = unTar(archive, outputDir);
-      File untarredSampleFile = getOnlyElement(untarredFiles, null);
-      assertNotNull(untarredSampleFile);
-      assertTrue(checkSum == TarUtils.computeCheckSum(Files.asByteSource(untarredSampleFile).read()));
-   }
-
-   private List<File> unTar(final File inputFile, final File outputDir) throws Exception {
-      final List<File> untarredFiles = Lists.newArrayList();
-      final InputStream is = new FileInputStream(inputFile);
-      final TarArchiveInputStream tarArchiveInputStream = (TarArchiveInputStream)
-              new ArchiveStreamFactory().createArchiveInputStream("tar", is);
-      TarArchiveEntry entry;
-      while ((entry = (TarArchiveEntry) tarArchiveInputStream.getNextEntry()) != null) {
-         final File outputFile = new File(outputDir, entry.getName());
-         if (entry.isDirectory()) {
-            if (!outputFile.exists()) {
-               if (!outputFile.mkdirs()) {
-                  throw new IllegalStateException(String.format("Couldn't create directory %s.", outputFile.getAbsolutePath()));
-               }
-            }
-         } else {
-            OutputStream outputFileStream = new FileOutputStream(outputFile);
-            ByteStreams.copy(tarArchiveInputStream, outputFileStream);
-            outputFileStream.close();
-         }
-         untarredFiles.add(outputFile);
-      }
-      tarArchiveInputStream.close();
-      return untarredFiles;
-   }
-
-   private File writeSampleFile(String fileName, final String contents) {
-      checkNotNull(fileName, "Provided file name for writing must NOT be null.");
-      checkNotNull(contents, "Unable to write null contents.");
-      File sampleFile = new File(tmpDir + File.separator + fileName);
-      try {
-         Files.write(contents.getBytes(), sampleFile);
-      } catch (IOException e) {
-         logger.error("ERROR trying to write to file '" + fileName + "' - " + e.toString());
-         Assert.fail();
-      }
-      return sampleFile;
-   }
-}


[2/3] git commit: Remove source of service loader typos with AutoService.

Posted by ad...@apache.org.
Remove source of service loader typos with AutoService.


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/0f460ce0
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/0f460ce0
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/0f460ce0

Branch: refs/heads/1.8.x
Commit: 0f460ce08b6c268d2905682ef115a4494db14ca2
Parents: a1ce199
Author: Adrian Cole <ac...@twitter.com>
Authored: Tue Oct 28 08:55:04 2014 -0700
Committer: Adrian Cole <ad...@apache.org>
Committed: Thu Oct 30 21:20:00 2014 -0700

----------------------------------------------------------------------
 docker/pom.xml                                                  | 1 -
 docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java  | 5 ++---
 .../resources/META-INF/services/org.jclouds.apis.ApiMetadata    | 1 -
 3 files changed, 2 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/0f460ce0/docker/pom.xml
----------------------------------------------------------------------
diff --git a/docker/pom.xml b/docker/pom.xml
index e44114b..bf332db 100644
--- a/docker/pom.xml
+++ b/docker/pom.xml
@@ -60,7 +60,6 @@
     <dependency>
       <groupId>com.google.auto.value</groupId>
       <artifactId>auto-value</artifactId>
-      <version>1.0-rc2</version>
       <scope>provided</scope>
     </dependency>
     <dependency>

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/0f460ce0/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java
----------------------------------------------------------------------
diff --git a/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java b/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java
index b281eb7..a533614 100644
--- a/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java
+++ b/docker/src/main/java/org/jclouds/docker/DockerApiMetadata.java
@@ -16,6 +16,7 @@
  */
 package org.jclouds.docker;
 
+import com.google.auto.service.AutoService;
 import com.google.common.collect.ImmutableSet;
 import com.google.inject.Module;
 import org.jclouds.Constants;
@@ -33,9 +34,7 @@ import java.util.Properties;
 import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE;
 import static org.jclouds.reflect.Reflection2.typeToken;
 
-/**
- * Implementation of {@link BaseHttpApiMetadata} for the Docker API
- */
+@AutoService(ApiMetadata.class)
 public class DockerApiMetadata extends BaseHttpApiMetadata<DockerApi> {
 
    @Override

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/0f460ce0/docker/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
----------------------------------------------------------------------
diff --git a/docker/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/docker/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
deleted file mode 100644
index ca1a6cb..0000000
--- a/docker/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
+++ /dev/null
@@ -1 +0,0 @@
-org.jclouds.docker.DockerApiMetadata
\ No newline at end of file


[3/3] git commit: Decomplicate consuming the output of docker commands in tests.

Posted by ad...@apache.org.
Decomplicate consuming the output of docker commands in tests.


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/0c6c1296
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/0c6c1296
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/0c6c1296

Branch: refs/heads/1.8.x
Commit: 0c6c12962aea5da9aaed9cebea6f215a83f96def
Parents: 0f460ce
Author: Adrian Cole <ac...@twitter.com>
Authored: Wed Oct 29 12:52:13 2014 -0700
Committer: Adrian Cole <ad...@apache.org>
Committed: Thu Oct 30 21:20:00 2014 -0700

----------------------------------------------------------------------
 .../docker/compute/BaseDockerApiLiveTest.java   | 22 +++++++-------------
 .../docker/features/RemoteApiLiveTest.java      | 10 +++------
 2 files changed, 10 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/0c6c1296/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
----------------------------------------------------------------------
diff --git a/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java b/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
index 3e25dde..f779b7f 100644
--- a/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
+++ b/docker/src/test/java/org/jclouds/docker/compute/BaseDockerApiLiveTest.java
@@ -16,6 +16,9 @@
  */
 package org.jclouds.docker.compute;
 
+import static com.google.common.base.Charsets.UTF_8;
+import static org.jclouds.util.Closeables2.closeQuietly;
+
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -32,10 +35,8 @@ import org.jclouds.docker.DockerApi;
 import org.jclouds.io.Payload;
 import org.jclouds.io.Payloads;
 import org.jclouds.sshj.config.SshjSshClientModule;
-import org.testng.Assert;
 import org.testng.annotations.Test;
 
-import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.io.CharStreams;
 import com.google.common.io.Closeables;
@@ -61,23 +62,14 @@ public class BaseDockerApiLiveTest extends BaseApiLiveTest<DockerApi> {
       return overrides;
    }
 
-   protected String consumeStream(InputStream stream, boolean swallowIOException) {
-      String result = null;
+   protected String consumeStream(InputStream stream) {
       try {
-         result = CharStreams.toString(new InputStreamReader(stream, Charsets.UTF_8));
+         return CharStreams.toString(new InputStreamReader(stream, UTF_8));
       } catch (IOException e) {
-         Assert.fail();
+         throw new AssertionError(e);
       } finally {
-         // TODO: remove swallowIOException over-optimization and just use Closeables2.closeQuietly
-         try {
-            stream.close();
-         } catch (IOException e) {
-            if (!swallowIOException) {
-               throw new RuntimeException(e);
-            }
-         }
+         closeQuietly(stream);
       }
-      return result;
    }
 
    public static Payload tarredDockerfile() throws IOException {

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/0c6c1296/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java
----------------------------------------------------------------------
diff --git a/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java b/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java
index a489ac3..3f23212 100644
--- a/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java
+++ b/docker/src/test/java/org/jclouds/docker/features/RemoteApiLiveTest.java
@@ -23,7 +23,6 @@ import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URISyntaxException;
 
 import org.jclouds.docker.compute.BaseDockerApiLiveTest;
@@ -55,8 +54,7 @@ public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
    @Test(dependsOnMethods = "testVersion")
    public void testCreateImage() throws IOException, InterruptedException {
       CreateImageOptions options = CreateImageOptions.Builder.fromImage(BUSYBOX_IMAGE);
-      InputStream createImageStream = api().createImage(options);
-      consumeStream(createImageStream, false);
+      consumeStream(api().createImage(options));
       image = api().inspectImage(BUSYBOX_IMAGE);
       assertNotNull(image);
    }
@@ -96,15 +94,13 @@ public class RemoteApiLiveTest extends BaseDockerApiLiveTest {
 
    @Test(dependsOnMethods = "testRemoveContainer", expectedExceptions = ResourceNotFoundException.class)
    public void testDeleteImage() {
-      InputStream deleteImageStream = api().deleteImage(image.id());
-      consumeStream(deleteImageStream, false);
+      consumeStream(api().deleteImage(image.id()));
       assertNull(api().inspectImage(image.id()));
    }
 
    public void testBuildImage() throws IOException, InterruptedException, URISyntaxException {
       BuildOptions options = BuildOptions.Builder.tag("testBuildImage").verbose(false).nocache(false);
-      InputStream buildImageStream = api().build(tarredDockerfile(), options);
-      String buildStream = consumeStream(buildImageStream, false);
+      String buildStream = consumeStream(api().build(tarredDockerfile(), options));
       Iterable<String> splitted = Splitter.on("\n").split(buildStream.replace("\r", "").trim());
       String lastStreamedLine = Iterables.getLast(splitted).trim();
       String rawImageId = Iterables.getLast(Splitter.on("Successfully built ").split(lastStreamedLine));