http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/predicates/CookbookVersionPredicates.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/predicates/CookbookVersionPredicates.java b/core/src/main/java/org/jclouds/chef/predicates/CookbookVersionPredicates.java deleted file mode 100644 index 7edbcae..0000000 --- a/core/src/main/java/org/jclouds/chef/predicates/CookbookVersionPredicates.java +++ /dev/null @@ -1,93 +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.predicates; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.any; -import static com.google.common.collect.Iterables.get; - -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.chef.domain.Resource; - -import com.google.common.base.Predicate; -import com.google.common.base.Splitter; -import com.google.common.collect.LinkedListMultimap; -import com.google.common.collect.Multimap; - -/** - * Container for cookbook filters (predicates). - * - * This class has static methods that create customized predicates to use with - * {@link org.jclouds.chef.ChefService}. - */ -public class CookbookVersionPredicates { - /** - * @see #containsRecipes - */ - public static Predicate<CookbookVersion> containsRecipe(String recipe) { - return containsRecipes(checkNotNull(recipe, "recipe must be defined")); - } - - /** - * Note that the default recipe of a cookbook is its name. Otherwise, you - * prefix the recipe with the name of the cookbook. ex. {@code apache2} will - * be the default recipe where {@code apache2::mod_proxy} is a specific one - * in the cookbook. - * - * @param recipes - * names of the recipes. - * @return true if the cookbook version contains a recipe in the list. - */ - public static Predicate<CookbookVersion> containsRecipes(String... recipes) { - checkNotNull(recipes, "recipes must be defined"); - final Multimap<String, String> search = LinkedListMultimap.create(); - for (String recipe : recipes) { - if (recipe.indexOf("::") != -1) { - Iterable<String> nameRecipe = Splitter.on("::").split(recipe); - search.put(get(nameRecipe, 0), get(nameRecipe, 1) + ".rb"); - } else { - search.put(recipe, "default.rb"); - } - } - return new Predicate<CookbookVersion>() { - @Override - public boolean apply(final CookbookVersion cookbookVersion) { - return search.containsKey(cookbookVersion.getCookbookName()) - && any(search.get(cookbookVersion.getCookbookName()), new Predicate<String>() { - - @Override - public boolean apply(final String recipeName) { - return any(cookbookVersion.getRecipes(), new Predicate<Resource>() { - - @Override - public boolean apply(Resource resource) { - return resource.getName().equals(recipeName); - } - - }); - } - - }); - } - - @Override - public String toString() { - return "containsRecipes(" + search + ")"; - } - }; - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/CleanupStaleNodesAndClients.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/CleanupStaleNodesAndClients.java b/core/src/main/java/org/jclouds/chef/strategy/CleanupStaleNodesAndClients.java deleted file mode 100644 index 8519450..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/CleanupStaleNodesAndClients.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.strategy; - -import org.jclouds.chef.strategy.internal.CleanupStaleNodesAndClientsImpl; - -import com.google.inject.ImplementedBy; - -/** - * - * Cleans up nodes and clients who have been hanging around too long. - */ -@ImplementedBy(CleanupStaleNodesAndClientsImpl.class) -public interface CleanupStaleNodesAndClients { - - void execute(String prefix, int secondsStale); - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/CreateNodeAndPopulateAutomaticAttributes.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/CreateNodeAndPopulateAutomaticAttributes.java b/core/src/main/java/org/jclouds/chef/strategy/CreateNodeAndPopulateAutomaticAttributes.java deleted file mode 100644 index 249be48..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/CreateNodeAndPopulateAutomaticAttributes.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.strategy; - -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.internal.CreateNodeAndPopulateAutomaticAttributesImpl; - -import com.google.inject.ImplementedBy; - -/** - * - * Creates a new node with automatic attributes. - */ -@ImplementedBy(CreateNodeAndPopulateAutomaticAttributesImpl.class) -public interface CreateNodeAndPopulateAutomaticAttributes { - Node execute(Node node); - - Node execute(String nodeName, Iterable<String> runList); -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/DeleteAllClientsInList.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/DeleteAllClientsInList.java b/core/src/main/java/org/jclouds/chef/strategy/DeleteAllClientsInList.java deleted file mode 100644 index 7dd7b89..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/DeleteAllClientsInList.java +++ /dev/null @@ -1,34 +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.strategy; - -import org.jclouds.chef.strategy.internal.DeleteAllClientsInListImpl; - -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.ImplementedBy; - -/** - * Deletes all clients in a given list. - */ -@ImplementedBy(DeleteAllClientsInListImpl.class) -public interface DeleteAllClientsInList { - - void execute(Iterable<String> names); - - void execute(ListeningExecutorService executor, Iterable<String> names); - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/DeleteAllNodesInList.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/DeleteAllNodesInList.java b/core/src/main/java/org/jclouds/chef/strategy/DeleteAllNodesInList.java deleted file mode 100644 index 8867e49..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/DeleteAllNodesInList.java +++ /dev/null @@ -1,31 +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.strategy; - -import org.jclouds.chef.strategy.internal.DeleteAllNodesInListImpl; - -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.ImplementedBy; - -@ImplementedBy(DeleteAllNodesInListImpl.class) -public interface DeleteAllNodesInList { - - void execute(Iterable<String> names); - - void execute(ListeningExecutorService executor, Iterable<String> names); - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/ListClients.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/ListClients.java b/core/src/main/java/org/jclouds/chef/strategy/ListClients.java deleted file mode 100644 index aa40c2a..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/ListClients.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.strategy; - -import com.google.inject.ImplementedBy; -import org.jclouds.chef.domain.Client; -import org.jclouds.chef.strategy.internal.ListClientsImpl; - -import java.util.concurrent.ExecutorService; - -@ImplementedBy(ListClientsImpl.class) -public interface ListClients { - - Iterable<? extends Client> execute(); - - Iterable<? extends Client> execute(ExecutorService executor); - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/ListCookbookVersions.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/ListCookbookVersions.java b/core/src/main/java/org/jclouds/chef/strategy/ListCookbookVersions.java deleted file mode 100644 index 45663a3..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/ListCookbookVersions.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.strategy; - -import com.google.inject.ImplementedBy; -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.chef.strategy.internal.ListCookbookVersionsImpl; - -import java.util.concurrent.ExecutorService; - -@ImplementedBy(ListCookbookVersionsImpl.class) -public interface ListCookbookVersions { - - Iterable<? extends CookbookVersion> execute(); - - Iterable<? extends CookbookVersion> execute(ExecutorService executor); - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/ListCookbookVersionsInEnvironment.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/ListCookbookVersionsInEnvironment.java b/core/src/main/java/org/jclouds/chef/strategy/ListCookbookVersionsInEnvironment.java deleted file mode 100644 index 188d29f..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/ListCookbookVersionsInEnvironment.java +++ /dev/null @@ -1,37 +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.strategy; - -import com.google.inject.ImplementedBy; -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.chef.strategy.internal.ListCookbookVersionsInEnvironmentImpl; - -import java.util.concurrent.ExecutorService; - -@ImplementedBy(ListCookbookVersionsInEnvironmentImpl.class) -public interface ListCookbookVersionsInEnvironment { - - Iterable<? extends CookbookVersion> execute(String environmentName); - - Iterable<? extends CookbookVersion> execute(String environmentName, String numVersions); - - Iterable<? extends CookbookVersion> execute(ExecutorService executor, String environmentName); - - Iterable<? extends CookbookVersion> execute(ExecutorService executor, String environmentName, String numVersions); - - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/ListEnvironments.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/ListEnvironments.java b/core/src/main/java/org/jclouds/chef/strategy/ListEnvironments.java deleted file mode 100644 index 553e8d4..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/ListEnvironments.java +++ /dev/null @@ -1,31 +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.strategy; - -import com.google.inject.ImplementedBy; -import org.jclouds.chef.domain.Environment; -import org.jclouds.chef.strategy.internal.ListEnvironmentsImpl; - -import java.util.concurrent.ExecutorService; - -@ImplementedBy(ListEnvironmentsImpl.class) -public interface ListEnvironments { - - Iterable<? extends Environment> execute(); - - Iterable<? extends Environment> execute(ExecutorService executor); -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/ListNodes.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/ListNodes.java b/core/src/main/java/org/jclouds/chef/strategy/ListNodes.java deleted file mode 100644 index 660eed0..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/ListNodes.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.strategy; - -import com.google.inject.ImplementedBy; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.internal.ListNodesImpl; - -import java.util.concurrent.ExecutorService; - -@ImplementedBy(ListNodesImpl.class) -public interface ListNodes { - - Iterable<? extends Node> execute(); - - Iterable<? extends Node> execute(ExecutorService executor); - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/ListNodesInEnvironment.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/ListNodesInEnvironment.java b/core/src/main/java/org/jclouds/chef/strategy/ListNodesInEnvironment.java deleted file mode 100644 index efeffe6..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/ListNodesInEnvironment.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.strategy; - -import com.google.inject.ImplementedBy; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.internal.ListNodesInEnvironmentImpl; - -import java.util.concurrent.ExecutorService; - -@ImplementedBy(ListNodesInEnvironmentImpl.class) -public interface ListNodesInEnvironment { - - Iterable<? extends Node> execute(String environmentName); - - Iterable<? extends Node> execute(ExecutorService executor, String environmentName); - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/UpdateAutomaticAttributesOnNode.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/UpdateAutomaticAttributesOnNode.java b/core/src/main/java/org/jclouds/chef/strategy/UpdateAutomaticAttributesOnNode.java deleted file mode 100644 index 0dcb81e..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/UpdateAutomaticAttributesOnNode.java +++ /dev/null @@ -1,31 +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.strategy; - -import org.jclouds.chef.strategy.internal.UpdateAutomaticAttributesOnNodeImpl; - -import com.google.inject.ImplementedBy; - -/** - * - * Updates node with new automatic attributes. - */ -@ImplementedBy(UpdateAutomaticAttributesOnNodeImpl.class) -public interface UpdateAutomaticAttributesOnNode { - - void execute(String nodeName); -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/BaseListCookbookVersionsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/BaseListCookbookVersionsImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/BaseListCookbookVersionsImpl.java deleted file mode 100644 index 94cf79a..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/BaseListCookbookVersionsImpl.java +++ /dev/null @@ -1,97 +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.strategy.internal; - -import com.google.common.base.Function; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.logging.Logger; - -import java.util.List; -import java.util.Set; -import java.util.concurrent.Callable; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; - -public abstract class BaseListCookbookVersionsImpl { - - protected final ChefApi api; - - protected Logger logger = Logger.NULL; - - BaseListCookbookVersionsImpl(ChefApi api) { - this.api = checkNotNull(api, "api"); - } - - protected Iterable<? extends CookbookVersion> execute(Iterable<String> toGet) { - return concat(transform(toGet, new Function<String, Iterable<? extends CookbookVersion>>() { - - @Override - public Iterable<? extends CookbookVersion> apply(final String cookbook) { - // TODO getting each version could also go parallel - Set<String> cookbookVersions = api.listVersionsOfCookbook(cookbook); - Iterable<? extends CookbookVersion> cookbooksVersions = transform(cookbookVersions, - new Function<String, CookbookVersion>() { - @Override - public CookbookVersion apply(final String version) { - return api.getCookbook(cookbook, version); - } - } - ); - - logger.trace(String.format("getting versions of cookbook: %s", cookbook)); - return cookbooksVersions; - } - })); - - } - - protected Iterable<? extends CookbookVersion> executeConcurrently(final ListeningExecutorService executor, - Iterable<String> cookbookNames) { - return concat(transform(cookbookNames, new Function<String, Iterable<? extends CookbookVersion>>() { - - @Override - public Iterable<? extends CookbookVersion> apply(final String cookbook) { - // TODO getting each version could also go parallel - Set<String> cookbookVersions = api.listVersionsOfCookbook(cookbook); - ListenableFuture<List<CookbookVersion>> futures = allAsList(transform(cookbookVersions, - new Function<String, ListenableFuture<CookbookVersion>>() { - @Override - public ListenableFuture<CookbookVersion> apply(final String version) { - return executor.submit(new Callable<CookbookVersion>() { - @Override - public CookbookVersion call() throws Exception { - return api.getCookbook(cookbook, version); - } - }); - } - } - )); - - logger.trace(String.format("getting versions of cookbook: %s", cookbook)); - return getUnchecked(futures); - } - })); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/BaseListNodesImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/BaseListNodesImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/BaseListNodesImpl.java deleted file mode 100644 index a426b8d..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/BaseListNodesImpl.java +++ /dev/null @@ -1,77 +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.strategy.internal; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.domain.Node; -import org.jclouds.logging.Logger; - -import java.util.List; -import java.util.concurrent.Callable; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; - -public abstract class BaseListNodesImpl { - - protected final ChefApi api; - - protected Logger logger = Logger.NULL; - - BaseListNodesImpl(ChefApi api) { - this.api = checkNotNull(api, "api"); - } - - protected Iterable<? extends Node> execute(Iterable<String> toGet) { - Iterable<? extends Node> nodes = transform(toGet, new Function<String, Node>() { - @Override - public Node apply(final String input) { - return api.getNode(input); - } - } - ); - - logger.trace(String.format("getting nodes: %s", Joiner.on(',').join(toGet))); - return nodes; - - } - - protected Iterable<? extends Node> executeConcurrently(final ListeningExecutorService executor, - Iterable<String> toGet) { - ListenableFuture<List<Node>> futures = allAsList(transform(toGet, new Function<String, ListenableFuture<Node>>() { - @Override - public ListenableFuture<Node> apply(final String input) { - return executor.submit(new Callable<Node>() { - @Override - public Node call() throws Exception { - return api.getNode(input); - } - }); - } - })); - - logger.trace(String.format("getting nodes: %s", Joiner.on(',').join(toGet))); - return getUnchecked(futures); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/CleanupStaleNodesAndClientsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/CleanupStaleNodesAndClientsImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/CleanupStaleNodesAndClientsImpl.java deleted file mode 100644 index 46c765b..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/CleanupStaleNodesAndClientsImpl.java +++ /dev/null @@ -1,102 +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.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Predicates.and; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static org.jclouds.chef.util.ChefUtils.fromOhaiTime; - -import java.util.Calendar; -import java.util.Date; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.CleanupStaleNodesAndClients; -import org.jclouds.chef.strategy.DeleteAllClientsInList; -import org.jclouds.chef.strategy.DeleteAllNodesInList; -import org.jclouds.chef.strategy.ListNodes; -import org.jclouds.domain.JsonBall; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Predicate; - -/** - * - * Cleans up nodes and apis who have been hanging around too long. - */ -@Singleton -public class CleanupStaleNodesAndClientsImpl implements CleanupStaleNodesAndClients { - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - private final ListNodes nodeLister; - private final DeleteAllNodesInList nodeDeleter; - private final DeleteAllClientsInList clientDeleter; - - @Inject - public CleanupStaleNodesAndClientsImpl(DeleteAllNodesInList nodeDeleter, DeleteAllClientsInList clientDeleter, - ListNodes nodeLister) { - this.nodeLister = checkNotNull(nodeLister, "nodeLister"); - this.nodeDeleter = checkNotNull(nodeDeleter, "nodeDeleter"); - this.clientDeleter = checkNotNull(clientDeleter, "clientDeleter"); - } - - @Override - public void execute(final String prefix, int secondsStale) { - final Calendar expired = Calendar.getInstance(); - expired.setTime(new Date()); - expired.add(Calendar.SECOND, -secondsStale); - Iterable<? extends Node> staleNodes = filter( - nodeLister.execute(), and(notNull(), new Predicate<Node>() { - @Override - public boolean apply(Node input) { - return input.getName().startsWith(prefix); - } - }, - new Predicate<Node>() { - @Override - public boolean apply(Node input) { - JsonBall dateLong = input.getAutomaticAttributes().get("ohai_time"); - if (dateLong == null) - return true; - Calendar nodeUpdate = Calendar.getInstance(); - nodeUpdate.setTime(fromOhaiTime(dateLong)); - return expired.after(nodeUpdate); - } - })); - Iterable<String> nodeNames = transform(staleNodes, new Function<Node, String>() { - - @Override - public String apply(Node from) { - return from.getName(); - } - - }); - nodeDeleter.execute(nodeNames); - clientDeleter.execute(nodeNames); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/CreateNodeAndPopulateAutomaticAttributesImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/CreateNodeAndPopulateAutomaticAttributesImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/CreateNodeAndPopulateAutomaticAttributesImpl.java deleted file mode 100644 index 7dabd06..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/CreateNodeAndPopulateAutomaticAttributesImpl.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.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.CreateNodeAndPopulateAutomaticAttributes; -import org.jclouds.domain.JsonBall; -import org.jclouds.logging.Logger; -import org.jclouds.ohai.Automatic; - -import com.google.common.base.Supplier; - -/** - * - * Updates node with new automatic attributes. - */ -@Singleton -public class CreateNodeAndPopulateAutomaticAttributesImpl implements CreateNodeAndPopulateAutomaticAttributes { - - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - private final ChefApi chef; - private final Supplier<Map<String, JsonBall>> automaticSupplier; - - @Inject - public CreateNodeAndPopulateAutomaticAttributesImpl(ChefApi chef, - @Automatic Supplier<Map<String, JsonBall>> automaticSupplier) { - this.chef = checkNotNull(chef, "chef"); - this.automaticSupplier = checkNotNull(automaticSupplier, "automaticSupplier"); - } - - @Override - public Node execute(Node node) { - logger.trace("creating node %s", node.getName()); - Node withAutomatic = Node.builder() // - .name(node.getName()) // - .normalAttributes(node.getNormalAttributes()) // - .overrideAttributes(node.getOverrideAttributes()) // - .defaultAttributes(node.getDefaultAttributes()) // - .automaticAttributes(node.getAutomaticAttributes()) // - .automaticAttributes(automaticSupplier.get()) // - .runList(node.getRunList()) // - .environment(node.getEnvironment()) // - .build(); - - - chef.createNode(withAutomatic); - logger.debug("created node %s", withAutomatic.getName()); - return node; - } - - @Override - public Node execute(String nodeName, Iterable<String> runList) { - return execute(Node.builder().name(nodeName).runList(runList).environment("_default").build()); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/DeleteAllClientsInListImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/DeleteAllClientsInListImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/DeleteAllClientsInListImpl.java deleted file mode 100644 index ffdd3ec..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/DeleteAllClientsInListImpl.java +++ /dev/null @@ -1,85 +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.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Client; -import org.jclouds.chef.strategy.DeleteAllClientsInList; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.Inject; - -/** - * Concurrently delete all given clients. - */ -@Singleton -public class DeleteAllClientsInListImpl implements DeleteAllClientsInList { - - protected final ChefApi api; - protected final ListeningExecutorService userExecutor; - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - DeleteAllClientsInListImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ChefApi api) { - this.userExecutor = checkNotNull(userExecutor, "userExecuor"); - this.api = checkNotNull(api, "api"); - } - - @Override - public void execute(Iterable<String> names) { - execute(userExecutor, names); - } - - @Override - public void execute(final ListeningExecutorService executor, Iterable<String> names) { - ListenableFuture<List<Client>> futures = allAsList(transform(names, - new Function<String, ListenableFuture<Client>>() { - @Override - public ListenableFuture<Client> apply(final String input) { - return executor.submit(new Callable<Client>() { - @Override - public Client call() throws Exception { - return api.deleteClient(input); - } - }); - } - })); - - logger.trace(String.format("deleting clients: %s", Joiner.on(',').join(names))); - getUnchecked(futures); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/DeleteAllNodesInListImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/DeleteAllNodesInListImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/DeleteAllNodesInListImpl.java deleted file mode 100644 index 212d8b7..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/DeleteAllNodesInListImpl.java +++ /dev/null @@ -1,81 +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.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.DeleteAllNodesInList; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.Inject; - -@Singleton -public class DeleteAllNodesInListImpl implements DeleteAllNodesInList { - - protected final ChefApi api; - protected final ListeningExecutorService userExecutor; - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - DeleteAllNodesInListImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ChefApi api) { - this.userExecutor = checkNotNull(userExecutor, "userExecuor"); - this.api = checkNotNull(api, "api"); - } - - @Override - public void execute(Iterable<String> names) { - execute(userExecutor, names); - } - - @Override - public void execute(final ListeningExecutorService executor, Iterable<String> names) { - ListenableFuture<List<Node>> futures = allAsList(transform(names, new Function<String, ListenableFuture<Node>>() { - @Override - public ListenableFuture<Node> apply(final String input) { - return executor.submit(new Callable<Node>() { - @Override - public Node call() throws Exception { - return api.deleteNode(input); - } - }); - } - })); - - logger.trace(String.format("deleting nodes: %s", Joiner.on(',').join(names))); - getUnchecked(futures); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/ListClientsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/ListClientsImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/ListClientsImpl.java deleted file mode 100644 index 105be2f..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/ListClientsImpl.java +++ /dev/null @@ -1,109 +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.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.inject.Inject; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Client; -import org.jclouds.chef.strategy.ListClients; -import org.jclouds.logging.Logger; - -import java.util.concurrent.ExecutorService; - - -@Singleton -public class ListClientsImpl implements ListClients { - - protected final ChefApi api; - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - ListClientsImpl(ChefApi api) { - this.api = checkNotNull(api, "api"); - } - - @Override - public Iterable<? extends Client> execute() { - - Iterable<String> toGet = api.listClients(); - Iterable<? extends Client> clients = transform(toGet, - new Function<String, Client>() { - @Override - public Client apply(final String input) { - - return api.getClient(input); - } - - } - ); - - logger.trace(String.format("getting clients: %s", Joiner.on(',').join(toGet))); - return clients; - - } - - @Override - public Iterable<? extends Client> execute(ExecutorService executorService) { - return this.execute(MoreExecutors.listeningDecorator(executorService)); - } - - - private Iterable<? extends Client> execute(ListeningExecutorService listeningExecutor) { - return executeConcurrently(listeningExecutor, api.listClients()); - } - - private Iterable<? extends Client> executeConcurrently(final ListeningExecutorService executor, - Iterable<String> toGet) { - ListenableFuture<List<Client>> futures = allAsList(transform(toGet, - new Function<String, ListenableFuture<Client>>() { - @Override - public ListenableFuture<Client> apply(final String input) { - return executor.submit(new Callable<Client>() { - @Override - public Client call() throws Exception { - return api.getClient(input); - } - }); - } - } - )); - - logger.trace(String.format("getting clients: %s", Joiner.on(',').join(toGet))); - return getUnchecked(futures); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/ListCookbookVersionsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/ListCookbookVersionsImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/ListCookbookVersionsImpl.java deleted file mode 100644 index d109038..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/ListCookbookVersionsImpl.java +++ /dev/null @@ -1,60 +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.strategy.internal; - -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.inject.Inject; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.chef.strategy.ListCookbookVersions; -import org.jclouds.logging.Logger; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; -import java.util.concurrent.ExecutorService; - -@Singleton -public class ListCookbookVersionsImpl extends BaseListCookbookVersionsImpl implements ListCookbookVersions { - - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - ListCookbookVersionsImpl(ChefApi api) { - super(api); - } - - @Override - public Iterable<? extends CookbookVersion> execute() { - return super.execute(api.listCookbooks()); - } - - @Override - public Iterable<? extends CookbookVersion> execute(ExecutorService executor) { - return this.executeConcurrently(MoreExecutors.listeningDecorator(executor)); - } - - - private Iterable<? extends CookbookVersion> executeConcurrently(ListeningExecutorService executor) { - return super.executeConcurrently(executor, api.listCookbooks()); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/ListCookbookVersionsInEnvironmentImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/ListCookbookVersionsInEnvironmentImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/ListCookbookVersionsInEnvironmentImpl.java deleted file mode 100644 index a7142dc..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/ListCookbookVersionsInEnvironmentImpl.java +++ /dev/null @@ -1,117 +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.strategy.internal; - -import static com.google.common.collect.Iterables.transform; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import com.google.common.base.Function; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.inject.Inject; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.CookbookDefinition; -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.chef.strategy.ListCookbookVersionsInEnvironment; -import org.jclouds.logging.Logger; - -import java.util.concurrent.ExecutorService; - -@Singleton -public class ListCookbookVersionsInEnvironmentImpl extends BaseListCookbookVersionsImpl - implements ListCookbookVersionsInEnvironment { - - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - ListCookbookVersionsInEnvironmentImpl(ChefApi api) { - super(api); - } - - @Override - public Iterable<? extends CookbookVersion> execute(String environmentName) { - return super.execute(transform(api.listCookbooksInEnvironment(environmentName), - new Function<CookbookDefinition, String>() { - - @Override - public String apply(CookbookDefinition cookbookDefinition) { - return cookbookDefinition.getName(); - } - } - )); - } - - @Override - public Iterable<? extends CookbookVersion> execute(String environmentName, String numVersions) { - return super.execute(transform(api.listCookbooksInEnvironment(environmentName, numVersions), - new Function<CookbookDefinition, String>() { - - @Override - public String apply(CookbookDefinition cookbookDefinition) { - return cookbookDefinition.getName(); - } - } - )); - } - - @Override - public Iterable<? extends CookbookVersion> execute(ExecutorService executor, - String environmentName) { - return this.executeConcurrently(MoreExecutors.listeningDecorator(executor), environmentName); - } - - @Override - public Iterable<? extends CookbookVersion> execute(ExecutorService executor, - String environmentName, String numVersions) { - return this.executeConcurrently(MoreExecutors.listeningDecorator(executor), environmentName, numVersions); - } - - - private Iterable<? extends CookbookVersion> executeConcurrently(ListeningExecutorService executor, - String environmentName) { - return super.execute( - transform(api.listCookbooksInEnvironment(environmentName), new Function<CookbookDefinition, String>() { - - @Override - public String apply(CookbookDefinition cookbookDefinition) { - return cookbookDefinition.getName(); - } - }) - ); - } - - - private Iterable<? extends CookbookVersion> executeConcurrently(ListeningExecutorService executor, - String environmentName, String numVersions) { - return super.execute(transform(api.listCookbooksInEnvironment(environmentName, numVersions), - new Function<CookbookDefinition, String>() { - - @Override - public String apply(CookbookDefinition cookbookDefinition) { - return cookbookDefinition.getName(); - } - } - )); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/ListEnvironmentsImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/ListEnvironmentsImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/ListEnvironmentsImpl.java deleted file mode 100644 index 0ed792e..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/ListEnvironmentsImpl.java +++ /dev/null @@ -1,96 +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.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.util.concurrent.Futures.allAsList; -import static com.google.common.util.concurrent.Futures.getUnchecked; - -import java.util.List; -import java.util.concurrent.Callable; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Constants; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Environment; -import org.jclouds.chef.strategy.ListEnvironments; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.inject.Inject; -import com.google.common.util.concurrent.MoreExecutors; - - -import java.util.concurrent.ExecutorService; - - - -@Singleton -public class ListEnvironmentsImpl implements ListEnvironments { - - protected final ChefApi api; - protected final ListeningExecutorService userExecutor; - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - ListEnvironmentsImpl(@Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor, ChefApi api) { - this.userExecutor = checkNotNull(userExecutor, "userExecuor"); - this.api = checkNotNull(api, "api"); - } - - @Override - public Iterable<? extends Environment> execute() { - return execute(userExecutor); - } - - @Override - public Iterable<? extends Environment> execute(ExecutorService executor) { - return this.execute(MoreExecutors.listeningDecorator(executor)); - } - - private Iterable<? extends Environment> execute(ListeningExecutorService executor) { - return execute(executor, api.listEnvironments()); - } - - private Iterable<? extends Environment> execute(final ListeningExecutorService executor, Iterable<String> toGet) { - ListenableFuture<List<Environment>> futures = allAsList(transform(toGet, - new Function<String, ListenableFuture<Environment>>() { - @Override - public ListenableFuture<Environment> apply(final String input) { - return executor.submit(new Callable<Environment>() { - @Override - public Environment call() throws Exception { - return api.getEnvironment(input); - } - }); - } - })); - - logger.trace(String.format("deleting environments: %s", Joiner.on(',').join(toGet))); - return getUnchecked(futures); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesImpl.java deleted file mode 100644 index 8d95965..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.chef.strategy.internal; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.inject.Inject; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.ListNodes; -import org.jclouds.logging.Logger; - -import java.util.concurrent.ExecutorService; - -@Singleton -public class ListNodesImpl extends BaseListNodesImpl implements ListNodes { - - - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - ListNodesImpl(ChefApi api) { - super(api); - } - - @Override - public Iterable<? extends Node> execute() { - return super.execute(api.listNodes()); - } - - @Override - public Iterable<? extends Node> execute(ExecutorService executor) { - return this.executeConcurrently(MoreExecutors.listeningDecorator(executor)); - } - - - private Iterable<? extends Node> executeConcurrently(ListeningExecutorService executor) { - return super.executeConcurrently(executor, api.listNodes()); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImpl.java deleted file mode 100644 index 58ecaaa..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/ListNodesInEnvironmentImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.chef.strategy.internal; - -import javax.annotation.Resource; -import javax.inject.Named; -import javax.inject.Singleton; - -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.inject.Inject; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.ListNodesInEnvironment; -import org.jclouds.logging.Logger; - -import java.util.concurrent.ExecutorService; - -@Singleton -public class ListNodesInEnvironmentImpl extends BaseListNodesImpl implements ListNodesInEnvironment { - - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - @Inject - ListNodesInEnvironmentImpl(ChefApi api) { - super(api); - } - - @Override - public Iterable<? extends Node> execute(String environmentName) { - return super.execute(api.listNodesInEnvironment(environmentName)); - } - - @Override - public Iterable<? extends Node> execute(ExecutorService executor, String environmentName) { - return this.executeConcurrently(MoreExecutors.listeningDecorator(executor), environmentName); - } - - - private Iterable<? extends Node> executeConcurrently(ListeningExecutorService executor, - String environmentName) { - return super.executeConcurrently(executor, api.listNodesInEnvironment(environmentName)); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/strategy/internal/UpdateAutomaticAttributesOnNodeImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/strategy/internal/UpdateAutomaticAttributesOnNodeImpl.java b/core/src/main/java/org/jclouds/chef/strategy/internal/UpdateAutomaticAttributesOnNodeImpl.java deleted file mode 100644 index a6dcac2..0000000 --- a/core/src/main/java/org/jclouds/chef/strategy/internal/UpdateAutomaticAttributesOnNodeImpl.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.strategy.internal; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.strategy.UpdateAutomaticAttributesOnNode; -import org.jclouds.domain.JsonBall; -import org.jclouds.logging.Logger; -import org.jclouds.ohai.Automatic; - -import com.google.common.base.Supplier; - -/** - * - * Updates node with new automatic attributes. - */ -@Singleton -public class UpdateAutomaticAttributesOnNodeImpl implements UpdateAutomaticAttributesOnNode { - - @Resource - @Named(ChefProperties.CHEF_LOGGER) - protected Logger logger = Logger.NULL; - - private final ChefApi chef; - private final Supplier<Map<String, JsonBall>> automaticSupplier; - - @Inject - public UpdateAutomaticAttributesOnNodeImpl(ChefApi chef, @Automatic Supplier<Map<String, JsonBall>> automaticSupplier) { - this.chef = checkNotNull(chef, "chef"); - this.automaticSupplier = checkNotNull(automaticSupplier, "automaticSupplier"); - } - - @Override - public void execute(String nodeName) { - logger.trace("updating node %s", nodeName); - Node node = chef.getNode(nodeName); - Node updated = Node.builder() // - .name(node.getName()) // - .normalAttributes(node.getNormalAttributes()) // - .overrideAttributes(node.getOverrideAttributes()) // - .defaultAttributes(node.getDefaultAttributes()) // - .automaticAttributes(automaticSupplier.get()) // - .runList(node.getRunList()) // - .environment(node.getEnvironment()) // - .build(); - - chef.updateNode(updated); - logger.debug("updated node %s", nodeName); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/suppliers/ChefVersionSupplier.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/suppliers/ChefVersionSupplier.java b/core/src/main/java/org/jclouds/chef/suppliers/ChefVersionSupplier.java deleted file mode 100644 index a0d8b04..0000000 --- a/core/src/main/java/org/jclouds/chef/suppliers/ChefVersionSupplier.java +++ /dev/null @@ -1,73 +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.suppliers; - -import static com.google.common.base.Objects.firstNonNull; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.chef.config.ChefProperties; -import org.jclouds.logging.Logger; -import org.jclouds.rest.annotations.ApiVersion; - -import com.google.common.base.Supplier; - -/** - * Properly supply the version of the Chef Server. - */ -@Singleton -public class ChefVersionSupplier implements Supplier<Integer> { - - /** The default version to assume in case we can not parse it. */ - public static final Integer FALLBACK_VERSION = 10; - - @Resource - @Named(ChefProperties.CHEF_LOGGER) - private Logger logger = Logger.NULL; - - /** The configured version of the Chef Server API. */ - private final String apiVersion; - - @Inject - ChefVersionSupplier(@ApiVersion String apiVersion) { - this.apiVersion = checkNotNull(apiVersion, "apiVersion must not be null"); - } - - @Override - public Integer get() { - // Old versions of Chef have versions like 0.9.x, 0.10.x, but newer - // versions are in the format 10.x.y, 11.x.y - Pattern versionPattern = Pattern.compile("(?:0\\.(\\d+)|(\\d+)\\.\\d+)(?:\\.\\d)*"); - - Matcher m = versionPattern.matcher(apiVersion); - if (!m.matches()) { - logger.warn("Configured version does not match the standard version pattern. Assuming version %s", - FALLBACK_VERSION); - return FALLBACK_VERSION; - } - - return Integer.valueOf(firstNonNull(m.group(1), m.group(2))); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-chef/blob/fc6ad4fc/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java b/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java deleted file mode 100644 index c2c5f10..0000000 --- a/core/src/main/java/org/jclouds/chef/test/TransientChefApi.java +++ /dev/null @@ -1,387 +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 static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Throwables.propagate; -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Sets.newLinkedHashSet; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.List; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.blobstore.config.LocalBlobStore; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.blobstore.domain.PageSet; -import org.jclouds.blobstore.domain.StorageMetadata; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.domain.Client; -import org.jclouds.chef.domain.CookbookDefinition; -import org.jclouds.chef.domain.CookbookVersion; -import org.jclouds.chef.domain.DatabagItem; -import org.jclouds.chef.domain.Environment; -import org.jclouds.chef.domain.Node; -import org.jclouds.chef.domain.Resource; -import org.jclouds.chef.domain.Role; -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.chef.options.SearchOptions; -import org.jclouds.io.Payload; -import org.jclouds.lifecycle.Closer; -import org.jclouds.util.Strings2; - -import com.google.common.base.Function; - -/** - * In-memory chef simulator. - */ -public class TransientChefApi implements ChefApi { - @Singleton - private static class StorageMetadataToName implements Function<PageSet<? extends StorageMetadata>, Set<String>> { - @Override - public Set<String> apply(PageSet<? extends StorageMetadata> from) { - return newLinkedHashSet(transform(from, new Function<StorageMetadata, String>() { - - @Override - public String apply(StorageMetadata from) { - return from.getName(); - } - })); - } - } - - @Singleton - private static class BlobToDatabagItem implements Function<Blob, DatabagItem> { - @Override - public DatabagItem apply(Blob from) { - try { - return from == null ? null : new DatabagItem(from.getMetadata().getName(), Strings2.toStringAndClose(from - .getPayload().getInput())); - } catch (IOException e) { - propagate(e); - return null; - } - } - } - - private final LocalBlobStore databags; - private final BlobToDatabagItem blobToDatabagItem; - private final StorageMetadataToName storageMetadataToName; - private final Closer closer; - - @Inject - TransientChefApi(@Named("databags") LocalBlobStore databags, StorageMetadataToName storageMetadataToName, - BlobToDatabagItem blobToDatabagItem, Closer closer) { - this.databags = checkNotNull(databags, "databags"); - this.storageMetadataToName = checkNotNull(storageMetadataToName, "storageMetadataToName"); - this.blobToDatabagItem = checkNotNull(blobToDatabagItem, "blobToDatabagItem"); - this.closer = checkNotNull(closer, "closer"); - } - - @Override - public Sandbox commitSandbox(String id, boolean isCompleted) { - throw new UnsupportedOperationException(); - } - - @Override - public Client createClient(String clientName) { - throw new UnsupportedOperationException(); - } - - @Override - public Client createClient(String clientName, CreateClientOptions options) { - throw new UnsupportedOperationException(); - } - - @Override - public void createDatabag(String databagName) { - databags.createContainerInLocation(null, databagName); - } - - @Override - public DatabagItem createDatabagItem(String databagName, DatabagItem databagItem) { - Blob blob = databags.blobBuilder(databagItem.getId()).payload(databagItem.toString()).build(); - databags.putBlob(databagName, blob); - return databagItem; - } - - @Override - public void createNode(Node node) { - throw new UnsupportedOperationException(); - } - - @Override - public void createRole(Role role) { - throw new UnsupportedOperationException(); - } - - @Override - public Client deleteClient(String clientName) { - throw new UnsupportedOperationException(); - } - - @Override - public CookbookVersion deleteCookbook(String cookbookName, String version) { - throw new UnsupportedOperationException(); - } - - @Override - public void deleteDatabag(String databagName) { - databags.deleteContainer(databagName); - } - - @Override - public DatabagItem deleteDatabagItem(String databagName, String databagItemId) { - DatabagItem item = blobToDatabagItem.apply(databags.getBlob(databagName, databagItemId)); - databags.removeBlob(databagName, databagItemId); - return item; - } - - @Override - public Node deleteNode(String nodeName) { - throw new UnsupportedOperationException(); - } - - @Override - public Role deleteRole(String rolename) { - throw new UnsupportedOperationException(); - } - - @Override - public Client generateKeyForClient(String clientName) { - throw new UnsupportedOperationException(); - } - - @Override - public Client getClient(String clientName) { - throw new UnsupportedOperationException(); - } - - @Override - public CookbookVersion getCookbook(String cookbookName, String version) { - throw new UnsupportedOperationException(); - } - - @Override - public DatabagItem getDatabagItem(String databagName, String databagItemId) { - return blobToDatabagItem.apply(databags.getBlob(databagName, databagItemId)); - } - - @Override - public Node getNode(String nodeName) { - throw new UnsupportedOperationException(); - } - - @Override - public Role getRole(String roleName) { - throw new UnsupportedOperationException(); - } - - @Override - public UploadSandbox createUploadSandboxForChecksums(Set<List<Byte>> md5s) { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listVersionsOfCookbook(String cookbookName) { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listClients() { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listCookbooks() { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listDatabagItems(String databagName) { - return storageMetadataToName.apply(databags.list(databagName)); - } - - @Override - public Set<String> listDatabags() { - return storageMetadataToName.apply(databags.list()); - } - - @Override - public Set<String> listNodes() { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listRoles() { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listSearchIndexes() { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends Client> searchClients() { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends Client> searchClients(SearchOptions options) { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends DatabagItem> searchDatabagItems(String databagName) { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends DatabagItem> searchDatabagItems(String databagName, SearchOptions options) { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends Node> searchNodes() { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends Node> searchNodes(SearchOptions options) { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends Role> searchRoles() { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends Role> searchRoles(SearchOptions options) { - throw new UnsupportedOperationException(); - } - - @Override - public CookbookVersion updateCookbook(String cookbookName, String version, CookbookVersion cookbook) { - throw new UnsupportedOperationException(); - } - - @Override - public DatabagItem updateDatabagItem(String databagName, DatabagItem item) { - return createDatabagItem(databagName, item); - } - - @Override - public Node updateNode(Node node) { - throw new UnsupportedOperationException(); - } - - @Override - public Role updateRole(Role role) { - throw new UnsupportedOperationException(); - } - - @Override - public void uploadContent(URI location, Payload content) { - throw new UnsupportedOperationException(); - } - - @Override - public InputStream getResourceContents(Resource resource) { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listEnvironments() { - throw new UnsupportedOperationException(); - } - - @Override - public void createEnvironment(Environment environment) { - throw new UnsupportedOperationException(); - } - - @Override - public Environment deleteEnvironment(String environmentName) { - throw new UnsupportedOperationException(); - } - - @Override - public Environment getEnvironment(String environmentName) { - throw new UnsupportedOperationException(); - } - - @Override - public Environment updateEnvironment(Environment environment) { - throw new UnsupportedOperationException(); - } - - @Override - public Set<CookbookDefinition> listCookbooksInEnvironment(String environmentName) { - throw new UnsupportedOperationException(); - } - - @Override - public Set<CookbookDefinition> listCookbooksInEnvironment(String environmentName, String numVersions) { - throw new UnsupportedOperationException(); - } - - @Override - public CookbookDefinition getCookbookInEnvironment(String environmentName, String cookbookName) { - throw new UnsupportedOperationException(); - } - - @Override - public CookbookDefinition getCookbookInEnvironment(String environmentName, String cookbookName, String numVersions) { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends Environment> searchEnvironments() { - throw new UnsupportedOperationException(); - } - - @Override - public SearchResult<? extends Environment> searchEnvironments(SearchOptions options) { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listRecipesInEnvironment(String environmentName) { - throw new UnsupportedOperationException(); - } - - @Override - public Set<String> listNodesInEnvironment(String environmentName) { - throw new UnsupportedOperationException(); - } - - @Override - public void close() throws IOException { - closer.close(); - } -}
