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

COVERAGE SUMMARY FOR SOURCE FILE [MapToServerInfo.java]

nameclass, %method, %block, %line, %
MapToServerInfo.java100% (1/1)100% (2/2)86%  (207/242)94%  (31.8/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MapToServerInfo100% (1/1)100% (2/2)86%  (207/242)94%  (31.8/34)
apply (Map): ServerInfo 100% (1/1)85%  (195/230)92%  (26.8/29)
MapToServerInfo (Function, Function, Function): void 100% (1/1)100% (12/12)100% (5/5)

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.cloudsigma.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.cloudsigma.domain.Device;
30import org.jclouds.cloudsigma.domain.NIC;
31import org.jclouds.cloudsigma.domain.ServerInfo;
32import org.jclouds.cloudsigma.domain.ServerMetrics;
33import org.jclouds.cloudsigma.domain.ServerStatus;
34import org.jclouds.cloudsigma.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.description(from.get("description"));
65      builder.persistent(Boolean.parseBoolean(from.get("persistent")));
66      if (from.containsKey("use"))
67         builder.use(Splitter.on(' ').split(from.get("use")));
68      if (from.containsKey("status"))
69         builder.status(ServerStatus.fromValue(from.get("status")));
70      if (from.containsKey("smp") && !"auto".equals(from.get("smp")))
71         builder.smp(new Integer(from.get("smp")));
72      builder.cpu(Integer.parseInt(from.get("cpu")));
73      builder.mem(Integer.parseInt(from.get("mem")));
74      builder.user(from.get("user"));
75      if (from.containsKey("started"))
76         builder.started(new Date(new Long(from.get("started"))));
77      builder.uuid(from.get("server"));
78      builder.vnc(new VNC(from.get("vnc:ip"), from.get("vnc:password"), from.containsKey("vnc:tls")
79            && Boolean.valueOf(from.get("vnc:tls"))));
80      if (from.containsKey("boot"))
81         builder.bootDeviceIds(Splitter.on(' ').split(from.get("boot")));
82 
83      Map<String, String> metadata = Maps.newLinkedHashMap();
84      for (Entry<String, String> entry : from.entrySet()) {
85         if (entry.getKey().startsWith("user:"))
86            metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue());
87      }
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.cloudsigma.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov