EMMA Coverage Report (generated Wed Jun 22 19:47:49 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)75%  (172/228)60%  (15/25)

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)78%  (118/151)62%  (13/21)
amiOwners (String): String [] 0%   (0/1)0%   (0/16)0%   (0/3)
credentialsMap (Function): Map 0%   (0/1)0%   (0/2)0%   (0/1)
provideImageMap (Function): Map 0%   (0/1)0%   (0/6)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)
securityGroupMap (Function): Map 0%   (0/1)0%   (0/2)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 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * 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, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.ec2.compute.config;
20 
21import static com.google.common.collect.Iterables.toArray;
22import static com.google.common.collect.Maps.newLinkedHashMap;
23import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
24 
25import java.security.SecureRandom;
26import java.util.Map;
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.domain.RegionNameAndIngressRules;
45import org.jclouds.ec2.compute.functions.CreateSecurityGroupIfNeeded;
46import org.jclouds.ec2.compute.functions.CreateUniqueKeyPair;
47import org.jclouds.ec2.compute.functions.CredentialsForInstance;
48import org.jclouds.ec2.compute.functions.RegionAndIdToImage;
49import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
50import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
51import org.jclouds.ec2.compute.options.EC2TemplateOptions;
52import org.jclouds.ec2.domain.InstanceState;
53import org.jclouds.ec2.domain.KeyPair;
54import org.jclouds.ec2.domain.RunningInstance;
55import org.jclouds.rest.RestContext;
56import org.jclouds.rest.internal.RestContextImpl;
57 
58import com.google.common.base.Function;
59import com.google.common.base.Splitter;
60import com.google.common.base.Supplier;
61import com.google.common.collect.ImmutableMap;
62import com.google.common.collect.MapMaker;
63import com.google.inject.AbstractModule;
64import com.google.inject.Provides;
65import com.google.inject.Scopes;
66import com.google.inject.TypeLiteral;
67 
68/**
69 * 
70 * @author Adrian Cole
71 */
72public class EC2ComputeServiceDependenciesModule extends AbstractModule {
73 
74   public static final Map<InstanceState, NodeState> instanceToNodeState = ImmutableMap
75            .<InstanceState, NodeState> builder().put(InstanceState.PENDING, NodeState.PENDING).put(
76                     InstanceState.RUNNING, NodeState.RUNNING).put(InstanceState.SHUTTING_DOWN, NodeState.PENDING).put(
77                     InstanceState.TERMINATED, NodeState.TERMINATED).put(InstanceState.STOPPING, NodeState.PENDING)
78            .put(InstanceState.STOPPED, NodeState.SUSPENDED).put(InstanceState.UNRECOGNIZED, NodeState.UNRECOGNIZED)
79            .build();
80 
81   @Singleton
82   @Provides
83   Map<InstanceState, NodeState> provideServerToNodeState() {
84      return instanceToNodeState;
85   }
86 
87   @Override
88   protected void configure() {
89      bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
90      bind(TemplateOptions.class).to(EC2TemplateOptions.class);
91      bind(ComputeService.class).to(EC2ComputeService.class);
92      bind(new TypeLiteral<Function<RunningInstance, NodeMetadata>>() {
93      }).to(RunningInstanceToNodeMetadata.class);
94      bind(new TypeLiteral<Function<RunningInstance, Credentials>>() {
95      }).to(CredentialsForInstance.class);
96      bind(new TypeLiteral<Function<RegionNameAndIngressRules, String>>() {
97      }).to(CreateSecurityGroupIfNeeded.class);
98      bind(new TypeLiteral<Function<RegionAndName, KeyPair>>() {
99      }).to(CreateUniqueKeyPair.class);
100      bind(new TypeLiteral<Function<RegionAndName, Image>>() {
101      }).to(RegionAndIdToImage.class);
102      bind(new TypeLiteral<ComputeServiceContext>() {
103      }).to(new TypeLiteral<ComputeServiceContextImpl<EC2Client, EC2AsyncClient>>() {
104      }).in(Scopes.SINGLETON);
105      bind(new TypeLiteral<RestContext<EC2Client, EC2AsyncClient>>() {
106      }).to(new TypeLiteral<RestContextImpl<EC2Client, EC2AsyncClient>>() {
107      }).in(Scopes.SINGLETON);
108   }
109 
110   @Provides
111   @Singleton
112   Supplier<String> provideSuffix() {
113      return new Supplier<String>() {
114         final SecureRandom random = new SecureRandom();
115 
116         @Override
117         public String get() {
118            return random.nextInt(100) + "";
119         }
120      };
121 
122   }
123 
124   @Provides
125   @Singleton
126   protected final Map<RegionAndName, KeyPair> credentialsMap(Function<RegionAndName, KeyPair> in) {
127      // doesn't seem to clear when someone issues remove(key)
128      // return new MapMaker().makeComputingMap(in);
129      return newLinkedHashMap();
130   }
131 
132   @Provides
133   @Singleton
134   @Named("SECURITY")
135   protected final Map<RegionAndName, String> securityGroupMap(Function<RegionNameAndIngressRules, String> in) {
136      // doesn't seem to clear when someone issues remove(key)
137      // return new MapMaker().makeComputingMap(in);
138      return newLinkedHashMap();
139   }
140 
141   @Provides
142   @Singleton
143   @Named(PROPERTY_EC2_AMI_OWNERS)
144   String[] amiOwners(@Named(PROPERTY_EC2_AMI_OWNERS) String amiOwners) {
145      if (amiOwners.trim().equals(""))
146         return new String[] {};
147      return toArray(Splitter.on(',').split(amiOwners), String.class);
148   }
149 
150   @Provides
151   @Singleton
152   protected Map<RegionAndName, Image> provideImageMap(Function<RegionAndName, Image> regionAndIdToImage) {
153      return new MapMaker().makeComputingMap(regionAndIdToImage);
154   }
155 
156}

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