JCLOUDS-82: Use unwrapApi from View and remove custom method in ChefContext
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 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 @@
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 @@
}
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);
}
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 @@
*/
ChefService getChefService();
- /**
- * Provides access to the underlying Chef api.
- */
- <A extends ChefApi> A getApi(Class<A> apiClass);
-
}
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 @@
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) {
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 @@
@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";
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 @@
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) {
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.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 @@
}
@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();
}
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);
- }
- }
-}
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 void testCanAccessHostedChefApi() {
- HostedChefApi api = context.getApi(HostedChefApi.class);
+ HostedChefApi api = context.unwrapApi(HostedChefApi.class);
assertNotNull(api);
}
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 void testCanAccessPrivateChefApi() {
- PrivateChefApi api = context.getApi(PrivateChefApi.class);
+ PrivateChefApi api = context.unwrapApi(PrivateChefApi.class);
assertNotNull(api);
}
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 @@
}
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);