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

COVERAGE SUMMARY FOR SOURCE FILE [EC2HardwareBuilder.java]

nameclass, %method, %block, %line, %
EC2HardwareBuilder.java100% (4/4)76%  (29/38)81%  (601/739)74%  (45.2/61)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2HardwareBuilder$RequiresRootDeviceType100% (1/1)67%  (2/3)41%  (16/39)68%  (3.4/5)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
apply (Image): boolean 100% (1/1)39%  (7/18)38%  (0.4/1)
EC2HardwareBuilder$RequiresRootDeviceType (RootDeviceType): void 100% (1/1)100% (9/9)100% (3/3)
     
class EC2HardwareBuilder$RequiresVirtualizationType100% (1/1)67%  (2/3)69%  (27/39)80%  (4/5)
toString (): String 0%   (0/1)0%   (0/12)0%   (0/1)
EC2HardwareBuilder$RequiresVirtualizationType (VirtualizationType): void 100% (1/1)100% (9/9)100% (3/3)
apply (Image): boolean 100% (1/1)100% (18/18)100% (1/1)
     
class EC2HardwareBuilder$IsWindows100% (1/1)67%  (2/3)76%  (13/17)61%  (1.8/3)
toString (): String 0%   (0/1)0%   (0/2)0%   (0/1)
apply (Image): boolean 100% (1/1)83%  (10/12)83%  (0.8/1)
EC2HardwareBuilder$IsWindows (): void 100% (1/1)100% (3/3)100% (1/1)
     
class EC2HardwareBuilder100% (1/1)79%  (23/29)85%  (545/644)75%  (36/48)
EC2HardwareBuilder (): void 0%   (0/1)0%   (0/25)0%   (0/7)
m1_small (): EC2HardwareBuilder 0%   (0/1)0%   (0/32)0%   (0/1)
name (String): EC2HardwareBuilder 0%   (0/1)0%   (0/7)0%   (0/1)
supportsImage (Predicate): EC2HardwareBuilder 0%   (0/1)0%   (0/7)0%   (0/1)
uri (URI): EC2HardwareBuilder 0%   (0/1)0%   (0/7)0%   (0/1)
userMetadata (Map): EC2HardwareBuilder 0%   (0/1)0%   (0/7)0%   (0/1)
build (): Hardware 100% (1/1)74%  (37/50)73%  (5.1/7)
supportsImageIds (String []): EC2HardwareBuilder 100% (1/1)94%  (16/17)98%  (2.9/3)
EC2HardwareBuilder (String): void 100% (1/1)100% (26/26)100% (7/7)
c1_medium (): EC2HardwareBuilder 100% (1/1)100% (34/34)100% (1/1)
c1_xlarge (): EC2HardwareBuilder 100% (1/1)100% (58/58)100% (1/1)
cc1_4xlarge (): EC2HardwareBuilder 100% (1/1)100% (47/47)100% (1/1)
id (String): EC2HardwareBuilder 100% (1/1)100% (7/7)100% (1/1)
ids (String): EC2HardwareBuilder 100% (1/1)100% (7/7)100% (1/1)
is64Bit (boolean): EC2HardwareBuilder 100% (1/1)100% (10/10)100% (2/2)
location (Location): EC2HardwareBuilder 100% (1/1)100% (7/7)100% (1/1)
m1_large (): EC2HardwareBuilder 100% (1/1)100% (42/42)100% (1/1)
m1_small32 (): EC2HardwareBuilder 100% (1/1)100% (34/34)100% (1/1)
m1_xlarge (): EC2HardwareBuilder 100% (1/1)100% (58/58)100% (1/1)
m2_2xlarge (): EC2HardwareBuilder 100% (1/1)100% (34/34)100% (1/1)
m2_4xlarge (): EC2HardwareBuilder 100% (1/1)100% (42/42)100% (1/1)
m2_xlarge (): EC2HardwareBuilder 100% (1/1)100% (26/26)100% (1/1)
processors (List): EC2HardwareBuilder 100% (1/1)100% (7/7)100% (1/1)
providerId (String): EC2HardwareBuilder 100% (1/1)100% (7/7)100% (1/1)
ram (int): EC2HardwareBuilder 100% (1/1)100% (7/7)100% (1/1)
rootDeviceType (RootDeviceType): EC2HardwareBuilder 100% (1/1)100% (8/8)100% (2/2)
t1_micro (): EC2HardwareBuilder 100% (1/1)100% (16/16)100% (1/1)
virtualizationType (VirtualizationType): EC2HardwareBuilder 100% (1/1)100% (8/8)100% (2/2)
volumes (List): EC2HardwareBuilder 100% (1/1)100% (7/7)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.domain;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22import static com.google.common.base.Preconditions.checkNotNull;
23import static com.google.common.base.Predicates.not;
24import static org.jclouds.compute.predicates.ImagePredicates.any;
25import static org.jclouds.compute.predicates.ImagePredicates.idIn;
26 
27import java.net.URI;
28import java.util.Arrays;
29import java.util.List;
30import java.util.Map;
31 
32import org.jclouds.compute.domain.Hardware;
33import org.jclouds.compute.domain.HardwareBuilder;
34import org.jclouds.compute.domain.Image;
35import org.jclouds.compute.domain.OsFamily;
36import org.jclouds.compute.domain.Processor;
37import org.jclouds.compute.domain.Volume;
38import org.jclouds.compute.domain.internal.VolumeImpl;
39import org.jclouds.compute.predicates.ImagePredicates;
40import org.jclouds.domain.Location;
41import org.jclouds.ec2.domain.InstanceType;
42import org.jclouds.ec2.domain.RootDeviceType;
43import org.jclouds.ec2.domain.VirtualizationType;
44 
45import com.google.common.base.Predicate;
46import com.google.common.base.Predicates;
47import com.google.common.collect.ImmutableList;
48 
49/**
50 * 
51 * @author Adrian Cole
52 * @see <a
53 *      href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html"
54 *      />
55 */
56public class EC2HardwareBuilder extends HardwareBuilder {
57   private Predicate<Image> rootDeviceType = any();
58   private Predicate<Image> virtualizationType = Predicates.or(new IsWindows(), new RequiresVirtualizationType(
59            VirtualizationType.PARAVIRTUAL));
60   private Predicate<Image> imageIds = any();
61   private Predicate<Image> is64Bit = any();
62 
63   public EC2HardwareBuilder() {
64      this.supportsImage = null;
65   }
66 
67   /**
68    * evaluates true if the Image has the following rootDeviceType
69    * 
70    * @param type
71    *           rootDeviceType of the image
72    * @return predicate
73    */
74   public static class RequiresRootDeviceType implements Predicate<Image> {
75      final RootDeviceType type;
76 
77      public RequiresRootDeviceType(final RootDeviceType type) {
78         this.type = checkNotNull(type, "type must be defined");
79      }
80 
81      @Override
82      public boolean apply(Image image) {
83         return image.getUserMetadata().containsKey("rootDeviceType")
84                  && type == RootDeviceType.fromValue(image.getUserMetadata().get("rootDeviceType"));
85      }
86 
87      @Override
88      public String toString() {
89         return "requiresRootDeviceType(" + type + ")";
90      }
91 
92   }
93 
94   public static class IsWindows implements Predicate<Image> {
95 
96      @Override
97      public boolean apply(Image image) {
98         return image.getOperatingSystem() != null && OsFamily.WINDOWS == image.getOperatingSystem().getFamily();
99      }
100 
101      @Override
102      public String toString() {
103         return "isWindows()";
104      }
105 
106   }
107 
108   /**
109    * evaluates true if the Image requires the following virtualizationType
110    * 
111    * @param type
112    *           virtualizationType of the image
113    * @return predicate
114    */
115   public static class RequiresVirtualizationType implements Predicate<Image> {
116      final VirtualizationType type;
117 
118      public RequiresVirtualizationType(final VirtualizationType type) {
119         this.type = checkNotNull(type, "type must be defined");
120      }
121 
122      @Override
123      public boolean apply(Image image) {
124         return image.getOperatingSystem() != null && image.getOperatingSystem().getArch() != null
125                  && type == VirtualizationType.fromValue(image.getOperatingSystem().getArch());
126      }
127 
128      @Override
129      public String toString() {
130         return "requiresVirtualizationType(" + type + ")";
131      }
132 
133   }
134 
135   public EC2HardwareBuilder(String instanceType) {
136      ids(instanceType);
137   }
138 
139   public EC2HardwareBuilder virtualizationType(VirtualizationType virtualizationType) {
140      this.virtualizationType = new RequiresVirtualizationType(virtualizationType);
141      return this;
142   }
143 
144   public EC2HardwareBuilder rootDeviceType(RootDeviceType rootDeviceType) {
145      this.rootDeviceType = new RequiresRootDeviceType(rootDeviceType);
146      return this;
147   }
148 
149   public EC2HardwareBuilder supportsImageIds(String... ids) {
150      checkArgument(ids != null && ids.length > 0, "ids must be specified");
151      this.imageIds = idIn(Arrays.asList(ids));
152      return this;
153   }
154 
155   public EC2HardwareBuilder ids(String id) {
156      return EC2HardwareBuilder.class.cast(super.ids(id));
157   }
158 
159   public EC2HardwareBuilder ram(int ram) {
160      return EC2HardwareBuilder.class.cast(super.ram(ram));
161   }
162 
163   public EC2HardwareBuilder processors(List<Processor> processors) {
164      return EC2HardwareBuilder.class.cast(super.processors(processors));
165   }
166 
167   public EC2HardwareBuilder volumes(List<Volume> volumes) {
168      return EC2HardwareBuilder.class.cast(super.volumes(volumes));
169   }
170 
171   public EC2HardwareBuilder supportsImage(Predicate<Image> supportsImage) {
172      return EC2HardwareBuilder.class.cast(super.supportsImage(supportsImage));
173   }
174 
175   public EC2HardwareBuilder is64Bit(boolean is64Bit) {
176      this.is64Bit = is64Bit ? ImagePredicates.is64Bit() : not(ImagePredicates.is64Bit());
177      return this;
178   }
179 
180   public EC2HardwareBuilder id(String id) {
181      return EC2HardwareBuilder.class.cast(super.id(id));
182   }
183 
184   @Override
185   public EC2HardwareBuilder providerId(String providerId) {
186      return EC2HardwareBuilder.class.cast(super.providerId(providerId));
187   }
188 
189   @Override
190   public EC2HardwareBuilder name(String name) {
191      return EC2HardwareBuilder.class.cast(super.name(name));
192   }
193 
194   @Override
195   public EC2HardwareBuilder location(Location location) {
196      return EC2HardwareBuilder.class.cast(super.location(location));
197   }
198 
199   @Override
200   public EC2HardwareBuilder uri(URI uri) {
201      return EC2HardwareBuilder.class.cast(super.uri(uri));
202   }
203 
204   @Override
205   public EC2HardwareBuilder userMetadata(Map<String, String> userMetadata) {
206      return EC2HardwareBuilder.class.cast(super.userMetadata(userMetadata));
207   }
208 
209   /**
210    * @see InstanceType#M1_SMALL
211    */
212   public static EC2HardwareBuilder m1_small32() {
213      return new EC2HardwareBuilder(InstanceType.M1_SMALL).ram(1740).processors(
214               ImmutableList.of(new Processor(1.0, 1.0))).volumes(
215               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(150.0f,
216                        "/dev/sda2", false, false))).is64Bit(false);
217   }
218   
219   /**
220    * @see InstanceType#M1_SMALL
221    */
222   public static EC2HardwareBuilder m1_small() {
223      return new EC2HardwareBuilder(InstanceType.M1_SMALL).ram(1740).processors(
224               ImmutableList.of(new Processor(1.0, 1.0))).volumes(
225               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(150.0f,
226                        "/dev/sda2", false, false)));
227   }
228   
229   /**
230    * @see InstanceType#T1_MICRO
231    */
232   public static EC2HardwareBuilder t1_micro() {
233      return new EC2HardwareBuilder(InstanceType.T1_MICRO).ram(630).processors(
234               ImmutableList.of(new Processor(1.0, 1.0))).rootDeviceType(RootDeviceType.EBS);
235   }
236 
237   /**
238    * @see InstanceType#M1_LARGE
239    */
240   public static EC2HardwareBuilder m1_large() {
241      return new EC2HardwareBuilder(InstanceType.M1_LARGE).ram(7680).processors(
242               ImmutableList.of(new Processor(2.0, 2.0))).volumes(
243               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
244                        "/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false))).is64Bit(true);
245   }
246 
247   /**
248    * @see InstanceType#M1_XLARGE
249    */
250   public static EC2HardwareBuilder m1_xlarge() {
251      return new EC2HardwareBuilder(InstanceType.M1_XLARGE).ram(15360).processors(
252               ImmutableList.of(new Processor(4.0, 2.0))).volumes(
253               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
254                        "/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false), new VolumeImpl(
255                        420.0f, "/dev/sdd", false, false), new VolumeImpl(420.0f, "/dev/sde", false, false))).is64Bit(
256               true);
257   }
258 
259   /**
260    * @see InstanceType#M2_XLARGE
261    */
262   public static EC2HardwareBuilder m2_xlarge() {
263      return new EC2HardwareBuilder(InstanceType.M2_XLARGE).ram(17510).processors(
264               ImmutableList.of(new Processor(2.0, 3.25))).volumes(
265               ImmutableList.<Volume> of(new VolumeImpl(420.0f, "/dev/sda1", true, false))).is64Bit(true);
266   }
267 
268   /**
269    * @see InstanceType#M2_2XLARGE
270    */
271   public static EC2HardwareBuilder m2_2xlarge() {
272      return new EC2HardwareBuilder(InstanceType.M2_2XLARGE).ram(35020).processors(
273               ImmutableList.of(new Processor(4.0, 3.25))).volumes(
274               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(840.0f,
275                        "/dev/sdb", false, false))).is64Bit(true);
276   }
277 
278   /**
279    * @see InstanceType#M2_4XLARGE
280    */
281   public static EC2HardwareBuilder m2_4xlarge() {
282      return new EC2HardwareBuilder(InstanceType.M2_4XLARGE).ram(70041).processors(
283               ImmutableList.of(new Processor(8.0, 3.25))).volumes(
284               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(840.0f,
285                        "/dev/sdb", false, false), new VolumeImpl(840.0f, "/dev/sdc", false, false))).is64Bit(true);
286   }
287 
288   /**
289    * @see InstanceType#C1_MEDIUM
290    */
291   public static EC2HardwareBuilder c1_medium() {
292      return new EC2HardwareBuilder(InstanceType.C1_MEDIUM).ram(1740).processors(
293               ImmutableList.of(new Processor(2.0, 2.5))).volumes(
294               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(340.0f,
295                        "/dev/sda2", false, false))).is64Bit(false);
296   }
297 
298   /**
299    * @see InstanceType#C1_XLARGE
300    */
301   public static EC2HardwareBuilder c1_xlarge() {
302      return new EC2HardwareBuilder(InstanceType.C1_XLARGE).ram(7168).processors(
303               ImmutableList.of(new Processor(8.0, 2.5))).volumes(
304               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
305                        "/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false), new VolumeImpl(
306                        420.0f, "/dev/sdd", false, false), new VolumeImpl(420.0f, "/dev/sde", false, false))).is64Bit(
307               true);
308   }
309 
310   public static EC2HardwareBuilder cc1_4xlarge() {
311      return new EC2HardwareBuilder(InstanceType.CC1_4XLARGE).ram(23 * 1024).processors(
312               ImmutableList.of(new Processor(4.0, 4.0), new Processor(4.0, 4.0))).volumes(
313               ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(840.0f,
314                        "/dev/sdb", false, false), new VolumeImpl(840.0f, "/dev/sdc", false, false)))
315               .virtualizationType(VirtualizationType.HVM);
316   }
317 
318   @SuppressWarnings("unchecked")
319   @Override
320   public Hardware build() {
321      boolean reset = false;
322      if (this.supportsImage == null)
323         reset = true;
324      try {
325         supportsImage = Predicates.<Image> and(rootDeviceType, virtualizationType, imageIds, is64Bit);
326         return super.build();
327      } finally {
328         if (reset)
329            this.supportsImage = null;
330      }
331 
332   }
333 
334}

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