Remove the deprecated methods in Chef

This commit is contained in:
Ignasi Barrera 2015-04-30 17:20:47 +02:00
parent deeebe46f7
commit 4863bb83a9
32 changed files with 122 additions and 714 deletions

View File

@ -56,10 +56,10 @@ import org.jclouds.chef.domain.Sandbox;
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.ParseCookbookDefinitionFromJsonv10;
import org.jclouds.chef.functions.ParseCookbookDefinitionListFromJsonv10;
import org.jclouds.chef.functions.ParseCookbookVersionsCheckingChefVersion;
import org.jclouds.chef.functions.ParseCookbookDefinitionListFromJson;
import org.jclouds.chef.functions.ParseCookbookNamesFromJson;
import org.jclouds.chef.functions.ParseCookbookDefinitionFromJson;
import org.jclouds.chef.functions.ParseCookbookVersionsFromJson;
import org.jclouds.chef.functions.ParseKeySetFromJson;
import org.jclouds.chef.functions.ParseSearchClientsFromJson;
import org.jclouds.chef.functions.ParseSearchDatabagFromJson;
@ -118,7 +118,7 @@ public interface ChefApi extends Closeable {
/**
* Gets the details of existing client.
*
* @param clientname The name of the client to get.
* @param clientName The name of the client to get.
* @return The details of the given client.
*/
@Named("client:get")
@ -130,7 +130,7 @@ public interface ChefApi extends Closeable {
/**
* Creates a new client.
*
* @param clientname The name of the new client
* @param clientName The name of the new client
* @return The client with the generated private key. This key should be
* stored so client can be properly authenticated .
*/
@ -143,7 +143,7 @@ public interface ChefApi extends Closeable {
/**
* Creates a new client with custom options.
*
* @param clientname The name of the new client
* @param clientName The name of the new client
* @param options The options to customize the client creation.
* @return The client with the generated private key. This key should be
* stored so client can be properly authenticated .
@ -158,7 +158,7 @@ public interface ChefApi extends Closeable {
* Generates a new key-pair for this client, and return the new private key in
* the response body.
*
* @param clientname The name of the client.
* @param clientName The name of the client.
* @return The details of the client with the new private key.
*/
@Named("client:generatekey")
@ -170,7 +170,7 @@ public interface ChefApi extends Closeable {
/**
* Deletes the given client.
*
* @param clientname The name of the client to delete.
* @param clientName The name of the client to delete.
* @return The deleted client.
*/
@Named("client:delete")
@ -189,14 +189,14 @@ public interface ChefApi extends Closeable {
@Named("cookbook:list")
@GET
@Path("/cookbooks")
@ResponseParser(ParseCookbookDefinitionCheckingChefVersion.class)
@ResponseParser(ParseCookbookNamesFromJson.class)
@Fallback(EmptySetOnNotFoundOr404.class)
Set<String> listCookbooks();
/**
* Lists the cookbooks that are available in the given environment.
*
* @param environmentname The name of the environment to get the cookbooks
* @param environmentName The name of the environment to get the cookbooks
* from.
* @return The definitions of the cookbooks (name, URL and versions) available in
* the given environment.
@ -204,7 +204,7 @@ public interface ChefApi extends Closeable {
@SinceApiVersion("0.10.0")
@Named("cookbook:list")
@GET
@ResponseParser(ParseCookbookDefinitionListFromJsonv10.class)
@ResponseParser(ParseCookbookDefinitionListFromJson.class)
@Path("/environments/{environmentname}/cookbooks")
@Fallback(EmptySetOnNotFoundOr404.class)
Set<CookbookDefinition> listCookbooksInEnvironment(@PathParam("environmentname") String environmentName);
@ -213,9 +213,9 @@ public interface ChefApi extends Closeable {
* Lists the cookbooks that are available in the given environment, limiting
* the number of versions returned for each cookbook.
*
* @param environmentname The name of the environment to get the cookbooks
* @param environmentName The name of the environment to get the cookbooks
* from.
* @param numversions The number of cookbook versions to include in the
* @param numVersions The number of cookbook versions to include in the
* response, where n is the number of cookbook versions.
* @return The definitions of the cookbooks (name, URL and versions) available in
* the given environment.
@ -223,7 +223,7 @@ public interface ChefApi extends Closeable {
@SinceApiVersion("0.10.0")
@Named("cookbook:list")
@GET
@ResponseParser(ParseCookbookDefinitionListFromJsonv10.class)
@ResponseParser(ParseCookbookDefinitionListFromJson.class)
@Path("/environments/{environmentname}/cookbooks?num_versions={numversions}")
@Fallback(EmptySetOnNotFoundOr404.class)
Set<CookbookDefinition> listCookbooksInEnvironment(@PathParam("environmentname") String environmentName,
@ -238,7 +238,7 @@ public interface ChefApi extends Closeable {
@Named("cookbook:versions")
@GET
@Path("/cookbooks/{cookbookname}")
@ResponseParser(ParseCookbookVersionsCheckingChefVersion.class)
@ResponseParser(ParseCookbookVersionsFromJson.class)
@Fallback(EmptySetOnNotFoundOr404.class)
Set<String> listVersionsOfCookbook(@PathParam("cookbookname") String cookbookName);
@ -259,15 +259,15 @@ public interface ChefApi extends Closeable {
/**
* Gets the definition of the cookbook in the given environment.
*
* @param environmentname The name of the environment.
* @param cookbookname The name of the cookbook.
* @param environmentName The name of the environment.
* @param cookbookName The name of the cookbook.
* @return The definition of the cookbook (URL and versions) of the cookbook
* in the given environment.
*/
@SinceApiVersion("0.10.0")
@Named("environment:cookbook")
@GET
@ResponseParser(ParseCookbookDefinitionFromJsonv10.class)
@ResponseParser(ParseCookbookDefinitionFromJson.class)
@Path("/environments/{environmentname}/cookbooks/{cookbookname}")
CookbookDefinition getCookbookInEnvironment(@PathParam("environmentname") String environmentName,
@PathParam("cookbookname") String cookbookName);
@ -275,9 +275,9 @@ public interface ChefApi extends Closeable {
/**
* Gets the definition of the cookbook in the given environment.
*
* @param environmentname The name of the environment.
* @param cookbookname The name of the cookbook.
* @param numversions The number of cookbook versions to include in the
* @param environmentName The name of the environment.
* @param cookbookName The name of the cookbook.
* @param numVersions The number of cookbook versions to include in the
* response, where n is the number of cookbook versions.
* @return The definition of the cookbook (URL and versions) of the cookbook
* in the given environment.
@ -285,7 +285,7 @@ public interface ChefApi extends Closeable {
@SinceApiVersion("0.10.0")
@Named("environment:cookbook")
@GET
@ResponseParser(ParseCookbookDefinitionFromJsonv10.class)
@ResponseParser(ParseCookbookDefinitionFromJson.class)
@Path("/environments/{environmentname}/cookbooks/{cookbookname}?num_versions={numversions}")
CookbookDefinition getCookbookInEnvironment(@PathParam("environmentname") String environmentName,
@PathParam("cookbookname") String cookbookName, @PathParam("numversions") String numVersions);
@ -293,7 +293,7 @@ public interface ChefApi extends Closeable {
/**
* Lists the names of the recipes in the given environment.
*
* @param environmentname The name of the environment.
* @param environmentName The name of the environment.
* @return The names of the recipes in the given environment.
*/
@SinceApiVersion("0.10.0")
@ -396,8 +396,8 @@ public interface ChefApi extends Closeable {
* Adds an item in a data bag.
*
* @param databagName The name of the data bag.
* @param The item to add to the data bag.
* @param The item just added to the data bag.
* @param databagItem item to add to the data bag.
* @return The item just added to the data bag.
*/
@Named("databag:createitem")
@POST
@ -452,7 +452,7 @@ public interface ChefApi extends Closeable {
/**
* Gets the details of an existing environment.
*
* @param environmentname The name of the environment to get.
* @param environmentName The name of the environment to get.
* @return The details of the given environment.
*/
@SinceApiVersion("0.10.0")
@ -489,7 +489,7 @@ public interface ChefApi extends Closeable {
/**
* Deletes the given environment.
*
* @param environmentname The name of the environment to delete.
* @param environmentName The name of the environment to delete.
* @return The details of the deleted environment.
*/
@SinceApiVersion("0.10.0")
@ -516,7 +516,7 @@ public interface ChefApi extends Closeable {
/**
* Lists the names of the nodes in the given environment.
*
* @param environmentname The name of the environment.
* @param environmentName The name of the environment.
* @return The names of the existing nodes in the given environment.
*/
@SinceApiVersion("0.10.0")
@ -530,7 +530,7 @@ public interface ChefApi extends Closeable {
/**
* Gets the details of the given node.
*
* @param nodename The name of the node to get.
* @param nodeName The name of the node to get.
* @return The details of the given node.
*/
@Named("node:get")
@ -563,7 +563,7 @@ public interface ChefApi extends Closeable {
/**
* Deletes the given node.
*
* @param nodename The name of the node to delete.
* @param nodeName The name of the node to delete.
* @return The details of the deleted node.
*/
@Named("node:delete")
@ -589,7 +589,7 @@ public interface ChefApi extends Closeable {
/**
* Gets the details of the given role.
*
* @param rolename The name of the role to get.
* @param roleName The name of the role to get.
* @return The details of the given role.
*/
@Named("role:get")
@ -622,7 +622,7 @@ public interface ChefApi extends Closeable {
/**
* Deletes the given role.
*
* @param rolename The name of the role to delete.
* @param roleName The name of the role to delete.
* @return The details of the deleted role.
*/
@Named("role:delete")

View File

@ -93,7 +93,6 @@ public class ChefApiMetadata extends BaseHttpApiMetadata<ChefApi> {
.documentation(URI.create("http://wiki.opscode.com/display/chef/Server+API"))
.defaultEndpoint("http://localhost:4000")
.defaultProperties(ChefApiMetadata.defaultProperties())
.view(ChefContext.class)
.defaultModules(
ImmutableSet.<Class<? extends Module>> of(ChefHttpApiModule.class, ChefParserModule.class,
ChefBootstrapModule.class, JMXOhaiModule.class));

View File

@ -1,42 +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;
import java.io.Closeable;
import org.jclouds.View;
import org.jclouds.chef.internal.ChefContextImpl;
import com.google.inject.ImplementedBy;
/**
* Provides an entry point to Chef features.
*
* @deprecated Will be removed in next version. Directly create the
* {@link ChefApi} instead and access the {@link ChefService} from
* it.
*/
@ImplementedBy(ChefContextImpl.class)
@Deprecated
public interface ChefContext extends View, Closeable {
/**
* Provides access to high level Chef features.
*/
ChefService getChefService();
}

View File

@ -18,7 +18,6 @@ package org.jclouds.chef;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.concurrent.ExecutorService;
import org.jclouds.chef.config.ChefProperties;
@ -34,7 +33,6 @@ import org.jclouds.ohai.config.OhaiModule;
import org.jclouds.rest.annotations.SinceApiVersion;
import org.jclouds.scriptbuilder.domain.Statement;
import com.google.common.io.InputSupplier;
import com.google.inject.ImplementedBy;
/**
@ -43,32 +41,25 @@ import com.google.inject.ImplementedBy;
@ImplementedBy(BaseChefService.class)
public interface ChefService {
/**
* Gets the context that created this service.
*
* @return The context that created the service.
*/
ChefContext getContext();
// Crypto
/**
* Encrypts the given input stream.
*
* @param supplier The input stream to encrypt.
* @param input The input stream to encrypt.
* @return The encrypted bytes for the given input stream.
* @throws IOException If there is an error reading from the input stream.
*/
byte[] encrypt(InputSupplier<? extends InputStream> supplier) throws IOException;
byte[] encrypt(InputStream input) throws IOException;
/**
* Decrypts the given input stream.
*
* @param supplier The input stream to decrypt.
* @param input The input stream to decrypt.
* @return The decrypted bytes for the given input stream.
* @throws IOException If there is an error reading from the input stream.
*/
byte[] decrypt(InputSupplier<? extends InputStream> supplier) throws IOException;
byte[] decrypt(InputStream input) throws IOException;
// Bootstrap
@ -103,16 +94,6 @@ public interface ChefService {
*/
void updateBootstrapConfigForGroup(String group, BootstrapConfig bootstrapConfig);
/**
* Gets the run list for the given group.
*
* @param The group to get the configured run list for.
* @return run list for all nodes bootstrapped with a certain group
* @deprecated USe {{@link #getBootstrapConfigForGroup(String)}.
*/
@Deprecated
List<String> getRunListForGroup(String group);
/**
* Gets the bootstrap configuration for a given group.
*

View File

@ -30,27 +30,19 @@ import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.util.Map;
import java.util.Set;
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.chef.suppliers.ChefVersionSupplier;
import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.Pems;
import org.jclouds.http.HttpResponse;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.json.internal.NullFilteringTypeAdapterFactories.MapTypeAdapterFactory;
import org.jclouds.json.internal.NullHackJsonLiteralAdapter;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
@ -297,22 +289,6 @@ public class ChefParserModule extends AbstractModule {
PublicKey.class, publicAdapter, X509Certificate.class, certAdapter);
}
@Provides
@Singleton
@CookbookParser
public Function<HttpResponse, Set<String>> provideCookbookDefinitionAdapter(ChefVersionSupplier chefVersionSupplier,
ParseCookbookDefinitionFromJson v10parser, ParseKeySetFromJson v09parser) {
return chefVersionSupplier.get() >= 10 ? v10parser : v09parser;
}
@Provides
@Singleton
@CookbookVersionsParser
public Function<HttpResponse, Set<String>> provideCookbookDefinitionAdapter(ChefVersionSupplier chefVersionSupplier,
ParseCookbookVersionsV10FromJson v10parser, ParseCookbookVersionsV09FromJson v09parser) {
return chefVersionSupplier.get() >= 10 ? v10parser : v09parser;
}
@Override
protected void configure() {
bind(DateAdapter.class).to(Iso8601DateAdapter.class);

View File

@ -1,43 +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.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.
* @deprecated Support for Chef 0.9 and 0.10 will be removed in upcoming versions.
*/
@Target({ METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Qualifier
@Deprecated
public @interface CookbookParser {
}

View File

@ -1,43 +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.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.
* @deprecated Support for Chef 0.9 and 0.10 will be removed in upcoming versions.
*/
@Target({ METHOD, PARAMETER, FIELD })
@Retention(RUNTIME)
@Qualifier
@Deprecated
public @interface CookbookVersionsParser {
}

View File

@ -1,51 +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.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.chef.config.CookbookParser;
import org.jclouds.http.HttpResponse;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
/**
* Parses a cookbook definition from a Json response, taking care of using the
* appropriate parser.
* @deprecated Support for Chef 0.9 and 0.10 will be removed in upcoming verions.
*/
@Singleton
@Deprecated
public class ParseCookbookDefinitionCheckingChefVersion implements Function<HttpResponse, Set<String>> {
@VisibleForTesting
final Function<HttpResponse, Set<String>> parser;
@Inject
ParseCookbookDefinitionCheckingChefVersion(@CookbookParser Function<HttpResponse, Set<String>> parser) {
this.parser = parser;
}
@Override
public Set<String> apply(HttpResponse response) {
return parser.apply(response);
}
}

View File

@ -16,24 +16,20 @@
*/
package org.jclouds.chef.functions;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.common.base.Function;
import org.jclouds.chef.domain.CookbookDefinition;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import com.google.common.base.Function;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Map;
/**
* Parses a cookbook definition from a Json response, assuming a Chef Server >=
* 0.10.8.
* Parses the cookbook versions in a Chef Server >= 0.10.8.
*/
@Singleton
public class ParseCookbookDefinitionFromJson implements Function<HttpResponse, Set<String>> {
public class ParseCookbookDefinitionFromJson implements Function<HttpResponse, CookbookDefinition> {
/** Parser for responses from chef server >= 0.10.8 */
private final ParseJson<Map<String, CookbookDefinition>> parser;
@ -44,7 +40,13 @@ public class ParseCookbookDefinitionFromJson implements Function<HttpResponse, S
}
@Override
public Set<String> apply(HttpResponse response) {
return parser.apply(response).keySet();
public CookbookDefinition apply(HttpResponse response) {
Map<String, CookbookDefinition> result = parser.apply(response);
String cookbookName = result.keySet().iterator().next();
CookbookDefinition def = result.values().iterator().next();
return CookbookDefinition.builder() //
.from(def) //
.name(cookbookName) //
.build();
}
}

View File

@ -1,52 +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.functions;
import com.google.common.base.Function;
import org.jclouds.chef.domain.CookbookDefinition;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Map;
/**
* Parses the cookbook versions in a Chef Server >= 0.10.8.
*/
@Singleton
public class ParseCookbookDefinitionFromJsonv10 implements Function<HttpResponse, CookbookDefinition> {
/** Parser for responses from chef server >= 0.10.8 */
private final ParseJson<Map<String, CookbookDefinition>> parser;
@Inject
ParseCookbookDefinitionFromJsonv10(ParseJson<Map<String, CookbookDefinition>> parser) {
this.parser = parser;
}
@Override
public CookbookDefinition apply(HttpResponse response) {
Map<String, CookbookDefinition> result = parser.apply(response);
String cookbookName = result.keySet().iterator().next();
CookbookDefinition def = result.values().iterator().next();
return CookbookDefinition.builder() //
.from(def) //
.name(cookbookName) //
.build();
}
}

View File

@ -33,7 +33,7 @@ import static com.google.common.collect.Sets.newLinkedHashSet;
* Parses the cookbook versions in a Chef Server >= 0.10.8.
*/
@Singleton
public class ParseCookbookDefinitionListFromJsonv10 implements Function<HttpResponse, Set<CookbookDefinition>> {
public class ParseCookbookDefinitionListFromJson implements Function<HttpResponse, Set<CookbookDefinition>> {
/**
* Parser for responses from chef server >= 0.10.8
@ -41,7 +41,7 @@ public class ParseCookbookDefinitionListFromJsonv10 implements Function<HttpResp
private final ParseJson<Map<String, CookbookDefinition>> parser;
@Inject
ParseCookbookDefinitionListFromJsonv10(ParseJson<Map<String, CookbookDefinition>> parser) {
ParseCookbookDefinitionListFromJson(ParseJson<Map<String, CookbookDefinition>> parser) {
this.parser = parser;
}

View File

@ -22,30 +22,29 @@ import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.chef.domain.CookbookDefinition;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import com.google.common.base.Function;
import static com.google.common.collect.Iterables.getFirst;
/**
* Parses the cookbook versions in a Chef Server <= 0.9.8.
* @deprecated Support for Chef 0.9 and 0.10 will be removed in upcoming versions.
* Parses a cookbook definition from a Json response, assuming a Chef Server >=
* 0.10.8.
*/
@Singleton
@Deprecated
public class ParseCookbookVersionsV09FromJson implements Function<HttpResponse, Set<String>> {
public class ParseCookbookNamesFromJson implements Function<HttpResponse, Set<String>> {
private final ParseJson<Map<String, Set<String>>> json;
/** Parser for responses from chef server >= 0.10.8 */
private final ParseJson<Map<String, CookbookDefinition>> parser;
@Inject
ParseCookbookVersionsV09FromJson(ParseJson<Map<String, Set<String>>> json) {
this.json = json;
ParseCookbookNamesFromJson(ParseJson<Map<String, CookbookDefinition>> parser) {
this.parser = parser;
}
@Override
public Set<String> apply(HttpResponse response) {
return getFirst(json.apply(response).values(), null);
return parser.apply(response).keySet();
}
}

View File

@ -1,51 +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.functions;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.chef.config.CookbookVersionsParser;
import org.jclouds.http.HttpResponse;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
/**
* Parses a cookbook versions from a Json response, taking care of using the
* appropriate parser.
* @deprecated Support for Chef 0.9 and 0.10 will be removed in upcoming verions.
*/
@Singleton
@Deprecated
public class ParseCookbookVersionsCheckingChefVersion implements Function<HttpResponse, Set<String>> {
@VisibleForTesting
final Function<HttpResponse, Set<String>> parser;
@Inject
ParseCookbookVersionsCheckingChefVersion(@CookbookVersionsParser Function<HttpResponse, Set<String>> parser) {
this.parser = parser;
}
@Override
public Set<String> apply(HttpResponse response) {
return parser.apply(response);
}
}

View File

@ -36,13 +36,13 @@ import static com.google.common.collect.Sets.newLinkedHashSet;
* Parses the cookbook versions in a Chef Server >= 0.10.8.
*/
@Singleton
public class ParseCookbookVersionsV10FromJson implements Function<HttpResponse, Set<String>> {
public class ParseCookbookVersionsFromJson implements Function<HttpResponse, Set<String>> {
/** Parser for responses from chef server >= 0.10.8 */
private final ParseJson<Map<String, CookbookDefinition>> parser;
@Inject
ParseCookbookVersionsV10FromJson(ParseJson<Map<String, CookbookDefinition>> parser) {
ParseCookbookVersionsFromJson(ParseJson<Map<String, CookbookDefinition>> parser) {
this.parser = parser;
}

View File

@ -22,8 +22,6 @@ import static org.jclouds.chef.config.ChefProperties.CHEF_BOOTSTRAP_DATABAG;
import java.io.IOException;
import java.io.InputStream;
import java.security.PrivateKey;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import javax.annotation.Resource;
@ -32,7 +30,6 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.chef.ChefApi;
import org.jclouds.chef.ChefContext;
import org.jclouds.chef.ChefService;
import org.jclouds.chef.config.ChefProperties;
import org.jclouds.chef.domain.BootstrapConfig;
@ -56,6 +53,7 @@ import org.jclouds.chef.strategy.ListNodesInEnvironment;
import org.jclouds.chef.strategy.UpdateAutomaticAttributesOnNode;
import org.jclouds.crypto.Crypto;
import org.jclouds.io.ByteStreams2;
import org.jclouds.io.Payload;
import org.jclouds.io.Payloads;
import org.jclouds.io.payloads.RSADecryptingPayload;
import org.jclouds.io.payloads.RSAEncryptingPayload;
@ -65,14 +63,11 @@ import org.jclouds.logging.Logger;
import org.jclouds.scriptbuilder.domain.Statement;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.io.InputSupplier;
@Singleton
public class BaseChefService implements ChefService {
private final ChefContext chefContext;
private final ChefApi api;
private final CleanupStaleNodesAndClients cleanupStaleNodesAndClients;
private final CreateNodeAndPopulateAutomaticAttributes createNodeAndPopulateAutomaticAttributes;
@ -97,7 +92,7 @@ public class BaseChefService implements ChefService {
protected Logger logger = Logger.NULL;
@Inject
BaseChefService(ChefContext chefContext, ChefApi api, CleanupStaleNodesAndClients cleanupStaleNodesAndClients,
BaseChefService(ChefApi api, CleanupStaleNodesAndClients cleanupStaleNodesAndClients,
CreateNodeAndPopulateAutomaticAttributes createNodeAndPopulateAutomaticAttributes,
DeleteAllNodesInList deleteAllNodesInList, ListNodes listNodes, DeleteAllClientsInList deleteAllClientsInList,
ListClients listClients, ListCookbookVersions listCookbookVersions,
@ -106,7 +101,6 @@ public class BaseChefService implements ChefService {
BootstrapConfigForGroup bootstrapConfigForGroup, ListEnvironments listEnvironments,
ListNodesInEnvironment listNodesInEnvironment,
ListCookbookVersionsInEnvironment listCookbookVersionsInEnvironment, Json json, Crypto crypto) {
this.chefContext = chefContext;
this.api = api;
this.cleanupStaleNodesAndClients = cleanupStaleNodesAndClients;
this.createNodeAndPopulateAutomaticAttributes = createNodeAndPopulateAutomaticAttributes;
@ -128,26 +122,17 @@ public class BaseChefService implements ChefService {
}
@Override
public ChefContext getContext() {
return chefContext;
public byte[] encrypt(InputStream input) throws IOException {
@SuppressWarnings("resource")
Payload payload = new RSAEncryptingPayload(crypto, Payloads.newPayload(input), privateKey.get());
return ByteStreams2.toByteArrayAndClose(payload.openStream());
}
@Override
public byte[] encrypt(InputSupplier<? extends InputStream> supplier) throws IOException {
return ByteStreams2.toByteArrayAndClose(new RSAEncryptingPayload(crypto,
Payloads.newPayload(supplier.getInput()), privateKey.get()).openStream());
}
@Override
public byte[] decrypt(InputSupplier<? extends InputStream> supplier) throws IOException {
return ByteStreams2.toByteArrayAndClose(new RSADecryptingPayload(crypto,
Payloads.newPayload(supplier.getInput()), privateKey.get()).openStream());
}
private static void putIfPresent(Map<String, Object> configMap, Optional<?> configProperty, String name) {
if (configProperty.isPresent()) {
configMap.put(name, configProperty.get().toString());
}
public byte[] decrypt(InputStream input) throws IOException {
@SuppressWarnings("resource")
Payload payload = new RSADecryptingPayload(crypto, Payloads.newPayload(input), privateKey.get());
return ByteStreams2.toByteArrayAndClose(payload.openStream());
}
@Override
@ -184,15 +169,6 @@ public class BaseChefService implements ChefService {
return json.toJson(config);
}
/**
* @deprecated Use {{@link #getBootstrapConfigForGroup(String)}.
*/
@Override
@Deprecated
public List<String> getRunListForGroup(String group) {
return getBootstrapConfigForGroup(group).getRunList();
}
@Override
public BootstrapConfig getBootstrapConfigForGroup(String group) {
return bootstrapConfigForGroup.apply(group);

View File

@ -1,62 +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.Preconditions.checkNotNull;
import java.io.IOException;
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 com.google.common.reflect.TypeToken;
/**
* @deprecated Will be removed in next version. Directly create the
* {@link ChefApi} instead and access the {@link ChefService} from
* it.
*/
@Singleton
@Deprecated
public class ChefContextImpl extends BaseView implements ChefContext {
private final ChefService chefService;
@Inject
protected ChefContextImpl(@Provider Context backend, @Provider TypeToken<? extends Context> backendType,
ChefService chefService) {
super(backend, backendType);
this.chefService = checkNotNull(chefService, "chefService");
}
@Override
public ChefService getChefService() {
return chefService;
}
@Override
public void close() throws IOException {
delegate().close();
}
}

View File

@ -39,7 +39,7 @@ import org.jclouds.chef.domain.Resource;
import org.jclouds.chef.domain.Role;
import org.jclouds.chef.filters.SignedHeaderAuth;
import org.jclouds.chef.filters.SignedHeaderAuthTest;
import org.jclouds.chef.functions.ParseCookbookVersionsCheckingChefVersion;
import org.jclouds.chef.functions.ParseCookbookVersionsFromJson;
import org.jclouds.chef.functions.ParseKeySetFromJson;
import org.jclouds.chef.functions.ParseSearchClientsFromJson;
import org.jclouds.chef.functions.ParseSearchDatabagFromJson;
@ -199,7 +199,7 @@ public class ChefApiTest extends BaseRestAnnotationProcessingTest<ChefApi> {
+ "-test\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionsCheckingChefVersion.class);
assertResponseParserClassEquals(method, httpRequest, ParseCookbookVersionsFromJson.class);
assertSaxResponseParserClassEquals(method, null);
assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);

View File

@ -79,6 +79,7 @@ public class ParseClientFromJsonTest {
privateKey = crypto.rsaKeyFactory().generatePrivate(Pems.privateKeySpec(ByteSource.wrap(PRIVATE_KEY.getBytes(Charsets.UTF_8))));
}
@SuppressWarnings("resource")
public void test() throws IOException, CertificateException, NoSuchAlgorithmException {
Client user = Client.builder().certificate(certificate).orgname("jclouds").clientname("adriancole-jcloudstest")

View File

@ -1,62 +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.functions;
import static org.testng.Assert.assertTrue;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.ApiVersion;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseCookbookDefinitionCheckingChefVersion}.
*/
@Test(groups = { "unit" }, singleThreaded = true)
public class ParseCookbookDefinitionCheckingChefVersionTest {
public void testParserFor09() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8");
}
}, new ChefParserModule(), new GsonModule());
ParseCookbookDefinitionCheckingChefVersion parser = injector
.getInstance(ParseCookbookDefinitionCheckingChefVersion.class);
assertTrue(parser.parser instanceof ParseKeySetFromJson);
}
public void testParserFor010() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8");
}
}, new ChefParserModule(), new GsonModule());
ParseCookbookDefinitionCheckingChefVersion parser = injector
.getInstance(ParseCookbookDefinitionCheckingChefVersion.class);
assertTrue(parser.parser instanceof ParseCookbookDefinitionFromJson);
}
}

View File

@ -19,25 +19,25 @@ package org.jclouds.chef.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.chef.domain.CookbookDefinition;
import org.jclouds.http.HttpResponse;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.ApiVersion;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseCookbookDefinitionFromJson}.
*/
@Test(groups = { "unit" }, singleThreaded = true)
public class ParseCookbookDefinitionFromJsonTest {
public class ParseCookbookDefinitionFromJsonTest
{
private ParseCookbookDefinitionFromJson handler;
@ -53,7 +53,14 @@ public class ParseCookbookDefinitionFromJsonTest {
handler = injector.getInstance(ParseCookbookDefinitionFromJson.class);
}
public void testParse010Response() {
public void testCookbokDefinitionParsing() throws URISyntaxException {
CookbookDefinition.Version v510 = CookbookDefinition.Version.builder()
.url(new URI("http://localhost:4000/cookbooks/apache2/5.1.0")).version("5.1.0").build();
CookbookDefinition.Version v420 = CookbookDefinition.Version.builder()
.url(new URI("http://localhost:4000/cookbooks/apache2/4.2.0")).version("4.2.0").build();
CookbookDefinition definition = CookbookDefinition.builder()
.name("apache2").url(new URI("http://localhost:4000/cookbooks/apache2")).version(v510).version(v420).build();
assertEquals(handler.apply(HttpResponse
.builder()
.statusCode(200)
@ -63,10 +70,6 @@ public class ParseCookbookDefinitionFromJsonTest {
+ "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\","
+ "\"version\" => \"5.1.0\"},"
+ "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\","
+ "\"version\" => \"4.2.0\"}" + "]" + "}," + "\"nginx\" => {"
+ "\"url\" => \"http://localhost:4000/cookbooks/nginx\"," + "\"versions\" => ["
+ "{\"url\" => \"http://localhost:4000/cookbooks/nginx/1.0.0\"," + "\"version\" => \"1.0.0\"},"
+ "{\"url\" => \"http://localhost:4000/cookbooks/nginx/0.3.0\"," + "\"version\" => \"0.3.0\"}"
+ "]" + "}" + "}").build()), ImmutableSet.of("apache2", "nginx"));
+ "\"version\" => \"4.2.0\"}" + "]" + "}" + "}").build()), definition);
}
}

View File

@ -37,9 +37,9 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
@Test(groups = {"unit"}, singleThreaded = true)
public class ParseCookbookDefinitionListFromJsonv10Test {
private ParseCookbookDefinitionListFromJsonv10 handler;
public class ParseCookbookDefinitionListFromJsonTest
{
private ParseCookbookDefinitionListFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
@ -50,7 +50,7 @@ public class ParseCookbookDefinitionListFromJsonv10Test {
}
}, new ChefParserModule(), new GsonModule());
handler = injector.getInstance(ParseCookbookDefinitionListFromJsonv10.class);
handler = injector.getInstance(ParseCookbookDefinitionListFromJson.class);
}
public void testCookbokDefinitionListParsing() throws URISyntaxException {

View File

@ -19,26 +19,27 @@ package org.jclouds.chef.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.chef.domain.CookbookDefinition;
import org.jclouds.http.HttpResponse;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.ApiVersion;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseCookbookNamesFromJson}.
*/
@Test(groups = { "unit" }, singleThreaded = true)
public class ParseCookbookDefinitionFromJsonv10Test {
private ParseCookbookDefinitionFromJsonv10 handler;
public class ParseCookbookNamesFromJsonTest
{
private ParseCookbookNamesFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
@ -49,17 +50,10 @@ public class ParseCookbookDefinitionFromJsonv10Test {
}
}, new ChefParserModule(), new GsonModule());
handler = injector.getInstance(ParseCookbookDefinitionFromJsonv10.class);
handler = injector.getInstance(ParseCookbookNamesFromJson.class);
}
public void testCookbokDefinitionParsing() throws URISyntaxException {
CookbookDefinition.Version v510 = CookbookDefinition.Version.builder()
.url(new URI("http://localhost:4000/cookbooks/apache2/5.1.0")).version("5.1.0").build();
CookbookDefinition.Version v420 = CookbookDefinition.Version.builder()
.url(new URI("http://localhost:4000/cookbooks/apache2/4.2.0")).version("4.2.0").build();
CookbookDefinition definition = CookbookDefinition.builder()
.name("apache2").url(new URI("http://localhost:4000/cookbooks/apache2")).version(v510).version(v420).build();
public void testParse010Response() {
assertEquals(handler.apply(HttpResponse
.builder()
.statusCode(200)
@ -69,6 +63,10 @@ public class ParseCookbookDefinitionFromJsonv10Test {
+ "\"versions\" => [" + "{\"url\" => \"http://localhost:4000/cookbooks/apache2/5.1.0\","
+ "\"version\" => \"5.1.0\"},"
+ "{\"url\" => \"http://localhost:4000/cookbooks/apache2/4.2.0\","
+ "\"version\" => \"4.2.0\"}" + "]" + "}" + "}").build()), definition);
+ "\"version\" => \"4.2.0\"}" + "]" + "}," + "\"nginx\" => {"
+ "\"url\" => \"http://localhost:4000/cookbooks/nginx\"," + "\"versions\" => ["
+ "{\"url\" => \"http://localhost:4000/cookbooks/nginx/1.0.0\"," + "\"version\" => \"1.0.0\"},"
+ "{\"url\" => \"http://localhost:4000/cookbooks/nginx/0.3.0\"," + "\"version\" => \"0.3.0\"}"
+ "]" + "}" + "}").build()), ImmutableSet.of("apache2", "nginx"));
}
}

View File

@ -1,62 +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.functions;
import static org.testng.Assert.assertTrue;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.ApiVersion;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseCookbookVersionsCheckingChefVersion}.
*/
@Test(groups = { "unit" }, singleThreaded = true)
public class ParseCookbookVersionsCheckingChefVersionTest {
public void testParserFor09() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.9.8");
}
}, new ChefParserModule(), new GsonModule());
ParseCookbookVersionsCheckingChefVersion parser = injector
.getInstance(ParseCookbookVersionsCheckingChefVersion.class);
assertTrue(parser.parser instanceof ParseCookbookVersionsV09FromJson);
}
public void testParserFor010() {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(ApiVersion.class).toInstance("0.10.8");
}
}, new ChefParserModule(), new GsonModule());
ParseCookbookVersionsCheckingChefVersion parser = injector
.getInstance(ParseCookbookVersionsCheckingChefVersion.class);
assertTrue(parser.parser instanceof ParseCookbookVersionsV10FromJson);
}
}

View File

@ -34,12 +34,12 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseCookbookVersionsV10FromJson}
* Tests behavior of {@code ParseCookbookVersionsFromJson}
*/
@Test(groups = { "unit" }, singleThreaded = true)
public class ParseCookbookVersionsV10FromJsonTest {
private ParseCookbookVersionsV10FromJson handler;
public class ParseCookbookVersionsFromJsonTest
{
private ParseCookbookVersionsFromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
@ -50,7 +50,7 @@ public class ParseCookbookVersionsV10FromJsonTest {
}
}, new ChefParserModule(), new GsonModule());
handler = injector.getInstance(ParseCookbookVersionsV10FromJson.class);
handler = injector.getInstance(ParseCookbookVersionsFromJson.class);
}
public void testRegex() {

View File

@ -1,61 +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.functions;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.http.HttpResponse;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.ApiVersion;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code ParseCookbookVersionsV09FromJson}
*/
@Test(groups = { "unit" }, singleThreaded = true)
public class ParseCookbookVersionsV09FromJsonTest {
private ParseCookbookVersionsV09FromJson handler;
@BeforeTest
protected void setUpInjector() throws IOException {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApiMetadata.DEFAULT_API_VERSION);
}
}, new ChefParserModule(), new GsonModule());
handler = injector.getInstance(ParseCookbookVersionsV09FromJson.class);
}
public void testRegex() {
assertEquals(
handler.apply(HttpResponse.builder().statusCode(200).message("ok")
.payload("{\"apache2\": [\"0.1.8\", \"0.2\"]}").build()), ImmutableSet.of("0.1.8", "0.2"));
}
}

View File

@ -37,6 +37,7 @@ public class CleanupStaleNodesAndClientsImplLiveTest extends BaseChefLiveTest<Ch
@Override
protected void initialize() {
super.initialize();
this.prefix = this.prefix + "-" + this.hashCode();
this.creator = injector.getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class);
this.strategy = injector.getInstance(CleanupStaleNodesAndClientsImpl.class);
}

View File

@ -41,6 +41,7 @@ public class CreateNodeAndPopulateAutomaticAttributesImplLiveTest extends BaseCh
@Override
protected void initialize() {
super.initialize();
this.prefix = this.prefix + "-" + this.hashCode();
this.currentUserProvider = injector.getInstance(CurrentUserProvider.class);
this.strategy = injector.getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class);
}

View File

@ -37,6 +37,7 @@ public class DeleteAllApisAndNodesInListImplLiveTest extends BaseChefLiveTest<Ch
@Override
protected void initialize() {
super.initialize();
this.prefix = this.prefix + "-" + this.hashCode();
this.creator = injector.getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class);
this.strategy = injector.getInstance(DeleteAllNodesInListImpl.class);
}

View File

@ -53,8 +53,6 @@ public class ListCookbookVersionsInEnvironmentImplLiveTest extends BaseChefLiveT
public static final String PREFIX = "jcloudstest-strategy-" + System.getProperty("user.name");
private ListCookbookVersionsInEnvironmentImpl strategy;
private CreateNodeAndPopulateAutomaticAttributesImpl creator;
private ExecutorService testExecutorService;
private ListeningExecutorService testListeningExecutorService;
@ -174,7 +172,7 @@ public class ListCookbookVersionsInEnvironmentImplLiveTest extends BaseChefLiveT
private void createCookbooksWithMultipleVersions(String cookbookName) throws Exception {
FilePayload v0content = uploadContent("pom.xml");
FilePayload v1content = uploadContent("../README.md");
FilePayload v1content = uploadContent("../../README.md");
// Create the metadata of the cookbook
Metadata metadata = Metadata.builder() //

View File

@ -46,6 +46,7 @@ public class ListNodesInEnvironmentImplLiveTest extends BaseChefLiveTest<ChefApi
@Override
protected void initialize() {
super.initialize();
this.prefix = this.prefix + "-" + this.hashCode();
this.creator = injector.getInstance(CreateNodeAndPopulateAutomaticAttributesImpl.class);
this.strategy = injector.getInstance(ListNodesInEnvironmentImpl.class);
creator.execute(prefix, ImmutableSet.<String>of());

View File

@ -40,6 +40,7 @@ public class UpdateAutomaticAttributesOnNodeImplLiveTest extends BaseChefLiveTes
@Override
protected void initialize() {
super.initialize();
this.prefix = this.prefix + "-" + this.hashCode();
this.currentUserProvider = injector.getInstance(CurrentUserProvider.class);
this.strategy = injector.getInstance(UpdateAutomaticAttributesOnNodeImpl.class);
}

View File

@ -19,8 +19,8 @@ package org.jclouds.enterprisechef;
import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.chef.ChefContext;
import org.jclouds.chef.config.ChefBootstrapModule;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.enterprisechef.config.EnterpriseChefHttpApiModule;
@ -44,7 +44,7 @@ public class EnterpriseChefApiMetadata extends BaseHttpApiMetadata<EnterpriseChe
this(new Builder());
}
protected EnterpriseChefApiMetadata(Builder builder) {
protected EnterpriseChefApiMetadata(final Builder builder) {
super(builder);
}
@ -62,7 +62,6 @@ public class EnterpriseChefApiMetadata extends BaseHttpApiMetadata<EnterpriseChe
.version(ChefApiMetadata.DEFAULT_API_VERSION)
.documentation(URI.create("http://www.opscode.com/support"))
.defaultEndpoint("https://api.opscode.com")
.view(ChefContext.class)
.defaultProperties(EnterpriseChefApiMetadata.defaultProperties())
.defaultModules(
ImmutableSet.<Class<? extends Module>> of(EnterpriseChefHttpApiModule.class,