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

COVERAGE SUMMARY FOR SOURCE FILE [ElasticStackComputeServiceContextModule.java]

nameclass, %method, %block, %line, %
ElasticStackComputeServiceContextModule.java79%  (11/14)60%  (12/20)69%  (158/228)58%  (14/24)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ElasticStackComputeServiceContextModule$110%   (0/1)0%   (0/1)0%   (0/6)0%   (0/1)
ElasticStackComputeServiceContextModule$11 (ElasticStackComputeServiceContext... 0%   (0/1)0%   (0/6)0%   (0/1)
     
class ElasticStackComputeServiceContextModule$120%   (0/1)0%   (0/2)0%   (0/9)0%   (0/2)
ElasticStackComputeServiceContextModule$12 (ElasticStackComputeServiceContext... 0%   (0/1)0%   (0/6)0%   (0/1)
apply (WellKnownImage): String 0%   (0/1)0%   (0/3)0%   (0/1)
     
class ElasticStackComputeServiceContextModule$GetDrive0%   (0/1)0%   (0/2)0%   (0/11)0%   (0/4)
ElasticStackComputeServiceContextModule$GetDrive (ElasticStackClient): void 0%   (0/1)0%   (0/6)0%   (0/3)
load (String): DriveInfo 0%   (0/1)0%   (0/5)0%   (0/1)
     
class ElasticStackComputeServiceContextModule100% (1/1)40%  (2/5)69%  (98/142)78%  (14/18)
cache (ElasticStackComputeServiceContextModule$GetDrive): Cache 0%   (0/1)0%   (0/4)0%   (0/1)
provideImages (Json, String): Map 0%   (0/1)0%   (0/30)0%   (0/2)
supplyDriveUnclaimed (DriveClaimed, ComputeServiceConstants$Timeouts): Predicate 0%   (0/1)0%   (0/10)0%   (0/1)
ElasticStackComputeServiceContextModule (): void 100% (1/1)100% (5/5)100% (2/2)
configure (): void 100% (1/1)100% (93/93)100% (12/12)
     
class ElasticStackComputeServiceContextModule$1100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$1 (ElasticStackComputeServiceContextM... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$10100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$10 (ElasticStackComputeServiceContext... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$2100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$2 (ElasticStackComputeServiceContextM... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$3100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$3 (ElasticStackComputeServiceContextM... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$4100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$4 (ElasticStackComputeServiceContextM... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$5100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$5 (ElasticStackComputeServiceContextM... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$6100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$6 (ElasticStackComputeServiceContextM... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$7100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$7 (ElasticStackComputeServiceContextM... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$8100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$8 (ElasticStackComputeServiceContextM... 100% (1/1)100% (6/6)100% (1/1)
     
class ElasticStackComputeServiceContextModule$9100% (1/1)100% (1/1)100% (6/6)100% (1/1)
ElasticStackComputeServiceContextModule$9 (ElasticStackComputeServiceContextM... 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.elasticstack.compute.config;
20 
21import java.io.IOException;
22import java.util.List;
23import java.util.Map;
24import java.util.concurrent.TimeUnit;
25 
26import javax.inject.Inject;
27import javax.inject.Singleton;
28 
29import org.jclouds.compute.ComputeServiceAdapter;
30import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
31import org.jclouds.compute.domain.Hardware;
32import org.jclouds.compute.domain.Image;
33import org.jclouds.compute.domain.NodeMetadata;
34import org.jclouds.compute.domain.Volume;
35import org.jclouds.compute.reference.ComputeServiceConstants;
36import org.jclouds.domain.Location;
37import org.jclouds.elasticstack.ElasticStackAsyncClient;
38import org.jclouds.elasticstack.ElasticStackClient;
39import org.jclouds.elasticstack.compute.ElasticStackComputeServiceAdapter;
40import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata;
41import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.DeviceToVolume;
42import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.FindImageForId;
43import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.GetImageIdFromServer;
44import org.jclouds.elasticstack.compute.functions.WellKnownImageToImage;
45import org.jclouds.elasticstack.domain.Device;
46import org.jclouds.elasticstack.domain.DriveInfo;
47import org.jclouds.elasticstack.domain.Server;
48import org.jclouds.elasticstack.domain.ServerInfo;
49import org.jclouds.elasticstack.domain.WellKnownImage;
50import org.jclouds.elasticstack.predicates.DriveClaimed;
51import org.jclouds.functions.IdentityFunction;
52import org.jclouds.json.Json;
53import org.jclouds.location.Provider;
54import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
55import org.jclouds.predicates.RetryablePredicate;
56import org.jclouds.util.Strings2;
57 
58import com.google.common.base.Function;
59import com.google.common.base.Predicate;
60import com.google.common.base.Predicates;
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.Maps;
66import com.google.inject.Provides;
67import com.google.inject.TypeLiteral;
68 
69/**
70 * 
71 * @author Adrian Cole
72 */
73public class ElasticStackComputeServiceContextModule
74         extends
75         ComputeServiceAdapterContextModule<ElasticStackClient, ElasticStackAsyncClient, ServerInfo, Hardware, DriveInfo, Location> {
76 
77   public ElasticStackComputeServiceContextModule() {
78      super(ElasticStackClient.class, ElasticStackAsyncClient.class);
79   }
80 
81   @SuppressWarnings( { "unchecked", "rawtypes" })
82   @Override
83   protected void configure() {
84      super.configure();
85      bind(new TypeLiteral<ComputeServiceAdapter<ServerInfo, Hardware, DriveInfo, Location>>() {
86      }).to(ElasticStackComputeServiceAdapter.class);
87      bind(new TypeLiteral<Function<ServerInfo, NodeMetadata>>() {
88      }).to(ServerInfoToNodeMetadata.class);
89      bind(new TypeLiteral<Function<Image, Image>>() {
90      }).to((Class) IdentityFunction.class);
91      bind(new TypeLiteral<Function<Hardware, Hardware>>() {
92      }).to((Class) IdentityFunction.class);
93      bind(new TypeLiteral<Function<Location, Location>>() {
94      }).to((Class) IdentityFunction.class);
95      bind(new TypeLiteral<Function<Device, Volume>>() {
96      }).to(DeviceToVolume.class);
97      bind(new TypeLiteral<Function<Server, String>>() {
98      }).to(GetImageIdFromServer.class);
99      bind(new TypeLiteral<Function<String, Image>>() {
100      }).to(FindImageForId.class);
101      bind(new TypeLiteral<Function<DriveInfo, Image>>() {
102      }).to(WellKnownImageToImage.class);
103      bind(new TypeLiteral<Supplier<Location>>() {
104      }).to(OnlyLocationOrFirstZone.class);
105   }
106 
107   @Provides
108   @Singleton
109   protected Cache<String, DriveInfo> cache(GetDrive getDrive) {
110      return CacheBuilder.newBuilder().build(getDrive);
111   }
112 
113   @Singleton
114   public static class GetDrive extends CacheLoader<String, DriveInfo> {
115      private final ElasticStackClient client;
116 
117      @Inject
118      public GetDrive(ElasticStackClient client) {
119         this.client = client;
120      }
121 
122      @Override
123      public DriveInfo load(String input) {
124         return client.getDriveInfo(input);
125      }
126   }
127 
128   @Singleton
129   @Provides
130   protected Map<String, WellKnownImage> provideImages(Json json, @Provider String providerName) throws IOException {
131      List<WellKnownImage> wellKnowns = json.fromJson(Strings2.toStringAndClose(getClass().getResourceAsStream(
132               "/" + providerName + "/preinstalled_images.json")), new TypeLiteral<List<WellKnownImage>>() {
133      }.getType());
134      return Maps.uniqueIndex(wellKnowns, new Function<WellKnownImage, String>() {
135 
136         @Override
137         public String apply(WellKnownImage input) {
138            return input.getUuid();
139         }
140 
141      });
142   }
143 
144   @Provides
145   @Singleton
146   protected Predicate<DriveInfo> supplyDriveUnclaimed(DriveClaimed driveClaimed,
147            ComputeServiceConstants.Timeouts timeouts) {
148      return new RetryablePredicate<DriveInfo>(Predicates.not(driveClaimed), timeouts.nodeRunning, 1000,
149               TimeUnit.MILLISECONDS);
150   }
151}

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