EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.compute.config]

COVERAGE SUMMARY FOR SOURCE FILE [BaseComputeServiceContextModule.java]

nameclass, %method, %block, %line, %
BaseComputeServiceContextModule.java67%  (10/15)43%  (15/35)58%  (204/350)55%  (22/40)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BaseComputeServiceContextModule$110%   (0/1)0%   (0/2)0%   (0/9)0%   (0/2)
BaseComputeServiceContextModule$11 (BaseComputeServiceContextModule): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (ComputeMetadata): String 0%   (0/1)0%   (0/3)0%   (0/1)
     
class BaseComputeServiceContextModule$70%   (0/1)0%   (0/2)0%   (0/13)0%   (0/2)
BaseComputeServiceContextModule$7 (BaseComputeServiceContextModule): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (Set): Map 0%   (0/1)0%   (0/7)0%   (0/1)
     
class BaseComputeServiceContextModule$7$10%   (0/1)0%   (0/2)0%   (0/9)0%   (0/2)
BaseComputeServiceContextModule$7$1 (BaseComputeServiceContextModule$7): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (Image): String 0%   (0/1)0%   (0/3)0%   (0/1)
     
class BaseComputeServiceContextModule$90%   (0/1)0%   (0/2)0%   (0/13)0%   (0/2)
BaseComputeServiceContextModule$9 (BaseComputeServiceContextModule): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (Set): Map 0%   (0/1)0%   (0/7)0%   (0/1)
     
class BaseComputeServiceContextModule$9$10%   (0/1)0%   (0/2)0%   (0/9)0%   (0/2)
BaseComputeServiceContextModule$9$1 (BaseComputeServiceContextModule$9): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (Hardware): String 0%   (0/1)0%   (0/3)0%   (0/1)
     
class BaseComputeServiceContextModule$RunScriptOnNodeFactoryImpl100% (1/1)25%  (1/4)14%  (9/63)33%  (3/9)
create (NodeMetadata, Statement): RunScriptOnNode 0%   (0/1)0%   (0/6)0%   (0/1)
create (NodeMetadata, Statement, RunScriptOptions): RunScriptOnNode 0%   (0/1)0%   (0/39)0%   (0/4)
create (NodeMetadata, String): RunScriptOnNode 0%   (0/1)0%   (0/9)0%   (0/1)
BaseComputeServiceContextModule$RunScriptOnNodeFactoryImpl (BaseComputeServic... 100% (1/1)100% (9/9)100% (3/3)
     
class BaseComputeServiceContextModule$10100% (1/1)50%  (1/2)64%  (9/14)50%  (1/2)
get (): Set 0%   (0/1)0%   (0/5)0%   (0/1)
BaseComputeServiceContextModule$10 (BaseComputeServiceContextModule, Supplier... 100% (1/1)100% (9/9)100% (1/1)
     
class BaseComputeServiceContextModule$8100% (1/1)50%  (1/2)64%  (9/14)50%  (1/2)
get (): Set 0%   (0/1)0%   (0/5)0%   (0/1)
BaseComputeServiceContextModule$8 (BaseComputeServiceContextModule, Supplier)... 100% (1/1)100% (9/9)100% (1/1)
     
class BaseComputeServiceContextModule100% (1/1)55%  (6/11)83%  (141/170)76%  (16/21)
indexer (): Function 0%   (0/1)0%   (0/5)0%   (0/1)
provideImageMap (Supplier): Supplier 0%   (0/1)0%   (0/7)0%   (0/1)
provideSizeMap (Supplier): Supplier 0%   (0/1)0%   (0/7)0%   (0/1)
provideTemplate (Injector, TemplateBuilder): TemplateBuilder 0%   (0/1)0%   (0/8)0%   (0/1)
provideTemplateOptions (Injector, TemplateOptions): TemplateOptions 0%   (0/1)0%   (0/2)0%   (0/1)
BaseComputeServiceContextModule (): void 100% (1/1)100% (8/8)100% (2/2)
configure (): void 100% (1/1)100% (96/96)100% (10/10)
provideNamingConvention (): String 100% (1/1)100% (2/2)100% (1/1)
provideOsVersionMap (ComputeServiceConstants$ReferenceData, Json): Map 100% (1/1)100% (11/11)100% (1/1)
supplyImageCache (long, Supplier): Supplier 100% (1/1)100% (12/12)100% (1/1)
supplySizeCache (long, Supplier): Supplier 100% (1/1)100% (12/12)100% (1/1)
     
class BaseComputeServiceContextModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
BaseComputeServiceContextModule$1 (BaseComputeServiceContextModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class BaseComputeServiceContextModule$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
BaseComputeServiceContextModule$2 (BaseComputeServiceContextModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class BaseComputeServiceContextModule$3100% (1/1)100% (1/1)100% (6/6)100% (1/1)
BaseComputeServiceContextModule$3 (BaseComputeServiceContextModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class BaseComputeServiceContextModule$4100% (1/1)100% (1/1)100% (6/6)100% (1/1)
BaseComputeServiceContextModule$4 (BaseComputeServiceContextModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class BaseComputeServiceContextModule$5100% (1/1)100% (1/1)100% (6/6)100% (1/1)
BaseComputeServiceContextModule$5 (BaseComputeServiceContextModule): void 100% (1/1)100% (6/6)100% (1/1)
     
class BaseComputeServiceContextModule$6100% (1/1)100% (1/1)100% (6/6)100% (1/1)
BaseComputeServiceContextModule$6 (BaseComputeServiceContextModule): void 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.compute.config;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
23import static org.jclouds.compute.domain.OsFamily.UBUNTU;
24 
25import java.util.Map;
26import java.util.Set;
27import java.util.concurrent.Callable;
28import java.util.concurrent.atomic.AtomicReference;
29 
30import javax.inject.Named;
31import javax.inject.Singleton;
32 
33import org.jclouds.collect.Memoized;
34import org.jclouds.compute.callables.RunScriptOnNode;
35import org.jclouds.compute.callables.RunScriptOnNodeAsInitScriptUsingSsh;
36import org.jclouds.compute.callables.RunScriptOnNodeAsInitScriptUsingSshAndBlockUntilComplete;
37import org.jclouds.compute.callables.RunScriptOnNodeUsingSsh;
38import org.jclouds.compute.domain.ComputeMetadata;
39import org.jclouds.compute.domain.Hardware;
40import org.jclouds.compute.domain.Image;
41import org.jclouds.compute.domain.NodeMetadata;
42import org.jclouds.compute.domain.OsFamily;
43import org.jclouds.compute.domain.TemplateBuilder;
44import org.jclouds.compute.functions.CreateSshClientOncePortIsListeningOnNode;
45import org.jclouds.compute.functions.TemplateOptionsToStatement;
46import org.jclouds.compute.options.RunScriptOptions;
47import org.jclouds.compute.options.TemplateOptions;
48import org.jclouds.compute.reference.ComputeServiceConstants;
49import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
50import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
51import org.jclouds.json.Json;
52import org.jclouds.location.config.LocationModule;
53import org.jclouds.rest.AuthorizationException;
54import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
55import org.jclouds.scriptbuilder.domain.Statement;
56import org.jclouds.scriptbuilder.domain.Statements;
57import org.jclouds.ssh.SshClient;
58 
59import com.google.common.base.Function;
60import com.google.common.base.Supplier;
61import com.google.common.base.Suppliers;
62import com.google.common.collect.Maps;
63import com.google.inject.AbstractModule;
64import com.google.inject.Inject;
65import com.google.inject.Injector;
66import com.google.inject.Provides;
67import com.google.inject.TypeLiteral;
68import com.google.inject.assistedinject.FactoryModuleBuilder;
69import com.google.inject.name.Names;
70 
71/**
72 * 
73 * @author Adrian Cole
74 */
75public abstract class BaseComputeServiceContextModule extends AbstractModule {
76 
77   @Override
78   protected void configure() {
79      install(new LocationModule(authException));
80      install(new ComputeServiceTimeoutsModule());
81      bind(new TypeLiteral<Function<NodeMetadata, SshClient>>() {
82      }).to(CreateSshClientOncePortIsListeningOnNode.class);
83      bind(new TypeLiteral<Function<TemplateOptions, Statement>>() {
84      }).to(TemplateOptionsToStatement.class);
85 
86      install(new FactoryModuleBuilder()
87            .implement(RunScriptOnNode.class, Names.named("direct"), RunScriptOnNodeUsingSsh.class)
88            .implement(RunScriptOnNode.class, Names.named("blocking"),
89                  RunScriptOnNodeAsInitScriptUsingSshAndBlockUntilComplete.class)
90            .implement(RunScriptOnNode.class, Names.named("nonblocking"), RunScriptOnNodeAsInitScriptUsingSsh.class)
91            .build(RunScriptOnNodeFactoryImpl.Factory.class));
92 
93      install(new PersistNodeCredentialsModule());
94 
95      bind(RunScriptOnNode.Factory.class).to(RunScriptOnNodeFactoryImpl.class);
96 
97      install(new FactoryModuleBuilder().implement(new TypeLiteral<Callable<Void>>() {
98      }, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.class)
99            .implement(new TypeLiteral<Function<NodeMetadata, Void>>() {
100            }, CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.class)
101            .build(CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap.Factory.class));
102 
103      install(new FactoryModuleBuilder().implement(new TypeLiteral<Callable<RunScriptOnNode>>() {
104      }, InitializeRunScriptOnNodeOrPlaceInBadMap.class).build(InitializeRunScriptOnNodeOrPlaceInBadMap.Factory.class));
105   }
106 
107   @Singleton
108   static class RunScriptOnNodeFactoryImpl implements RunScriptOnNode.Factory {
109 
110      static interface Factory {
111 
112         @Named("direct")
113         RunScriptOnNode exec(NodeMetadata node, Statement script, RunScriptOptions options);
114 
115         @Named("blocking")
116         RunScriptOnNode backgroundAndBlockOnComplete(NodeMetadata node, Statement script, RunScriptOptions options);
117 
118         @Named("nonblocking")
119         RunScriptOnNode background(NodeMetadata node, Statement script, RunScriptOptions options);
120      }
121 
122      private final Factory factory;
123 
124      @Inject
125      RunScriptOnNodeFactoryImpl(Factory factory) {
126         this.factory = checkNotNull(factory, "factory");
127      }
128 
129      @Override
130      public RunScriptOnNode create(NodeMetadata node, Statement runScript, RunScriptOptions options) {
131         checkNotNull(node, "node");
132         checkNotNull(runScript, "runScript");
133         checkNotNull(options, "options");
134         return !options.shouldWrapInInitScript() ? factory.exec(node, runScript, options) : (options
135               .shouldBlockOnComplete() ? factory.backgroundAndBlockOnComplete(node, runScript, options) : factory
136               .background(node, runScript, options));
137      }
138 
139      @Override
140      public RunScriptOnNode create(NodeMetadata node, String script) {
141         return create(node, Statements.exec(checkNotNull(script, "script")));
142      }
143 
144      @Override
145      public RunScriptOnNode create(NodeMetadata node, Statement script) {
146         return create(node, script, RunScriptOptions.NONE);
147      }
148   }
149 
150   @Provides
151   @Singleton
152   public Map<OsFamily, Map<String, String>> provideOsVersionMap(ComputeServiceConstants.ReferenceData data, Json json) {
153      return json.fromJson(data.osVersionMapJson, new TypeLiteral<Map<OsFamily, Map<String, String>>>() {
154      }.getType());
155   }
156 
157   /**
158    * The default template if none is provided.
159    */
160   @Provides
161   @Named("DEFAULT")
162   protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
163      return template.osFamily(UBUNTU).osVersionMatches("1[10].[10][04]").os64Bit(true);
164   }
165 
166   /**
167    * The default options if none are provided.
168    */
169   @Provides
170   @Named("DEFAULT")
171   protected TemplateOptions provideTemplateOptions(Injector injector, TemplateOptions options) {
172      return options;
173   }
174 
175   /**
176    * supplies how the tag is encoded into the name. A string of hex characters
177    * is the last argument and tag is the first
178    */
179   @Provides
180   @Named("NAMING_CONVENTION")
181   @Singleton
182   protected String provideNamingConvention() {
183      return "%s-%s";
184   }
185 
186   protected AtomicReference<AuthorizationException> authException = new AtomicReference<AuthorizationException>();
187 
188   @Provides
189   @Singleton
190   protected Supplier<Map<String, ? extends Image>> provideImageMap(@Memoized Supplier<Set<? extends Image>> images) {
191      return Suppliers.compose(new Function<Set<? extends Image>, Map<String, ? extends Image>>() {
192 
193         @Override
194         public Map<String, ? extends Image> apply(Set<? extends Image> from) {
195            return Maps.uniqueIndex(from, new Function<Image, String>() {
196 
197               @Override
198               public String apply(Image from) {
199                  return from.getId();
200               }
201 
202            });
203         }
204 
205      }, images);
206   }
207 
208   @Provides
209   @Singleton
210   @Memoized
211   protected Supplier<Set<? extends Image>> supplyImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
212         final Supplier<Set<? extends Image>> imageSupplier) {
213      return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Image>>(authException,
214            seconds, new Supplier<Set<? extends Image>>() {
215               @Override
216               public Set<? extends Image> get() {
217                  return imageSupplier.get();
218               }
219            });
220   }
221 
222   @Provides
223   @Singleton
224   protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(@Memoized Supplier<Set<? extends Hardware>> sizes) {
225      return Suppliers.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
226 
227         @Override
228         public Map<String, ? extends Hardware> apply(Set<? extends Hardware> from) {
229            return Maps.uniqueIndex(from, new Function<Hardware, String>() {
230 
231               @Override
232               public String apply(Hardware from) {
233                  return from.getId();
234               }
235 
236            });
237         }
238 
239      }, sizes);
240   }
241 
242   @Provides
243   @Singleton
244   @Memoized
245   protected Supplier<Set<? extends Hardware>> supplySizeCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
246         final Supplier<Set<? extends Hardware>> hardwareSupplier) {
247      return new MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Hardware>>(authException,
248            seconds, new Supplier<Set<? extends Hardware>>() {
249               @Override
250               public Set<? extends Hardware> get() {
251                  return hardwareSupplier.get();
252               }
253            });
254   }
255 
256   @Provides
257   @Singleton
258   protected Function<ComputeMetadata, String> indexer() {
259      return new Function<ComputeMetadata, String>() {
260         @Override
261         public String apply(ComputeMetadata from) {
262            return from.getProviderId();
263         }
264      };
265   }
266 
267}

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