You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2013/08/01 22:45:43 UTC

[1/5] git commit: Fixing bad package for StubSecurityGroupExtensionIntegrationTest

Updated Branches:
  refs/heads/fix-jclouds-155 e0514a1bc -> ac17241c0 (forced update)


Fixing bad package for StubSecurityGroupExtensionIntegrationTest


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

Branch: refs/heads/fix-jclouds-155
Commit: 70af0ea5abe5c85e9e34c3da5a913aa1eb68cd11
Parents: f6b5b67
Author: Andrew Bayer <an...@gmail.com>
Authored: Wed Jul 31 16:16:37 2013 -0700
Committer: Andrew Bayer <an...@gmail.com>
Committed: Wed Jul 31 16:16:37 2013 -0700

----------------------------------------------------------------------
 ...ubSecurityGroupExtensionIntegrationTest.java | 27 ++------------------
 1 file changed, 2 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/70af0ea5/compute/src/test/java/org/jclouds/compute/stub/extensions/StubSecurityGroupExtensionIntegrationTest.java
----------------------------------------------------------------------
diff --git a/compute/src/test/java/org/jclouds/compute/stub/extensions/StubSecurityGroupExtensionIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/stub/extensions/StubSecurityGroupExtensionIntegrationTest.java
index 8c2b31c..70e7359 100644
--- a/compute/src/test/java/org/jclouds/compute/stub/extensions/StubSecurityGroupExtensionIntegrationTest.java
+++ b/compute/src/test/java/org/jclouds/compute/stub/extensions/StubSecurityGroupExtensionIntegrationTest.java
@@ -14,37 +14,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.jclouds.compute.extensions.internal;
-
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.jclouds.util.Predicates2.retry;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+package org.jclouds.compute.stub.extensions;
 
 import java.util.Properties;
-import java.util.concurrent.ExecutionException;
-
-import javax.annotation.Resource;
-import javax.inject.Named;
 
-import org.jclouds.compute.ComputeService;
-import org.jclouds.compute.RunNodesException;
-import org.jclouds.compute.domain.SecurityGroup;
-import org.jclouds.compute.domain.SecurityGroupBuilder;
-import org.jclouds.compute.domain.Template;
 import org.jclouds.compute.extensions.SecurityGroupExtension;
-import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.domain.Location;
-import org.jclouds.logging.Logger;
-import org.jclouds.net.domain.IpPermission;
-import org.jclouds.ssh.SshClient;
+import org.jclouds.compute.extensions.internal.BaseSecurityGroupExtensionLiveTest;
 import org.testng.annotations.Test;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-
 
 /**
  * Base test for {@link SecurityGroupExtension} implementations.


[2/5] git commit: URL encode string to sign.

Posted by an...@apache.org.
URL encode string to sign.

As recommended at
http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html:

"You can also send a signature as a URL-encoded query-string parameter
in the URL for the request."

Also deals with some of the craziness of URL encoding/decoding in
jclouds.

References JCLOUDS-200


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

Branch: refs/heads/fix-jclouds-155
Commit: 675c649cb6c0d81cec7b6115b80fe807366244e8
Parents: 70af0ea
Author: Diwaker Gupta <di...@maginatics.com>
Authored: Tue Jul 30 17:01:05 2013 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Wed Jul 31 16:32:53 2013 -0700

----------------------------------------------------------------------
 .../s3/blobstore/AWSS3BlobRequestSigner.java    | 22 +++++++++++++++++---
 .../s3/blobstore/AWSS3BlobSignerExpectTest.java | 12 ++++++-----
 2 files changed, 26 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/675c649c/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobRequestSigner.java
----------------------------------------------------------------------
diff --git a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobRequestSigner.java b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobRequestSigner.java
index 775cdf5..dc33ec2 100644
--- a/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobRequestSigner.java
+++ b/providers/aws-s3/src/main/java/org/jclouds/aws/s3/blobstore/AWSS3BlobRequestSigner.java
@@ -19,6 +19,8 @@ package org.jclouds.aws.s3.blobstore;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.jclouds.blobstore.util.BlobStoreUtils.cleanRequest;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.Date;
 import java.util.concurrent.TimeUnit;
 
@@ -35,6 +37,7 @@ import org.jclouds.s3.blobstore.S3BlobRequestSigner;
 import org.jclouds.s3.blobstore.functions.BlobToObject;
 import org.jclouds.s3.filters.RequestAuthorizeSignature;
 
+import com.google.common.base.Charsets;
 import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableList;
 import com.google.common.net.HttpHeaders;
@@ -91,10 +94,23 @@ public class AWSS3BlobRequestSigner extends S3BlobRequestSigner<AWSS3AsyncClient
       Date date = dateService.rfc1123DateParse(dateString);
       String expiration = String.valueOf(TimeUnit.MILLISECONDS.toSeconds(date.getTime()) + timeInSeconds);
       HttpRequest.Builder<?> builder = request.toBuilder().replaceHeader(HttpHeaders.DATE, expiration);
-      final String signature = authSigner.sign(authSigner.createStringToSign(builder.build()));
-      return builder.addQueryParam(TEMPORARY_SIGNATURE_PARAM, signature)
-         .addQueryParam(HttpHeaders.EXPIRES, expiration)
+      String stringToSign = authSigner.createStringToSign(builder.build());
+      // We MUST encode the signature because addQueryParam internally _always_ decodes values
+      // and if we don't encode the signature here, the decoding may change the signature. For e.g.
+      // any '+' characters in the signature will be converted to space ' ' on decoding.
+      String signature = authSigner.sign(stringToSign);
+      try {
+         signature = URLEncoder.encode(signature, Charsets.UTF_8.name());
+      } catch (UnsupportedEncodingException e) {
+         throw new IllegalStateException("Bad encoding on input: " + signature, e);
+      }
+      HttpRequest ret = builder.addQueryParam(HttpHeaders.EXPIRES, expiration)
          .addQueryParam("AWSAccessKeyId", identity)
+         // Signature MUST be the last parameter because if it isn't, even encoded '+' values in the
+         // signature will be converted to a space by a subsequent addQueryParameter.
+         // See HttpRequestTest.testAddBase64AndUrlEncodedQueryParams for more details.
+         .addQueryParam(TEMPORARY_SIGNATURE_PARAM, signature)
          .build();
+      return ret;
    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/675c649c/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/AWSS3BlobSignerExpectTest.java
----------------------------------------------------------------------
diff --git a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/AWSS3BlobSignerExpectTest.java b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/AWSS3BlobSignerExpectTest.java
index d041abd..0b38b0b 100644
--- a/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/AWSS3BlobSignerExpectTest.java
+++ b/providers/aws-s3/src/test/java/org/jclouds/aws/s3/blobstore/AWSS3BlobSignerExpectTest.java
@@ -35,6 +35,8 @@ import com.google.inject.Module;
  */
 @Test(groups = "unit", testName = "AWSS3BlobSignerExpectTest")
 public class AWSS3BlobSignerExpectTest extends S3BlobSignerExpectTest {
+   private static final String DATE = "Thu, 05 Jun 2008 16:38:19 GMT";
+
    public AWSS3BlobSignerExpectTest() {
       provider = "aws-s3";
    }
@@ -43,9 +45,9 @@ public class AWSS3BlobSignerExpectTest extends S3BlobSignerExpectTest {
    protected HttpRequest getBlobWithTime() {
       return HttpRequest.builder().method("GET")
          .endpoint("https://container.s3.amazonaws.com/name" +
-            "?Signature=Y4Ac4sZfBemGZmgfG78F7IX%20IFg%3D&Expires=1212683902&AWSAccessKeyId=identity")
+            "?Expires=1212683902&AWSAccessKeyId=identity&Signature=Y4Ac4sZfBemGZmgfG78F7IX%2BIFg%3D")
          .addHeader("Host", "container.s3.amazonaws.com")
-         .addHeader("Date", "Thu, 05 Jun 2008 16:38:19 GMT").build();
+         .addHeader("Date", DATE).build();
    }
 
    @Test
@@ -60,10 +62,10 @@ public class AWSS3BlobSignerExpectTest extends S3BlobSignerExpectTest {
    protected HttpRequest putBlobWithTime() {
       return HttpRequest.builder().method("PUT")
          .endpoint("https://container.s3.amazonaws.com/name" +
-            "?Signature=genkB2vLxe3AWV/bPvRTMqQts7E%3D&Expires=1212683902&AWSAccessKeyId=identity")
+            "?Expires=1212683902&AWSAccessKeyId=identity&Signature=genkB2vLxe3AWV/bPvRTMqQts7E%3D")
          .addHeader("Expect", "100-continue")
          .addHeader("Host", "container.s3.amazonaws.com")
-         .addHeader("Date", "Thu, 05 Jun 2008 16:38:19 GMT").build();
+         .addHeader("Date", DATE).build();
    }
 
    @Test
@@ -86,7 +88,7 @@ public class AWSS3BlobSignerExpectTest extends S3BlobSignerExpectTest {
       @Override
       @TimeStamp
       protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
-         return "Thu, 05 Jun 2008 16:38:19 GMT";
+         return DATE;
       }
    }
 }


[4/5] git commit: Update URL for commons-logging-1.1.1-bin.tar.gz

Posted by an...@apache.org.
Update URL for commons-logging-1.1.1-bin.tar.gz

This allows testCopyUrl to succeed against blobstore integration
tests.


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

Branch: refs/heads/fix-jclouds-155
Commit: f1673194ad9f17c5945c643e48403728c72596e7
Parents: e6b6e4e
Author: Andrew Gaul <ga...@apache.org>
Authored: Thu Aug 1 10:19:31 2013 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Thu Aug 1 10:35:26 2013 -0700

----------------------------------------------------------------------
 project/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/f1673194/project/pom.xml
----------------------------------------------------------------------
diff --git a/project/pom.xml b/project/pom.xml
index dc9f570..c77a8aa 100644
--- a/project/pom.xml
+++ b/project/pom.xml
@@ -207,7 +207,7 @@
     <maven.site.url.base>gitsite:git@github.com/jclouds/jclouds-maven-site.git</maven.site.url.base>
     <http.proxyHost />
     <http.proxyPort />
-    <jclouds.wire.httpstream.url>http://apache.deathculture.net//commons/logging/binaries/commons-logging-1.1.1-bin.tar.gz</jclouds.wire.httpstream.url>
+    <jclouds.wire.httpstream.url>http://archive.apache.org/dist/commons/logging/binaries/commons-logging-1.1.1-bin.tar.gz</jclouds.wire.httpstream.url>
     <jclouds.wire.httpstream.md5>e5de09672af9b386c30a311654d8541a</jclouds.wire.httpstream.md5>
     <jclouds.blobstore.httpstream.url>${jclouds.wire.httpstream.url}</jclouds.blobstore.httpstream.url>
     <jclouds.blobstore.httpstream.md5>${jclouds.wire.httpstream.md5}</jclouds.blobstore.httpstream.md5>


[5/5] git commit: JCLOUDS-155: Making header handling in OpenStack case-insensitive

Posted by an...@apache.org.
JCLOUDS-155: Making header handling in OpenStack case-insensitive

Submitted by Rodney Beede


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

Branch: refs/heads/fix-jclouds-155
Commit: ac17241c089a78372afe136513cc5d76f8ea228c
Parents: f167319
Author: Andrew Phillips <an...@apache.org>
Authored: Mon Jul 29 20:24:15 2013 -0400
Committer: Andrew Phillips <an...@apache.org>
Committed: Thu Aug 1 16:44:53 2013 -0400

----------------------------------------------------------------------
 ...seAuthenticationResponseFromHeadersTest.java | 66 -----------------
 .../ParseAuthenticationResponseFromHeaders.java |  4 +-
 ...seAuthenticationResponseFromHeadersTest.java | 77 ++++++++++++++++++++
 3 files changed, 80 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/ac17241c/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
----------------------------------------------------------------------
diff --git a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java b/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
deleted file mode 100644
index 85ae254..0000000
--- a/apis/swift/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.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.openstack.functions;
-
-import static org.testng.Assert.assertEquals;
-
-import java.net.URI;
-
-import org.jclouds.Constants;
-import org.jclouds.blobstore.reference.BlobStoreConstants;
-import org.jclouds.http.HttpResponse;
-import org.jclouds.openstack.domain.AuthenticationResponse;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.name.Names;
-
-/**
- * Tests behavior of {@code ParseContainerListFromJsonResponse}
- * 
- * @author Adrian Cole
- */
-@Test(groups = "unit", testName = "ParseAuthenticationResponseFromHeadersTest")
-public class ParseAuthenticationResponseFromHeadersTest {
-
-   Injector i = Guice.createInjector(new AbstractModule() {
-
-      @Override
-      protected void configure() {
-         bindConstant().annotatedWith(Names.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to("sdf");
-         bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1");
-      }
-
-   });
-
-   public void testReplaceLocalhost() {
-      ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class);
-      parser = parser.setHostToReplace("fooman");
-      
-      HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
-                                          .addHeader("X-Auth-Token", "token")
-                                          .addHeader("X-Storage-Token", "token")
-                                          .addHeader("X-Storage-Url", "http://127.0.0.1:8080/v1/token").build();
-
-      AuthenticationResponse md = parser.apply(response);
-      assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url", URI
-               .create("http://fooman:8080/v1/token"))));
-   }
-}

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/ac17241c/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
----------------------------------------------------------------------
diff --git a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
index aa988fb..c824d9c 100644
--- a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
+++ b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
@@ -56,9 +56,11 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
     */
    public AuthenticationResponse apply(HttpResponse from) {
       releasePayload(from);
+
+      // HTTP headers are case insensitive (RFC 2616) so we must allow for that when looking an header names for the URL keyword
       Builder<String, URI> builder = ImmutableMap.builder();
       for (Entry<String, String> entry : from.getHeaders().entries()) {
-         if (entry.getKey().endsWith(URL_SUFFIX))
+         if (entry.getKey().toLowerCase().endsWith(URL_SUFFIX.toLowerCase()))
             builder.put(entry.getKey(), getURI(entry.getValue()));
       }
       AuthenticationResponse response = new AuthenticationResponse(checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN),

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/ac17241c/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
----------------------------------------------------------------------
diff --git a/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
new file mode 100644
index 0000000..7578394
--- /dev/null
+++ b/common/openstack/src/test/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeadersTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.openstack.functions;
+
+import static org.testng.Assert.assertEquals;
+
+import java.net.URI;
+
+import org.jclouds.Constants;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.domain.AuthenticationResponse;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.name.Names;
+
+/**
+ * Tests behavior of {@code ParseAuthenticationResponseFromHeaders}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "unit", testName = "ParseAuthenticationResponseFromHeadersTest")
+public class ParseAuthenticationResponseFromHeadersTest {
+
+   Injector i = Guice.createInjector(new AbstractModule() {
+
+      @Override
+      protected void configure() {
+         bindConstant().annotatedWith(Names.named(Constants.PROPERTY_API_VERSION)).to("1");
+      }
+
+   });
+
+   public void testReplaceLocalhost() {
+      ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class);
+      parser = parser.setHostToReplace("fooman");
+
+      HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
+                                          .addHeader("X-Auth-Token", "token")
+                                          .addHeader("X-Storage-Token", "token")
+                                          .addHeader("X-Storage-Url", "http://127.0.0.1:8080/v1/token").build();
+
+      AuthenticationResponse md = parser.apply(response);
+      assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("X-Storage-Url", 
+               URI.create("http://fooman:8080/v1/token"))));
+   }
+
+   public void testHandleHeadersCaseInsensitively() {
+      ParseAuthenticationResponseFromHeaders parser = i.getInstance(ParseAuthenticationResponseFromHeaders.class);
+      parser = parser.setHostToReplace("fooman");
+
+      HttpResponse response = HttpResponse.builder().statusCode(204).message("No Content")
+              .addHeader("x-auth-token", "token")
+              .addHeader("x-storage-token", "token")
+              .addHeader("x-storage-url", "http://127.0.0.1:8080/v1/token").build();
+      AuthenticationResponse md = parser.apply(response);
+      assertEquals(md, new AuthenticationResponse("token", ImmutableMap.<String, URI> of("x-storage-url", 
+              URI.create("http://fooman:8080/v1/token"))));
+   }
+}


[3/5] git commit: Support Disk Configuration Extension

Posted by an...@apache.org.
Support Disk Configuration Extension


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

Branch: refs/heads/fix-jclouds-155
Commit: e6b6e4edb2b5f829e60b31e742c6b1e45b9b6816
Parents: 675c649
Author: Everett Toews <ev...@rackspace.com>
Authored: Wed Jul 31 21:11:30 2013 -0500
Committer: Everett Toews <ev...@rackspace.com>
Committed: Wed Jul 31 23:10:35 2013 -0500

----------------------------------------------------------------------
 .../openstack/nova/v2_0/domain/Server.java      | 13 ++++-
 .../nova/v2_0/domain/ServerCreated.java         | 35 ++++++++++---
 .../nova/v2_0/options/CreateServerOptions.java  | 42 +++++++++++++++-
 .../nova/v2_0/features/ServerApiExpectTest.java | 53 ++++++++++++++++++++
 .../nova/v2_0/parse/ParseCreatedServerTest.java | 15 ++++++
 .../resources/new_server_disk_config_auto.json  | 42 ++++++++++++++++
 .../new_server_disk_config_manual.json          | 42 ++++++++++++++++
 7 files changed, 232 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/e6b6e4ed/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java
----------------------------------------------------------------------
diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java
index 36f6826..a02cc04 100644
--- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java
+++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import javax.inject.Named;
 
 import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
 import org.jclouds.openstack.v2_0.domain.Link;
 import org.jclouds.openstack.v2_0.domain.Resource;
 
@@ -45,6 +46,8 @@ import com.google.common.collect.Multimap;
  *      />
  */
 public class Server extends Resource {
+   public final static String DISK_CONFIG_MANUAL = "MANUAL";
+   public final static String DISK_CONFIG_AUTO = "AUTO";
 
    /**
     * Servers contain a status attribute that can be used as an indication of the current server
@@ -441,12 +444,18 @@ public class Server extends Resource {
    }
 
    /**
-    * Disk config attribute from the Disk Config Extension (alias "OS-DCF")
+    * Disk config attribute from the Disk Config Extension (alias "OS-DCF").
+    * One of {@link Server#DISK_CONFIG_AUTO} or {@link Server#DISK_CONFIG_MANUAL}.
+    * This field is only present if the Disk Config extension is installed.
     * <p/>
-    * NOTE: This field is only present if the Disk Config extension is installed
+    * NOTE: Typically a field like this would be implemented as an enum but this field was
+    * originally implmented as a String and {@link Server#DISK_CONFIG_AUTO} and 
+    * {@link Server#DISK_CONFIG_MANUAL} were added later as Strings to preserve backwards
+    * compatibility.
     *
     * @see org.jclouds.openstack.nova.v2_0.features.ExtensionApi#getExtensionByAlias
     * @see org.jclouds.openstack.nova.v2_0.extensions.ExtensionNamespaces#DISK_CONFIG
+    * @see CreateServerOptions#getDiskConfig()
     */
    public Optional<String> getDiskConfig() {
       return this.diskConfig;

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/e6b6e4ed/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.java
----------------------------------------------------------------------
diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.java
index b7ac6c9..13a5590 100644
--- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.java
+++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.java
@@ -20,6 +20,7 @@ import java.beans.ConstructorProperties;
 import java.util.Set;
 
 import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
 import org.jclouds.openstack.v2_0.domain.Link;
 import org.jclouds.openstack.v2_0.domain.Resource;
 
@@ -47,6 +48,7 @@ public class ServerCreated extends Resource {
 
    public static final class Builder extends Resource.Builder<Builder>  {
       protected String adminPass;
+      protected String diskConfig;
    
       /** 
        * @see ServerCreated#getAdminPass()
@@ -55,13 +57,21 @@ public class ServerCreated extends Resource {
          this.adminPass = adminPass;
          return self();
       }
+      
+      /** 
+       * @see ServerCreated#getDiskConfig()
+       */
+      public Builder diskConfig(String diskConfig) {
+         this.diskConfig = diskConfig;
+         return self();
+      }
 
       public ServerCreated build() {
-         return new ServerCreated(id, name, links, adminPass);
+         return new ServerCreated(id, name, links, adminPass, diskConfig);
       }
       
       public Builder fromServerCreated(ServerCreated in) {
-         return super.fromResource(in).adminPass(in.getAdminPass().orNull());
+         return super.fromResource(in).adminPass(in.getAdminPass().orNull()).diskConfig(in.getDiskConfig().orNull());
       }
 
       @Override
@@ -71,13 +81,16 @@ public class ServerCreated extends Resource {
    }
 
    private final Optional<String> adminPass;
+   private final Optional<String> diskConfig;
 
    @ConstructorProperties({
-      "id", "name", "links", "adminPass"
+      "id", "name", "links", "adminPass", "OS-DCF:diskConfig" 
    })
-   protected ServerCreated(String id, @Nullable String name, Set<Link> links, @Nullable String adminPass) {
+   protected ServerCreated(String id, @Nullable String name, Set<Link> links, @Nullable String adminPass, 
+         @Nullable String diskConfig) {
       super(id, name, links);
       this.adminPass = Optional.fromNullable(adminPass);
+      this.diskConfig = Optional.fromNullable(diskConfig);
    }
 
    /**
@@ -87,9 +100,16 @@ public class ServerCreated extends Resource {
       return this.adminPass;
    }
 
+   /**
+    * @see CreateServerOptions#getDiskConfig()
+    */
+   public Optional<String> getDiskConfig() {
+      return this.diskConfig;
+   }
+
    @Override
    public int hashCode() {
-      return Objects.hashCode(adminPass);
+      return Objects.hashCode(adminPass, diskConfig);
    }
 
    @Override
@@ -97,11 +117,12 @@ public class ServerCreated extends Resource {
       if (this == obj) return true;
       if (obj == null || getClass() != obj.getClass()) return false;
       ServerCreated that = ServerCreated.class.cast(obj);
-      return super.equals(that) && Objects.equal(this.adminPass, that.adminPass);
+      return super.equals(that) && Objects.equal(this.adminPass, that.adminPass)
+            && Objects.equal(this.diskConfig, that.diskConfig);
    }
 
    @Override
    protected ToStringHelper string() {
-      return super.string().add("adminPass", adminPass.orNull());
+      return super.string().add("adminPass", adminPass.orNull()).add("diskConfig", diskConfig.orNull());
    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/e6b6e4ed/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java
----------------------------------------------------------------------
diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java
index efa16bf..3ce1fb3 100644
--- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java
+++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java
@@ -34,6 +34,7 @@ import javax.inject.Named;
 
 import org.jclouds.http.HttpRequest;
 import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
 import org.jclouds.rest.MapBinder;
 import org.jclouds.rest.binders.BindToJsonPayload;
 
@@ -109,6 +110,7 @@ public class CreateServerOptions implements MapBinder {
    private Map<String, String> metadata = ImmutableMap.of();
    private List<File> personality = Lists.newArrayList();
    private byte[] userData;
+   private String diskConfig;
 
    @Override
    public boolean equals(Object object) {
@@ -119,7 +121,7 @@ public class CreateServerOptions implements MapBinder {
          final CreateServerOptions other = CreateServerOptions.class.cast(object);
          return equal(keyName, other.keyName) && equal(securityGroupNames, other.securityGroupNames)
                   && equal(metadata, other.metadata) && equal(personality, other.personality)
-                  && equal(adminPass, other.adminPass);
+                  && equal(adminPass, other.adminPass) && equal(diskConfig, other.diskConfig);
       } else {
          return false;
       }
@@ -141,6 +143,8 @@ public class CreateServerOptions implements MapBinder {
          toString.add("personality", personality);
       if (adminPass != null)
          toString.add("adminPassPresent", true);
+      if (diskConfig != null)
+         toString.add("diskConfig", diskConfig);
       toString.add("userData", userData == null ? null : new String(userData));
       return toString;
    }
@@ -161,6 +165,8 @@ public class CreateServerOptions implements MapBinder {
       @Named("security_groups")
       Set<NamedThingy> securityGroupNames;
       String user_data;
+      @Named("OS-DCF:diskConfig")
+      String diskConfig;
 
       private ServerRequest(String name, String imageRef, String flavorRef) {
          this.name = name;
@@ -192,6 +198,9 @@ public class CreateServerOptions implements MapBinder {
       if (adminPass != null) {
          server.adminPass = adminPass;
       }
+      if (diskConfig != null) {
+         server.diskConfig = diskConfig;
+      }
 
       return bindToRequest(request, ImmutableMap.of("server", server));
    }
@@ -320,6 +329,29 @@ public class CreateServerOptions implements MapBinder {
       this.securityGroupNames = ImmutableSet.copyOf(securityGroupNames);
       return this;
    }
+
+   /**
+    * When you create a server from an image with the diskConfig value set to 
+    * {@link Server#DISK_CONFIG_AUTO}, the server is built with a single partition that is expanded to 
+    * the disk size of the flavor selected. When you set the diskConfig attribute to 
+    * {@link Server#DISK_CONFIG_MANUAL}, the server is built by using the partition scheme and file 
+    * system that is in the source image.
+    * <p/> 
+    * If the target flavor disk is larger, remaining disk space is left unpartitioned. A server inherits the diskConfig
+    * attribute from the image from which it is created. However, you can override the diskConfig value when you create
+    * a server. This field is only present if the Disk Config extension is installed in your OpenStack deployment.
+    */
+   public String getDiskConfig() {
+      return diskConfig;
+   }
+   
+   /**
+    * @see #getDiskConfig
+    */
+   public CreateServerOptions diskConfig(String diskConfig) {
+      this.diskConfig = diskConfig;
+      return this;
+   }
    
    public static class Builder {
 
@@ -367,6 +399,14 @@ public class CreateServerOptions implements MapBinder {
          CreateServerOptions options = new CreateServerOptions();
          return CreateServerOptions.class.cast(options.securityGroupNames(groupNames));
       }
+
+      /**
+       * @see CreateServerOptions#getDiskConfig
+       */
+      public static CreateServerOptions diskConfig(String diskConfig) {
+         CreateServerOptions options = new CreateServerOptions();
+         return CreateServerOptions.class.cast(options.diskConfig(diskConfig));
+      }
    }
 
    @Override

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/e6b6e4ed/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java
----------------------------------------------------------------------
diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java
index c74a834..b6c0011 100644
--- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java
+++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerApiExpectTest.java
@@ -23,6 +23,7 @@ import static org.testng.Assert.fail;
 import org.jclouds.http.HttpRequest;
 import org.jclouds.http.HttpResponse;
 import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
 import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
 import org.jclouds.openstack.nova.v2_0.options.CreateServerOptions;
 import org.jclouds.openstack.nova.v2_0.parse.ParseCreatedServerTest;
@@ -127,6 +128,58 @@ public class ServerApiExpectTest extends BaseNovaApiExpectTest {
               new ParseCreatedServerTest().expected().toString());
    }
 
+   public void testCreateServerWithDiskConfigAuto() throws Exception {
+
+      HttpRequest createServer = HttpRequest
+         .builder()
+         .method("POST")
+         .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers")
+         .addHeader("Accept", "application/json")
+         .addHeader("X-Auth-Token", authToken)
+         .payload(payloadFromStringWithContentType(
+                  "{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\",\"OS-DCF:diskConfig\":\"AUTO\"}}","application/json"))
+         .build();
+
+
+      HttpResponse createServerResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted")
+         .payload(payloadFromResourceWithContentType("/new_server_disk_config_auto.json","application/json; charset=UTF-8")).build();
+
+
+      NovaApi apiWithNewServer = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, 
+            createServer, createServerResponse);
+
+      assertEquals(apiWithNewServer.getServerApiForZone("az-1.region-a.geo-1").create("test-e92", "1241",
+               "100", new CreateServerOptions().diskConfig(Server.DISK_CONFIG_AUTO)).toString(),
+              new ParseCreatedServerTest().expectedWithDiskConfig(Server.DISK_CONFIG_AUTO).toString());
+   }
+
+   public void testCreateServerWithDiskConfigManual() throws Exception {
+
+      HttpRequest createServer = HttpRequest
+         .builder()
+         .method("POST")
+         .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers")
+         .addHeader("Accept", "application/json")
+         .addHeader("X-Auth-Token", authToken)
+         .payload(payloadFromStringWithContentType(
+                  "{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\",\"OS-DCF:diskConfig\":\"MANUAL\"}}","application/json"))
+         .build();
+
+
+      HttpResponse createServerResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted")
+         .payload(payloadFromResourceWithContentType("/new_server_disk_config_manual.json","application/json; charset=UTF-8")).build();
+
+
+      NovaApi apiWithNewServer = requestsSendResponses(
+            keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, 
+            createServer, createServerResponse);
+
+      assertEquals(apiWithNewServer.getServerApiForZone("az-1.region-a.geo-1").create("test-e92", "1241",
+               "100", new CreateServerOptions().diskConfig(Server.DISK_CONFIG_MANUAL)).toString(),
+              new ParseCreatedServerTest().expectedWithDiskConfig(Server.DISK_CONFIG_MANUAL).toString());
+   }
+
    public void testCreateImageWhenResponseIs2xx() throws Exception {
       String serverId = "123";
       String imageId = "456";

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/e6b6e4ed/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseCreatedServerTest.java
----------------------------------------------------------------------
diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseCreatedServerTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseCreatedServerTest.java
index 9b6ce0a..3b2a774 100644
--- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseCreatedServerTest.java
+++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseCreatedServerTest.java
@@ -59,6 +59,21 @@ public class ParseCreatedServerTest extends BaseItemParserTest<ServerCreated> {
 
    }
 
+   @SelectJson("server")
+   @Consumes(MediaType.APPLICATION_JSON)
+   public ServerCreated expectedWithDiskConfig(String diskConfig) {
+      return ServerCreated
+            .builder()
+            .id("71752")
+            .name("test-e92")
+            .adminPass("ZWuHcmTMQ7eXoHeM")
+            .diskConfig(diskConfig)
+            .links(
+                     Link.create(Relation.SELF, URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71752")),
+                     Link.create(Relation.BOOKMARK, URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/servers/71752"))).build();
+
+   }
+
    protected Injector injector() {
       return Guice.createInjector(new NovaParserModule(), new GsonModule());
    }

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/e6b6e4ed/apis/openstack-nova/src/test/resources/new_server_disk_config_auto.json
----------------------------------------------------------------------
diff --git a/apis/openstack-nova/src/test/resources/new_server_disk_config_auto.json b/apis/openstack-nova/src/test/resources/new_server_disk_config_auto.json
new file mode 100644
index 0000000..7238333
--- /dev/null
+++ b/apis/openstack-nova/src/test/resources/new_server_disk_config_auto.json
@@ -0,0 +1,42 @@
+{
+    "server": {
+        "status": "BUILD(scheduling)",
+        "updated": "2012-03-19T06:21:13Z",
+        "hostId": "",
+        "user_id": "54297837463082",
+        "name": "test-e92",
+        "links": [{
+            "href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71752",
+            "rel": "self"
+        }, {
+            "href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/servers/71752",
+            "rel": "bookmark"
+        }],
+        "addresses": {},
+        "tenant_id": "37936628937291",
+        "image": {
+            "id": "1241",
+            "links": [{
+                "href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/images/1241",
+                "rel": "bookmark"
+            }]
+        },
+        "created": "2012-03-19T06:21:13Z",
+        "uuid": "47491020-6a78-4f63-9475-23195ac4515c",
+        "accessIPv4": "",
+        "accessIPv6": "",
+        "key_name": null,
+        "adminPass": "ZWuHcmTMQ7eXoHeM",
+        "flavor": {
+            "id": "100",
+            "links": [{
+                "href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/100",
+                "rel": "bookmark"
+            }]
+        },
+        "config_drive": "",
+        "id": 71752,
+        "metadata": {},
+        "OS-DCF:diskConfig": "AUTO"
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/e6b6e4ed/apis/openstack-nova/src/test/resources/new_server_disk_config_manual.json
----------------------------------------------------------------------
diff --git a/apis/openstack-nova/src/test/resources/new_server_disk_config_manual.json b/apis/openstack-nova/src/test/resources/new_server_disk_config_manual.json
new file mode 100644
index 0000000..2cfba41
--- /dev/null
+++ b/apis/openstack-nova/src/test/resources/new_server_disk_config_manual.json
@@ -0,0 +1,42 @@
+{
+    "server": {
+        "status": "BUILD(scheduling)",
+        "updated": "2012-03-19T06:21:13Z",
+        "hostId": "",
+        "user_id": "54297837463082",
+        "name": "test-e92",
+        "links": [{
+            "href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71752",
+            "rel": "self"
+        }, {
+            "href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/servers/71752",
+            "rel": "bookmark"
+        }],
+        "addresses": {},
+        "tenant_id": "37936628937291",
+        "image": {
+            "id": "1241",
+            "links": [{
+                "href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/images/1241",
+                "rel": "bookmark"
+            }]
+        },
+        "created": "2012-03-19T06:21:13Z",
+        "uuid": "47491020-6a78-4f63-9475-23195ac4515c",
+        "accessIPv4": "",
+        "accessIPv6": "",
+        "key_name": null,
+        "adminPass": "ZWuHcmTMQ7eXoHeM",
+        "flavor": {
+            "id": "100",
+            "links": [{
+                "href": "https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/100",
+                "rel": "bookmark"
+            }]
+        },
+        "config_drive": "",
+        "id": 71752,
+        "metadata": {},
+        "OS-DCF:diskConfig": "MANUAL"
+    }
+}
\ No newline at end of file