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

COVERAGE SUMMARY FOR SOURCE FILE [EC2TemplateBuilderImpl.java]

nameclass, %method, %block, %line, %
EC2TemplateBuilderImpl.java100% (2/2)100% (9/9)79%  (126/159)70%  (19/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EC2TemplateBuilderImpl$1100% (1/1)100% (2/2)77%  (70/91)73%  (8/11)
get (): Image 100% (1/1)75%  (64/85)70%  (7/10)
EC2TemplateBuilderImpl$1 (EC2TemplateBuilderImpl): void 100% (1/1)100% (6/6)100% (1/1)
     
class EC2TemplateBuilderImpl100% (1/1)100% (7/7)82%  (56/68)71%  (12/17)
resolveImage (Hardware, Iterable): Image 100% (1/1)29%  (5/17)17%  (1/6)
EC2TemplateBuilderImpl (Supplier, Supplier, Supplier, Supplier, Provider, Pro... 100% (1/1)100% (18/18)100% (4/4)
access$000 (EC2TemplateBuilderImpl): String 100% (1/1)100% (3/3)100% (1/1)
access$100 (EC2TemplateBuilderImpl): String 100% (1/1)100% (3/3)100% (1/1)
access$200 (EC2TemplateBuilderImpl): String 100% (1/1)100% (3/3)100% (1/1)
access$300 (EC2TemplateBuilderImpl): Map 100% (1/1)100% (3/3)100% (1/1)
getImages (): Set 100% (1/1)100% (21/21)100% (6/6)

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.internal;
20 
21import static com.google.common.base.Preconditions.checkArgument;
22 
23import java.util.Map;
24import java.util.NoSuchElementException;
25import java.util.Set;
26 
27import javax.inject.Inject;
28import javax.inject.Named;
29import javax.inject.Provider;
30 
31import org.jclouds.collect.Memoized;
32import org.jclouds.compute.domain.Hardware;
33import org.jclouds.compute.domain.Image;
34import org.jclouds.compute.domain.TemplateBuilder;
35import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
36import org.jclouds.compute.options.TemplateOptions;
37import org.jclouds.domain.Location;
38import org.jclouds.ec2.compute.domain.RegionAndName;
39 
40import com.google.common.base.Supplier;
41import com.google.common.collect.ComputationException;
42 
43/**
44 * 
45 * @author Adrian Cole
46 */
47public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
48 
49   private final Map<RegionAndName, Image> imageMap;
50 
51   @Inject
52   protected EC2TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
53         @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> sizes,
54         Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
55         @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, Map<RegionAndName, Image> imageMap) {
56      super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
57      this.imageMap = imageMap;
58   }
59 
60   final Provider<Image> lazyImageProvider = new Provider<Image>() {
61 
62      @Override
63      public Image get() {
64         if (imageId != null) {
65            String[] regionName = imageId.split("/");
66            checkArgument(regionName.length == 2,
67                  "amazon image ids must include the region ( ex. us-east-1/ami-7ea24a17 ) you specified: " + imageId);
68            RegionAndName key = new RegionAndName(regionName[0], regionName[1]);
69            try {
70               return imageMap.get(key);
71            } catch (NullPointerException nex) {
72               throw new NoSuchElementException(String.format("image %s/%s not found", key.getRegion(), key.getName()));
73            } catch (ComputationException nex) {
74               throw new NoSuchElementException(String.format("image %s/%s not found", key.getRegion(), key.getName()));
75            }
76         }
77         return null;
78      }
79 
80   };
81 
82   /**
83    * @throws NoSuchElementException
84    *            if the image is not found
85    */
86   @Override
87   protected Image resolveImage(Hardware size, Iterable<? extends Image> supportedImages) {
88      try {
89         return super.resolveImage(size, supportedImages);
90      } catch (NoSuchElementException e) {
91         Image returnVal = lazyImageProvider.get();
92         if (returnVal != null)
93            return returnVal;
94         throw e;
95      }
96   }
97 
98   @SuppressWarnings("unchecked")
99   @Override
100   protected Set<? extends Image> getImages() {
101      Set<Image> images = (Set<Image>) this.images.get();
102      if (images.size() == 0) {
103         Image toReturn = lazyImageProvider.get();
104         if (toReturn != null) {
105            images.add(toReturn);
106         }
107      }
108      return images;
109   }
110 
111}

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