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

COVERAGE SUMMARY FOR SOURCE FILE [EC2ComputeServiceDependenciesModule.java]

nameclass, %method, %block, %line, %
EC2ComputeServiceDependenciesModule.java100% (7/7)94%  (17/18)92%  (176/192)92%  (22/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2ComputeServiceDependenciesModule$6100% (1/1)50%  (1/2)48%  (11/23)67%  (2/3)
get (): String 0%   (0/1)0%   (0/12)0%   (0/1)
EC2ComputeServiceDependenciesModule$6 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (11/11)100% (2/2)
     
class EC2ComputeServiceDependenciesModule100% (1/1)100% (11/11)97%  (135/139)95%  (21/22)
bindNodeConverter (RunningInstanceToNodeMetadata, AddElasticIpsToNodemetadata... 100% (1/1)50%  (4/8)67%  (2/3)
<static initializer> 100% (1/1)100% (25/25)100% (1/1)
EC2ComputeServiceDependenciesModule (): void 100% (1/1)100% (3/3)100% (1/1)
configure (): void 100% (1/1)100% (74/74)100% (10/10)
credentialsMap (CacheLoader): LoadingCache 100% (1/1)100% (4/4)100% (1/1)
instanceToElasticIp (CacheLoader): LoadingCache 100% (1/1)100% (4/4)100% (1/1)
keypairMap (Injector): ConcurrentMap 100% (1/1)100% (2/2)100% (1/1)
provideServerToNodeState (): Map 100% (1/1)100% (2/2)100% (1/1)
provideSuffix (): Supplier 100% (1/1)100% (5/5)100% (1/1)
securityGroupEventualConsistencyDelay (SecurityGroupPresent, long): Predicate 100% (1/1)100% (8/8)100% (1/1)
securityGroupMap (CacheLoader): LoadingCache 100% (1/1)100% (4/4)100% (1/1)
     
class EC2ComputeServiceDependenciesModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$1 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (6/6)100% (1/1)
     
class EC2ComputeServiceDependenciesModule$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$2 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (6/6)100% (1/1)
     
class EC2ComputeServiceDependenciesModule$3100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$3 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (6/6)100% (1/1)
     
class EC2ComputeServiceDependenciesModule$4100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$4 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (6/6)100% (1/1)
     
class EC2ComputeServiceDependenciesModule$5100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$5 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (6/6)100% (1/1)

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.config;
20 
21import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT;
22 
23import java.security.SecureRandom;
24import java.util.Map;
25import java.util.concurrent.ConcurrentMap;
26import java.util.concurrent.TimeUnit;
27 
28import javax.inject.Named;
29import javax.inject.Singleton;
30 
31import org.jclouds.compute.ComputeService;
32import org.jclouds.compute.domain.Image;
33import org.jclouds.compute.domain.NodeMetadata;
34import org.jclouds.compute.domain.NodeState;
35import org.jclouds.compute.domain.TemplateBuilder;
36import org.jclouds.compute.options.TemplateOptions;
37import org.jclouds.domain.Credentials;
38import org.jclouds.ec2.compute.EC2ComputeService;
39import org.jclouds.ec2.compute.domain.RegionAndName;
40import org.jclouds.ec2.compute.functions.AddElasticIpsToNodemetadata;
41import org.jclouds.ec2.compute.functions.CreateUniqueKeyPair;
42import org.jclouds.ec2.compute.functions.CredentialsForInstance;
43import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
44import org.jclouds.ec2.compute.functions.WindowsLoginCredentialsFromEncryptedData;
45import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
46import org.jclouds.ec2.compute.loaders.CreateSecurityGroupIfNeeded;
47import org.jclouds.ec2.compute.loaders.LoadPublicIpForInstanceOrNull;
48import org.jclouds.ec2.compute.loaders.RegionAndIdToImage;
49import org.jclouds.ec2.compute.options.EC2TemplateOptions;
50import org.jclouds.ec2.compute.predicates.SecurityGroupPresent;
51import org.jclouds.ec2.domain.InstanceState;
52import org.jclouds.ec2.domain.KeyPair;
53import org.jclouds.ec2.domain.RunningInstance;
54import org.jclouds.ec2.reference.EC2Constants;
55import org.jclouds.predicates.RetryablePredicate;
56 
57import com.google.common.base.Function;
58import com.google.common.base.Functions;
59import com.google.common.base.Predicate;
60import com.google.common.base.Supplier;
61import com.google.common.cache.CacheBuilder;
62import com.google.common.cache.CacheLoader;
63import com.google.common.cache.LoadingCache;
64import com.google.common.collect.ImmutableMap;
65import com.google.common.collect.Maps;
66import com.google.inject.AbstractModule;
67import com.google.inject.Injector;
68import com.google.inject.Provides;
69import com.google.inject.TypeLiteral;
70import com.google.inject.name.Names;
71 
72/**
73 * 
74 * @author Adrian Cole
75 */
76public class EC2ComputeServiceDependenciesModule extends AbstractModule {
77 
78   public static final Map<InstanceState, NodeState> instanceToNodeState = ImmutableMap
79            .<InstanceState, NodeState> builder().put(InstanceState.PENDING, NodeState.PENDING).put(
80                     InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN, NodeState.PENDING).put(
81                     InstanceState.TERMINATED, NodeState.TERMINATED).put(InstanceState.STOPPING, NodeState.PENDING)
82            .put(InstanceState.STOPPED, NodeState.SUSPENDED).put(InstanceState.UNRECOGNIZED, NodeState.UNRECOGNIZED)
83            .build();
84 
85   @Singleton
86   @Provides
87   Map<InstanceState, NodeState> provideServerToNodeState() {
88      return instanceToNodeState;
89   }
90 
91   @Override
92   protected void configure() {
93      bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
94      bind(TemplateOptions.class).to(EC2TemplateOptions.class);
95      bind(ComputeService.class).to(EC2ComputeService.class);
96      bind(new TypeLiteral<CacheLoader<RunningInstance, Credentials>>() {
97      }).to(CredentialsForInstance.class);
98      bind(new TypeLiteral<Function<RegionAndName, KeyPair>>() {
99      }).to(CreateUniqueKeyPair.class);
100      bind(new TypeLiteral<CacheLoader<RegionAndName, Image>>() {
101      }).to(RegionAndIdToImage.class);
102      bind(new TypeLiteral<CacheLoader<RegionAndName, String>>() {
103      }).annotatedWith(Names.named("SECURITY")).to(CreateSecurityGroupIfNeeded.class);
104      bind(new TypeLiteral<CacheLoader<RegionAndName, String>>() {
105      }).annotatedWith(Names.named("ELASTICIP")).to(LoadPublicIpForInstanceOrNull.class);      
106      bind(WindowsLoginCredentialsFromEncryptedData.class);
107   }
108 
109   /**
110    * only add the overhead of looking up ips when we have enabled the auto-allocate functionality
111    */
112   @Provides
113   @Singleton
114   public Function<RunningInstance, NodeMetadata> bindNodeConverter(RunningInstanceToNodeMetadata baseConverter,
115            AddElasticIpsToNodemetadata addElasticIpsToNodemetadata,
116            @Named(EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS) boolean autoAllocateElasticIps) {
117      if (!autoAllocateElasticIps)
118         return baseConverter;
119      return Functions.compose(addElasticIpsToNodemetadata, baseConverter);
120   }
121 
122   @Provides
123   @Singleton
124   Supplier<String> provideSuffix() {
125      return new Supplier<String>() {
126         final SecureRandom random = new SecureRandom();
127 
128         @Override
129         public String get() {
130            return random.nextInt(100) + "";
131         }
132      };
133 
134   }
135 
136   @Provides
137   @Singleton
138   protected LoadingCache<RunningInstance, Credentials> credentialsMap(CacheLoader<RunningInstance, Credentials> in) {
139      return CacheBuilder.newBuilder().build(in);
140   }
141 
142   @Provides
143   @Singleton
144   protected ConcurrentMap<RegionAndName, KeyPair> keypairMap(Injector i) {
145      return Maps.newConcurrentMap();
146   }
147 
148   @Provides
149   @Singleton
150   @Named("SECURITY")
151   protected LoadingCache<RegionAndName, String> securityGroupMap(
152            @Named("SECURITY") CacheLoader<RegionAndName, String> in) {
153      return CacheBuilder.newBuilder().build(in);
154   }
155 
156   @Provides
157   @Singleton
158   @Named("ELASTICIP")
159   protected LoadingCache<RegionAndName, String> instanceToElasticIp(
160            @Named("ELASTICIP") CacheLoader<RegionAndName, String> in) {
161      return CacheBuilder.newBuilder().build(in);
162   }
163 
164   @Provides
165   @Singleton
166   @Named("SECURITY")
167   protected Predicate<RegionAndName> securityGroupEventualConsistencyDelay(SecurityGroupPresent in,
168            @Named(PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT) long msDelay) {
169      return new RetryablePredicate<RegionAndName>(in, msDelay, 100l, TimeUnit.MILLISECONDS);
170   }
171 
172}

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