EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.vcloud.terremark.compute.functions]

COVERAGE SUMMARY FOR SOURCE FILE [TerremarkVCloudExpressVAppToNodeMetadata.java]

nameclass, %method, %block, %line, %
TerremarkVCloudExpressVAppToNodeMetadata.java0%   (0/1)0%   (0/4)0%   (0/112)0%   (0/21)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class TerremarkVCloudExpressVAppToNodeMetadata0%   (0/1)0%   (0/4)0%   (0/112)0%   (0/21)
TerremarkVCloudExpressVAppToNodeMetadata (VCloudExpressComputeClient, Map, Ma... 0%   (0/1)0%   (0/15)0%   (0/3)
apply (VCloudExpressVApp): NodeMetadata 0%   (0/1)0%   (0/17)0%   (0/6)
getOrgAndNameFromNode (NodeMetadata): OrgAndName 0%   (0/1)0%   (0/15)0%   (0/3)
installCredentialsFromCache (NodeMetadata): NodeMetadata 0%   (0/1)0%   (0/65)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.vcloud.terremark.compute.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.net.URI;
24import java.util.Map;
25import java.util.Set;
26import java.util.concurrent.ConcurrentMap;
27 
28import javax.inject.Inject;
29import javax.inject.Singleton;
30 
31import org.jclouds.collect.Memoized;
32import org.jclouds.compute.domain.Image;
33import org.jclouds.compute.domain.NodeMetadata;
34import org.jclouds.compute.domain.NodeMetadataBuilder;
35import org.jclouds.compute.domain.NodeState;
36import org.jclouds.domain.Credentials;
37import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
38import org.jclouds.vcloud.compute.functions.FindLocationForResource;
39import org.jclouds.vcloud.compute.functions.HardwareForVCloudExpressVApp;
40import org.jclouds.vcloud.compute.functions.VCloudExpressVAppToNodeMetadata;
41import org.jclouds.vcloud.domain.Status;
42import org.jclouds.vcloud.domain.VCloudExpressVApp;
43import org.jclouds.vcloud.terremark.compute.domain.KeyPairCredentials;
44import org.jclouds.vcloud.terremark.compute.domain.OrgAndName;
45 
46import com.google.common.base.Supplier;
47 
48/**
49 * @author Adrian Cole
50 */
51@Singleton
52public class TerremarkVCloudExpressVAppToNodeMetadata extends VCloudExpressVAppToNodeMetadata {
53   private final ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap;
54 
55   @Inject
56   public TerremarkVCloudExpressVAppToNodeMetadata(VCloudExpressComputeClient computeClient,
57            Map<String, Credentials> credentialStore, Map<Status, NodeState> vAppStatusToNodeState,
58            HardwareForVCloudExpressVApp hardwareForVCloudExpressVApp,
59            FindLocationForResource findLocationForResourceInVDC, @Memoized Supplier<Set<? extends Image>> images,
60            ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap) {
61      super(computeClient, credentialStore, vAppStatusToNodeState, hardwareForVCloudExpressVApp,
62               findLocationForResourceInVDC, images);
63      this.credentialsMap = checkNotNull(credentialsMap, "credentialsMap");
64   }
65 
66   @Override
67   public NodeMetadata apply(VCloudExpressVApp from) {
68      NodeMetadata node = super.apply(from);
69      if (node == null)
70         return null;
71      if (node.getGroup() != null) {
72         node = installCredentialsFromCache(node);
73      }
74      return node;
75   }
76 
77   NodeMetadata installCredentialsFromCache(NodeMetadata node) {
78      OrgAndName orgAndName = getOrgAndNameFromNode(node);
79      if (credentialsMap.containsKey(orgAndName)) {
80         Credentials creds = credentialsMap.get(orgAndName);
81         node = NodeMetadataBuilder.fromNodeMetadata(node).credentials(creds).build();
82         credentialStore.put("node#" + node.getId(), creds);
83      }
84      // this is going to need refactoring.. we really need a credential list in the store per
85      // node.
86      String adminPasswordKey = "node#" + node.getId() + "#adminPassword";
87      if (credentialStore.containsKey(adminPasswordKey)) {
88         node = NodeMetadataBuilder.fromNodeMetadata(node).adminPassword(
89                  credentialStore.get(adminPasswordKey).credential).build();
90      }
91      return node;
92   }
93 
94   OrgAndName getOrgAndNameFromNode(NodeMetadata node) {
95      URI orgId = URI.create(node.getLocation().getParent().getId());
96      OrgAndName orgAndName = new OrgAndName(orgId, node.getGroup());
97      return orgAndName;
98   }
99 
100}

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