EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.compute.config]

COVERAGE SUMMARY FOR SOURCE FILE [PersistNodeCredentialsModule.java]

nameclass, %method, %block, %line, %
PersistNodeCredentialsModule.java100% (5/5)100% (8/8)100% (112/112)100% (22/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PersistNodeCredentialsModule100% (1/1)100% (2/2)100% (27/27)100% (4/4)
PersistNodeCredentialsModule (): void 100% (1/1)100% (3/3)100% (2/2)
configure (): void 100% (1/1)100% (24/24)100% (2/2)
     
class PersistNodeCredentialsModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
PersistNodeCredentialsModule$1 (PersistNodeCredentialsModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class PersistNodeCredentialsModule$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
PersistNodeCredentialsModule$2 (PersistNodeCredentialsModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class PersistNodeCredentialsModule$RefreshCredentialsForNode100% (1/1)100% (2/2)100% (29/29)100% (6/6)
PersistNodeCredentialsModule$RefreshCredentialsForNode (Map, Statement): void 100% (1/1)100% (5/5)100% (2/2)
apply (NodeMetadata): NodeMetadata 100% (1/1)100% (24/24)100% (4/4)
     
class PersistNodeCredentialsModule$RefreshCredentialsForNodeIfRanAdminAccess100% (1/1)100% (2/2)100% (44/44)100% (11/11)
PersistNodeCredentialsModule$RefreshCredentialsForNodeIfRanAdminAccess (Map, ... 100% (1/1)100% (9/9)100% (4/4)
apply (NodeMetadata): NodeMetadata 100% (1/1)100% (35/35)100% (7/7)

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.compute.config;
20 
21import java.util.Map;
22 
23import org.jclouds.javax.annotation.Nullable;
24 
25import org.jclouds.compute.domain.NodeMetadata;
26import org.jclouds.compute.domain.NodeMetadataBuilder;
27import org.jclouds.compute.internal.PersistNodeCredentials;
28import org.jclouds.domain.Credentials;
29import org.jclouds.scriptbuilder.domain.Statement;
30import org.jclouds.scriptbuilder.functions.CredentialsFromAdminAccess;
31 
32import com.google.common.base.Function;
33import com.google.inject.AbstractModule;
34import com.google.inject.Inject;
35import com.google.inject.TypeLiteral;
36import com.google.inject.assistedinject.Assisted;
37import com.google.inject.assistedinject.FactoryModuleBuilder;
38import com.google.inject.name.Names;
39 
40/**
41 * 
42 * @author Adrian Cole
43 */
44public class PersistNodeCredentialsModule extends AbstractModule {
45 
46   static class RefreshCredentialsForNodeIfRanAdminAccess implements Function<NodeMetadata, NodeMetadata> {
47      protected final Map<String, Credentials> credentialStore;
48      protected final Statement statement;
49 
50      @Inject
51      protected RefreshCredentialsForNodeIfRanAdminAccess(Map<String, Credentials> credentialStore,
52            @Nullable @Assisted Statement statement) {
53         this.credentialStore = credentialStore;
54         this.statement = statement;
55      }
56 
57      @Override
58      public NodeMetadata apply(NodeMetadata input) {
59         if (statement == null)
60            return input;
61         Credentials credentials = CredentialsFromAdminAccess.INSTANCE.apply(statement);
62         if (credentials != null) {
63            input = NodeMetadataBuilder.fromNodeMetadata(input).credentials(credentials).build();
64            credentialStore.put("node#" + input.getId(), input.getCredentials());
65         }
66         return input;
67      }
68 
69   }
70 
71   static class RefreshCredentialsForNode extends RefreshCredentialsForNodeIfRanAdminAccess {
72 
73      @Inject
74      public RefreshCredentialsForNode(Map<String, Credentials> credentialStore, @Assisted @Nullable Statement statement) {
75         super(credentialStore, statement);
76      }
77 
78      @Override
79      public NodeMetadata apply(NodeMetadata input) {
80         input = super.apply(input);
81         if (input.getCredentials() != null)
82            credentialStore.put("node#" + input.getId(), input.getCredentials());
83         return input;
84      }
85 
86   }
87 
88   @Override
89   protected void configure() {
90 
91      install(new FactoryModuleBuilder().implement(new TypeLiteral<Function<NodeMetadata, NodeMetadata>>() {
92      }, Names.named("ifAdminAccess"), RefreshCredentialsForNodeIfRanAdminAccess.class)
93            .implement(new TypeLiteral<Function<NodeMetadata, NodeMetadata>>() {
94            }, Names.named("always"), RefreshCredentialsForNode.class).build(PersistNodeCredentials.class));
95   }
96 
97}

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