EMMA Coverage Report (generated Fri Aug 26 14:14:05 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/142)0%   (0/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RegionAndNameToImageSupplier0%   (0/1)0%   (0/4)0%   (0/127)0%   (0/25)
RegionAndNameToImageSupplier (Set, DescribeImagesParallel, String [], EC2Imag... 0%   (0/1)0%   (0/21)0%   (0/8)
get (): Map 0%   (0/1)0%   (0/60)0%   (0/8)
getDescribeQueriesForOwnersInRegions (Set, String []): Iterable 0%   (0/1)0%   (0/26)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.ImmutableSet;
69import com.google.common.collect.ImmutableMap.Builder;
70 
71/**
72 * 
73 * @author Adrian Cole
74 */
75@Singleton
76public class RegionAndNameToImageSupplier implements Supplier<Map<RegionAndName, ? extends Image>> {
77   @Resource
78   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
79   protected Logger logger = Logger.NULL;
80 
81   private final Set<String> regions;
82   private final DescribeImagesParallel describer;
83   private final String[] amiOwners;
84   private final EC2ImageParser parser;
85   private final Map<RegionAndName, Image> images;
86 
87   @Inject
88   protected RegionAndNameToImageSupplier(@Region Set<String> regions, DescribeImagesParallel describer,
89            @Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, EC2ImageParser parser, Map<RegionAndName, Image> images) {
90      this.regions = regions;
91      this.describer = describer;
92      this.amiOwners = amiOwners;
93      this.parser = parser;
94      this.images = images;
95   }
96 
97   @Override
98   public Map<RegionAndName, ? extends Image> get() {
99      if (amiOwners.length == 0) {
100         logger.debug(">> no owners specified, skipping image parsing");
101      } else {
102         logger.debug(">> providing images");
103 
104         Iterable<Entry<String, DescribeImagesOptions>> queries = getDescribeQueriesForOwnersInRegions(regions,
105                  amiOwners);
106 
107         Iterable<? extends Image> parsedImages = ImmutableSet.copyOf(filter(transform(describer.apply(queries), parser), Predicates
108                  .notNull()));
109 
110         images.putAll(uniqueIndex(parsedImages, new Function<Image, RegionAndName>() {
111 
112            @Override
113            public RegionAndName apply(Image from) {
114               return new RegionAndName(from.getLocation().getId(), from.getProviderId());
115            }
116 
117         }));
118 
119         logger.debug("<< images(%d)", images.size());
120      }
121      return images;
122   }
123 
124   public Iterable<Entry<String, DescribeImagesOptions>> getDescribeQueriesForOwnersInRegions(Set<String> regions,
125            String[] amiOwners) {
126      DescribeImagesOptions options = getOptionsForOwners(amiOwners);
127      Builder<String, DescribeImagesOptions> builder = ImmutableMap.<String, DescribeImagesOptions> builder();
128      for (String region : regions)
129         builder.put(region, options);
130      return builder.build().entrySet();
131   }
132 
133   public DescribeImagesOptions getOptionsForOwners(String... amiOwners) {
134      DescribeImagesOptions options;
135      if (amiOwners.length == 1 && amiOwners[0].equals("*"))
136         options = new DescribeImagesOptions();
137      else
138         options = ownedBy(amiOwners);
139      return options;
140   }
141}

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