upgraded to 1.5.0-SNAPSHOT

This commit is contained in:
Adrian Cole 2012-04-16 11:07:42 -07:00
parent 5f8bd736c2
commit 73c5ff84d9
30 changed files with 476 additions and 549 deletions

View File

@ -25,7 +25,7 @@
<parent>
<groupId>org.jclouds.provider</groupId>
<artifactId>chef-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
</parent>
<artifactId>jclouds-chef</artifactId>

View File

@ -46,8 +46,9 @@ See http://code.google.com/p/jclouds for details."}
(:require (org.danlarkin [json :as json]))
(:import
java.util.Properties
[org.jclouds ContextBuilder]
[org.jclouds.chef ChefClient
ChefService ChefContext ChefContextFactory]
ChefService ChefContext]
[org.jclouds.chef.domain DatabagItem]))
(try
(use '[clojure.contrib.reflect :only [get-field]])
@ -75,12 +76,13 @@ unit testing"
(let [module-keys (set (keys module-lookup))
ext-modules (filter #(module-keys %) options)
opts (apply hash-map (filter #(not (module-keys %)) options))]
(.. (ChefContextFactory.)
(createContext provider identity credential
(apply modules (concat ext-modules (opts :extensions)))
(reduce #(do (.put %1 (name (first %2)) (second %2)) %1)
(Properties.) (dissoc opts :extensions)))
(getChefService)))))
(.. (ContextBuilder/newBuilder provider)
(credentials provider-identity provider-credential)
(modules (apply modules (concat ext-modules (opts :extensions))))
(overrides (reduce #(do (.put %1 (name (first %2)) (second %2)) %1)
(Properties.) (dissoc opts :extensions)))
(build ChefContext)
(getChefService)))))
(defn chef-context
"Returns a chef context from a chef service."

View File

@ -0,0 +1,99 @@
/**
* 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;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.chef.reference.ChefConstants.CHEF_BOOTSTRAP_DATABAG;
import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.chef.config.ChefRestClientModule;
import org.jclouds.ohai.config.JMXOhaiModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.BaseRestApiMetadata;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for OpsCode's Chef api.
*
* @author Adrian Cole
*/
public class ChefApiMetadata extends BaseRestApiMetadata {
/** The serialVersionUID */
private static final long serialVersionUID = 3450830053589179249L;
public static final TypeToken<RestContext<ChefClient, ChefAsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<ChefClient, ChefAsyncClient>>() {
private static final long serialVersionUID = -5070937833892503232L;
};
@Override
public Builder toBuilder() {
return new Builder(getApi(), getAsyncApi()).fromApiMetadata(this);
}
public ChefApiMetadata() {
this(new Builder(ChefClient.class, ChefAsyncClient.class));
}
protected ChefApiMetadata(Builder builder) {
super(Builder.class.cast(builder));
}
public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties();
properties.setProperty(PROPERTY_SESSION_INTERVAL, "1");
properties.setProperty(CHEF_BOOTSTRAP_DATABAG, "bootstrap");
return properties;
}
public static class Builder extends BaseRestApiMetadata.Builder {
protected Builder(Class<?> client, Class<?> asyncClient) {
super(client, asyncClient);
id("chef")
.name("OpsCode Chef Api")
.identityName("User")
.credentialName("Certificate")
.version(ChefAsyncClient.VERSION)
.documentation(URI.create("http://wiki.opscode.com/display/chef/Server+API"))
.defaultEndpoint("http://localhost:4000")
.defaultProperties(ChefApiMetadata.defaultProperties())
.context(TypeToken.of(ChefContext.class))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(ChefRestClientModule.class, JMXOhaiModule.class));
}
@Override
public ChefApiMetadata build() {
return new ChefApiMetadata(this);
}
@Override
public Builder fromApiMetadata(ApiMetadata in) {
super.fromApiMetadata(in);
return this;
}
}
}

View File

@ -1,64 +0,0 @@
/**
* 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;
import java.util.List;
import java.util.Properties;
import org.jclouds.chef.config.ChefRestClientModule;
import org.jclouds.ohai.OhaiContextBuilder;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
* @author Adrian Cole
*/
public class ChefContextBuilder extends OhaiContextBuilder<ChefClient, ChefAsyncClient> {
public ChefContextBuilder(Properties props) {
super(ChefClient.class, ChefAsyncClient.class, props);
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new ChefRestClientModule());
}
@Override
public Injector buildInjector() {
addOhaiModuleIfNotPresent();
return super.buildInjector();
}
/**
* {@inheritDoc}
*/
@Override
public ChefContextBuilder withModules(Iterable<Module> modules) {
return (ChefContextBuilder) super.withModules(modules);
}
@SuppressWarnings("unchecked")
@Override
public ChefContext buildContext() {
Injector injector = buildInjector();
return injector.getInstance(ChefContext.class);
}
}

View File

@ -18,162 +18,118 @@
*/
package org.jclouds.chef;
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
import static org.jclouds.util.Utils.propagateAuthorizationOrOriginalException;
import java.util.NoSuchElementException;
import java.util.Properties;
import javax.annotation.Nullable;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.ContextBuilder;
import org.jclouds.Wrapper;
import org.jclouds.apis.Apis;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.Providers;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
* Helper class to instantiate {@code ChefContext} instances.
*
* @see ContextBuilder
* @author Adrian Cole
*/
@Deprecated
public class ChefContextFactory {
private final RestContextFactory contextFactory;
/**
* Initializes with the default properties built-in to jclouds. This is
* typically stored in the classpath resource {@code rest.properties}
*
* @see RestContextFactory#getPropertiesFromResource
* for porting old code to {@link ContextBuilder}
*/
public ChefContextFactory() {
this(new RestContextFactory());
}
/**
* Finds definitions in the specified properties.
* for porting old code to {@link ContextBuilder}
*/
public ChefContextFactory(Properties properties) {
this(new RestContextFactory(properties));
}
/**
* @see #createContext(String, String,String, Iterable, Properties)
*/
public ChefContext createContext(String providerOrApi, String identity, String credential) {
return createContext(providerOrApi, identity, credential, ImmutableSet.<Module> of(), new Properties());
}
/**
* @see #createContext(String, String, String, Iterable, Properties)
*/
public ChefContext createContext(String providerOrApi, Properties overrides) {
return createContext(providerOrApi, null, null, ImmutableSet.<Module> of(), overrides);
}
/**
* @see #createContext(String, String,String, Iterable, Properties)
*/
public ChefContext createContext(String providerOrApi, Iterable<? extends Module> wiring,
Properties overrides) {
return createContext(providerOrApi, null, null, wiring, overrides);
}
/**
* @see #createContext(String, String,String, Iterable, Properties)
*/
public ChefContext createContext(String providerOrApi, @Nullable String identity,
@Nullable String credential, Properties overrides) {
return createContext(providerOrApi, identity, credential, ImmutableSet.<Module> of(), overrides);
}
/**
* @see createContext(String, String,String, Iterable, Properties)
*/
public ChefContext createContext(String providerOrApi, @Nullable String identity,
@Nullable String credential, Iterable<? extends Module> wiring) {
return createContext(providerOrApi, identity, credential, wiring, new Properties());
}
/**
* for porting old code to {@link ContextBuilder}
*
* Uses the supplied RestContextFactory to create {@link ChefContext}s
* @param providerOrApi
* @param identity
* nullable, if credentials are present in the overrides
* @param credential
* nullable, if credentials are present in the overrides
* @param wiring
* Configuration you'd like to pass to the context. Ex.
* ImmutableSet.<Module>of(new ExecutorServiceModule(myexecutor))
* @param overrides
* properties to override defaults with.
* @return initialized context ready for use
*/
public ChefContextFactory(RestContextFactory restContextFactory) {
this.contextFactory = restContextFactory;
}
public static <S, A> ChefContext buildContextUnwrappingExceptions(RestContextBuilder<S, A> builder) {
@SuppressWarnings("unchecked")
public ChefContext createContext(String providerOrApi, @Nullable String identity,
@Nullable String credential, Iterable<? extends Module> wiring, Properties overrides) {
ContextBuilder builder = null;
try {
return (ChefContext) builder.buildContext();
} catch (Exception e) {
return propagateAuthorizationOrOriginalException(e);
ProviderMetadata pm = Providers.withId(providerOrApi);
builder = ContextBuilder.newBuilder(pm);
} catch (NoSuchElementException e) {
builder = ContextBuilder.newBuilder(Apis.withId(providerOrApi));
}
builder.modules(Iterable.class.cast(wiring));
builder.overrides(overrides);
if (identity != null)
builder.credentials(identity, credential);
Object context = builder.build();
if (context instanceof ChefContext) {
return ChefContext.class.cast(context);
} else if (context instanceof Wrapper) {
Wrapper tctx = Wrapper.class.cast(context);
return tctx.unwrap(TypeToken.of(ChefContext.class));
} else {
throw new IllegalArgumentException("provider " + providerOrApi + " contains an unknown context type: "
+ context.getClass().getSimpleName());
}
}
/**
* @see #createContext(String, String, String)
*/
public ChefContext createContext(String identity, String credential) {
return createContext("chef", identity, credential);
}
/**
* @see RestContextFactory#createContextBuilder(String, String, String)
*/
public ChefContext createContext(String provider, String identity, String credential) {
RestContextBuilder<?, ?> builder = RestContextBuilder.class.cast(contextFactory.createContextBuilder(provider,
identity, credential));
return buildContextUnwrappingExceptions(builder);
}
/**
* @see #createContext(String, Properties)
*/
public ChefContext createContext(Properties overrides) {
return createContext("chef", overrides);
}
/**
* @see RestContextFactory#createContextBuilder(String, Properties)
*/
public ChefContext createContext(String provider, Properties overrides) {
RestContextBuilder<?, ?> builder = RestContextBuilder.class.cast(contextFactory.createContextBuilder(provider,
overrides));
return buildContextUnwrappingExceptions(builder);
}
/**
* @see #createContext(String, Iterable, Properties)
*/
public ChefContext createContext(Iterable<? extends Module> modules, Properties overrides) {
return createContext("chef", modules, overrides);
}
/**
* @see RestContextFactory#createContextBuilder(String, Iterable, Properties)
*/
public ChefContext createContext(String provider, Iterable<? extends Module> modules, Properties overrides) {
RestContextBuilder<?, ?> builder = RestContextBuilder.class.cast(contextFactory.createContextBuilder(provider,
modules, overrides));
return buildContextUnwrappingExceptions(builder);
}
/**
* @see #createContext(String,String,String,Iterable)
*/
public ChefContext createContext(@Nullable String identity, @Nullable String credential,
Iterable<? extends Module> modules) {
return createContext("chef", identity, credential, modules);
}
/**
* @see RestContextFactory#createContextBuilder(String,String String,
* Iterable)
*/
public ChefContext createContext(String provider, @Nullable String identity, @Nullable String credential,
Iterable<? extends Module> modules) {
RestContextBuilder<?, ?> builder = RestContextBuilder.class.cast(contextFactory.createContextBuilder(provider,
identity, credential, modules));
return buildContextUnwrappingExceptions(builder);
}
/**
* @see #createContext(String,String, String, Iterable, Properties)
*/
public ChefContext createContext(@Nullable String identity, @Nullable String credential,
Iterable<? extends Module> modules, Properties overrides) {
return createContext("chef", identity, credential, modules, overrides);
}
/**
* @see RestContextFactory#createContextBuilder(String,String,String,
* Iterable, Properties)
*/
public ChefContext createContext(String provider, @Nullable String identity, @Nullable String credential,
Iterable<? extends Module> modules, Properties overrides) {
RestContextBuilder<?, ?> builder = RestContextBuilder.class.cast(contextFactory.createContextBuilder(provider,
identity, credential, modules, overrides));
return buildContextUnwrappingExceptions(builder);
}
/**
* @see RestContextFactory#createContextBuilder(ContextSpec)
*/
public <S, A> ChefContext createContext(RestContextSpec<S, A> contextSpec) {
RestContextBuilder<?, ?> builder = RestContextBuilder.class.cast(createContextBuilder(contextSpec));
return buildContextUnwrappingExceptions(builder);
}
/**
* @see RestContextFactory#createContextBuilder(ContextSpec, Properties)
*/
public <S, A> ChefContext createContext(RestContextSpec<S, A> contextSpec, Properties overrides) {
RestContextBuilder<?, ?> builder = RestContextBuilder.class.cast(createContextBuilder(contextSpec, overrides));
return buildContextUnwrappingExceptions(builder);
}
}
}

View File

@ -1,44 +0,0 @@
/**
* 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;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import java.util.Properties;
import org.jclouds.chef.internal.BaseChefPropertiesBuilder;
/**
* Builds properties used in Chef Clients
*
* @author Adrian Cole
*/
public class ChefPropertiesBuilder extends BaseChefPropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost:4000");
return properties;
}
public ChefPropertiesBuilder(Properties properties) {
super(properties);
}
}

View File

@ -38,7 +38,6 @@ import org.jclouds.date.DateService;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
@ -55,7 +54,6 @@ import com.google.inject.Provides;
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class BaseChefRestClientModule<S, A> extends RestClientModule<S, A> {

View File

@ -38,19 +38,18 @@ import org.jclouds.chef.domain.DatabagItem;
import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.Pems;
import org.jclouds.io.InputSuppliers;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.json.internal.NullHackJsonLiteralAdapter;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonLiteral;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
import com.google.inject.AbstractModule;
import com.google.inject.ImplementedBy;
import com.google.inject.Provides;
@ -160,49 +159,41 @@ public class ChefParserModule extends AbstractModule {
}
}
@ImplementedBy(DataBagItemAdapterImpl.class)
public static interface DataBagItemAdapter extends JsonSerializer<DatabagItem>, JsonDeserializer<DatabagItem> {
}
/**
* writes or reads the literal directly
*/
@Singleton
public static class DataBagItemAdapterImpl implements DataBagItemAdapter {
private final Json json;
@Inject
DataBagItemAdapterImpl(Json json) {
this.json = json;
}
public static class DataBagItemAdapter extends NullHackJsonLiteralAdapter<DatabagItem> {
final Gson gson = new Gson();
@Override
public JsonElement serialize(DatabagItem src, Type typeOfSrc, JsonSerializationContext context) {
String text = src.toString();
try {
IdHolder idHolder = json.fromJson(text, IdHolder.class);
if (idHolder.id == null)
text = text.replaceFirst("\\{", String.format("{\"id\":\"%s\",", src.getId()));
else
checkArgument(src.getId().equals(idHolder.id), "incorrect id in databagItem text, should be %s: was %s",
src.getId(), idHolder.id);
return new JsonLiteral(text);
} catch (JsonParseException e) {
throw new IllegalArgumentException(String.format(
"databag item must be a json hash ex. {\"id\":\"item1\",\"my_key\":\"my_data\"}; was %s", text), e);
}
}
@Override
public DatabagItem deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
String text = jsonElement.toString();
IdHolder idHolder = json.fromJson(text, IdHolder.class);
protected DatabagItem createJsonLiteralFromRawJson(String text) {
IdHolder idHolder = gson.fromJson(text, IdHolder.class);
checkState(idHolder.id != null,
"databag item must be a json hash ex. {\"id\":\"item1\",\"my_key\":\"my_data\"}; was %s", text);
text = text.replaceFirst(String.format("\\{\"id\"[ ]?:\"%s\",", idHolder.id), "{");
return new DatabagItem(idHolder.id, text);
}
}
@Override
protected String toString(DatabagItem value) {
String text = value.toString();
try {
IdHolder idHolder = gson.fromJson(text, IdHolder.class);
if (idHolder.id == null)
text = text.replaceFirst("\\{", String.format("{\"id\":\"%s\",", value.getId()));
else
checkArgument(value.getId().equals(idHolder.id),
"incorrect id in databagItem text, should be %s: was %s", value.getId(), idHolder.id);
} catch (JsonSyntaxException e) {
throw new IllegalArgumentException(e);
}
return text;
}
}
private static class IdHolder {
private String id;
}

View File

@ -29,7 +29,6 @@ import org.jclouds.chef.domain.Client;
import org.jclouds.chef.functions.ClientForTag;
import org.jclouds.chef.functions.RunListForTag;
import org.jclouds.chef.statements.InstallChefGems;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.scriptbuilder.domain.Statement;
@ -42,7 +41,6 @@ import com.google.inject.name.Names;
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class ChefRestClientModule extends BaseChefRestClientModule<ChefClient, ChefAsyncClient> {

View File

@ -19,14 +19,9 @@
package org.jclouds.chef.filters;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.Constants.PROPERTY_IDENTITY;
import java.security.PrivateKey;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import javax.annotation.Resource;
@ -35,11 +30,6 @@ import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import org.jclouds.Constants;
import org.jclouds.crypto.Crypto;
import org.jclouds.crypto.CryptoStreams;
@ -57,13 +47,15 @@ import org.jclouds.io.payloads.MultipartForm;
import org.jclouds.io.payloads.Part;
import org.jclouds.io.payloads.RSAEncryptingPayload;
import org.jclouds.logging.Logger;
import org.jclouds.util.Utils;
import org.jclouds.util.Strings2;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Throwables;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import com.google.common.io.ByteStreams;
/**
@ -122,7 +114,7 @@ public class SignedHeaderAuth implements HttpRequestFilter {
HttpRequest calculateAndReplaceAuthorizationHeaders( HttpRequest request, String toSign ) throws HttpException {
String signature = sign(toSign);
if (signatureWire.enabled())
signatureWire.input(Utils.toInputStream(signature));
signatureWire.input(Strings2.toInputStream(signature));
String[] signatureLines = Iterables.toArray(Splitter.fixedLength(60).split(signature), String.class);
Multimap<String, String> headers = ArrayListMultimap.create();

View File

@ -46,29 +46,30 @@ import org.jclouds.scriptbuilder.domain.Statement;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Splitter;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.inject.TypeLiteral;
/**
*
* Generates a bootstrap script relevant for a particular tag
* Generates a bootstrap script relevant for a particular group
*
* @author Adrian Cole
*/
@Singleton
public class TagToBootScript implements Function<String, Payload> {
public class GroupToBootScript implements Function<String, Payload> {
@VisibleForTesting
static final Type RUN_LIST_TYPE = new TypeLiteral<Map<String, List<String>>>() {
}.getType();
private final URI endpoint;
private final Supplier<URI> endpoint;
private final Json json;
private final Map<String, Client> tagToClient;
private final Map<String, List<String>> runListForTag;
private final Statement installChefGems;
@Inject
public TagToBootScript(@Provider URI endpoint, Json json, Map<String, Client> tagToClient,
public GroupToBootScript(@Provider Supplier<URI> endpoint, Json json, Map<String, Client> tagToClient,
Map<String, List<String>> runListForTag, @Named("installChefGems") Statement installChefGems) {
this.endpoint = checkNotNull(endpoint, "endpoint");
this.json = checkNotNull(json, "json");
@ -95,7 +96,7 @@ public class TagToBootScript implements Function<String, Payload> {
"require 'ohai'", "o = Ohai::System.new", "o.all_plugins", String.format(
"node_name \"%s-\" + o[:ipaddress]", tag), "log_level :info", "log_location STDOUT", String
.format("validation_client_name \"%s\"", client.getClientname()), String.format(
"chef_server_url \"%s\"", endpoint)));
"chef_server_url \"%s\"", endpoint.get())));
Statement createValidationPem = appendFile(chefConfigDir + "{fs}validation.pem", Splitter.on('\n').split(
Pems.pem(client.getPrivateKey())));

View File

@ -1,48 +0,0 @@
/**
* 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.internal;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
import static org.jclouds.chef.reference.ChefConstants.CHEF_BOOTSTRAP_DATABAG;
import java.util.Properties;
import org.jclouds.PropertiesBuilder;
import org.jclouds.chef.ChefAsyncClient;
/**
* Builds properties used in Chef Clients
*
* @author Adrian Cole
*/
public abstract class BaseChefPropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_SESSION_INTERVAL, "1");
properties.setProperty(PROPERTY_API_VERSION, ChefAsyncClient.VERSION);
properties.setProperty(CHEF_BOOTSTRAP_DATABAG, "bootstrap");
return properties;
}
public BaseChefPropertiesBuilder(Properties properties) {
super(properties);
}
}

View File

@ -39,7 +39,7 @@ import org.jclouds.chef.domain.CookbookVersion;
import org.jclouds.chef.domain.DatabagItem;
import org.jclouds.chef.domain.Node;
import org.jclouds.chef.functions.RunListForTag;
import org.jclouds.chef.functions.TagToBootScript;
import org.jclouds.chef.functions.GroupToBootScript;
import org.jclouds.chef.reference.ChefConstants;
import org.jclouds.chef.strategy.CleanupStaleNodesAndClients;
import org.jclouds.chef.strategy.CreateNodeAndPopulateAutomaticAttributes;
@ -81,7 +81,7 @@ public class BaseChefService implements ChefService {
private final ListClients listClients;
private final UpdateAutomaticAttributesOnNode updateAutomaticAttributesOnNode;
private final Provider<PrivateKey> privateKey;
private final TagToBootScript tagToBootScript;
private final GroupToBootScript tagToBootScript;
private final String databag;
private final RunListForTag runListForTag;
private final ListCookbookVersions listCookbookVersions;
@ -93,7 +93,7 @@ public class BaseChefService implements ChefService {
DeleteAllClientsInList deleteAllClientsInList, ListClients listClients,
ListCookbookVersions listCookbookVersions, UpdateAutomaticAttributesOnNode updateAutomaticAttributesOnNode,
Provider<PrivateKey> privateKey, @Named(CHEF_BOOTSTRAP_DATABAG) String databag,
TagToBootScript tagToBootScript, RunListForTag runListForTag) {
GroupToBootScript tagToBootScript, RunListForTag runListForTag) {
this.chefContext = checkNotNull(chefContext, "chefContext");
this.cleanupStaleNodesAndClients = checkNotNull(cleanupStaleNodesAndClients, "cleanupStaleNodesAndClients");
this.createNodeAndPopulateAutomaticAttributes = checkNotNull(createNodeAndPopulateAutomaticAttributes,

View File

@ -19,7 +19,6 @@
package org.jclouds.chef.internal;
import java.net.URI;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@ -32,12 +31,15 @@ import org.jclouds.chef.ChefContext;
import org.jclouds.chef.ChefService;
import org.jclouds.domain.Credentials;
import org.jclouds.lifecycle.Closer;
import org.jclouds.location.Iso3166;
import org.jclouds.location.Provider;
import org.jclouds.rest.Utils;
import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.rest.annotations.BuildVersion;
import org.jclouds.rest.annotations.Identity;
import org.jclouds.location.Provider;
import org.jclouds.rest.internal.RestContextImpl;
import com.google.common.base.Supplier;
import com.google.inject.Injector;
import com.google.inject.TypeLiteral;
@ -50,9 +52,12 @@ public class ChefContextImpl extends RestContextImpl<ChefClient, ChefAsyncClient
@Inject
protected ChefContextImpl(Closer closer, Map<String, Credentials> credentialStore, Utils utils, Injector injector,
TypeLiteral<ChefClient> syncApi, TypeLiteral<ChefAsyncClient> asyncApi, @Provider URI endpoint,
@Provider String provider, @Identity String identity, @ApiVersion String apiVersion, ChefService chefService) {
super(closer, credentialStore, utils, injector, syncApi, asyncApi, endpoint, provider, identity, apiVersion, null ); // Not sure what needs to go here for Chef
@Provider Supplier<URI> endpoint, @Provider String provider, @Identity String identity,
@ApiVersion String apiVersion, @BuildVersion String buildVersion, @Iso3166 Set<String> iso3166Codes,
ChefService chefService) {
super(closer, credentialStore, utils, injector, TypeLiteral.get(ChefClient.class), TypeLiteral
.get(ChefAsyncClient.class), endpoint, buildVersion, buildVersion, buildVersion, buildVersion,
iso3166Codes);
this.chefService = chefService;
}

View File

@ -0,0 +1,103 @@
/**
* 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.test;
import java.net.URI;
import java.util.Properties;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.chef.ChefAsyncClient;
import org.jclouds.chef.ChefContext;
import org.jclouds.chef.test.config.TransientChefClientModule;
import org.jclouds.ohai.config.JMXOhaiModule;
import org.jclouds.rest.RestContext;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.google.inject.Module;
/**
* Implementation of {@link ApiMetadata} for the Amazon-specific Chef API
*
* @author Adrian Cole
*/
public class TransientChefApiMetadata extends ChefApiMetadata {
/** The serialVersionUID */
private static final long serialVersionUID = -1492951757032303845L;
public static final TypeToken<RestContext<TransientChefClient, TransientChefAsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<TransientChefClient, TransientChefAsyncClient>>() {
private static final long serialVersionUID = -5070937833892503232L;
};
private static Builder builder() {
return new Builder();
}
@Override
public Builder toBuilder() {
return builder().fromApiMetadata(this);
}
public TransientChefApiMetadata() {
this(builder());
}
protected TransientChefApiMetadata(Builder builder) {
super(builder);
}
public static Properties defaultProperties() {
Properties properties = ChefApiMetadata.defaultProperties();
// auth fail sometimes happens in Chef, as the rc.local script that injects the
// authorized key executes after ssh has started.
properties.setProperty("jclouds.ssh.max-retries", "7");
properties.setProperty("jclouds.ssh.retry-auth", "true");
return properties;
}
public static class Builder extends ChefApiMetadata.Builder {
protected Builder(){
super(TransientChefClient.class, TransientChefAsyncClient.class);
id("transientchef")
.name("In-memory Chef API")
.identityName("unused")
.version(ChefAsyncClient.VERSION)
.documentation(URI.create("http://wiki.opscode.com/display/chef/Server+API"))
.defaultEndpoint("http://localhost:4000")
.defaultProperties(ChefApiMetadata.defaultProperties())
.context(TypeToken.of(ChefContext.class))
.defaultProperties(TransientChefApiMetadata.defaultProperties())
.defaultModules(ImmutableSet.<Class<? extends Module>>of(TransientChefClientModule.class, JMXOhaiModule.class));
}
@Override
public TransientChefApiMetadata build() {
return new TransientChefApiMetadata(this);
}
@Override
public Builder fromApiMetadata(ApiMetadata in) {
super.fromApiMetadata(in);
return this;
}
}
}

View File

@ -48,7 +48,7 @@ import org.jclouds.chef.domain.Sandbox;
import org.jclouds.chef.domain.SearchResult;
import org.jclouds.chef.domain.UploadSandbox;
import org.jclouds.chef.options.CreateClientOptions;
import org.jclouds.util.Utils;
import org.jclouds.util.Strings2;
import com.google.common.base.Function;
import com.google.common.util.concurrent.Futures;
@ -80,7 +80,7 @@ public class TransientChefAsyncClient implements ChefAsyncClient {
@Override
public DatabagItem apply(Blob from) {
try {
return from == null ? null : new DatabagItem(from.getMetadata().getName(), Utils.toStringAndClose(from
return from == null ? null : new DatabagItem(from.getMetadata().getName(), Strings2.toStringAndClose(from
.getPayload().getInput()));
} catch (IOException e) {
propagate(e);
@ -135,8 +135,7 @@ public class TransientChefAsyncClient implements ChefAsyncClient {
@Override
public ListenableFuture<DatabagItem> createDatabagItem(String databagName, DatabagItem databagItem) {
Blob blob = databags.newBlob(databagItem.getId());
blob.setPayload(databagItem.toString());
Blob blob = databags.blobBuilder(databagItem.getId()).payload(databagItem.toString()).build();
databags.putBlobAndReturnOld(databagName, blob);
return Futures.immediateFuture(databagItem);
}

View File

@ -23,6 +23,8 @@ import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.ContextBuilder;
import org.jclouds.blobstore.TransientApiMetadata;
import org.jclouds.blobstore.TransientAsyncBlobStore;
import org.jclouds.chef.ChefAsyncClient;
import org.jclouds.chef.ChefClient;
@ -33,10 +35,13 @@ import org.jclouds.chef.functions.RunListForTag;
import org.jclouds.chef.statements.InstallChefGems;
import org.jclouds.chef.test.TransientChefAsyncClient;
import org.jclouds.chef.test.TransientChefClient;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.concurrent.MoreExecutors;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.scriptbuilder.domain.Statement;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.MapMaker;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.name.Names;
@ -53,7 +58,9 @@ public class TransientChefClientModule extends BaseChefRestClientModule<Transien
@Override
protected void configure() {
bind(TransientAsyncBlobStore.class).annotatedWith(Names.named("databags")).toInstance(
new RestContextFactory().createContextBuilder("transient", "foo", "bar").buildInjector().getInstance(
ContextBuilder.newBuilder(new TransientApiMetadata()).modules(
ImmutableSet.<Module> of(new ExecutorServiceModule(MoreExecutors.sameThreadExecutor(),
MoreExecutors.sameThreadExecutor()))).buildInjector().getInstance(
TransientAsyncBlobStore.class));
bind(Statement.class).annotatedWith(Names.named("installChefGems")).to(InstallChefGems.class);
super.configure();

View File

@ -1,60 +0,0 @@
/**
* 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.ohai;
import java.util.Properties;
import javax.inject.Inject;
import org.jclouds.ohai.config.ConfiguresOhai;
import org.jclouds.ohai.config.JMXOhaiModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.inject.Module;
/**
*
* @see RestContext
*/
public class OhaiContextBuilder<S, A> extends RestContextBuilder<S, A> {
@Inject
public OhaiContextBuilder(Class<S> syncClientClass, Class<A> asyncClientClass, Properties properties) {
super(syncClientClass, asyncClientClass, properties);
}
protected void addOhaiModuleIfNotPresent() {
if (!Iterables.any(modules, new Predicate<Module>() {
public boolean apply(Module input) {
return input.getClass().isAnnotationPresent(ConfiguresOhai.class);
}
})) {
addOhaiModule();
}
}
protected void addOhaiModule() {
modules.add(new JMXOhaiModule());
}
}

View File

@ -0,0 +1,2 @@
org.jclouds.chef.test.TransientChefApiMetadata
org.jclouds.chef.ChefApiMetadata

View File

@ -18,22 +18,22 @@
*/
package org.jclouds.chef;
import com.google.common.collect.Iterables;
import org.jclouds.rest.Providers;
import org.jclouds.Wrapper;
import org.jclouds.rest.internal.BaseRestApiMetadataTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
/**
*
* @author Adrian Cole
*
*/
@Test(groups = { "unit" })
public class ProvidersInPropertiesTest {
@Test(groups = "unit", testName = "ChefApiMetadataTest")
public class ChefApiMetadataTest extends BaseRestApiMetadataTest {
@Test
public void testSupportedProviders() {
Iterable<String> providers = Providers.getSupportedProviders();
assert Iterables.contains(providers, "chef") : providers;
// no config management abstraction, yet
public ChefApiMetadataTest() {
super(new ChefApiMetadata(), ImmutableSet.<TypeToken<? extends Wrapper>> of());
}
}

View File

@ -22,9 +22,9 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties;
import java.util.Set;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.chef.config.ChefRestClientModule;
import org.jclouds.chef.domain.CookbookVersion;
import org.jclouds.chef.domain.DatabagItem;
@ -41,19 +41,16 @@ import org.jclouds.chef.options.CreateClientOptions;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.date.TimeStamp;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.BaseAsyncClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
@ -70,7 +67,7 @@ import com.google.inject.TypeLiteral;
* @author Adrian Cole
*/
@Test(groups = { "unit" })
public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
public class ChefAsyncClientTest extends BaseAsyncClientTest<ChefAsyncClient> {
public void testCommitSandbox() throws SecurityException, NoSuchMethodException, IOException {
@ -743,7 +740,6 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
return new TestChefRestClientModule();
}
@RequiresHttp
@ConfiguresRestClient
static class TestChefRestClientModule extends ChefRestClientModule {
@Override
@ -753,9 +749,12 @@ public class ChefAsyncClientTest extends RestClientTest<ChefAsyncClient> {
}
@Override
public RestContextSpec<ChefClient, ChefAsyncClient> createContextSpec() {
return new RestContextFactory().createContextSpec("chef", "user", SignedHeaderAuthTest.PRIVATE_KEY,
new Properties());
public ApiMetadata createApiMetadata() {
identity = "user";
credential = SignedHeaderAuthTest.PRIVATE_KEY;
return new ChefApiMetadata();
}
}

View File

@ -23,8 +23,8 @@ import static org.testng.Assert.assertNotNull;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.ContextBuilder;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.chef.domain.CookbookVersion;
import org.jclouds.json.Json;
@ -74,10 +74,8 @@ public class ChefClientLiveTest extends BaseChefClientLiveTest {
}
private ChefContext createConnection(String identity, String key) throws IOException {
Properties props = new Properties();
props.setProperty("chef.endpoint", endpoint);
return new ChefContextFactory().createContext(identity, key, ImmutableSet.<Module> of(new Log4JLoggingModule()),
props);
return ContextBuilder.newBuilder(new ChefApiMetadata()).endpoint(endpoint).credentials(identity, key).modules(
ImmutableSet.<Module> of(new Log4JLoggingModule())).build();
}
@Override

View File

@ -24,20 +24,20 @@ import static org.testng.Assert.assertEqualsNoOrder;
import java.io.IOException;
import java.net.URI;
import java.security.PrivateKey;
import java.util.Properties;
import javax.inject.Provider;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.HttpHeaders;
import org.jclouds.ContextBuilder;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.crypto.Crypto;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.internal.SignatureWire;
import org.jclouds.logging.config.NullLoggingModule;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.BaseRestClientTest.MockModule;
import org.jclouds.util.Utils;
import org.jclouds.rest.internal.BaseRestClientTest.MockModule;
import org.jclouds.util.Strings2;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -107,9 +107,9 @@ public class SignedHeaderAuthTest {
static {
try {
PUBLIC_KEY = Utils.toStringAndClose(SignedHeaderAuthTest.class.getResourceAsStream("/pubkey.txt"));
PUBLIC_KEY = Strings2.toStringAndClose(SignedHeaderAuthTest.class.getResourceAsStream("/pubkey.txt"));
PRIVATE_KEY = Utils.toStringAndClose(SignedHeaderAuthTest.class.getResourceAsStream("/privkey.txt"));
PRIVATE_KEY = Strings2.toStringAndClose(SignedHeaderAuthTest.class.getResourceAsStream("/privkey.txt"));
} catch (IOException e) {
Throwables.propagate(e);
}
@ -181,8 +181,8 @@ public class SignedHeaderAuthTest {
@BeforeClass
protected void createFilter() throws IOException {
Injector injector = new RestContextFactory().createContextBuilder("chef", USER_ID, PRIVATE_KEY,
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule()), new Properties()).buildInjector();
Injector injector = ContextBuilder.newBuilder(new ChefApiMetadata()).credentials(USER_ID, PRIVATE_KEY).modules(
ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector();
crypto = injector.getInstance(Crypto.class);
HttpUtils utils = injector.getInstance(HttpUtils.class);

View File

@ -22,7 +22,6 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.URI;
import java.util.Set;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.chef.domain.Attribute;
@ -35,7 +34,7 @@ import org.jclouds.http.functions.ParseJson;
import org.jclouds.io.Payloads;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.util.Utils;
import org.jclouds.util.Strings2;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -71,7 +70,7 @@ public class ParseCookbookVersionFromJsonTest {
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
.newPayload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/brew-cookbook.json"))));
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils.toInputStream(json
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Strings2.toInputStream(json
.toJson(cookbook))))));
}
@ -80,7 +79,7 @@ public class ParseCookbookVersionFromJsonTest {
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
.newPayload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/tomcat-cookbook.json"))));
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils.toInputStream(json
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Strings2.toInputStream(json
.toJson(cookbook))))));
}
@ -89,7 +88,7 @@ public class ParseCookbookVersionFromJsonTest {
CookbookVersion cookbook = handler.apply(new HttpResponse(200, "ok", Payloads
.newPayload(ParseCookbookVersionFromJsonTest.class.getResourceAsStream("/mysql-cookbook.json"))));
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Utils.toInputStream(json
assertEquals(cookbook, handler.apply(new HttpResponse(200, "ok", Payloads.newPayload(Strings2.toInputStream(json
.toJson(cookbook))))));
}

View File

@ -26,7 +26,7 @@ import java.net.UnknownHostException;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ReturnStringIf2xx;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
/**
@ -37,7 +37,7 @@ public class ParseErrorFromJsonOrReturnBodyTest {
@Test
public void testApplyInputStreamDetails() throws UnknownHostException {
InputStream is = Utils
InputStream is = Strings2
.toInputStream("{\"error\":[\"invalid tarball: tarball root must contain java-bytearray\"]}");
ParseErrorFromJsonOrReturnBody parser = new ParseErrorFromJsonOrReturnBody(

View File

@ -39,6 +39,7 @@ import org.jclouds.scriptbuilder.domain.Statement;
import org.testng.annotations.Test;
import com.google.common.base.Charsets;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.CharStreams;
@ -58,7 +59,7 @@ public class TagToBootScriptTest {
@Test(expectedExceptions = IllegalStateException.class)
public void testMustHaveClients() {
TagToBootScript fn = new TagToBootScript(URI.create("http://localhost:4000"), json, ImmutableMap
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json, ImmutableMap
.<String, Client> of(), ImmutableMap.<String, List<String>> of("foo", ImmutableList
.of("recipe[apache2]")), installChefGems);
fn.apply("foo");
@ -66,14 +67,14 @@ public class TagToBootScriptTest {
@Test(expectedExceptions = IllegalStateException.class)
public void testMustHaveRunScripts() {
TagToBootScript fn = new TagToBootScript(URI.create("http://localhost:4000"), json, ImmutableMap
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json, ImmutableMap
.<String, Client> of("foo", createMock(Client.class)), ImmutableMap.<String, List<String>> of(), installChefGems);
fn.apply("foo");
}
@Test(expectedExceptions = IllegalStateException.class)
public void testMustHaveRunScriptsValue() {
TagToBootScript fn = new TagToBootScript(URI.create("http://localhost:4000"), json, ImmutableMap
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json, ImmutableMap
.<String, Client> of("foo", createMock(Client.class)), ImmutableMap.<String, List<String>> of("foo",
ImmutableList.<String> of()), installChefGems);
fn.apply("foo");
@ -83,7 +84,7 @@ public class TagToBootScriptTest {
Client client = createMock(Client.class);
PrivateKey privateKey = createMock(PrivateKey.class);
TagToBootScript fn = new TagToBootScript(URI.create("http://localhost:4000"), json, ImmutableMap
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json, ImmutableMap
.<String, Client> of("foo", client), ImmutableMap.<String, List<String>> of("foo", ImmutableList
.<String> of("recipe[apache2]")), installChefGems);

View File

@ -22,14 +22,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
import org.jclouds.chef.ChefAsyncClient;
import org.jclouds.chef.ChefClient;
import org.jclouds.ContextBuilder;
import org.jclouds.chef.ChefApiMetadata;
import org.jclouds.lifecycle.Closer;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContextFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -59,13 +57,11 @@ public abstract class BaseChefStrategyLiveTest {
String keyfile = System.getProperty("jclouds.test.credential");
if (keyfile == null || keyfile.equals(""))
keyfile = System.getProperty("user.home") + "/.chef/" + user + ".pem";
Properties props = new Properties();
props.setProperty("chef.endpoint", endpoint);
Set<Module> modules = Sets.newHashSet();
modules.add(new Log4JLoggingModule());
addTestModulesTo(modules);
injector = new RestContextFactory().<ChefClient, ChefAsyncClient> createContextBuilder("chef", user,
Files.toString(new File(keyfile), Charsets.UTF_8), modules, props).buildInjector();
injector = ContextBuilder.newBuilder(new ChefApiMetadata()).credentials(user, Files.toString(new File(keyfile), Charsets.UTF_8))
.endpoint(endpoint).modules(modules).buildInjector();
}
protected void addTestModulesTo(Set<Module> modules) {

View File

@ -18,25 +18,22 @@
*/
package org.jclouds.chef.test;
import java.util.List;
import java.util.Properties;
import org.jclouds.Wrapper;
import org.jclouds.rest.internal.BaseRestApiMetadataTest;
import org.testng.annotations.Test;
import org.jclouds.chef.ChefContextBuilder;
import org.jclouds.chef.test.config.TransientChefClientModule;
import com.google.inject.Module;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
/**
*
* @author Adrian Cole
*/
public class TransientChefContextBuilder extends ChefContextBuilder {
@Test(groups = "unit", testName = "TransientChefApiMetadataTest")
public class TransientChefApiMetadataTest extends BaseRestApiMetadataTest {
public TransientChefContextBuilder(Properties props) {
super(props);
// no config management abstraction, yet
public TransientChefApiMetadataTest() {
super(new TransientChefApiMetadata(), ImmutableSet.<TypeToken<? extends Wrapper>> of());
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new TransientChefClientModule());
}
}
}

View File

@ -24,10 +24,10 @@ import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.ContextBuilder;
import org.jclouds.chef.BaseChefClientLiveTest;
import org.jclouds.chef.ChefClient;
import org.jclouds.chef.ChefContext;
import org.jclouds.chef.ChefContextFactory;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.chef.domain.DatabagItem;
import org.jclouds.json.Json;
@ -284,7 +284,7 @@ public class TransientChefClientIntegrationTest extends BaseChefClientLiveTest {
}
private ChefContext createConnection(String identity, String key) throws IOException {
return new ChefContextFactory().createContext("transientchef", identity, key);
return ContextBuilder.newBuilder(new TransientChefApiMetadata()).credentials(identity, key).build();
}
@Override

View File

@ -13,57 +13,57 @@ if [ ! -f /usr/bin/chef-client ]; then
/usr/bin/gem install ohai chef --no-rdoc --no-ri --verbose
fi
mkdir -p /etc/chef
cat >> /etc/chef/client.rb <<'END_OF_FILE'
require 'rubygems'
require 'ohai'
o = Ohai::System.new
o.all_plugins
node_name "foo-" + o[:ipaddress]
log_level :info
log_location STDOUT
validation_client_name "fooclient"
chef_server_url "http://localhost:4000"
END_OF_FILE
cat >> /etc/chef/validation.pem <<'END_OF_FILE'
-----BEGIN PRIVATE KEY-----
LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcFFJQkFBS0NBUUVB
eWIyWkpKcUdtMEtLUis4bmZRSk5zU2QrRjl0WE5NVjdDZk9jVzZqc3FzOEVaZ2lW
Cl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BSU0EgUFJJVkFURSBLRVktLS0tLQo=
-----END PRIVATE KEY-----
END_OF_FILE
cat >> /etc/chef/first-boot.json <<'END_OF_FILE'
{"run_list":["recipe[apache2]"]}
END_OF_FILE
cat >> /etc/chef/client.rb <<-'END_OF_JCLOUDS_FILE'
require 'rubygems'
require 'ohai'
o = Ohai::System.new
o.all_plugins
node_name "foo-" + o[:ipaddress]
log_level :info
log_location STDOUT
validation_client_name "fooclient"
chef_server_url "http://localhost:4000"
END_OF_JCLOUDS_FILE
cat >> /etc/chef/validation.pem <<-'END_OF_JCLOUDS_FILE'
-----BEGIN PRIVATE KEY-----
LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcFFJQkFBS0NBUUVB
eWIyWkpKcUdtMEtLUis4bmZRSk5zU2QrRjl0WE5NVjdDZk9jVzZqc3FzOEVaZ2lW
ClIwOWhEMUlZT2o0WXFNMHFKT05sZ3lnNHhSV2V3ZFNHN1FUUGoxbEpwVkFpZGE5
c1h5MitrenlhZ1pBMUFtME8KWmNicWI1aG9lSURnY1grZURhNzlzMHUwRG9tamNm
TzlFS2h2SExCeit6TSszUXFQUmtQVjhuWVRiZnMrSGpWegp6T1U2RDFCMFhSMytJ
UFpabDJBbldzMmQwcWhuU3RIY0RVdm5SVlEwUDQ4Mll3TjlWZ2NlT1p0cFB6MERD
S0VKCjVUeDVTVHViOGswL3p0L1ZBTUhRYWZMU3VRTUxkMnM0Wkx1T1pwdE4vL3VB
c1RteGlyZXFkMzd6KzhaVGRCYkoKOExFcEoraUNYdVNmbTVhVWg3aXc2b3h2VG9Z
MkFMNTMraksyVVFJREFRQUJBb0lCQVFEQTg4QjNpL3hXbjB2WApCVnhGYW1DWW9l
Y3VOakd3WFhrU3laZXc2MTZBK0VPQ3U0N2JoNGFUdXJkRmJZTDBZRmFBdGFXdnps
YU4yZUhnCkRiK0hEdVRlZkUyOStXa2NHazZTc2hQbWl6NVQwWE9DQUlDV3c2d1NW
RGtIbUd3U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