EMMA�Coverage�Report�(generated�Fri�Apr�27�15:03:37�EDT�2012)
[all�classes][org.jclouds.ec2.compute.functions]

COVERAGE�SUMMARY�FOR�SOURCE�FILE�[CredentialsForInstance.java]

nameclass,�%method,�%block,�%line,�%
CredentialsForInstance.java100%�(1/1)25%��(1/4)19%��(12/64)36%��(4/11)

COVERAGE�BREAKDOWN�BY�CLASS�AND�METHOD

nameclass,�%method,�%block,�%line,�%
class�CredentialsForInstance100%�(1/1)25%��(1/4)19%��(12/64)36%��(4/11)
getLoginAccountFor�(RunningInstance):�String0%���(0/1)0%���(0/16)0%���(0/1)
getPrivateKeyOrNull�(RunningInstance):�String0%���(0/1)0%���(0/19)0%���(0/2)
load�(RunningInstance):�Credentials0%���(0/1)0%���(0/17)0%���(0/4)
CredentialsForInstance�(ConcurrentMap,�Supplier):�void100%�(1/1)100%�(12/12)100%�(4/4)

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.ec2.compute.functions;
20
21import�static�com.google.common.base.Preconditions.checkNotNull;
22
23import�java.util.concurrent.ConcurrentMap;
24import�java.util.concurrent.ExecutionException;
25
26import�javax.inject.Inject;
27import�javax.inject.Singleton;
28
29import�org.jclouds.compute.domain.Image;
30import�org.jclouds.domain.Credentials;
31import�org.jclouds.ec2.compute.domain.RegionAndName;
32import�org.jclouds.ec2.domain.KeyPair;
33import�org.jclouds.ec2.domain.RunningInstance;
34
35import�com.google.common.annotations.VisibleForTesting;
36import�com.google.common.base.Supplier;
37import�com.google.common.cache.CacheLoader;
38import�com.google.common.cache.LoadingCache;
39
40/**
41�*�
42�*�@author�Adrian�Cole
43�*/
44@Singleton
45public�class�CredentialsForInstance�extends�CacheLoader<RunningInstance,�Credentials>�{
46���private�final�ConcurrentMap<RegionAndName,�KeyPair>�credentialsMap;
47���private�final�Supplier<LoadingCache<RegionAndName,�?�extends�Image>>�imageMap;
48
49���@Inject
50���CredentialsForInstance(ConcurrentMap<RegionAndName,�KeyPair>�credentialsMap,
51���������Supplier<LoadingCache<RegionAndName,�?�extends�Image>>�imageMap)�{
52������this.credentialsMap�=�checkNotNull(credentialsMap,�"credentialsMap");
53������this.imageMap�=�imageMap;
54���}
55
56���@Override
57���public�Credentials�load(RunningInstance�instance)�throws�ExecutionException�{
58������Credentials�credentials�=�null;//�default�if�no�keypair�exists
59������if�(instance.getKeyName()�!=�null)�{
60���������credentials�=�new�Credentials(getLoginAccountFor(instance),�getPrivateKeyOrNull(instance));
61������}
62������return�credentials;
63���}
64
65���@VisibleForTesting
66���String�getPrivateKeyOrNull(RunningInstance�instance)�throws�ExecutionException�{
67������KeyPair�keyPair�=�credentialsMap.get(new�RegionAndName(instance.getRegion(),�instance.getKeyName()));
68������return�keyPair�!=�null�?�keyPair.getKeyMaterial()�:�null;
69���}
70
71���@VisibleForTesting
72���String�getLoginAccountFor(RunningInstance�from)�throws�ExecutionException�{
73������return�imageMap.get().get(new�RegionAndName(from.getRegion(),�from.getImageId())).getDefaultCredentials().identity;
74���}
75}

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