EMMA Coverage Report (generated Fri Aug 26 14:14:05 EDT 2011)
[all classes][org.jclouds.byon.functions]

COVERAGE SUMMARY FOR SOURCE FILE [NodesFromYamlStream.java]

nameclass, %method, %block, %line, %
NodesFromYamlStream.java100% (3/3)100% (5/5)100% (84/84)100% (15/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NodesFromYamlStream100% (1/1)100% (2/2)100% (72/72)100% (14/14)
NodesFromYamlStream (): void 100% (1/1)100% (3/3)100% (2/2)
apply (InputStream): Map 100% (1/1)100% (69/69)100% (12/12)
     
class NodesFromYamlStream$1100% (1/1)100% (2/2)100% (9/9)100% (2/2)
NodesFromYamlStream$1 (NodesFromYamlStream): void 100% (1/1)100% (6/6)100% (1/1)
apply (Node): String 100% (1/1)100% (3/3)100% (1/1)
     
class NodesFromYamlStream$Config100% (1/1)100% (1/1)100% (3/3)100% (1/1)
NodesFromYamlStream$Config (): void 100% (1/1)100% (3/3)100% (1/1)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.byon.functions;
20 
21import static com.google.common.base.Preconditions.checkState;
22 
23import java.io.InputStream;
24import java.util.List;
25import java.util.Map;
26 
27import javax.inject.Singleton;
28 
29import org.jclouds.byon.Node;
30import org.jclouds.byon.domain.YamlNode;
31import org.yaml.snakeyaml.Loader;
32import org.yaml.snakeyaml.TypeDescription;
33import org.yaml.snakeyaml.Yaml;
34import org.yaml.snakeyaml.constructor.Constructor;
35 
36import com.google.common.base.Function;
37import com.google.common.collect.Iterables;
38import com.google.common.collect.Maps;
39 
40/**
41 * Parses the following syntax.
42 * 
43 * <pre>
44 * nodes:
45 *     - id: cluster-1:
46 *       name: cluster-1
47 *       description: xyz
48 *       hostname: cluster-1.mydomain.com
49 *       location_id: virginia
50 *       os_arch: x86
51 *       os_family: linux
52 *       os_description: redhat
53 *       os_version: 5.3
54 *       group: hadoop
55 *       tags:
56 *           - vanilla
57 *       username: kelvin
58 *       credential: password_or_rsa
59 *         or
60 *       credential_url: password_or_rsa_file ex. resource:///id_rsa will get the classpath /id_rsa; file://path/to/id_rsa
61 *       sudo_password: password
62 * </pre>
63 * 
64 * @author Kelvin Kakugawa
65 * @author Adrian Cole
66 */
67@Singleton
68public class NodesFromYamlStream implements Function<InputStream, Map<String, Node>> {
69 
70   /**
71    * Type-safe config class for YAML
72    * 
73    */
74   public static class Config {
75      public List<YamlNode> nodes;
76   }
77 
78   @Override
79   public Map<String, Node> apply(InputStream source) {
80 
81      Constructor constructor = new Constructor(Config.class);
82 
83      TypeDescription nodeDesc = new TypeDescription(YamlNode.class);
84      nodeDesc.putListPropertyType("tags", String.class);
85      constructor.addTypeDescription(nodeDesc);
86 
87      TypeDescription configDesc = new TypeDescription(Config.class);
88      configDesc.putListPropertyType("nodes", YamlNode.class);
89      constructor.addTypeDescription(configDesc);
90      // note that snakeyaml also throws nosuchmethod error when you use the non-deprecated
91      // constructor
92      Yaml yaml = new Yaml(new Loader(constructor));
93      Config config = (Config) yaml.load(source);
94      checkState(config != null, "missing config: class");
95      checkState(config.nodes != null, "missing nodes: collection");
96 
97      return Maps.uniqueIndex(Iterables.transform(config.nodes, YamlNode.toNode), new Function<Node, String>() {
98         public String apply(Node node) {
99            return node.getId();
100         }
101      });
102   }
103}

[all classes][org.jclouds.byon.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov