Permalink
Browse files

Merge pull request #18 from nacx/1.5.0-SNAPSHOT

Added support for Chef 0.10
  • Loading branch information...
2 parents 20abbd3 + 8cc6732 commit 31348487829553369b92bd4367872ab4da13b92d Adrian Cole committed Jun 29, 2012
Showing with 1,187 additions and 79 deletions.
  1. +5 −4 core/src/main/java/org/jclouds/chef/ChefAsyncClient.java
  2. +0 −8 core/src/main/java/org/jclouds/chef/ChefClient.java
  3. +40 −0 core/src/main/java/org/jclouds/chef/config/ChefParserModule.java
  4. +45 −0 core/src/main/java/org/jclouds/chef/config/CookbookParser.java
  5. +45 −0 core/src/main/java/org/jclouds/chef/config/CookbookVersionsParser.java
  6. +157 −0 core/src/main/java/org/jclouds/chef/domain/CookbookDefinition.java
  7. +53 −0 core/src/main/java/org/jclouds/chef/functions/ParseCookbookDefinitionCheckingChefVersion.java
  8. +53 −0 core/src/main/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJson.java
  9. +53 −0 core/src/main/java/org/jclouds/chef/functions/ParseCookbookVersionsCheckingChefVersion.java
  10. +52 −0 core/src/main/java/org/jclouds/chef/functions/ParseCookbookVersionsV09FromJson.java
  11. +62 −0 core/src/main/java/org/jclouds/chef/functions/ParseCookbookVersionsV10FromJson.java
  12. +3 −0 core/src/main/java/org/jclouds/chef/functions/UriForResource.java
  13. +19 −1 core/src/test/java/org/jclouds/chef/ChefAsyncClientTest.java
  14. +11 −10 core/src/test/java/org/jclouds/chef/ChefClientLiveTest.java
  15. +11 −1 core/src/test/java/org/jclouds/chef/binders/BindHexEncodedMD5sToJsonPayloadTest.java
  16. +12 −2 core/src/test/java/org/jclouds/chef/functions/ParseClientFromJsonTest.java
  17. +66 −0 core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionCheckingChefVersionTest.java
  18. +91 −0 core/src/test/java/org/jclouds/chef/functions/ParseCookbookDefinitionFromJsonTest.java
  19. +12 −2 core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionFromJsonTest.java
  20. +66 −0 core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsCheckingChefVersionTest.java
  21. +72 −0 core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV09FromJsonTest.java
  22. +82 −0 core/src/test/java/org/jclouds/chef/functions/ParseCookbookVersionsV10FromJsonTest.java
  23. +11 −1 core/src/test/java/org/jclouds/chef/functions/ParseDataBagItemFromJsonTest.java
  24. +12 −2 core/src/test/java/org/jclouds/chef/functions/ParseKeySetFromJsonTest.java
  25. +12 −2 core/src/test/java/org/jclouds/chef/functions/ParseNodeFromJsonTest.java
  26. +12 −2 core/src/test/java/org/jclouds/chef/functions/ParseSandboxFromJsonTest.java
  27. +12 −2 core/src/test/java/org/jclouds/chef/functions/ParseUploadSandboxFromJsonTest.java
  28. +11 −1 core/src/test/java/org/jclouds/chef/functions/RunListForTagTest.java
  29. +11 −1 core/src/test/java/org/jclouds/chef/functions/TagToBootScriptTest.java
  30. +12 −7 core/src/test/java/org/jclouds/chef/internal/BaseChefClientLiveTest.java
  31. +1 −0 core/src/test/java/org/jclouds/chef/internal/BaseChefContextLiveTest.java
  32. +10 −1 core/src/test/java/org/jclouds/ohai/config/JMXTest.java
  33. +16 −2 core/src/test/java/org/jclouds/ohai/config/OhaiModuleTest.java
  34. +2 −12 core/src/test/java/org/jclouds/ohai/functions/ByteArrayToMacAddressTest.java
  35. +10 −1 core/src/test/java/org/jclouds/ohai/functions/NestSlashKeysTest.java
  36. +2 −2 labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefAsyncClient.java
  37. +23 −13 labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefAsyncClientTest.java
  38. +10 −1 labs/privatechef/src/test/java/org/jclouds/privatechef/functions/ParseOrganizationFromJsonTest.java
  39. +10 −1 labs/privatechef/src/test/java/org/jclouds/privatechef/functions/ParseUserFromJsonTest.java
@@ -53,6 +53,8 @@
import org.jclouds.chef.domain.SearchResult;
import org.jclouds.chef.domain.UploadSandbox;
import org.jclouds.chef.filters.SignedHeaderAuth;
+import org.jclouds.chef.functions.ParseCookbookDefinitionCheckingChefVersion;
+import org.jclouds.chef.functions.ParseCookbookVersionsCheckingChefVersion;
import org.jclouds.chef.functions.ParseKeySetFromJson;
import org.jclouds.chef.functions.ParseSearchClientsFromJson;
import org.jclouds.chef.functions.ParseSearchDatabagFromJson;
@@ -70,7 +72,6 @@
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
-import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
@@ -91,7 +92,7 @@
@Headers(keys = "X-Chef-Version", values = "{" + Constants.PROPERTY_API_VERSION + "}")
@Consumes(MediaType.APPLICATION_JSON)
public interface ChefAsyncClient {
- public static final String VERSION = "0.9.8";
+ public static final String VERSION = "0.10.8";
/**
* @see ChefClient#getUploadSandboxForChecksums(Set)
@@ -121,7 +122,7 @@
*/
@GET
@Path("/cookbooks")
- @ResponseParser(ParseKeySetFromJson.class)
+ @ResponseParser(ParseCookbookDefinitionCheckingChefVersion.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<String>> listCookbooks();
@@ -147,7 +148,7 @@
*/
@GET
@Path("/cookbooks/{cookbookname}")
- @Unwrap
+ @ResponseParser(ParseCookbookVersionsCheckingChefVersion.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<String>> getVersionsOfCookbook(@PathParam("cookbookname") String cookbookName);
@@ -24,8 +24,6 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import javax.ws.rs.GET;
-
import org.jclouds.chef.domain.Client;
import org.jclouds.chef.domain.CookbookVersion;
import org.jclouds.chef.domain.DatabagItem;
@@ -35,19 +33,13 @@
import org.jclouds.chef.domain.Sandbox;
import org.jclouds.chef.domain.SearchResult;
import org.jclouds.chef.domain.UploadSandbox;
-import org.jclouds.chef.functions.UriForResource;
import org.jclouds.chef.options.CreateClientOptions;
import org.jclouds.concurrent.Timeout;
import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payload;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.annotations.BinderParam;
-import org.jclouds.rest.annotations.EndpointParam;
-import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.binders.BindToJsonPayload;
-import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
-
-import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides synchronous access to Chef.
@@ -30,18 +30,28 @@
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.chef.domain.DatabagItem;
+import org.jclouds.chef.functions.ParseCookbookDefinitionFromJson;
+import org.jclouds.chef.functions.ParseCookbookVersionsV09FromJson;
+import org.jclouds.chef.functions.ParseCookbookVersionsV10FromJson;
+import org.jclouds.chef.functions.ParseKeySetFromJson;
import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.Pems;
+import org.jclouds.http.HttpResponse;
import org.jclouds.io.InputSuppliers;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.json.internal.NullHackJsonLiteralAdapter;
+import org.jclouds.rest.annotations.ApiVersion;
+import com.google.common.base.Function;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
@@ -205,6 +215,36 @@ protected String toString(DatabagItem value) {
return ImmutableMap.<Type, Object> of(DatabagItem.class, adapter, PrivateKey.class, privateAdapter,
PublicKey.class, publicAdapter, X509Certificate.class, certAdapter);
}
+
+ @Provides
+ @Singleton
+ @CookbookParser
+ public Function<HttpResponse, Set<String>> provideCookbookDefinitionAdapter(@ApiVersion String apiVersion,
+ ParseCookbookDefinitionFromJson v10parser, ParseKeySetFromJson v09parser) {
+ Pattern versionPattern = Pattern.compile("\\d\\.(\\d)\\.\\d");
+ Matcher m = versionPattern.matcher(apiVersion);
+ if (m.matches()) {
+ return Integer.valueOf(m.group(1)) > 9? v10parser : v09parser;
+ } else {
+ // Default to the latest version of the parser
+ return v10parser;
+ }
+ }
+
+ @Provides
+ @Singleton
+ @CookbookVersionsParser
+ public Function<HttpResponse, Set<String>> provideCookbookDefinitionAdapter(@ApiVersion String apiVersion,
+ ParseCookbookVersionsV10FromJson v10parser, ParseCookbookVersionsV09FromJson v09parser) {
+ Pattern versionPattern = Pattern.compile("\\d\\.(\\d)\\.\\d");
+ Matcher m = versionPattern.matcher(apiVersion);
+ if (m.matches()) {
+ return Integer.valueOf(m.group(1)) > 9? v10parser : v09parser;
+ } else {
+ // Default to the latest version of the parser
+ return v10parser;
+ }
+ }
@Override
protected void configure() {
@@ -0,0 +1,45 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds 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.chef.config;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Used to configure the cookbook Json parser.
+ * <p>
+ * Chef Server version 0.9 and 0.10 return a different Json when rquesting the cookbook
+ * definitions. This annotation can be used to setup the cookbook parser.
+ *
+ * @author Ignasi Barrera
+ */
+@Target({METHOD, PARAMETER, FIELD})
+@Retention(RUNTIME)
+@Qualifier
+public @interface CookbookParser
+{
+
+}
@@ -0,0 +1,45 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds 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.chef.config;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Used to configure the cookbook versions Json parser.
+ * <p>
+ * Chef Server version 0.9 and 0.10 return a different Json when rquesting the cookbook
+ * versions. This annotation can be used to setup the cookbook versions parser.
+ *
+ * @author Ignasi Barrera
+ */
+@Target({METHOD, PARAMETER, FIELD})
+@Retention(RUNTIME)
+@Qualifier
+public @interface CookbookVersionsParser
+{
+
+}
@@ -0,0 +1,157 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds 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.chef.domain;
+
+import java.net.URI;
+import java.util.Set;
+
+import com.google.common.collect.Sets;
+
+/**
+ * Cookbook definition as returned by the Chef server >= 0.10.8.
+ *
+ * @author Ignasi Barrera
+ */
+public class CookbookDefinition {
+
+ private URI url;
+ private Set<Version> versions = Sets.newLinkedHashSet();
+
+ // only for deserialization
+ CookbookDefinition() {
+
+ }
+
+ public CookbookDefinition(URI url, Set<Version> versions) {
+ this.url = url;
+ this.versions = versions;
+ }
+
+ public URI getUrl() {
+ return url;
+ }
+
+ public Set<Version> getVersions() {
+ return versions;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((url == null) ? 0 : url.hashCode());
+ result = prime * result + ((versions == null) ? 0 : versions.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ CookbookDefinition other = (CookbookDefinition) obj;
+ if (url == null)
+ {
+ if (other.url != null)
+ return false;
+ }
+ else if (!url.equals(other.url))
+ return false;
+ if (versions == null)
+ {
+ if (other.versions != null)
+ return false;
+ }
+ else if (!versions.equals(other.versions))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "CookbookDefinition [url=" + url + ", versions=" + versions + "]";
+ }
+
+
+ public static class Version {
+ private URI url;
+ private String version;
+
+ // only for deserialization
+ Version() {
+
+ }
+
+ public Version(URI url, String version) {
+ this.url = url;
+ this.version = version;
+ }
+
+ public URI getUrl() {
+ return url;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((url == null) ? 0 : url.hashCode());
+ result = prime * result + ((version == null) ? 0 : version.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Version other = (Version) obj;
+ if (url == null)
+ {
+ if (other.url != null)
+ return false;
+ }
+ else if (!url.equals(other.url))
+ return false;
+ if (version == null)
+ {
+ if (other.version != null)
+ return false;
+ }
+ else if (!version.equals(other.version))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "Version [url=" + url + ", version=" + version + "]";
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 3134848

Please sign in to comment.