EMMA Coverage Report (generated Mon Oct 17 05:41:20 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/305)0%   (0/46)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppToNodeMetadata0%   (0/1)0%   (0/3)0%   (0/305)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/200)0%   (0/28)
installCredentialsFromCache (URI, URI, String, NodeMetadataBuilder): void 0%   (0/1)0%   (0/60)0%   (0/9)

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.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, Map<String, Credentials> credentialStore,
68            Map<Status, NodeState> vAppStatusToNodeState, HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
69            FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images,
70            ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
71      this.images = checkNotNull(images, "images");
72      this.hardwareForVCloudExpressVApp = checkNotNull(hardwareForVCloudExpressVApp, "hardwareForVCloudExpressVApp");
73      this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
74      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
75      this.computeClient = checkNotNull(computeClient, "computeClient");
76      this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
77      this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
78   }
79 
80   @Override
81   public NodeMetadata apply(VApp from) {
82      NodeMetadataBuilder builder = new NodeMetadataBuilder();
83      builder.ids(from.getHref().toASCIIString());
84      builder.uri(from.getHref());
85      builder.name(from.getName());
86      builder.hostname(from.getName());
87      Location vdcLocation = findLocationForResourceInVDC.apply(from.getVDC());
88      builder.location(vdcLocation);
89      if (from.getOsType() != null && OSType.fromValue(from.getOsType()) != OSType.UNRECOGNIZED) {
90         builder.operatingSystem(new CIMOperatingSystem(OSType.fromValue(from.getOsType()), "", null, from
91                  .getOperatingSystemDescription()));
92      } else if (from.getOperatingSystemDescription() != null) {
93         OperatingSystem.Builder osBuilder = new OperatingSystem.Builder();
94         if (from.getOsType() != null)
95            osBuilder.name(from.getOsType() + "");
96         osBuilder.family(ComputeServiceUtils.parseOsFamilyOrUnrecognized(from.getOperatingSystemDescription()));
97         osBuilder.version("");
98         osBuilder.is64Bit(from.getOperatingSystemDescription().indexOf("64") != -1);
99         osBuilder.description(from.getOperatingSystemDescription());
100         builder.operatingSystem(osBuilder.build());
101      }
102      builder.hardware(hardwareForVCloudExpressVApp.apply(from));
103      builder.state(vAppStatusToNodeState.get(from.getStatus()));
104      builder.publicAddresses(computeClient.getPublicAddresses(from.getHref()));
105      builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref()));
106      String group = parseGroupFromName(from.getName());
107      builder.group(group);
108      // node-specific credentials override those from cache based on group
109      if (group != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString())) {
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 node.
126      String adminPasswordKey = "node#" + nodeId + "#adminPassword";
127      if (credentialStore.containsKey(adminPasswordKey)) {
128         builder.adminPassword(credentialStore.get(adminPasswordKey).credential);
129      }
130   }
131}

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