EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.byon.domain]

COVERAGE SUMMARY FOR SOURCE FILE [YamlNode.java]

nameclass, %method, %block, %line, %
YamlNode.java100% (5/5)57%  (8/14)29%  (126/434)15%  (12.8/83)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class YamlNode$3100% (1/1)50%  (1/2)2%   (3/192)2%   (1/43)
apply (YamlNode): InputStream 0%   (0/1)0%   (0/189)0%   (0/42)
YamlNode$3 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class YamlNode$4100% (1/1)50%  (1/2)3%   (3/93)4%   (1/23)
apply (Node): YamlNode 0%   (0/1)0%   (0/90)0%   (0/22)
YamlNode$4 (): void 100% (1/1)100% (3/3)100% (1/1)
     
class YamlNode100% (1/1)33%  (2/6)59%  (29/49)67%  (8/12)
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% (12/12)100% (4/4)
     
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$1100% (1/1)100% (2/2)97%  (68/70)75%  (3/4)
apply (YamlNode): Node 100% (1/1)97%  (65/67)67%  (2/3)
YamlNode$1 (): void 100% (1/1)100% (3/3)100% (1/1)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.byon.domain;
20 
21import java.io.InputStream;
22import java.net.URI;
23import java.util.List;
24import java.util.Map;
25 
26import org.jclouds.byon.Node;
27import org.jclouds.util.Strings2;
28import org.yaml.snakeyaml.DumperOptions;
29import org.yaml.snakeyaml.Loader;
30import org.yaml.snakeyaml.Yaml;
31import org.yaml.snakeyaml.constructor.Constructor;
32 
33import com.google.common.base.Function;
34import com.google.common.collect.ImmutableList;
35import com.google.common.collect.ImmutableMap;
36import com.google.common.collect.ImmutableMap.Builder;
37import com.google.common.collect.Lists;
38import com.google.common.collect.Maps;
39import com.google.common.io.Closeables;
40 
41/**
42 * Serializes to the following
43 * 
44 * <pre>
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 *       os_64bit: 5.3
55 *       login_port: 2022
56 *       group: hadoop
57 *       tags:
58 *           - vanilla
59 *       metadata:
60 *           key1: val1
61 *       username: kelvin
62 *       credential: password_or_rsa
63 *         or
64 *       credential_url: password_or_rsa_file ex. resource:///id_rsa will get the classpath /id_rsa; file://path/to/id_rsa
65 *       sudo_password: password
66 * </pre>
67 * 
68 * @author Kelvin Kakugawa
69 * @author Adrian Cole
70 */
71public class YamlNode {
72   public String id;
73   public String name;
74   public String description;
75   public String hostname;
76   public String location_id;
77   public String os_arch;
78   public String os_family;
79   public String os_description;
80   public String os_version;
81   public int login_port = 22;
82   public boolean os_64bit;
83   public String group;
84   public List<String> tags = Lists.newArrayList();
85   public Map<String, String> metadata = Maps.newLinkedHashMap();
86   public String username;
87   public String credential;
88   public String credential_url;
89   public String sudo_password;
90 
91   public static Function<YamlNode, Node> toNode = new Function<YamlNode, Node>() {
92      @Override
93      public Node apply(YamlNode arg0) {
94         if (arg0 == null)
95            return null;
96         return Node.builder().id(arg0.id).name(arg0.name).description(arg0.description).locationId(arg0.location_id)
97                  .hostname(arg0.hostname).osArch(arg0.os_arch).osFamily(arg0.os_family).osDescription(
98                           arg0.os_description).osVersion(arg0.os_version).os64Bit(arg0.os_64bit).group(arg0.group)
99                  .loginPort(arg0.login_port).tags(arg0.tags).metadata(arg0.metadata).username(arg0.username).credential(arg0.credential).credentialUrl(
100                           arg0.credential_url != null ? URI.create(arg0.credential_url) : null).sudoPassword(
101                           arg0.sudo_password).build();
102      }
103   };
104 
105   public Node toNode() {
106      return toNode.apply(this);
107   }
108 
109   public static Function<InputStream, YamlNode> inputStreamToYamlNode = new Function<InputStream, YamlNode>() {
110      @Override
111      public YamlNode apply(InputStream in) {
112         if (in == null)
113            return null;
114         // note that snakeyaml also throws nosuchmethod error when you use the non-deprecated
115         // constructor
116         try {
117            return (YamlNode) new Yaml(new Loader(new Constructor(YamlNode.class))).load(in);
118         } finally {
119            Closeables.closeQuietly(in);
120         }
121      }
122   };
123 
124   public static YamlNode fromYaml(InputStream in) {
125      return inputStreamToYamlNode.apply(in);
126   }
127 
128   public static Function<YamlNode, InputStream> yamlNodeToInputStream = new Function<YamlNode, InputStream>() {
129      @Override
130      public InputStream apply(YamlNode in) {
131         if (in == null)
132            return null;
133         Builder<String, Object> prettier = ImmutableMap.<String, Object> builder();
134         if (in.id != null)
135            prettier.put("id", in.id);
136         if (in.name != null)
137            prettier.put("name", in.name);
138         if (in.description != null)
139            prettier.put("description", in.description);
140         if (in.hostname != null)
141            prettier.put("hostname", in.hostname);
142         if (in.location_id != null)
143            prettier.put("location_id", in.location_id);
144         if (in.os_arch != null)
145            prettier.put("os_arch", in.os_arch);
146         if (in.os_family != null)
147            prettier.put("os_family", in.os_family);
148         if (in.os_description != null)
149            prettier.put("os_description", in.os_description);
150         if (in.os_version != null)
151            prettier.put("os_version", in.os_version);
152         if (in.os_64bit)
153            prettier.put("os_64bit", in.os_64bit);
154         if (in.login_port != 22)
155            prettier.put("login_port", in.login_port);
156         if (in.group != null)
157            prettier.put("group", in.group);
158         if (in.tags.size() != 0)
159            prettier.put("tags", in.tags);
160         if (in.metadata.size() != 0)
161            prettier.put("metadata", in.metadata);
162         if (in.username != null)
163            prettier.put("username", in.username);
164         if (in.credential != null)
165            prettier.put("credential", in.credential);
166         if (in.credential_url != null)
167            prettier.put("credential_url", in.credential_url);
168         if (in.sudo_password != null)
169            prettier.put("sudo_password", in.sudo_password);
170         DumperOptions options = new DumperOptions();
171         options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
172         return Strings2.toInputStream(new Yaml(options).dump(prettier.build()));
173      }
174   };
175 
176   public InputStream toYaml() {
177      return yamlNodeToInputStream.apply(this);
178   }
179 
180   public static YamlNode fromNode(Node in) {
181      return nodeToYamlNode.apply(in);
182   }
183 
184   public static Function<Node, YamlNode> nodeToYamlNode = new Function<Node, YamlNode>() {
185      @Override
186      public YamlNode apply(Node arg0) {
187         if (arg0 == null)
188            return null;
189         YamlNode yaml = new YamlNode();
190         yaml.id = arg0.getId();
191         yaml.name = arg0.getName();
192         yaml.description = arg0.getDescription();
193         yaml.hostname = arg0.getHostname();
194         yaml.location_id = arg0.getLocationId();
195         yaml.os_arch = arg0.getOsArch();
196         yaml.os_family = arg0.getOsFamily();
197         yaml.os_description = arg0.getOsDescription();
198         yaml.os_version = arg0.getOsVersion();
199         yaml.os_64bit = arg0.isOs64Bit();
200         yaml.login_port = arg0.getLoginPort();
201         yaml.group = arg0.getGroup();
202         yaml.tags = ImmutableList.copyOf(arg0.getTags());
203         yaml.metadata = ImmutableMap.copyOf(arg0.getMetadata());
204         yaml.username = arg0.getUsername();
205         yaml.credential = arg0.getCredential();
206         yaml.credential_url = arg0.getCredentialUrl() != null ? arg0.getCredentialUrl().toASCIIString() : null;
207         yaml.sudo_password = arg0.getSudoPassword();
208         return yaml;
209      }
210   };
211 
212}

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