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

COVERAGE SUMMARY FOR SOURCE FILE [ServerToNodeMetadata.java]

nameclass, %method, %block, %line, %
ServerToNodeMetadata.java100% (4/4)56%  (5/9)27%  (55/201)42%  (13/31)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ServerToNodeMetadata$FindHardwareForServer100% (1/1)50%  (1/2)24%  (4/17)67%  (2/3)
matches (Server, Hardware): boolean 0%   (0/1)0%   (0/13)0%   (0/1)
ServerToNodeMetadata$FindHardwareForServer (Supplier): void 100% (1/1)100% (4/4)100% (2/2)
     
class ServerToNodeMetadata$FindImageForServer100% (1/1)50%  (1/2)24%  (4/17)67%  (2/3)
matches (Server, Image): boolean 0%   (0/1)0%   (0/13)0%   (0/1)
ServerToNodeMetadata$FindImageForServer (Supplier): void 100% (1/1)100% (4/4)100% (2/2)
     
class ServerToNodeMetadata$FindLocationForServer100% (1/1)50%  (1/2)24%  (4/17)67%  (2/3)
matches (Server, Location): boolean 0%   (0/1)0%   (0/13)0%   (0/1)
ServerToNodeMetadata$FindLocationForServer (Supplier): void 100% (1/1)100% (4/4)100% (2/2)
     
class ServerToNodeMetadata100% (1/1)67%  (2/3)29%  (43/150)32%  (7/22)
apply (Server): NodeMetadata 0%   (0/1)0%   (0/107)0%   (0/15)
<static initializer> 100% (1/1)100% (16/16)100% (1/1)
ServerToNodeMetadata (Map, ServerToNodeMetadata$FindHardwareForServer, Server... 100% (1/1)100% (27/27)100% (6/6)

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.servermanager.compute.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
23 
24import java.util.Map;
25import java.util.Set;
26 
27import javax.inject.Inject;
28import javax.inject.Singleton;
29 
30import org.jclouds.collect.FindResourceInSet;
31import org.jclouds.collect.Memoized;
32import org.jclouds.compute.domain.Hardware;
33import org.jclouds.compute.domain.Image;
34import org.jclouds.compute.domain.NodeMetadata;
35import org.jclouds.compute.domain.NodeMetadataBuilder;
36import org.jclouds.compute.domain.NodeState;
37import org.jclouds.domain.Credentials;
38import org.jclouds.domain.Location;
39import org.jclouds.servermanager.Server;
40 
41import com.google.common.base.Function;
42import com.google.common.base.Supplier;
43import com.google.common.collect.ImmutableMap;
44import com.google.common.collect.ImmutableSet;
45 
46/**
47 * @author Adrian Cole
48 */
49@Singleton
50public class ServerToNodeMetadata implements Function<Server, NodeMetadata> {
51 
52   public static final Map<Server.Status, NodeState> serverStatusToNodeState = ImmutableMap
53         .<Server.Status, NodeState> builder().put(Server.Status.ACTIVE, NodeState.RUNNING)//
54         .put(Server.Status.BUILD, NodeState.PENDING)//
55         .put(Server.Status.TERMINATED, NodeState.TERMINATED)//
56         .put(Server.Status.UNRECOGNIZED, NodeState.UNRECOGNIZED)//
57         .build();
58 
59   private final FindHardwareForServer findHardwareForServer;
60   private final FindLocationForServer findLocationForServer;
61   private final FindImageForServer findImageForServer;
62   private final Map<String, Credentials> credentialStore;
63 
64   @Inject
65   ServerToNodeMetadata(Map<String, Credentials> credentialStore, FindHardwareForServer findHardwareForServer,
66         FindLocationForServer findLocationForServer, FindImageForServer findImageForServer) {
67      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
68      this.findHardwareForServer = checkNotNull(findHardwareForServer, "findHardwareForServer");
69      this.findLocationForServer = checkNotNull(findLocationForServer, "findLocationForServer");
70      this.findImageForServer = checkNotNull(findImageForServer, "findImageForServer");
71   }
72 
73   @Override
74   public NodeMetadata apply(Server from) {
75      // convert the result object to a jclouds NodeMetadata
76      NodeMetadataBuilder builder = new NodeMetadataBuilder();
77      builder.ids(from.id + "");
78      builder.name(from.name);
79      builder.location(findLocationForServer.apply(from));
80      builder.group(parseGroupFromName(from.name));
81      builder.imageId(from.imageId + "");
82      Image image = findImageForServer.apply(from);
83      if (image != null)
84         builder.operatingSystem(image.getOperatingSystem());
85      builder.hardware(findHardwareForServer.apply(from));
86      builder.state(serverStatusToNodeState.get(from.status));
87      builder.publicAddresses(ImmutableSet.<String> of(from.publicAddress));
88      builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress));
89      builder.credentials(credentialStore.get(from.id + ""));
90      return builder.build();
91   }
92 
93   @Singleton
94   public static class FindHardwareForServer extends FindResourceInSet<Server, Hardware> {
95 
96      @Inject
97      public FindHardwareForServer(@Memoized Supplier<Set<? extends Hardware>> hardware) {
98         super(hardware);
99      }
100 
101      @Override
102      public boolean matches(Server from, Hardware input) {
103         return input.getProviderId().equals(from.hardwareId + "");
104      }
105   }
106 
107   @Singleton
108   public static class FindImageForServer extends FindResourceInSet<Server, Image> {
109 
110      @Inject
111      public FindImageForServer(@Memoized Supplier<Set<? extends Image>> hardware) {
112         super(hardware);
113      }
114 
115      @Override
116      public boolean matches(Server from, Image input) {
117         return input.getProviderId().equals(from.imageId + "");
118      }
119   }
120 
121   @Singleton
122   public static class FindLocationForServer extends FindResourceInSet<Server, Location> {
123 
124      @Inject
125      public FindLocationForServer(@Memoized Supplier<Set<? extends Location>> hardware) {
126         super(hardware);
127      }
128 
129      @Override
130      public boolean matches(Server from, Location input) {
131         return input.getId().equals(from.datacenter + "");
132      }
133   }
134}

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