Updated Branches: refs/heads/master d9273ba56 -> 001c13d63
JCLOUDS-82: Use unwrapApi from View and remove custom method in ChefContext Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/commit/001c13d6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/tree/001c13d6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/diff/001c13d6 Branch: refs/heads/master Commit: 001c13d63f08ec819f01d6993090a7e110454c89 Parents: d9273ba Author: Ignasi Barrera <[email protected]> Authored: Mon May 27 09:48:26 2013 +0200 Committer: Ignasi Barrera <[email protected]> Committed: Mon May 27 22:14:55 2013 +0200 ---------------------------------------------------------------------- .../chef/compute/ChefComputeServiceLiveTest.java | 6 +- .../main/java/org/jclouds/chef/ChefContext.java | 5 - .../org/jclouds/chef/domain/CookbookVersion.java | 2 - .../java/org/jclouds/chef/domain/Environment.java | 2 - .../main/java/org/jclouds/chef/domain/Sandbox.java | 2 - .../org/jclouds/chef/internal/ChefContextImpl.java | 12 --- .../org/jclouds/chef/internal/ChefContextTest.java | 69 --------------- .../hostedchef/HostedChefApiContextTest.java | 2 +- .../privatechef/PrivateChefApiContextTest.java | 2 +- .../chef/servlet/ChefRegistrationListener.java | 2 +- 10 files changed, 7 insertions(+), 97 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java ---------------------------------------------------------------------- diff --git a/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java index 4e6ae16..71290d7 100644 --- a/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java @@ -33,6 +33,7 @@ import java.util.List; import org.jclouds.chef.ChefApi; import org.jclouds.chef.ChefContext; import org.jclouds.chef.compute.internal.BaseComputeServiceIntegratedChefClientLiveTest; +import org.jclouds.chef.domain.BootstrapConfig; import org.jclouds.chef.domain.CookbookVersion; import org.jclouds.chef.util.RunListBuilder; import org.jclouds.compute.RunNodesException; @@ -64,7 +65,8 @@ public class ChefComputeServiceLiveTest extends BaseComputeServiceIntegratedChef if (any(cookbookVersions, containsRecipe(recipe))) { List<String> runList = new RunListBuilder().addRecipe(recipe).build(); - view.getChefService().updateBootstrapConfigForGroup(runList, group); + BootstrapConfig bootstrap = BootstrapConfig.builder().runList(runList).build(); + view.getChefService().updateBootstrapConfigForGroup(group, bootstrap); assertEquals(view.getChefService().getRunListForGroup(group), runList); } else { assert false : String.format("recipe %s not in %s", recipe, cookbookVersions); @@ -105,7 +107,7 @@ public class ChefComputeServiceLiveTest extends BaseComputeServiceIntegratedChef } if (context != null) { view.getChefService().cleanupStaleNodesAndClients(group + "-", 1); - ChefApi api = view.getApi(ChefApi.class); + ChefApi api = view.unwrapApi(ChefApi.class); if (clientName != null && api.clientExists(clientName)) { api.deleteClient(clientName); } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/core/src/main/java/org/jclouds/chef/ChefContext.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/ChefContext.java b/core/src/main/java/org/jclouds/chef/ChefContext.java index f1ffb3b..a3d9d98 100644 --- a/core/src/main/java/org/jclouds/chef/ChefContext.java +++ b/core/src/main/java/org/jclouds/chef/ChefContext.java @@ -36,9 +36,4 @@ public interface ChefContext extends View, Closeable { */ ChefService getChefService(); - /** - * Provides access to the underlying Chef api. - */ - <A extends ChefApi> A getApi(Class<A> apiClass); - } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/core/src/main/java/org/jclouds/chef/domain/CookbookVersion.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/domain/CookbookVersion.java b/core/src/main/java/org/jclouds/chef/domain/CookbookVersion.java index 04ef11f..9251bd1 100644 --- a/core/src/main/java/org/jclouds/chef/domain/CookbookVersion.java +++ b/core/src/main/java/org/jclouds/chef/domain/CookbookVersion.java @@ -46,11 +46,9 @@ public class CookbookVersion { private Set<Resource> rootFiles = Sets.newLinkedHashSet(); // internal - @SuppressWarnings("unused") @SerializedName("json_class") private String _jsonClass = "Chef::CookbookVersion"; @SerializedName("chef_type") - @SuppressWarnings("unused") private String _chefType = "cookbook_version"; public CookbookVersion(String cookbookName, String version) { http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/core/src/main/java/org/jclouds/chef/domain/Environment.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/domain/Environment.java b/core/src/main/java/org/jclouds/chef/domain/Environment.java index 7d3e24a..d96caa7 100644 --- a/core/src/main/java/org/jclouds/chef/domain/Environment.java +++ b/core/src/main/java/org/jclouds/chef/domain/Environment.java @@ -33,10 +33,8 @@ public class Environment { @SerializedName("cookbook_versions") private Map<String, String> cookbookVersions = Maps.newLinkedHashMap(); // internal - @SuppressWarnings("unused") @SerializedName("json_class") private String _jsonClass = "Chef::Environment"; - @SuppressWarnings("unused") @SerializedName("chef_type") private String _chefType = "environment"; http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/core/src/main/java/org/jclouds/chef/domain/Sandbox.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/domain/Sandbox.java b/core/src/main/java/org/jclouds/chef/domain/Sandbox.java index 87c6aa4..2a2de28 100644 --- a/core/src/main/java/org/jclouds/chef/domain/Sandbox.java +++ b/core/src/main/java/org/jclouds/chef/domain/Sandbox.java @@ -41,11 +41,9 @@ public class Sandbox { private String guid; // internal - @SuppressWarnings("unused") @SerializedName("json_class") private String _jsonClass = "Chef::Sandbox"; @SerializedName("chef_type") - @SuppressWarnings("unused") private String _chefType = "sandbox"; public Sandbox(String rev, boolean isCompleted, Date createTime, Iterable<String> checksums, String name, String guid) { http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/core/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java b/core/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java index baa9786..e641e70 100644 --- a/core/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java +++ b/core/src/main/java/org/jclouds/chef/internal/ChefContextImpl.java @@ -24,14 +24,11 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.Context; -import org.jclouds.chef.ChefApi; import org.jclouds.chef.ChefContext; import org.jclouds.chef.ChefService; import org.jclouds.internal.BaseView; import org.jclouds.location.Provider; -import org.jclouds.rest.ApiContext; -import com.google.common.reflect.TypeParameter; import com.google.common.reflect.TypeToken; /** @@ -55,15 +52,6 @@ public class ChefContextImpl extends BaseView implements ChefContext { } @Override - public <A extends ChefApi> A getApi(Class<A> apiClass) { - TypeToken<ApiContext<A>> contextToken = new TypeToken<ApiContext<A>>(delegate().getClass()) { - private static final long serialVersionUID = 1L; - }.where(new TypeParameter<A>() { - }, TypeToken.of(apiClass)); - return unwrap(contextToken).getApi(); - } - - @Override public void close() throws IOException { delegate().close(); } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/core/src/test/java/org/jclouds/chef/internal/ChefContextTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/internal/ChefContextTest.java b/core/src/test/java/org/jclouds/chef/internal/ChefContextTest.java deleted file mode 100644 index f07cf02..0000000 --- a/core/src/test/java/org/jclouds/chef/internal/ChefContextTest.java +++ /dev/null @@ -1,69 +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.chef.internal; - -import static com.google.common.base.Throwables.propagate; -import static org.testng.Assert.assertNotNull; - -import java.io.IOException; - -import org.jclouds.ContextBuilder; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.ChefContext; -import org.jclouds.chef.filters.SignedHeaderAuthTest; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.internal.BaseRestApiTest.MockModule; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Tests the access to the underlying API from the context. - * - * @author Ignasi Barrera - */ -@Test(groups = "unit", testName = "ChefContextTest") -public class ChefContextTest { - - private ChefContext context; - - @BeforeClass - public void setup() { - context = ContextBuilder.newBuilder(new ChefApiMetadata()) - .credentials(SignedHeaderAuthTest.USER_ID, SignedHeaderAuthTest.PRIVATE_KEY) - .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())) // - .buildView(ChefContext.class); - } - - public void testCanAccessChefApi() { - ChefApi api = context.getApi(ChefApi.class); - assertNotNull(api); - } - - @AfterClass - public void tearDown() { - try { - context.close(); - } catch (IOException e) { - throw propagate(e); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java ---------------------------------------------------------------------- diff --git a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java index b6ede0c..ccdb53d 100644 --- a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java +++ b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java @@ -52,7 +52,7 @@ public class HostedChefApiContextTest { } public void testCanAccessHostedChefApi() { - HostedChefApi api = context.getApi(HostedChefApi.class); + HostedChefApi api = context.unwrapApi(HostedChefApi.class); assertNotNull(api); } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java ---------------------------------------------------------------------- diff --git a/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java b/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java index d0cc260..98fe2b9 100644 --- a/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java +++ b/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java @@ -52,7 +52,7 @@ public class PrivateChefApiContextTest { } public void testCanAccessPrivateChefApi() { - PrivateChefApi api = context.getApi(PrivateChefApi.class); + PrivateChefApi api = context.unwrapApi(PrivateChefApi.class); assertNotNull(api); } http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/001c13d6/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java ---------------------------------------------------------------------- diff --git a/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java b/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java index 95e8208..67b614b 100644 --- a/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java +++ b/servlet/src/main/java/org/jclouds/chef/servlet/ChefRegistrationListener.java @@ -93,7 +93,7 @@ public class ChefRegistrationListener implements ServletContextListener { } private String findNextNodeName(ChefService client, String pattern) { - ChefApi api = client.getContext().getApi(ChefApi.class); + ChefApi api = client.getContext().unwrapApi(ChefApi.class); Set<String> nodes = api.listNodes(); String nodeName; Set<String> names = newHashSet(nodes);
