http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/chef/test/TransientChefApiMetadata.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/test/TransientChefApiMetadata.java b/core/src/main/java/org/jclouds/chef/test/TransientChefApiMetadata.java deleted file mode 100644 index c485080..0000000 --- a/core/src/main/java/org/jclouds/chef/test/TransientChefApiMetadata.java +++ /dev/null @@ -1,75 +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.test; - -import java.net.URI; - -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.config.ChefBootstrapModule; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.chef.test.config.TransientChefApiModule; -import org.jclouds.ohai.config.JMXOhaiModule; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Implementation of {@link ApiMetadata} for the Amazon-specific Chef API - */ -public class TransientChefApiMetadata extends BaseHttpApiMetadata<TransientChefApi> { - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public TransientChefApiMetadata() { - this(new Builder()); - } - - protected TransientChefApiMetadata(Builder builder) { - super(builder); - } - - public static class Builder extends BaseHttpApiMetadata.Builder<TransientChefApi, Builder> { - protected Builder() { - id("transientchef") - .name("In-memory Chef API") - .identityName("unused") - .defaultIdentity("api") - .documentation(URI.create("http://localhost")) - .defaultCredential( - "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEAyb2ZJJqGm0KKR+8nfQJNsSd+F9tXNMV7CfOcW6jsqs8EZgiV\nR09hD1IYOj4YqM0qJONlgyg4xRWewdSG7QTPj1lJpVAida9sXy2+kzyagZA1Am0O\nZcbqb5hoeIDgcX+eDa79s0u0DomjcfO9EKhvHLBz+zM+3QqPRkPV8nYTbfs+HjVz\nzOU6D1B0XR3+IPZZl2AnWs2d0qhnStHcDUvnRVQ0P482YwN9VgceOZtpPz0DCKEJ\n5Tx5STub8k0/zt/VAMHQafLSuQMLd2s4ZLuOZptN//uAsTmxireqd37z+8ZTdBbJ\n8LEpJ+iCXuSfm5aUh7iw6oxvToY2AL53+jK2UQIDAQABAoIBAQDA88B3i/xWn0vX\nBVxFamCYoecuNjGwXXkSyZew616A+EOCu47bh4aTurdFbYL0YFaAtaWvzlaN2eHg\nDb+HDuTefE29+WkcGk6SshPmiz5T0XOCAICWw6wSVDkHmGwS4jZvbAFm7W8nwGk9\nYhxgxFiRngswJZFopOLoF5WXs2td8guIYNslMpo7tu50iFnBHwKO2ZsPAk8t9nnS\nxlDavKruymEmqHCr3+dtio5eaenJcp3fjoXBQOKUk3ipII29XRB8NqeCVV/7Kxwq\nckqOBEbRwBclckyIbD+RiAgKvOelORjEiE9R42vuqvxRA6k9kd9o7utlX0AUtpEn\n3gZc6LepAoGBAP9ael5Y75+sK2JJUNOOhO8ae45cdsilp2yI0X+UBaSuQs2+dyPp\nkpEHAxd4pmmSvn/8c9TlEZhr+qYbABXVPlDncxpIuw2Ajbk7s/S4XaSKsRqpXL57\nzj/QOqLkRk8+OVV9q6lMeQNqLtEj1u6JPviX70Ro+FQtRttNOYbfdP/fAoGBAMpA\nXjR5woV5sUb+REg9vE uYo8RSyOarxqKFCIXVUNsLOx+22+AK4+CQpbueWN7jotrl\nYD6uT6svWi3AAC7kiY0UI/fjVPRCUi8tVoQUE0TaU5VLITaYOB+W/bBaDE4M9560\n1NuDWO90baA5dfU44iuzva02rGJXK9+nS3o8nk/PAoGBALOL6djnDe4mwAaG6Jco\ncd4xr8jkyPzCRZuyBCSBbwphIUXLc7hDprPky064ncJD1UDmwIdkXd/fpMkg2QmA\n/CUk6LEFjMisqHojOaCL9gQZJPhLN5QUN2x1PJWGjs1vQh8Tkx0iUUCOa8bQPXNR\n+34OTsW6TUna4CSZAycLfhffAoGBAIggVsefBCvuQkF0NeUhmDCRZfhnd8y55RHR\n1HCvqKIlpv+rhcX/zmyBLuteopYyRJRsOiE2FW00i8+rIPRu4Z3Q5nybx7w3PzV9\noHN5R5baE9OyI4KpZWztpYYitZF67NcnAvVULHHOvVJQGnKYfLHJYmrJF7GA1ojM\nAuMdFbjFAoGAPxUhxwFy8gaqBahKUEZn4F81HFP5ihGhkT4QL6AFPO2e+JhIGjuR\n27+85hcFqQ+HHVtFsm81b/a+R7P4UuCRgc8eCjxQMoJ1Xl4n7VbjPbHMnIN0Ryvd\nO4ZpWDWYnCO021JTOUUOJ4J/y0416Bvkw0z59y7sNX7wDBBHHbK/XCc=\n-----END RSA PRIVATE KEY-----\n") - .defaultEndpoint("transientchef") - .defaultProperties(ChefApiMetadata.defaultProperties()) - .defaultModules( - ImmutableSet.<Class<? extends Module>> of(TransientChefApiModule.class, ChefParserModule.class, - ChefBootstrapModule.class, JMXOhaiModule.class)); - } - - @Override - public TransientChefApiMetadata build() { - return new TransientChefApiMetadata(this); - } - - @Override - protected Builder self() { - return this; - } - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/chef/test/config/TransientChefApiModule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/test/config/TransientChefApiModule.java b/core/src/main/java/org/jclouds/chef/test/config/TransientChefApiModule.java deleted file mode 100644 index bab35d0..0000000 --- a/core/src/main/java/org/jclouds/chef/test/config/TransientChefApiModule.java +++ /dev/null @@ -1,114 +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.test.config; - -import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; - -import java.io.IOException; -import java.security.PrivateKey; -import java.security.spec.InvalidKeySpecException; -import java.util.List; - -import javax.inject.Singleton; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.config.LocalBlobStore; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.Validator; -import org.jclouds.chef.domain.Client; -import org.jclouds.chef.functions.BootstrapConfigForGroup; -import org.jclouds.chef.functions.ClientForGroup; -import org.jclouds.chef.functions.RunListForGroup; -import org.jclouds.chef.test.TransientChefApi; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.crypto.Crypto; -import org.jclouds.domain.JsonBall; -import org.jclouds.rest.ConfiguresHttpApi; -import org.jclouds.rest.config.RestModule; - -import com.google.common.base.Optional; -import com.google.common.base.Supplier; -import com.google.common.cache.CacheLoader; -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.Provides; -import com.google.inject.name.Names; - -@ConfiguresHttpApi -public class TransientChefApiModule extends AbstractModule { - - @Override - protected void configure() { - install(new RestModule()); - bind(ChefApi.class).to(TransientChefApi.class); - bind(LocalBlobStore.class).annotatedWith(Names.named("databags")) - .toInstance( - ContextBuilder - .newBuilder(new TransientApiMetadata()) - .modules( - ImmutableSet.<Module> of(new ExecutorServiceModule(sameThreadExecutor(), - sameThreadExecutor()))).buildInjector().getInstance(LocalBlobStore.class)); - } - - @Provides - @Singleton - public Supplier<PrivateKey> supplyKey() { - return new Supplier<PrivateKey>() { - @Override - public PrivateKey get() { - return null; - } - }; - } - - @Provides - @Singleton - CacheLoader<String, List<String>> runListForGroup(RunListForGroup runListForGroup) { - return CacheLoader.from(runListForGroup); - } - - @Provides - @Singleton - CacheLoader<String, ? extends JsonBall> bootstrapConfigForGroup(BootstrapConfigForGroup bootstrapConfigForGroup) { - return CacheLoader.from(bootstrapConfigForGroup); - } - - @Provides - @Singleton - CacheLoader<String, Client> groupToClient(ClientForGroup clientForGroup) { - return CacheLoader.from(clientForGroup); - } - - @Provides - @Singleton - @Validator - public Optional<String> provideValidatorName(Injector injector) { - return Optional.absent(); - } - - @Provides - @Singleton - @Validator - public Optional<PrivateKey> provideValidatorCredential(Crypto crypto, Injector injector) - throws InvalidKeySpecException, IOException { - return Optional.absent(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/chef/util/ChefUtils.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/util/ChefUtils.java b/core/src/main/java/org/jclouds/chef/util/ChefUtils.java deleted file mode 100644 index 3ba0c59..0000000 --- a/core/src/main/java/org/jclouds/chef/util/ChefUtils.java +++ /dev/null @@ -1,71 +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.util; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Date; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jclouds.domain.JsonBall; -import org.jclouds.ohai.Automatic; - -import com.google.common.base.Predicate; -import com.google.common.base.Supplier; -import com.google.common.collect.Iterables; -import com.google.inject.Binder; -import com.google.inject.TypeLiteral; -import com.google.inject.multibindings.MapBinder; - -public class ChefUtils { - - public static Date fromOhaiTime(JsonBall ohaiDate) { - return new Date(Long.parseLong(checkNotNull(ohaiDate, "ohaiDate").toString().replaceAll("\\.[0-9]*$", ""))); - } - - public static JsonBall toOhaiTime(long millis) { - return new JsonBall(millis + ""); - } - - public static MapBinder<String, Supplier<JsonBall>> ohaiAutomaticAttributeBinder(Binder binder) { - MapBinder<String, Supplier<JsonBall>> mapbinder = MapBinder.newMapBinder(binder, new TypeLiteral<String>() { - }, new TypeLiteral<Supplier<JsonBall>>() { - }, Automatic.class); - return mapbinder; - } - - /** - * - * @return NoSuchElementException if no element in the runList is a role. - */ - public static String findRoleInRunList(List<String> runList) { - final Pattern pattern = Pattern.compile("^role\\[(.*)\\]$"); - String roleToParse = Iterables.find(runList, new Predicate<String>() { - - @Override - public boolean apply(String input) { - return pattern.matcher(input).matches(); - } - - }); - Matcher matcher = pattern.matcher(roleToParse); - matcher.find(); - return matcher.group(1); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/chef/util/CollectionUtils.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/util/CollectionUtils.java b/core/src/main/java/org/jclouds/chef/util/CollectionUtils.java deleted file mode 100644 index cabfbde..0000000 --- a/core/src/main/java/org/jclouds/chef/util/CollectionUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.chef.util; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -/** - * Utility methods to work with collections. - */ -public class CollectionUtils { - - /** - * Creates an immutable list with the elements of the given list. If the - * input list is <code>null</code>, it returns an empty list. - * - * @param input - * The list used to build the immutable one. - * @return An immutable list with the elements of the given list. - */ - public static <T> ImmutableList<T> copyOfOrEmpty(@Nullable List<T> input) { - return input == null ? ImmutableList.<T> of() : ImmutableList.copyOf(input); - } - - /** - * Creates an immutable set with the elements of the given set. If the input - * set is <code>null</code>, it returns an empty set. - * - * @param input - * The set used to build the immutable one. - * @return An immutable set with the elements of the given set. - */ - public static <T> ImmutableSet<T> copyOfOrEmpty(@Nullable Set<T> input) { - return input == null ? ImmutableSet.<T> of() : ImmutableSet.copyOf(input); - } - - /** - * Creates an immutable map with the elements of the given map. If the input - * map is <code>null</code>, it returns an empty map. - * - * @param input - * The map used to build the immutable one. - * @return An immutable map with the elements of the given map. - */ - public static <K, V> ImmutableMap<K, V> copyOfOrEmpty(@Nullable Map<K, V> input) { - return input == null ? ImmutableMap.<K, V> of() : ImmutableMap.copyOf(input); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/chef/util/RunListBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/util/RunListBuilder.java b/core/src/main/java/org/jclouds/chef/util/RunListBuilder.java deleted file mode 100644 index 27cc377..0000000 --- a/core/src/main/java/org/jclouds/chef/util/RunListBuilder.java +++ /dev/null @@ -1,83 +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.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.addAll; -import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Lists.transform; - -import java.util.Arrays; -import java.util.List; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; - -/** - * builds a run list in the correct syntax for chef. - */ -public class RunListBuilder { - private List<String> list = newArrayList(); - - /** - * Add the following recipe to the run list - */ - public RunListBuilder addRecipe(String recipe) { - return addRecipes(checkNotNull(recipe, "recipe")); - } - - /** - * Add the following recipes to the run list - */ - public RunListBuilder addRecipes(String... recipes) { - addAll(list, transform(Arrays.asList(checkNotNull(recipes, "recipes")), new Function<String, String>() { - - @Override - public String apply(String from) { - return "recipe[" + from + "]"; - } - - })); - return this; - } - - /** - * Add the following role to the run list - */ - public RunListBuilder addRole(String role) { - return addRoles(checkNotNull(role, "role")); - } - - /** - * Add the following roles to the run list - */ - public RunListBuilder addRoles(String... roles) { - addAll(list, transform(Arrays.asList(checkNotNull(roles, "roles")), new Function<String, String>() { - - @Override - public String apply(String from) { - return "role[" + from + "]"; - } - - })); - return this; - } - - public List<String> build() { - return ImmutableList.copyOf(list); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/Automatic.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/Automatic.java b/core/src/main/java/org/jclouds/ohai/Automatic.java deleted file mode 100644 index 9b3d134..0000000 --- a/core/src/main/java/org/jclouds/ohai/Automatic.java +++ /dev/null @@ -1,33 +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.ohai; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import javax.inject.Qualifier; - -@Retention(RUNTIME) -@Target({ TYPE, METHOD, PARAMETER }) -@Qualifier -public @interface Automatic { -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/AutomaticSupplier.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/AutomaticSupplier.java b/core/src/main/java/org/jclouds/ohai/AutomaticSupplier.java deleted file mode 100644 index 681558e..0000000 --- a/core/src/main/java/org/jclouds/ohai/AutomaticSupplier.java +++ /dev/null @@ -1,48 +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.ohai; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.domain.JsonBall; -import org.jclouds.ohai.functions.NestSlashKeys; - -import com.google.common.base.Supplier; -import com.google.common.collect.Multimap; - -@Singleton -public class AutomaticSupplier implements Supplier<Map<String, JsonBall>> { - private final Multimap<String, Supplier<JsonBall>> autoAttrs; - private final NestSlashKeys nester; - - @Inject - AutomaticSupplier(@Automatic Multimap<String, Supplier<JsonBall>> autoAttrs, NestSlashKeys nester) { - this.autoAttrs = checkNotNull(autoAttrs, "autoAttrs"); - this.nester = checkNotNull(nester, "nester"); - } - - @Override - public Map<String, JsonBall> get() { - return nester.apply(autoAttrs); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/config/ConfiguresOhai.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/config/ConfiguresOhai.java b/core/src/main/java/org/jclouds/ohai/config/ConfiguresOhai.java deleted file mode 100644 index 1ca0df4..0000000 --- a/core/src/main/java/org/jclouds/ohai/config/ConfiguresOhai.java +++ /dev/null @@ -1,28 +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.ohai.config; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Retention(RUNTIME) -@Target(TYPE) -public @interface ConfiguresOhai { -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/config/JMXOhaiModule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/config/JMXOhaiModule.java b/core/src/main/java/org/jclouds/ohai/config/JMXOhaiModule.java deleted file mode 100644 index a8d01f7..0000000 --- a/core/src/main/java/org/jclouds/ohai/config/JMXOhaiModule.java +++ /dev/null @@ -1,48 +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.ohai.config; - -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; - -import javax.inject.Singleton; - -import org.jclouds.domain.JsonBall; -import org.jclouds.ohai.suppliers.UptimeSecondsSupplier; - -import com.google.common.base.Supplier; -import com.google.inject.Provides; -import com.google.inject.multibindings.MapBinder; - -/** - * Wires the components needed to parse ohai data from a JVM - */ -@ConfiguresOhai -public class JMXOhaiModule extends OhaiModule { - - @Provides - @Singleton - protected RuntimeMXBean provideRuntimeMXBean() { - return ManagementFactory.getRuntimeMXBean(); - } - - public MapBinder<String, Supplier<JsonBall>> bindOhai() { - MapBinder<String, Supplier<JsonBall>> mapBinder = super.bindOhai(); - mapBinder.addBinding("uptime_seconds").to(UptimeSecondsSupplier.class); - return mapBinder; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/config/OhaiModule.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/config/OhaiModule.java b/core/src/main/java/org/jclouds/ohai/config/OhaiModule.java deleted file mode 100644 index 650fe9e..0000000 --- a/core/src/main/java/org/jclouds/ohai/config/OhaiModule.java +++ /dev/null @@ -1,183 +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.ohai.config; - -import static org.jclouds.chef.util.ChefUtils.ohaiAutomaticAttributeBinder; -import static org.jclouds.chef.util.ChefUtils.toOhaiTime; - -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; -import javax.inject.Singleton; - -import org.jclouds.domain.JsonBall; -import org.jclouds.json.Json; -import org.jclouds.ohai.Automatic; -import org.jclouds.ohai.AutomaticSupplier; -import org.jclouds.ohai.functions.ByteArrayToMacAddress; -import org.jclouds.ohai.functions.MapSetToMultimap; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.common.collect.Multimap; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; -import com.google.inject.multibindings.MapBinder; - -/** - * Wires the components needed to parse ohai data - */ -@ConfiguresOhai -public class OhaiModule extends AbstractModule { - - @Override - protected void configure() { - bind(new TypeLiteral<Function<byte[], String>>() { - }).to(new TypeLiteral<ByteArrayToMacAddress>() { - }); - bindOhai(); - } - - @Provides - @Automatic - protected Supplier<Map<String, JsonBall>> provideAutomatic(AutomaticSupplier in) { - return in; - } - - @Provides - @Automatic - Multimap<String, Supplier<JsonBall>> provideAutomatic(MapSetToMultimap<String, Supplier<JsonBall>> converter, - @Automatic Map<String, Set<Supplier<JsonBall>>> input) { - return converter.apply(input); - - } - - @Named("systemProperties") - @Provides - protected Properties systemProperties() { - return System.getProperties(); - } - - public MapBinder<String, Supplier<JsonBall>> bindOhai() { - MapBinder<String, Supplier<JsonBall>> mapbinder = ohaiAutomaticAttributeBinder(binder()).permitDuplicates(); - mapbinder.addBinding("ohai_time").to(OhaiTimeProvider.class); - mapbinder.addBinding("jvm/system").to(SystemPropertiesProvider.class); - mapbinder.addBinding("platform").to(PlatformProvider.class); - mapbinder.addBinding("platform_version").to(PlatformVersionProvider.class); - mapbinder.addBinding("current_user").to(CurrentUserProvider.class); - return mapbinder; - } - - @Singleton - public static class OhaiTimeProvider implements Supplier<JsonBall> { - private final Provider<Long> timeProvider; - - @Inject - OhaiTimeProvider(Provider<Long> timeProvider) { - this.timeProvider = timeProvider; - } - - @Override - public JsonBall get() { - return toOhaiTime(timeProvider.get()); - } - - } - - @Provides - protected Long millis() { - return System.currentTimeMillis(); - } - - @Singleton - public static class SystemPropertiesProvider implements Supplier<JsonBall> { - - private final Json json; - private final Properties systemProperties; - - @Inject - SystemPropertiesProvider(Json json, @Named("systemProperties") Properties systemProperties) { - this.json = json; - this.systemProperties = systemProperties; - } - - @Override - public JsonBall get() { - return new JsonBall(json.toJson(systemProperties)); - } - - } - - @Singleton - public static class PlatformProvider extends SystemPropertyProvider { - - @Inject - PlatformProvider(@Named("systemProperties") Properties systemProperties) { - super("os.name", systemProperties); - } - - @Override - public JsonBall get() { - JsonBall returnValue = super.get(); - return returnValue != null ? new JsonBall(returnValue.toString().replaceAll("[ -]", "").toLowerCase()) : null; - } - - } - - @Singleton - public static class PlatformVersionProvider extends SystemPropertyProvider { - - @Inject - PlatformVersionProvider(@Named("systemProperties") Properties systemProperties) { - super("os.version", systemProperties); - } - - } - - @Singleton - public static class CurrentUserProvider extends SystemPropertyProvider { - - @Inject - CurrentUserProvider(@Named("systemProperties") Properties systemProperties) { - super("user.name", systemProperties); - } - - } - - public static class SystemPropertyProvider implements Supplier<JsonBall> { - private final Properties systemProperties; - private final String property; - - @Inject - SystemPropertyProvider(String property, @Named("systemProperties") Properties systemProperties) { - this.property = property; - this.systemProperties = systemProperties; - } - - @Override - public JsonBall get() { - return systemProperties.containsKey(property) ? new JsonBall(systemProperties.getProperty(property)) : null; - } - - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/functions/ByteArrayToMacAddress.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/functions/ByteArrayToMacAddress.java b/core/src/main/java/org/jclouds/ohai/functions/ByteArrayToMacAddress.java deleted file mode 100644 index be7e46a..0000000 --- a/core/src/main/java/org/jclouds/ohai/functions/ByteArrayToMacAddress.java +++ /dev/null @@ -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.ohai.functions; - -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Lists.partition; -import static com.google.common.io.BaseEncoding.base16; -import static com.google.common.primitives.Bytes.asList; -import static com.google.common.primitives.Bytes.toArray; - -import java.util.List; - -import javax.inject.Singleton; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; - -/** - * - * Creates a string in the form: {@code 00:26:bb:09:e6:c4 } - */ -@Singleton -public class ByteArrayToMacAddress implements Function<byte[], String> { - - @Override - public String apply(byte[] from) { - return Joiner.on(':').join(transform(partition(asList(from), 1), new Function<List<Byte>, String>() { - - @Override - public String apply(List<Byte> from) { - return base16().lowerCase().encode(toArray(from)); - } - - })); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/functions/MapSetToMultimap.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/functions/MapSetToMultimap.java b/core/src/main/java/org/jclouds/ohai/functions/MapSetToMultimap.java deleted file mode 100644 index 4ef3c87..0000000 --- a/core/src/main/java/org/jclouds/ohai/functions/MapSetToMultimap.java +++ /dev/null @@ -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.ohai.functions; - -import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; - -import javax.inject.Singleton; - -import com.google.common.base.Function; -import com.google.common.collect.LinkedHashMultimap; -import com.google.common.collect.Multimap; - -@Singleton -public class MapSetToMultimap<K, V> implements Function<Map<K, Set<V>>, Multimap<K, V>> { - - @Override - public Multimap<K, V> apply(Map<K, Set<V>> from) { - Multimap<K, V> returnV = LinkedHashMultimap.create(); - for (Entry<K, Set<V>> entry : from.entrySet()) { - for (V value : entry.getValue()) - returnV.put(entry.getKey(), value); - } - return returnV; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/functions/NestSlashKeys.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/functions/NestSlashKeys.java b/core/src/main/java/org/jclouds/ohai/functions/NestSlashKeys.java deleted file mode 100644 index c709463..0000000 --- a/core/src/main/java/org/jclouds/ohai/functions/NestSlashKeys.java +++ /dev/null @@ -1,156 +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.ohai.functions; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.lang.reflect.Type; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.domain.JsonBall; -import org.jclouds.json.Json; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Splitter; -import com.google.common.base.Supplier; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; -import com.google.inject.TypeLiteral; - -@Singleton -public class NestSlashKeys implements Function<Multimap<String, Supplier<JsonBall>>, Map<String, JsonBall>> { - - private final Json json; - - @Inject - NestSlashKeys(Json json) { - this.json = checkNotNull(json, "json"); - } - - @Override - public Map<String, JsonBall> apply(Multimap<String, Supplier<JsonBall>> from) { - - Map<String, JsonBall> autoAttrs = mergeSameKeys(from); - - Map<String, JsonBall> modifiableFlatMap = Maps.newLinkedHashMap(Maps.filterKeys(autoAttrs, - new Predicate<String>() { - - @Override - public boolean apply(String input) { - return input.indexOf('/') == -1; - } - - })); - Map<String, JsonBall> withSlashesMap = Maps.difference(autoAttrs, modifiableFlatMap).entriesOnlyOnLeft(); - for (Entry<String, JsonBall> entry : withSlashesMap.entrySet()) { - List<String> keyParts = Lists.newArrayList(Splitter.on('/').split(entry.getKey())); - JsonBall toInsert = entry.getValue(); - try { - putUnderContext(keyParts, toInsert, modifiableFlatMap); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("error inserting value in entry: " + entry.getKey(), e); - } - } - return modifiableFlatMap; - } - - private Map<String, JsonBall> mergeSameKeys(Multimap<String, Supplier<JsonBall>> from) { - Map<String, JsonBall> merged = Maps.newLinkedHashMap(); - for (Entry<String, Supplier<JsonBall>> entry : from.entries()) { - if (merged.containsKey(entry.getKey())) { - mergeAsPeer(entry.getKey(), entry.getValue().get(), merged); - } else { - merged.put(entry.getKey(), entry.getValue().get()); - } - } - return merged; - } - - @VisibleForTesting - void mergeAsPeer(String key, JsonBall value, Map<String, JsonBall> insertionContext) { - Map<String, JsonBall> immutableValueContext = json.fromJson(insertionContext.get(key).toString(), mapLiteral); - Map<String, JsonBall> valueContext = Maps.newHashMap(immutableValueContext); - Map<String, JsonBall> toPut = json.<Map<String, JsonBall>> fromJson(value.toString(), mapLiteral); - Set<String> uniques = Sets.difference(toPut.keySet(), valueContext.keySet()); - for (String k : uniques) { - valueContext.put(k, toPut.get(k)); - } - Set<String> conflicts = Sets.difference(toPut.keySet(), uniques); - for (String k : conflicts) { - JsonBall v = toPut.get(k); - if (v.toString().matches("^\\{.*\\}$")) { - mergeAsPeer(k, v, valueContext); - } else { - // replace - valueContext.put(k, v); - } - } - insertionContext.put(key, new JsonBall(json.toJson(valueContext, mapLiteral))); - } - - /** - * @param keyParts - * @param toInsert - * @param destination - * @throws IllegalArgumentException - * <p/> - * if destination.get(keyParts(0)) is not a map * - * <p/> - * keyParts is zero length - */ - void putUnderContext(List<String> keyParts, JsonBall toInsert, Map<String, JsonBall> destination) { - checkNotNull(keyParts, "keyParts"); - checkArgument(keyParts.size() >= 1, "keyParts must contain at least one element"); - - checkNotNull(toInsert, "toInsert"); - checkNotNull(destination, "destination"); - - String rootKey = keyParts.remove(0); - String rootValue = destination.containsKey(rootKey) ? destination.get(rootKey).toString() : "{}"; - - checkArgument(rootValue.matches("^\\{.*\\}$"), "value must be a hash: %s", rootValue); - Map<String, JsonBall> immutableInsertionContext = json.fromJson(rootValue, mapLiteral); - Map<String, JsonBall> insertionContext = Maps.newHashMap(immutableInsertionContext); - if (keyParts.size() == 1) { - if (!insertionContext.containsKey(keyParts.get(0))) { - insertionContext.put(keyParts.get(0), toInsert); - } else { - String key = keyParts.get(0); - mergeAsPeer(key, toInsert, insertionContext); - } - } else { - putUnderContext(keyParts, toInsert, insertionContext); - } - destination.put(rootKey, new JsonBall(json.toJson(insertionContext, mapLiteral))); - } - - final Type mapLiteral = new TypeLiteral<Map<String, JsonBall>>() { - }.getType(); - final Type listLiteral = new TypeLiteral<List<JsonBall>>() { - }.getType(); -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/java/org/jclouds/ohai/suppliers/UptimeSecondsSupplier.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/ohai/suppliers/UptimeSecondsSupplier.java b/core/src/main/java/org/jclouds/ohai/suppliers/UptimeSecondsSupplier.java deleted file mode 100644 index 9713902..0000000 --- a/core/src/main/java/org/jclouds/ohai/suppliers/UptimeSecondsSupplier.java +++ /dev/null @@ -1,44 +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.ohai.suppliers; - -import java.lang.management.RuntimeMXBean; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.domain.JsonBall; - -import com.google.common.base.Supplier; - -@Singleton -public class UptimeSecondsSupplier implements Supplier<JsonBall> { - - @Inject - UptimeSecondsSupplier(RuntimeMXBean runtime) { - this.runtime = runtime; - } - - private final RuntimeMXBean runtime; - - @Override - public JsonBall get() { - long uptimeInSeconds = runtime.getUptime() / 1000; - return new JsonBall(uptimeInSeconds); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata ---------------------------------------------------------------------- diff --git a/core/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/core/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata deleted file mode 100644 index 07e3240..0000000 --- a/core/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata +++ /dev/null @@ -1,2 +0,0 @@ -org.jclouds.chef.test.TransientChefApiMetadata -org.jclouds.chef.ChefApiMetadata \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/test/clojure/org/jclouds/chef_test.clj ---------------------------------------------------------------------- diff --git a/core/src/test/clojure/org/jclouds/chef_test.clj b/core/src/test/clojure/org/jclouds/chef_test.clj deleted file mode 100644 index bc542f1..0000000 --- a/core/src/test/clojure/org/jclouds/chef_test.clj +++ /dev/null @@ -1,70 +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. -; - -(ns org.jclouds.chef-test - (:use [org.jclouds.chef] :reload-all) - (:use [clojure.test])) - -(defn clean-stub-fixture - "This should allow basic tests to easily be run with another service." - [service account key & options] - (fn [f] - (with-chef-service [(apply chef-service service account key options)] -(doseq [databag (databags)] - (delete-databag databag)) -(f)))) - -(use-fixtures :each (clean-stub-fixture "transientchef" "" "")) - -(deftest chef-service?-test - (is (chef-service? *chef*))) - -(deftest as-chef-service-test - (is (chef-service? (chef-service "transientchef" "" ""))) - (is (chef-service? (as-chef-service *chef*))) - (is (chef-service? (as-chef-service (chef-context *chef*))))) - -(deftest create-existing-databag-test - (is (not (databag-exists? ""))) - (create-databag "fred") - (is (databag-exists? "fred"))) - -(deftest create-databag-test - (create-databag "fred") - (is (databag-exists? "fred"))) - -(deftest databags-test - (is (empty? (databags))) - (create-databag "fred") - (is (= 1 (count (databags))))) - -(deftest databag-items-test - (create-databag "databag") - (is (empty? (databag-items "databag"))) - (is (create-databag-item "databag" {:id "databag-item1" :value "databag-value1"})) - (is (create-databag-item "databag" {:id "databag-item2" :value "databag-value2"})) - (is (= 2 (count (databag-items "databag"))))) - -(deftest databag-item-test - (create-databag "databag") - (is (create-databag-item "databag" {:id "databag-item1" :value "databag-value1"})) - (is (create-databag-item "databag" {:id "databag-item2" :value "databag-value2"})) - (is (= {:id "databag-item2" :value "databag-value2"} (databag-item "databag" "databag-item2")))) - -(deftest run-list-test - (update-run-list #{"recipe[foo]"} "tag") - (is (= ["recipe[foo]"] (run-list "tag")))) http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/test/java/org/jclouds/chef/BaseChefApiExpectTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/BaseChefApiExpectTest.java b/core/src/test/java/org/jclouds/chef/BaseChefApiExpectTest.java deleted file mode 100644 index 23013a9..0000000 --- a/core/src/test/java/org/jclouds/chef/BaseChefApiExpectTest.java +++ /dev/null @@ -1,44 +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 org.jclouds.chef.filters.SignedHeaderAuth; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.rest.internal.BaseRestApiExpectTest; - -import com.google.common.base.Functions; -import com.google.common.collect.ImmutableMap; - -/** - * Base class for Chef Api expect tests. - */ -public abstract class BaseChefApiExpectTest<S> extends BaseRestApiExpectTest<S> { - public static final String PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEAyb2ZJJqGm0KKR+8nfQJNsSd+F9tXNMV7CfOcW6jsqs8EZgiV\nR09hD1IYOj4YqM0qJONlgyg4xRWewdSG7QTPj1lJpVAida9sXy2+kzyagZA1Am0O\nZcbqb5hoeIDgcX+eDa79s0u0DomjcfO9EKhvHLBz+zM+3QqPRkPV8nYTbfs+HjVz\nzOU6D1B0XR3+IPZZl2AnWs2d0qhnStHcDUvnRVQ0P482YwN9VgceOZtpPz0DCKEJ\n5Tx5STub8k0/zt/VAMHQafLSuQMLd2s4ZLuOZptN//uAsTmxireqd37z+8ZTdBbJ\n8LEpJ+iCXuSfm5aUh7iw6oxvToY2AL53+jK2UQIDAQABAoIBAQDA88B3i/xWn0vX\nBVxFamCYoecuNjGwXXkSyZew616A+EOCu47bh4aTurdFbYL0YFaAtaWvzlaN2eHg\nDb+HDuTefE29+WkcGk6SshPmiz5T0XOCAICWw6wSVDkHmGwS4jZvbAFm7W8nwGk9\nYhxgxFiRngswJZFopOLoF5WXs2td8guIYNslMpo7tu50iFnBHwKO2ZsPAk8t9nnS\nxlDavKruymEmqHCr3+dtio5eaenJcp3fjoXBQOKUk3ipII29XRB8NqeCVV/7Kxwq\nckqOBEbRwBclckyIbD+RiAgKvOelORjEiE9R42vuqvxRA6k9kd9o7utlX0AUtpEn\n3gZc6LepAoGBAP9ael5Y75+sK2JJUNOOhO8ae45cdsilp2yI0X+UBaSuQs2+dyPp\nkpEHAxd4pmmSvn/8c9TlEZhr+qYbABXVPlDncxpIuw2Ajbk7s/S4XaSKsRqpXL57\nzj/QOqLkRk8+OVV9q6lMeQNqLtEj1u6JPviX70Ro+FQtRttNOYbfdP/fAoGBA MpA\nXjR5woV5sUb+REg9vEuYo8RSyOarxqKFCIXVUNsLOx+22+AK4+CQpbueWN7jotrl\nYD6uT6svWi3AAC7kiY0UI/fjVPRCUi8tVoQUE0TaU5VLITaYOB+W/bBaDE4M9560\n1NuDWO90baA5dfU44iuzva02rGJXK9+nS3o8nk/PAoGBALOL6djnDe4mwAaG6Jco\ncd4xr8jkyPzCRZuyBCSBbwphIUXLc7hDprPky064ncJD1UDmwIdkXd/fpMkg2QmA\n/CUk6LEFjMisqHojOaCL9gQZJPhLN5QUN2x1PJWGjs1vQh8Tkx0iUUCOa8bQPXNR\n+34OTsW6TUna4CSZAycLfhffAoGBAIggVsefBCvuQkF0NeUhmDCRZfhnd8y55RHR\n1HCvqKIlpv+rhcX/zmyBLuteopYyRJRsOiE2FW00i8+rIPRu4Z3Q5nybx7w3PzV9\noHN5R5baE9OyI4KpZWztpYYitZF67NcnAvVULHHOvVJQGnKYfLHJYmrJF7GA1ojM\nAuMdFbjFAoGAPxUhxwFy8gaqBahKUEZn4F81HFP5ihGhkT4QL6AFPO2e+JhIGjuR\n27+85hcFqQ+HHVtFsm81b/a+R7P4UuCRgc8eCjxQMoJ1Xl4n7VbjPbHMnIN0Ryvd\nO4ZpWDWYnCO021JTOUUOJ4J/y0416Bvkw0z59y7sNX7wDBBHHbK/XCc=\n-----END RSA PRIVATE KEY-----\n"; - - protected SignedHeaderAuth signedHeaderAuth; - - public BaseChefApiExpectTest() { - credential = PRIVATE_KEY; - signedHeaderAuth = createInjector(Functions.forMap(ImmutableMap.<HttpRequest, HttpResponse> of()), - createModule(), setupProperties()).getInstance(SignedHeaderAuth.class); - } - - protected HttpRequest signed(HttpRequest input) { - return signedHeaderAuth.filter(input); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java b/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java deleted file mode 100644 index 478959b..0000000 --- a/core/src/test/java/org/jclouds/chef/ChefApiExpectTest.java +++ /dev/null @@ -1,279 +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 static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Set; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.chef.config.ChefHttpApiModule; -import org.jclouds.chef.domain.CookbookDefinition; -import org.jclouds.chef.domain.Role; -import org.jclouds.chef.domain.SearchResult; -import org.jclouds.chef.options.SearchOptions; -import org.jclouds.date.TimeStamp; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.rest.ConfiguresHttpApi; -import org.testng.annotations.Test; - -import com.google.common.base.Supplier; -import com.google.inject.Module; - -/** - * Expect tests for the {@link ChefApi} class. - */ -@Test(groups = "unit", testName = "ChefApiExpectTest") -public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> { - public ChefApiExpectTest() { - provider = "chef"; - } - - private HttpRequest.Builder<?> getHttpRequestBuilder(String method, String endPoint) { - return HttpRequest.builder() // - .method(method) // - .endpoint("http://localhost:4000" + endPoint) // - .addHeader("X-Chef-Version", ChefApiMetadata.DEFAULT_API_VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON); - } - - public void testListClientsReturnsValidSet() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/clients").build()), - HttpResponse.builder().statusCode(200) // - .payload(payloadFromResourceWithContentType("/clients_list.json", MediaType.APPLICATION_JSON)) // - .build()); - Set<String> nodes = api.listClients(); - assertEquals(nodes.size(), 3); - assertTrue(nodes.contains("adam"), String.format("Expected nodes to contain 'adam' but was: %s", nodes)); - } - - public void testListClientsReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/clients").build()), - HttpResponse.builder().statusCode(404) - .build()); - Set<String> clients = api.listClients(); - assertTrue(clients.isEmpty(), String.format("Expected clients to be empty but was: %s", clients)); - } - - public void testListNodesReturnsValidSet() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/nodes").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/nodes_list.json", MediaType.APPLICATION_JSON)) // - .build()); - Set<String> nodes = api.listNodes(); - assertEquals(nodes.size(), 3); - assertTrue(nodes.contains("blah"), String.format("Expected nodes to contain 'blah' but was: %s", nodes)); - } - - public void testListNodesReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/nodes").build()), - HttpResponse.builder().statusCode(404).build()); - Set<String> nodes = api.listNodes(); - assertTrue(nodes.isEmpty(), String.format("Expected nodes to be empty but was: %s", nodes)); - } - - public void testListRecipesInEnvironmentReturnsValidSet() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/environments/dev/recipes").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/environment_recipes.json", MediaType.APPLICATION_JSON)) // - .build()); - Set<String> recipes = api.listRecipesInEnvironment("dev"); - assertEquals(recipes.size(), 3); - assertTrue(recipes.contains("apache2"), String.format("Expected recipes to contain 'apache2' but was: %s", recipes)); - } - - public void testListRecipesInEnvironmentReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/environments/dev/recipes").build()), - HttpResponse.builder().statusCode(404).build()); - Set<String> recipes = api.listRecipesInEnvironment("dev"); - assertTrue(recipes.isEmpty(), String.format("Expected recipes to be empty but was: %s", recipes)); - } - - public void testListNodesInEnvironmentReturnsValidSet() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/environments/dev/nodes").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/nodes_list.json", MediaType.APPLICATION_JSON)) // - .build()); - Set<String> nodes = api.listNodesInEnvironment("dev"); - assertEquals(nodes.size(), 3); - assertTrue(nodes.contains("blah"), String.format("Expected nodes to contain 'blah' but was: %s", nodes)); - } - - public void testListNodesInEnvironmentReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/environments/dev/nodes").build()), - HttpResponse.builder().statusCode(404).build()); - Set<String> nodes = api.listNodesInEnvironment("dev"); - assertTrue(nodes.isEmpty(), String.format("Expected nodes to be empty but was: %s", nodes)); - } - - public void testListCookbooksReturnsValidSet() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/cookbooks").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/env_cookbooks.json", MediaType.APPLICATION_JSON)) // - .build()); - Set<String> cookbooks = api.listCookbooks(); - assertEquals(cookbooks.size(), 2); - assertTrue(cookbooks.contains("apache2"), String.format("Expected cookbooks to contain 'apache2' but was: %s", cookbooks)); - } - - public void testListCookbooksReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/cookbooks").build()), - HttpResponse.builder().statusCode(404).build()); - Set<String> cookbooks = api.listCookbooks(); - assertTrue(cookbooks.isEmpty(), String.format("Expected cookbooks to be empty but was: %s", cookbooks)); - } - - public void testListCookbooksInEnvironmentReturnsValidSet() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/environments/dev/cookbooks").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/env_cookbooks.json", MediaType.APPLICATION_JSON)) // - .build()); - Set<CookbookDefinition> cookbooks = api.listCookbooksInEnvironment("dev"); - assertEquals(cookbooks.size(), 2); - } - - public void testListCookbooksInEnvironmentReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/environments/dev/cookbooks").build()), - HttpResponse.builder().statusCode(404).build()); - Set<CookbookDefinition> cookbooks = api.listCookbooksInEnvironment("dev"); - assertTrue(cookbooks.isEmpty(), String.format("Expected cookbooks to be empty but was: %s", cookbooks)); - } - - public void testListCookbooksInEnvironmentWithNumVersionReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/environments/dev/cookbooks").addQueryParam("num_versions", "2").build()), - HttpResponse.builder().statusCode(404).build()); - Set<CookbookDefinition> cookbooks = api.listCookbooksInEnvironment("dev", "2"); - assertTrue(cookbooks.isEmpty(), String.format("Expected cookbooks to be empty but was: %s", cookbooks)); - } - - public void testSearchRolesReturnsValidResult() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/search/role").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/search_role.json", MediaType.APPLICATION_JSON)) // - .build()); - SearchResult<? extends Role> result = api.searchRoles(); - assertEquals(result.size(), 1); - assertEquals(result.iterator().next().getName(), "webserver"); - } - - public void testSearchRolesReturnsEmptyResult() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/search/role").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/search_role_empty.json", MediaType.APPLICATION_JSON)) // - .build()); - SearchResult<? extends Role> result = api.searchRoles(); - assertTrue(result.isEmpty(), String.format("Expected search result to be empty but was: %s", result)); - } - - public void testSearchRolesWithOptionsReturnsValidResult() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/search/role").addQueryParam("q", "name:webserver").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/search_role.json", MediaType.APPLICATION_JSON)) // - .build()); - SearchOptions options = SearchOptions.Builder.query("name:webserver"); - SearchResult<? extends Role> result = api.searchRoles(options); - assertEquals(result.size(), 1); - assertEquals(result.iterator().next().getName(), "webserver"); - } - - public void testSearchRolesWithOptionsReturnsEmptyResult() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/search/role").addQueryParam("q", "name:dummy").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/search_role_empty.json", MediaType.APPLICATION_JSON)) // - .build()); - SearchOptions options = SearchOptions.Builder.query("name:dummy"); - SearchResult<? extends Role> result = api.searchRoles(options); - assertTrue(result.isEmpty(), String.format("Expected search result to be empty but was: %s", result)); - } - - public void testListRolesReturnsValidSet() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/roles").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/roles_list.json", MediaType.APPLICATION_JSON)) // - .build()); - Set<String> roles = api.listRoles(); - assertEquals(roles.size(), 2); - assertTrue(roles.contains("webserver"), String.format("Expected roles to contain 'websever' but was: %s", roles)); - } - - public void testListRolesReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/roles").build()), - HttpResponse.builder().statusCode(404).build()); - Set<String> roles = api.listRoles(); - assertTrue(roles.isEmpty(), String.format("Expected roles to be empty but was: %s", roles)); - } - - public void testListDatabagsReturnsValidSet() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/data").build()), - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/data_list.json", MediaType.APPLICATION_JSON)) // - .build()); - Set<String> databags = api.listDatabags(); - assertEquals(databags.size(), 2); - assertTrue(databags.contains("applications"), String.format("Expected databags to contain 'applications' but was: %s", databags)); - } - - public void testListDatabagsReturnsEmptySetOn404() { - ChefApi api = requestSendsResponse( - signed(getHttpRequestBuilder("GET", "/data").build()), - HttpResponse.builder().statusCode(404).build()); - Set<String> databags = api.listDatabags(); - assertTrue(databags.isEmpty(), String.format("Expected databags to be empty but was: %s", databags)); - } - - @Override - protected Module createModule() { - return new TestChefHttpApiModule(); - } - - @ConfiguresHttpApi - static class TestChefHttpApiModule extends ChefHttpApiModule { - @Override - protected String provideTimeStamp(@TimeStamp Supplier<String> cache) { - return "timestamp"; - } - } - - @Override - protected ChefApiMetadata createApiMetadata() { - return new ChefApiMetadata(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/test/java/org/jclouds/chef/ChefApiLiveTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/ChefApiLiveTest.java b/core/src/test/java/org/jclouds/chef/ChefApiLiveTest.java deleted file mode 100644 index e4ad583..0000000 --- a/core/src/test/java/org/jclouds/chef/ChefApiLiveTest.java +++ /dev/null @@ -1,32 +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 org.jclouds.chef.internal.BaseChefApiLiveTest; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code ChefApi} against a Chef Server <= 0.9.8. - */ -@Test(groups = { "live" }) -public class ChefApiLiveTest extends BaseChefApiLiveTest<ChefApi> { - - protected ChefApiLiveTest() { - provider = "chef"; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/cffeede4/core/src/test/java/org/jclouds/chef/ChefApiMetadataTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/jclouds/chef/ChefApiMetadataTest.java b/core/src/test/java/org/jclouds/chef/ChefApiMetadataTest.java deleted file mode 100644 index a78c20a..0000000 --- a/core/src/test/java/org/jclouds/chef/ChefApiMetadataTest.java +++ /dev/null @@ -1,33 +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 org.jclouds.View; -import org.jclouds.rest.internal.BaseHttpApiMetadataTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; - -@Test(groups = "unit", testName = "ChefApiMetadataTest") -public class ChefApiMetadataTest extends BaseHttpApiMetadataTest { - - // no config management abstraction, yet - public ChefApiMetadataTest() { - super(new ChefApiMetadata(), ImmutableSet.<TypeToken<? extends View>> of()); - } -}
