EMMA Coverage Report (generated Fri Aug 26 14:14:05 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%  (284/413)71%  (55.7/79)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class YamlNode$3100% (1/1)100% (2/2)48%  (88/182)61%  (25/41)
apply (YamlNode): InputStream 100% (1/1)47%  (85/179)60%  (24/40)
YamlNode$3 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class YamlNode100% (1/1)33%  (2/6)57%  (26/46)64%  (7/11)
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% (9/9)100% (3/3)
     
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%  (82/88)95%  (21/22)
apply (Node): YamlNode 100% (1/1)93%  (79/85)95%  (20/21)
YamlNode$4 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class YamlNode$1100% (1/1)100% (2/2)97%  (65/67)75%  (3/4)
apply (YamlNode): Node 100% (1/1)97%  (62/64)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.ImmutableMap.Builder;
36import com.google.common.collect.Lists;
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 *       login_port: 2022
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 */
67public class YamlNode {
68   public String id;
69   public String name;
70   public String description;
71   public String hostname;
72   public String location_id;
73   public String os_arch;
74   public String os_family;
75   public String os_description;
76   public String os_version;
77   public int login_port = 22;
78   public boolean os_64bit;
79   public String group;
80   public List<String> tags = Lists.newArrayList();
81   public String username;
82   public String credential;
83   public String credential_url;
84   public String sudo_password;
85 
86   public static Function<YamlNode, Node> toNode = new Function<YamlNode, Node>() {
87      @Override
88      public Node apply(YamlNode arg0) {
89         if (arg0 == null)
90            return null;
91         return Node.builder().id(arg0.id).name(arg0.name).description(arg0.description).locationId(arg0.location_id)
92                  .hostname(arg0.hostname).osArch(arg0.os_arch).osFamily(arg0.os_family).osDescription(
93                           arg0.os_description).osVersion(arg0.os_version).os64Bit(arg0.os_64bit).group(arg0.group)
94                  .loginPort(arg0.login_port).tags(arg0.tags).username(arg0.username).credential(arg0.credential).credentialUrl(
95                           arg0.credential_url != null ? URI.create(arg0.credential_url) : null).sudoPassword(
96                           arg0.sudo_password).build();
97      }
98   };
99 
100   public Node toNode() {
101      return toNode.apply(this);
102   }
103 
104   public static Function<InputStream, YamlNode> inputStreamToYamlNode = new Function<InputStream, YamlNode>() {
105      @Override
106      public YamlNode apply(InputStream in) {
107         if (in == null)
108            return null;
109         // note that snakeyaml also throws nosuchmethod error when you use the non-deprecated
110         // constructor
111         try {
112            return (YamlNode) new Yaml(new Loader(new Constructor(YamlNode.class))).load(in);
113         } finally {
114            Closeables.closeQuietly(in);
115         }
116      }
117   };
118 
119   public static YamlNode fromYaml(InputStream in) {
120      return inputStreamToYamlNode.apply(in);
121   }
122 
123   public static Function<YamlNode, InputStream> yamlNodeToInputStream = new Function<YamlNode, InputStream>() {
124      @Override
125      public InputStream apply(YamlNode in) {
126         if (in == null)
127            return null;
128         Builder<String, Object> prettier = ImmutableMap.<String, Object> builder();
129         if (in.id != null)
130            prettier.put("id", in.id);
131         if (in.name != null)
132            prettier.put("name", in.name);
133         if (in.description != null)
134            prettier.put("description", in.description);
135         if (in.hostname != null)
136            prettier.put("hostname", in.hostname);
137         if (in.location_id != null)
138            prettier.put("location_id", in.location_id);
139         if (in.os_arch != null)
140            prettier.put("os_arch", in.os_arch);
141         if (in.os_family != null)
142            prettier.put("os_family", in.os_family);
143         if (in.os_description != null)
144            prettier.put("os_description", in.os_description);
145         if (in.os_version != null)
146            prettier.put("os_version", in.os_version);
147         if (in.os_64bit)
148            prettier.put("os_64bit", in.os_64bit);
149         if (in.login_port != 22)
150            prettier.put("login_port", in.login_port);
151         if (in.group != null)
152            prettier.put("group", in.group);
153         if (in.tags.size() != 0)
154            prettier.put("tags", in.tags);
155         if (in.username != null)
156            prettier.put("username", in.username);
157         if (in.credential != null)
158            prettier.put("credential", in.credential);
159         if (in.credential_url != null)
160            prettier.put("credential_url", in.credential_url);
161         if (in.sudo_password != null)
162            prettier.put("sudo_password", in.sudo_password);
163         DumperOptions options = new DumperOptions();
164         options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
165         return Strings2.toInputStream(new Yaml(options).dump(prettier.build()));
166      }
167   };
168 
169   public InputStream toYaml() {
170      return yamlNodeToInputStream.apply(this);
171   }
172 
173   public static YamlNode fromNode(Node in) {
174      return nodeToYamlNode.apply(in);
175   }
176 
177   public static Function<Node, YamlNode> nodeToYamlNode = new Function<Node, YamlNode>() {
178      @Override
179      public YamlNode apply(Node arg0) {
180         if (arg0 == null)
181            return null;
182         YamlNode yaml = new YamlNode();
183         yaml.id = arg0.getId();
184         yaml.name = arg0.getName();
185         yaml.description = arg0.getDescription();
186         yaml.hostname = arg0.getHostname();
187         yaml.location_id = arg0.getLocationId();
188         yaml.os_arch = arg0.getOsArch();
189         yaml.os_family = arg0.getOsFamily();
190         yaml.os_description = arg0.getOsDescription();
191         yaml.os_version = arg0.getOsVersion();
192         yaml.os_64bit = arg0.isOs64Bit();
193         yaml.login_port = arg0.getLoginPort();
194         yaml.group = arg0.getGroup();
195         yaml.tags = ImmutableList.copyOf(arg0.getTags());
196         yaml.username = arg0.getUsername();
197         yaml.credential = arg0.getCredential();
198         yaml.credential_url = arg0.getCredentialUrl() != null ? arg0.getCredentialUrl().toASCIIString() : null;
199         yaml.sudo_password = arg0.getSudoPassword();
200         return yaml;
201      }
202   };
203 
204}

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