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

COVERAGE SUMMARY FOR SOURCE FILE [CleanupOrphanKeys.java]

nameclass, %method, %block, %line, %
CleanupOrphanKeys.java100% (1/1)100% (2/2)100% (98/98)100% (17/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CleanupOrphanKeys100% (1/1)100% (2/2)100% (98/98)100% (17/17)
CleanupOrphanKeys (Function, DeleteKeyPair, Map, ListNodesStrategy): void 100% (1/1)100% (15/15)100% (6/6)
execute (Iterable): void 100% (1/1)100% (83/83)100% (11/11)

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.strategy;
20 
21import static com.google.common.base.Predicates.notNull;
22import static com.google.common.collect.Iterables.all;
23import static com.google.common.collect.Iterables.filter;
24import static com.google.common.collect.Iterables.size;
25import static com.google.common.collect.Iterables.transform;
26import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
27import static org.jclouds.compute.predicates.NodePredicates.parentLocationId;
28import static org.jclouds.compute.predicates.NodePredicates.inGroup;
29 
30import java.util.Map;
31 
32import javax.inject.Inject;
33import javax.inject.Singleton;
34 
35import org.jclouds.compute.domain.NodeMetadata;
36import org.jclouds.compute.strategy.ListNodesStrategy;
37import org.jclouds.domain.Credentials;
38import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName;
39 
40import com.google.common.base.Function;
41 
42/**
43 * 
44 * @author Adrian Cole
45 * 
46 */
47@Singleton
48public class CleanupOrphanKeys {
49   final Function<NodeMetadata, OrgAndName> nodeToOrgAndName;
50   final DeleteKeyPair deleteKeyPair;
51   final ListNodesStrategy listNodes;
52   final Map<String, Credentials> credentialStore;
53 
54   @Inject
55   CleanupOrphanKeys(Function<NodeMetadata, OrgAndName> nodeToOrgAndName, DeleteKeyPair deleteKeyPair,
56            Map<String, Credentials> credentialStore, ListNodesStrategy listNodes) {
57      this.nodeToOrgAndName = nodeToOrgAndName;
58      this.deleteKeyPair = deleteKeyPair;
59      this.listNodes = listNodes;
60      this.credentialStore = credentialStore;
61   }
62 
63   public void execute(Iterable<? extends NodeMetadata> deadOnes) {
64      // TODO refactor so that admin passwords are cached properly, probably as a list value in the
65      // credentialStore
66      for (NodeMetadata node : deadOnes){
67         credentialStore.remove("node#" + node.getId());
68         credentialStore.remove("node#" + node.getId() + "#adminPassword");
69      }
70      Iterable<OrgAndName> orgGroups = filter(transform(deadOnes, nodeToOrgAndName), notNull());
71      for (OrgAndName orgGroup : orgGroups) {
72         Iterable<? extends NodeMetadata> nodesInOrg = listNodes.listDetailsOnNodesMatching(parentLocationId(orgGroup
73                  .getOrg().toASCIIString()));
74         Iterable<? extends NodeMetadata> nodesInGroup = filter(nodesInOrg, inGroup(orgGroup.getName()));
75         if (size(nodesInGroup) == 0 || all(nodesInGroup, TERMINATED))
76            deleteKeyPair.execute(orgGroup);
77      }
78   }
79 
80}

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