EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.vcloud.compute.functions]

COVERAGE SUMMARY FOR SOURCE FILE [VAppToNodeMetadata.java]

nameclass, %method, %block, %line, %
VAppToNodeMetadata.java100% (1/1)100% (3/3)100% (162/162)100% (25/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppToNodeMetadata100% (1/1)100% (3/3)100% (162/162)100% (25/25)
<static initializer> 100% (1/1)100% (3/3)100% (1/1)
VAppToNodeMetadata (Map, Map, FindLocationForResource, Function): void 100% (1/1)100% (27/27)100% (6/6)
apply (VApp): NodeMetadata 100% (1/1)100% (132/132)100% (18/18)

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.vcloud.compute.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static com.google.common.base.Predicates.not;
23import static com.google.common.collect.Iterables.filter;
24import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
25import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom;
26import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getIpsFromVApp;
27import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.toComputeOs;
28 
29import java.util.Map;
30import java.util.Set;
31 
32import javax.annotation.Resource;
33import javax.inject.Inject;
34import javax.inject.Singleton;
35 
36import org.jclouds.compute.domain.Hardware;
37import org.jclouds.compute.domain.NodeMetadata;
38import org.jclouds.compute.domain.NodeMetadataBuilder;
39import org.jclouds.compute.domain.NodeState;
40import org.jclouds.domain.Credentials;
41import org.jclouds.logging.Logger;
42import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
43import org.jclouds.vcloud.domain.Status;
44import org.jclouds.vcloud.domain.VApp;
45 
46import com.google.common.base.Function;
47 
48/**
49 * @author Adrian Cole
50 */
51@Singleton
52public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
53   @Resource
54   protected static Logger logger = Logger.NULL;
55 
56   protected final FindLocationForResource findLocationForResourceInVDC;
57   protected final Function<VApp, Hardware> hardwareForVApp;
58   protected final Map<Status, NodeState> vAppStatusToNodeState;
59   protected final Map<String, Credentials> credentialStore;
60 
61   @Inject
62   protected VAppToNodeMetadata(Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
63         FindLocationForResource findLocationForResourceInVDC, Function<VApp, Hardware> hardwareForVApp) {
64      this.hardwareForVApp = checkNotNull(hardwareForVApp, "hardwareForVApp");
65      this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
66      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
67      this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
68   }
69 
70   public NodeMetadata apply(VApp from) {
71      NodeMetadataBuilder builder = new NodeMetadataBuilder();
72      builder.ids(from.getHref().toASCIIString());
73      builder.uri(from.getHref());
74      builder.name(from.getName());
75      builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
76      builder.group(parseGroupFromName(from.getName()));
77      builder.operatingSystem(toComputeOs(from, null));
78      builder.hardware(hardwareForVApp.apply(from));
79      builder.state(vAppStatusToNodeState.get(from.getStatus()));
80      Set<String> addresses = getIpsFromVApp(from);
81      builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
82      builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
83      builder.credentials(getCredentialsFrom(from));
84      Credentials fromApi = getCredentialsFrom(from);
85      if (fromApi != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString()))
86         credentialStore.put("node#" + from.getHref().toASCIIString(), fromApi);
87      builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString()));
88      return builder.build();
89   }
90}

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