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

COVERAGE SUMMARY FOR SOURCE FILE [MapToServerInfo.java]

nameclass, %method, %block, %line, %
MapToServerInfo.java100% (1/1)100% (2/2)85%  (204/239)94%  (31.8/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapToServerInfo100% (1/1)100% (2/2)85%  (204/239)94%  (31.8/34)
apply (Map): ServerInfo 100% (1/1)85%  (192/227)92%  (26.8/29)
MapToServerInfo (Function, Function, Function): void 100% (1/1)100% (12/12)100% (5/5)

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.elasticstack.functions;
20 
21import java.util.Date;
22import java.util.List;
23import java.util.Map;
24import java.util.Map.Entry;
25 
26import javax.inject.Inject;
27import javax.inject.Singleton;
28 
29import org.jclouds.elasticstack.domain.Device;
30import org.jclouds.elasticstack.domain.NIC;
31import org.jclouds.elasticstack.domain.ServerInfo;
32import org.jclouds.elasticstack.domain.ServerMetrics;
33import org.jclouds.elasticstack.domain.ServerStatus;
34import org.jclouds.elasticstack.domain.VNC;
35 
36import com.google.common.base.Function;
37import com.google.common.base.Splitter;
38import com.google.common.collect.Maps;
39 
40/**
41 * 
42 * @author Adrian Cole
43 */
44@Singleton
45public class MapToServerInfo implements Function<Map<String, String>, ServerInfo> {
46   private final Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices;
47   private final Function<Map<String, String>, ServerMetrics> mapToMetrics;
48   private final Function<Map<String, String>, List<NIC>> mapToNICs;
49 
50   @Inject
51   public MapToServerInfo(Function<Map<String, String>, Map<String, ? extends Device>> mapToDevices,
52         Function<Map<String, String>, ServerMetrics> mapToMetrics, Function<Map<String, String>, List<NIC>> mapToNICs) {
53      this.mapToDevices = mapToDevices;
54      this.mapToMetrics = mapToMetrics;
55      this.mapToNICs = mapToNICs;
56   }
57 
58   @Override
59   public ServerInfo apply(Map<String, String> from) {
60      if (from.size() == 0)
61         return null;
62      ServerInfo.Builder builder = new ServerInfo.Builder();
63      builder.name(from.get("name"));
64      builder.persistent(Boolean.parseBoolean(from.get("persistent")));
65      if (from.containsKey("tags"))
66         builder.tags(Splitter.on(' ').split(from.get("tags")));
67      if (from.containsKey("status"))
68         builder.status(ServerStatus.fromValue(from.get("status")));
69      if (from.containsKey("smp") && !"auto".equals(from.get("smp")))
70         builder.smp(new Integer(from.get("smp")));
71      builder.cpu(Integer.parseInt(from.get("cpu")));
72      builder.mem(Integer.parseInt(from.get("mem")));
73      builder.user(from.get("user"));
74      if (from.containsKey("started"))
75         builder.started(new Date(new Long(from.get("started"))));
76      builder.uuid(from.get("server"));
77      builder.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls")
78            && Boolean.valueOf(from.get("vnc:tls"))));
79      if (from.containsKey("boot"))
80         builder.bootDeviceIds(Splitter.on(' ').split(from.get("boot")));
81 
82      Map<String, String> metadata = Maps.newLinkedHashMap();
83      for (Entry<String, String> entry : from.entrySet()) {
84         if (entry.getKey().startsWith("user:"))
85            metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue());
86      }
87      builder.userMetadata(metadata);
88      builder.nics(mapToNICs.apply(from));
89      builder.devices(mapToDevices.apply(from));
90      builder.metrics(mapToMetrics.apply(from));
91      return builder.build();
92   }
93}

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