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

COVERAGE SUMMARY FOR SOURCE FILE [VAppToNodeMetadata.java]

nameclass, %method, %block, %line, %
VAppToNodeMetadata.java0%   (0/1)0%   (0/3)0%   (0/291)0%   (0/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppToNodeMetadata0%   (0/1)0%   (0/3)0%   (0/291)0%   (0/46)
VAppToNodeMetadata (TerremarkVCloudComputeClient, Map, Map, HardwareForVCloud... 0%   (0/1)0%   (0/45)0%   (0/9)
apply (VApp): NodeMetadata 0%   (0/1)0%   (0/186)0%   (0/28)
installCredentialsFromCache (URI, URI, String, NodeMetadataBuilder): void 0%   (0/1)0%   (0/60)0%   (0/9)

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.trmk.vcloud_0_8.compute.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
23 
24import java.net.URI;
25import java.util.Map;
26import java.util.Set;
27import java.util.concurrent.ConcurrentMap;
28 
29import javax.inject.Inject;
30import javax.inject.Singleton;
31 
32import org.jclouds.cim.OSType;
33import org.jclouds.collect.Memoized;
34import org.jclouds.compute.domain.CIMOperatingSystem;
35import org.jclouds.compute.domain.Image;
36import org.jclouds.compute.domain.NodeMetadata;
37import org.jclouds.compute.domain.NodeMetadataBuilder;
38import org.jclouds.compute.domain.NodeState;
39import org.jclouds.compute.domain.OperatingSystem;
40import org.jclouds.compute.util.ComputeServiceUtils;
41import org.jclouds.domain.Credentials;
42import org.jclouds.domain.Location;
43import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
44import org.jclouds.trmk.vcloud_0_8.compute.domain.KeyPairCredentials;
45import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
46import org.jclouds.trmk.vcloud_0_8.domain.Status;
47import org.jclouds.trmk.vcloud_0_8.domain.VApp;
48 
49import com.google.common.base.Function;
50import com.google.common.base.Supplier;
51 
52/**
53 * @author Adrian Cole
54 */
55@Singleton
56public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
57 
58   protected final TerremarkVCloudComputeClient computeClient;
59   protected final Map<String, Credentials> credentialStore;
60   protected final Supplier<Set<? extends Image>> images;
61   protected final FindLocationForResource findLocationForResourceInVDC;
62   protected final HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp;
63   protected final Map<Status, NodeState> vAppStatusToNodeState;
64   protected final ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap;
65 
66   @Inject
67   protected VAppToNodeMetadata(TerremarkVCloudComputeClient computeClient,
68         Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
69         HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
70         FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images,
71         ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
72      this.images = checkNotNull(images, "images");
73      this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
74      this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
75      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
76      this.computeClient = checkNotNull(computeClient, "computeClient");
77      this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
78      this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
79   }
80 
81   @Override
82   public NodeMetadata apply(VApp from) {
83      NodeMetadataBuilder builder = new NodeMetadataBuilder();
84      builder.ids(from.getHref().toASCIIString());
85      builder.uri(from.getHref());
86      builder.name(from.getName());
87      builder.hostname(from.getName());
88      Location vdcLocation = findLocationForResourceInVDC.apply(from.getVDC());
89      builder.location(vdcLocation);
90      if (from.getOsType() != null && OSType.fromValue(from.getOsType()) != OSType.UNRECOGNIZED) {
91         builder.operatingSystem(new CIMOperatingSystem(OSType.fromValue(from.getOsType()), "", null, from
92               .getOperatingSystemDescription()));
93      } else if (from.getOperatingSystemDescription() != null) {
94         OperatingSystem.Builder osBuilder = new OperatingSystem.Builder();
95         if (from.getOsType() != null)
96            osBuilder.name(from.getOsType() + "");
97         osBuilder.family(ComputeServiceUtils.parseOsFamilyOrUnrecognized(from.getOperatingSystemDescription()));
98         osBuilder.version("");
99         osBuilder.is64Bit(from.getOperatingSystemDescription().indexOf("64") != -1);
100         osBuilder.description(from.getOperatingSystemDescription());
101         builder.operatingSystem(osBuilder.build());
102      }
103      builder.hardware(hardwareForVCloudExpressVApp.apply(from));
104      builder.state(vAppStatusToNodeState.get(from.getStatus()));
105      builder.publicAddresses(computeClient.getPublicAddresses(from.getHref()));
106      builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref()));
107      String group = parseGroupFromName(from.getName());
108      if (group != null) {
109         builder.group(group);
110         installCredentialsFromCache(from.getHref(), URI.create(vdcLocation.getParent().getId()), group, builder);
111      } else {
112         builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString()));
113      }
114      return builder.build();
115   }
116 
117   protected void installCredentialsFromCache(URI nodeId, URI orgId, String group, NodeMetadataBuilder builder) {
118      OrgAndName orgAndName = new OrgAndName(orgId, group);
119      if (credentialsMap.containsKey(orgAndName)) {
120         Credentials creds = credentialsMap.get(orgAndName);
121         builder.credentials(creds);
122         credentialStore.put("node#" + nodeId, creds);
123      }
124      // this is going to need refactoring.. we really need a credential list in
125      // the store per
126      // node.
127      String adminPasswordKey = "node#" + nodeId + "#adminPassword";
128      if (credentialStore.containsKey(adminPasswordKey)) {
129         builder.adminPassword(credentialStore.get(adminPasswordKey).credential);
130      }
131   }
132}

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