From 7d1e4ff51468dd20af7fafd8926b663bdaf1a31f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 25 Jul 2010 20:25:48 -0700 Subject: [PATCH] issue 191 --- .../java/org/jclouds/ohai/CreateNode.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 chef/src/main/java/org/jclouds/ohai/CreateNode.java diff --git a/chef/src/main/java/org/jclouds/ohai/CreateNode.java b/chef/src/main/java/org/jclouds/ohai/CreateNode.java new file mode 100644 index 0000000000..dcb1b24b2f --- /dev/null +++ b/chef/src/main/java/org/jclouds/ohai/CreateNode.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.chef.ChefClient; +import org.jclouds.chef.domain.Node; +import org.jclouds.domain.JsonBall; +import org.jclouds.logging.Logger; + +import com.google.common.base.Supplier; + +/** + * + * Updates node with new automatic attributes. + * + * @author Adrian Cole + */ +@Singleton +public class CreateNode { + + @Resource + protected Logger logger = Logger.NULL; + + private final ChefClient chef; + private final Supplier> automaticSupplier; + + @Inject + public CreateNode(ChefClient chef, @Named("automatic") Supplier> automaticSupplier) { + this.chef = checkNotNull(chef, "chef"); + this.automaticSupplier = checkNotNull(automaticSupplier, "automaticSupplier"); + } + + public Node createNode(String nodeName, Iterable runList) { + logger.info("creating node %s", nodeName); + Node node = new Node(nodeName, runList); + node.getAutomatic().putAll(automaticSupplier.get()); + node = chef.createNode(node); + logger.debug("done creating node %s", nodeName); + return node; + } +} \ No newline at end of file