EMMA Coverage Report (generated Wed Aug 10 12:30:04 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/230)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)
apply (String): DriveInfo 0%   (0/1)0%   (0/5)0%   (0/1)
     
class ElasticStackComputeServiceContextModule100% (1/1)40%  (2/5)68%  (98/144)78%  (14/18)
cache (ElasticStackComputeServiceContextModule$GetDrive): Map 0%   (0/1)0%   (0/6)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 *
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.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.WellKnownImageToImage;
42import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.DeviceToVolume;
43import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.FindImageForId;
44import org.jclouds.elasticstack.compute.functions.ServerInfoToNodeMetadata.GetImageIdFromServer;
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.collect.MapMaker;
63import com.google.common.collect.Maps;
64import com.google.inject.Provides;
65import com.google.inject.TypeLiteral;
66 
67/**
68 * 
69 * @author Adrian Cole
70 */
71public class ElasticStackComputeServiceContextModule
72         extends
73         ComputeServiceAdapterContextModule<ElasticStackClient, ElasticStackAsyncClient, ServerInfo, Hardware, DriveInfo, Location> {
74 
75   public ElasticStackComputeServiceContextModule() {
76      super(ElasticStackClient.class, ElasticStackAsyncClient.class);
77   }
78 
79   @SuppressWarnings( { "unchecked", "rawtypes" })
80   @Override
81   protected void configure() {
82      super.configure();
83      bind(new TypeLiteral<ComputeServiceAdapter<ServerInfo, Hardware, DriveInfo, Location>>() {
84      }).to(ElasticStackComputeServiceAdapter.class);
85      bind(new TypeLiteral<Function<ServerInfo, NodeMetadata>>() {
86      }).to(ServerInfoToNodeMetadata.class);
87      bind(new TypeLiteral<Function<Image, Image>>() {
88      }).to((Class) IdentityFunction.class);
89      bind(new TypeLiteral<Function<Hardware, Hardware>>() {
90      }).to((Class) IdentityFunction.class);
91      bind(new TypeLiteral<Function<Location, Location>>() {
92      }).to((Class) IdentityFunction.class);
93      bind(new TypeLiteral<Function<Device, Volume>>() {
94      }).to(DeviceToVolume.class);
95      bind(new TypeLiteral<Function<Server, String>>() {
96      }).to(GetImageIdFromServer.class);
97      bind(new TypeLiteral<Function<String, Image>>() {
98      }).to(FindImageForId.class);
99      bind(new TypeLiteral<Function<DriveInfo, Image>>() {
100      }).to(WellKnownImageToImage.class);
101      bind(new TypeLiteral<Supplier<Location>>() {
102      }).to(OnlyLocationOrFirstZone.class);
103   }
104 
105   @Provides
106   @Singleton
107   protected Map<String, DriveInfo> cache(GetDrive getDrive) {
108      return new MapMaker().makeComputingMap(getDrive);
109   }
110 
111   @Singleton
112   public static class GetDrive implements Function<String, DriveInfo> {
113      private final ElasticStackClient client;
114 
115      @Inject
116      public GetDrive(ElasticStackClient client) {
117         this.client = client;
118      }
119 
120      @Override
121      public DriveInfo apply(String input) {
122         return client.getDriveInfo(input);
123      }
124   }
125 
126   @Singleton
127   @Provides
128   protected Map<String, WellKnownImage> provideImages(Json json, @Provider String providerName) throws IOException {
129      List<WellKnownImage> wellKnowns = json.fromJson(Strings2.toStringAndClose(getClass().getResourceAsStream(
130               "/" + providerName + "/preinstalled_images.json")), new TypeLiteral<List<WellKnownImage>>() {
131      }.getType());
132      return Maps.uniqueIndex(wellKnowns, new Function<WellKnownImage, String>() {
133 
134         @Override
135         public String apply(WellKnownImage input) {
136            return input.getUuid();
137         }
138 
139      });
140   }
141 
142   @Provides
143   @Singleton
144   protected Predicate<DriveInfo> supplyDriveUnclaimed(DriveClaimed driveClaimed,
145            ComputeServiceConstants.Timeouts timeouts) {
146      return new RetryablePredicate<DriveInfo>(Predicates.not(driveClaimed), timeouts.nodeRunning, 1000,
147               TimeUnit.MILLISECONDS);
148   }
149}

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