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

COVERAGE SUMMARY FOR SOURCE FILE [RegionAndNameToImageSupplier.java]

nameclass, %method, %block, %line, %
RegionAndNameToImageSupplier.java0%   (0/2)0%   (0/6)0%   (0/140)0%   (0/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RegionAndNameToImageSupplier0%   (0/1)0%   (0/4)0%   (0/125)0%   (0/25)
RegionAndNameToImageSupplier (Set, DescribeImagesParallel, String [], EC2Imag... 0%   (0/1)0%   (0/21)0%   (0/8)
get (): Map 0%   (0/1)0%   (0/59)0%   (0/8)
getDescribeQueriesForOwnersInRegions (Set, String []): Iterable 0%   (0/1)0%   (0/25)0%   (0/5)
getOptionsForOwners (String []): DescribeImagesOptions 0%   (0/1)0%   (0/20)0%   (0/4)
     
class RegionAndNameToImageSupplier$10%   (0/1)0%   (0/2)0%   (0/15)0%   (0/2)
RegionAndNameToImageSupplier$1 (RegionAndNameToImageSupplier): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (Image): RegionAndName 0%   (0/1)0%   (0/9)0%   (0/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.suppliers;
20 
21/**
22 *
23 * Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
24 *
25 * ====================================================================
26 * Licensed under the Apache License, Version 2.0 (the "License");
27 * you may not use this file except in compliance with the License.
28 * You may obtain a copy of the License at
29 *
30 * http://www.apache.org/licenses/LICENSE-2.0
31 *
32 * Unless required by applicable law or agreed to in writing, software
33 * distributed under the License is distributed on an "AS IS" BASIS,
34 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35 * See the License for the specific language governing permissions and
36 * limitations under the License.
37 * ====================================================================
38 */
39 
40import static com.google.common.collect.Iterables.filter;
41import static com.google.common.collect.Iterables.transform;
42import static com.google.common.collect.Maps.uniqueIndex;
43import static org.jclouds.ec2.options.DescribeImagesOptions.Builder.ownedBy;
44import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
45 
46import java.util.Map;
47import java.util.Set;
48import java.util.Map.Entry;
49 
50import javax.annotation.Resource;
51import javax.inject.Inject;
52import javax.inject.Named;
53import javax.inject.Singleton;
54 
55import org.jclouds.compute.domain.Image;
56import org.jclouds.compute.reference.ComputeServiceConstants;
57import org.jclouds.ec2.compute.domain.RegionAndName;
58import org.jclouds.ec2.compute.functions.EC2ImageParser;
59import org.jclouds.ec2.compute.strategy.DescribeImagesParallel;
60import org.jclouds.ec2.options.DescribeImagesOptions;
61import org.jclouds.location.Region;
62import org.jclouds.logging.Logger;
63 
64import com.google.common.base.Function;
65import com.google.common.base.Predicates;
66import com.google.common.base.Supplier;
67import com.google.common.collect.ImmutableMap;
68import com.google.common.collect.ImmutableMap.Builder;
69 
70/**
71 * 
72 * @author Adrian Cole
73 */
74@Singleton
75public class RegionAndNameToImageSupplier implements Supplier<Map<RegionAndName, ? extends Image>> {
76   @Resource
77   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
78   protected Logger logger = Logger.NULL;
79 
80   private final Set<String> regions;
81   private final DescribeImagesParallel describer;
82   private final String[] amiOwners;
83   private final EC2ImageParser parser;
84   private final Map<RegionAndName, Image> images;
85 
86   @Inject
87   protected RegionAndNameToImageSupplier(@Region Set<String> regions, DescribeImagesParallel describer,
88            @Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, EC2ImageParser parser, Map<RegionAndName, Image> images) {
89      this.regions = regions;
90      this.describer = describer;
91      this.amiOwners = amiOwners;
92      this.parser = parser;
93      this.images = images;
94   }
95 
96   @Override
97   public Map<RegionAndName, ? extends Image> get() {
98      if (amiOwners.length == 0) {
99         logger.debug(">> no owners specified, skipping image parsing");
100      } else {
101         logger.debug(">> providing images");
102 
103         Iterable<Entry<String, DescribeImagesOptions>> queries = getDescribeQueriesForOwnersInRegions(regions,
104                  amiOwners);
105 
106         Iterable<? extends Image> parsedImages = filter(transform(describer.apply(queries), parser), Predicates
107                  .notNull());
108 
109         images.putAll(uniqueIndex(parsedImages, new Function<Image, RegionAndName>() {
110 
111            @Override
112            public RegionAndName apply(Image from) {
113               return new RegionAndName(from.getLocation().getId(), from.getProviderId());
114            }
115 
116         }));
117 
118         logger.debug("<< images(%d)", images.size());
119      }
120      return images;
121   }
122 
123   public Iterable<Entry<String, DescribeImagesOptions>> getDescribeQueriesForOwnersInRegions(Set<String> regions,
124            String[] amiOwners) {
125      DescribeImagesOptions options = getOptionsForOwners(amiOwners);
126      Builder<String, DescribeImagesOptions> builder = ImmutableMap.<String, DescribeImagesOptions> builder();
127      for (String region : regions)
128         builder.put(region, options);
129      return builder.build().entrySet();
130   }
131 
132   public static DescribeImagesOptions getOptionsForOwners(String[] amiOwners) {
133      final DescribeImagesOptions options;
134      if (amiOwners.length == 1 && amiOwners[0].equals("*"))
135         options = new DescribeImagesOptions();
136      else
137         options = ownedBy(amiOwners);
138      return options;
139   }
140}

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