EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.byon.domain]

COVERAGE SUMMARY FOR SOURCE FILE [YamlNode.java]

nameclass, %method, %block, %line, %
YamlNode.java100% (5/5)71%  (10/14)69%  (270/392)70%  (52.7/75)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class YamlNode$3100% (1/1)100% (2/2)49%  (84/171)62%  (24/39)
apply (YamlNode): InputStream 100% (1/1)48%  (81/168)61%  (23/38)
YamlNode$3 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class YamlNode100% (1/1)33%  (2/6)53%  (23/43)60%  (6/10)
fromNode (Node): YamlNode 0%   (0/1)0%   (0/5)0%   (0/1)
fromYaml (InputStream): YamlNode 0%   (0/1)0%   (0/5)0%   (0/1)
toNode (): Node 0%   (0/1)0%   (0/5)0%   (0/1)
toYaml (): InputStream 0%   (0/1)0%   (0/5)0%   (0/1)
<static initializer> 100% (1/1)100% (17/17)100% (4/4)
YamlNode (): void 100% (1/1)100% (6/6)100% (2/2)
     
class YamlNode$2100% (1/1)100% (2/2)77%  (23/30)76%  (3.8/5)
apply (InputStream): YamlNode 100% (1/1)74%  (20/27)70%  (2.8/4)
YamlNode$2 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class YamlNode$4100% (1/1)100% (2/2)93%  (78/84)95%  (19.9/21)
apply (Node): YamlNode 100% (1/1)93%  (75/81)95%  (18.9/20)
YamlNode$4 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class YamlNode$1100% (1/1)100% (2/2)97%  (62/64)75%  (3/4)
apply (YamlNode): Node 100% (1/1)97%  (59/61)67%  (2/3)
YamlNode$1 (): 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.domain;
20 
21import java.io.InputStream;
22import java.net.URI;
23import java.util.List;
24 
25import org.jclouds.byon.Node;
26import org.jclouds.util.Strings2;
27import org.yaml.snakeyaml.DumperOptions;
28import org.yaml.snakeyaml.Loader;
29import org.yaml.snakeyaml.Yaml;
30import org.yaml.snakeyaml.constructor.Constructor;
31 
32import com.google.common.base.Function;
33import com.google.common.collect.ImmutableList;
34import com.google.common.collect.ImmutableMap;
35import com.google.common.collect.Lists;
36import com.google.common.collect.ImmutableMap.Builder;
37import com.google.common.io.Closeables;
38 
39/**
40 * Serializes to the following
41 * 
42 * <pre>
43 *       id: cluster-1
44 *       name: cluster-1
45 *       description: xyz
46 *       hostname: cluster-1.mydomain.com
47 *       location_id: virginia
48 *       os_arch: x86
49 *       os_family: linux
50 *       os_description: redhat
51 *       os_version: 5.3
52 *       os_64bit: 5.3
53 *       group: hadoop
54 *       tags:
55 *           - vanilla
56 *       username: kelvin
57 *       credential: password_or_rsa
58 *         or
59 *       credential_url: password_or_rsa_file ex. resource:///id_rsa will get the classpath /id_rsa; file://path/to/id_rsa
60 *       sudo_password: password
61 * </pre>
62 * 
63 * @author Kelvin Kakugawa
64 * @author Adrian Cole
65 */
66public class YamlNode {
67   public String id;
68   public String name;
69   public String description;
70   public String hostname;
71   public String location_id;
72   public String os_arch;
73   public String os_family;
74   public String os_description;
75   public String os_version;
76   public boolean os_64bit;
77   public String group;
78   public List<String> tags = Lists.newArrayList();
79   public String username;
80   public String credential;
81   public String credential_url;
82   public String sudo_password;
83 
84   public static Function<YamlNode, Node> toNode = new Function<YamlNode, Node>() {
85      @Override
86      public Node apply(YamlNode arg0) {
87         if (arg0 == null)
88            return null;
89         return Node.builder().id(arg0.id).name(arg0.name).description(arg0.description).locationId(arg0.location_id)
90                  .hostname(arg0.hostname).osArch(arg0.os_arch).osFamily(arg0.os_family).osDescription(
91                           arg0.os_description).osVersion(arg0.os_version).os64Bit(arg0.os_64bit).group(arg0.group)
92                  .tags(arg0.tags).username(arg0.username).credential(arg0.credential).credentialUrl(
93                           arg0.credential_url != null ? URI.create(arg0.credential_url) : null).sudoPassword(
94                           arg0.sudo_password).build();
95      }
96   };
97 
98   public Node toNode() {
99      return toNode.apply(this);
100   }
101 
102   public static Function<InputStream, YamlNode> inputStreamToYamlNode = new Function<InputStream, YamlNode>() {
103      @Override
104      public YamlNode apply(InputStream in) {
105         if (in == null)
106            return null;
107         // note that snakeyaml also throws nosuchmethod error when you use the non-deprecated
108         // constructor
109         try {
110            return (YamlNode) new Yaml(new Loader(new Constructor(YamlNode.class))).load(in);
111         } finally {
112            Closeables.closeQuietly(in);
113         }
114      }
115   };
116 
117   public static YamlNode fromYaml(InputStream in) {
118      return inputStreamToYamlNode.apply(in);
119   }
120 
121   public static Function<YamlNode, InputStream> yamlNodeToInputStream = new Function<YamlNode, InputStream>() {
122      @Override
123      public InputStream apply(YamlNode in) {
124         if (in == null)
125            return null;
126         Builder<String, Object> prettier = ImmutableMap.<String, Object> builder();
127         if (in.id != null)
128            prettier.put("id", in.id);
129         if (in.name != null)
130            prettier.put("name", in.name);
131         if (in.description != null)
132            prettier.put("description", in.description);
133         if (in.hostname != null)
134            prettier.put("hostname", in.hostname);
135         if (in.location_id != null)
136            prettier.put("location_id", in.location_id);
137         if (in.os_arch != null)
138            prettier.put("os_arch", in.os_arch);
139         if (in.os_family != null)
140            prettier.put("os_family", in.os_family);
141         if (in.os_description != null)
142            prettier.put("os_description", in.os_description);
143         if (in.os_version != null)
144            prettier.put("os_version", in.os_version);
145         if (in.os_64bit)
146            prettier.put("os_64bit", in.os_64bit);
147         if (in.group != null)
148            prettier.put("group", in.group);
149         if (in.tags.size() != 0)
150            prettier.put("tags", in.tags);
151         if (in.username != null)
152            prettier.put("username", in.username);
153         if (in.credential != null)
154            prettier.put("credential", in.credential);
155         if (in.credential_url != null)
156            prettier.put("credential_url", in.credential_url);
157         if (in.sudo_password != null)
158            prettier.put("sudo_password", in.sudo_password);
159         DumperOptions options = new DumperOptions();
160         options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
161         return Strings2.toInputStream(new Yaml(options).dump(prettier.build()));
162      }
163   };
164 
165   public InputStream toYaml() {
166      return yamlNodeToInputStream.apply(this);
167   }
168 
169   public static YamlNode fromNode(Node in) {
170      return nodeToYamlNode.apply(in);
171   }
172 
173   public static Function<Node, YamlNode> nodeToYamlNode = new Function<Node, YamlNode>() {
174      @Override
175      public YamlNode apply(Node arg0) {
176         if (arg0 == null)
177            return null;
178         YamlNode yaml = new YamlNode();
179         yaml.id = arg0.getId();
180         yaml.name = arg0.getName();
181         yaml.description = arg0.getDescription();
182         yaml.hostname = arg0.getHostname();
183         yaml.location_id = arg0.getLocationId();
184         yaml.os_arch = arg0.getOsArch();
185         yaml.os_family = arg0.getOsFamily();
186         yaml.os_description = arg0.getOsDescription();
187         yaml.os_version = arg0.getOsVersion();
188         yaml.os_64bit = arg0.isOs64Bit();
189         yaml.group = arg0.getGroup();
190         yaml.tags = ImmutableList.copyOf(arg0.getTags());
191         yaml.username = arg0.getUsername();
192         yaml.credential = arg0.getCredential();
193         yaml.credential_url = arg0.getCredentialUrl() != null ? arg0.getCredentialUrl().toASCIIString() : null;
194         yaml.sudo_password = arg0.getSudoPassword();
195         return yaml;
196      }
197   };
198 
199}

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