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

COVERAGE SUMMARY FOR SOURCE FILE [EC2ComputeServiceDependenciesModule.java]

nameclass, %method, %block, %line, %
EC2ComputeServiceDependenciesModule.java91%  (10/11)60%  (12/20)78%  (172/220)65%  (15/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2ComputeServiceDependenciesModule$100%   (0/1)0%   (0/2)0%   (0/23)0%   (0/3)
EC2ComputeServiceDependenciesModule$10 (EC2ComputeServiceDependenciesModule):... 0%   (0/1)0%   (0/11)0%   (0/2)
get (): String 0%   (0/1)0%   (0/12)0%   (0/1)
     
class EC2ComputeServiceDependenciesModule100% (1/1)33%  (3/9)83%  (118/143)68%  (13/19)
credentialsMap (CacheLoader): Cache 0%   (0/1)0%   (0/4)0%   (0/1)
keypairMap (Injector): ConcurrentMap 0%   (0/1)0%   (0/2)0%   (0/1)
provideServerToNodeState (): Map 0%   (0/1)0%   (0/2)0%   (0/1)
provideSuffix (): Supplier 0%   (0/1)0%   (0/5)0%   (0/1)
securityGroupEventualConsistencyDelay (SecurityGroupPresent, long): Predicate 0%   (0/1)0%   (0/8)0%   (0/1)
securityGroupMap (CacheLoader): Cache 0%   (0/1)0%   (0/4)0%   (0/1)
<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% (90/90)100% (11/11)
     
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)
     
class EC2ComputeServiceDependenciesModule$6100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$6 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (6/6)100% (1/1)
     
class EC2ComputeServiceDependenciesModule$7100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$7 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (6/6)100% (1/1)
     
class EC2ComputeServiceDependenciesModule$8100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$8 (EC2ComputeServiceDependenciesModule): ... 100% (1/1)100% (6/6)100% (1/1)
     
class EC2ComputeServiceDependenciesModule$9100% (1/1)100% (1/1)100% (6/6)100% (1/1)
EC2ComputeServiceDependenciesModule$9 (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.ComputeServiceContext;
33import org.jclouds.compute.domain.Image;
34import org.jclouds.compute.domain.NodeMetadata;
35import org.jclouds.compute.domain.NodeState;
36import org.jclouds.compute.domain.TemplateBuilder;
37import org.jclouds.compute.internal.ComputeServiceContextImpl;
38import org.jclouds.compute.options.TemplateOptions;
39import org.jclouds.domain.Credentials;
40import org.jclouds.ec2.EC2AsyncClient;
41import org.jclouds.ec2.EC2Client;
42import org.jclouds.ec2.compute.EC2ComputeService;
43import org.jclouds.ec2.compute.domain.RegionAndName;
44import org.jclouds.ec2.compute.functions.CreateSecurityGroupIfNeeded;
45import org.jclouds.ec2.compute.functions.CreateUniqueKeyPair;
46import org.jclouds.ec2.compute.functions.CredentialsForInstance;
47import org.jclouds.ec2.compute.functions.RegionAndIdToImage;
48import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
49import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
50import org.jclouds.ec2.compute.options.EC2TemplateOptions;
51import org.jclouds.ec2.compute.predicates.SecurityGroupPresent;
52import org.jclouds.ec2.domain.InstanceState;
53import org.jclouds.ec2.domain.KeyPair;
54import org.jclouds.ec2.domain.RunningInstance;
55import org.jclouds.predicates.RetryablePredicate;
56import org.jclouds.rest.RestContext;
57import org.jclouds.rest.internal.RestContextImpl;
58 
59import com.google.common.base.Function;
60import com.google.common.base.Predicate;
61import com.google.common.base.Supplier;
62import com.google.common.cache.Cache;
63import com.google.common.cache.CacheBuilder;
64import com.google.common.cache.CacheLoader;
65import com.google.common.collect.ImmutableMap;
66import com.google.common.collect.Maps;
67import com.google.inject.AbstractModule;
68import com.google.inject.Injector;
69import com.google.inject.Provides;
70import com.google.inject.Scopes;
71import com.google.inject.TypeLiteral;
72 
73/**
74 * 
75 * @author Adrian Cole
76 */
77public class EC2ComputeServiceDependenciesModule extends AbstractModule {
78 
79   public static final Map<InstanceState, NodeState> instanceToNodeState = ImmutableMap
80         .<InstanceState, NodeState> builder().put(InstanceState.PENDING, NodeState.PENDING)
81         .put(InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN, NodeState.PENDING)
82         .put(InstanceState.TERMINATED, NodeState.TERMINATED).put(InstanceState.STOPPING, NodeState.PENDING)
83         .put(InstanceState.STOPPED, NodeState.SUSPENDED).put(InstanceState.UNRECOGNIZED, NodeState.UNRECOGNIZED)
84         .build();
85 
86   @Singleton
87   @Provides
88   Map<InstanceState, NodeState> provideServerToNodeState() {
89      return instanceToNodeState;
90   }
91 
92   @Override
93   protected void configure() {
94      bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
95      bind(TemplateOptions.class).to(EC2TemplateOptions.class);
96      bind(ComputeService.class).to(EC2ComputeService.class);
97      bind(new TypeLiteral<Function<RunningInstance, NodeMetadata>>() {
98      }).to(RunningInstanceToNodeMetadata.class);
99      bind(new TypeLiteral<CacheLoader<RunningInstance, Credentials>>() {
100      }).to(CredentialsForInstance.class);
101      bind(new TypeLiteral<CacheLoader<RegionAndName, String>>() {
102      }).to(CreateSecurityGroupIfNeeded.class);
103      bind(new TypeLiteral<Function<RegionAndName, KeyPair>>() {
104      }).to(CreateUniqueKeyPair.class);
105      bind(new TypeLiteral<CacheLoader<RegionAndName, Image>>() {
106      }).to(RegionAndIdToImage.class);
107      bind(new TypeLiteral<ComputeServiceContext>() {
108      }).to(new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
109      }).in(Scopes.SINGLETON);
110      bind(new TypeLiteral<RestContext<EC2Client, EC2AsyncClient>>() {
111      }).to(new TypeLiteral<RestContextImpl<EC2Client, EC2AsyncClient>>() {
112      }).in(Scopes.SINGLETON);
113   }
114 
115   @Provides
116   @Singleton
117   Supplier<String> provideSuffix() {
118      return new Supplier<String>() {
119         final SecureRandom random = new SecureRandom();
120 
121         @Override
122         public String get() {
123            return random.nextInt(100) + "";
124         }
125      };
126 
127   }
128 
129   @Provides
130   @Singleton
131   protected Cache<RunningInstance, Credentials> credentialsMap(CacheLoader<RunningInstance, Credentials> in) {
132      return CacheBuilder.newBuilder().build(in);
133   }
134 
135   @Provides
136   @Singleton
137   protected ConcurrentMap<RegionAndName, KeyPair> keypairMap(Injector i) {
138      return Maps.newConcurrentMap();
139   }
140   
141   @Provides
142   @Singleton
143   @Named("SECURITY")
144   protected Cache<RegionAndName, String> securityGroupMap(CacheLoader<RegionAndName, String> in) {
145      return CacheBuilder.newBuilder().build(in);
146   }
147   
148   @Provides
149   @Singleton
150   @Named("SECURITY")
151   protected Predicate<RegionAndName> securityGroupEventualConsistencyDelay(SecurityGroupPresent in,
152         @Named(PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT) long msDelay) {
153      return new RetryablePredicate<RegionAndName>(in, msDelay, 100l, TimeUnit.MILLISECONDS);
154   }
155   
156}

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