EMMA Coverage Report (generated Wed Oct 26 13:47:17 EDT 2011)
[all classes][org.jclouds.compute.config]

COVERAGE SUMMARY FOR SOURCE FILE [BaseComputeServiceContextModule.java]

nameclass, %method, %block, %line, %
BaseComputeServiceContextModule.java67%  (10/15)47%  (16/34)59%  (216/366)55%  (24/44)

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

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