EMMA Coverage Report (generated Fri Apr 27 15:03:37 EDT 2012)
[all classes][org.jclouds.ec2.suppliers]

COVERAGE SUMMARY FOR SOURCE FILE [DescribeAvailabilityZonesInRegion.java]

nameclass, %method, %block, %line, %
DescribeAvailabilityZonesInRegion.java100% (2/2)100% (4/4)98%  (96/98)96%  (22/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DescribeAvailabilityZonesInRegion100% (1/1)100% (2/2)98%  (87/89)95%  (20/21)
get (): Map 100% (1/1)97%  (74/76)94%  (15/16)
DescribeAvailabilityZonesInRegion (EC2Client, Supplier): void 100% (1/1)100% (13/13)100% (5/5)
     
class DescribeAvailabilityZonesInRegion$1100% (1/1)100% (2/2)100% (9/9)100% (2/2)
DescribeAvailabilityZonesInRegion$1 (DescribeAvailabilityZonesInRegion): void 100% (1/1)100% (6/6)100% (1/1)
apply (AvailabilityZoneInfo): String 100% (1/1)100% (3/3)100% (1/1)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.ec2.suppliers;
20 
21import java.util.Map;
22import java.util.Set;
23 
24import javax.annotation.Resource;
25import javax.inject.Inject;
26import javax.inject.Singleton;
27 
28import org.jclouds.ec2.EC2Client;
29import org.jclouds.ec2.domain.AvailabilityZoneInfo;
30import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient;
31import org.jclouds.http.HttpResponseException;
32import org.jclouds.location.Region;
33import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
34import org.jclouds.logging.Logger;
35import org.jclouds.util.Suppliers2;
36 
37import com.google.common.base.Function;
38import com.google.common.base.Supplier;
39import com.google.common.collect.ImmutableMap;
40import com.google.common.collect.ImmutableMap.Builder;
41import com.google.common.collect.ImmutableSet;
42import com.google.common.collect.Iterables;
43import com.google.common.collect.Maps;
44 
45@Singleton
46public class DescribeAvailabilityZonesInRegion implements RegionIdToZoneIdsSupplier {
47   @Resource
48   protected Logger logger = Logger.NULL;
49 
50   private final AvailabilityZoneAndRegionClient client;
51   private final Supplier<Set<String>> regions;
52 
53   @Inject
54   public DescribeAvailabilityZonesInRegion(EC2Client client, @Region Supplier<Set<String>> regions) {
55      this.client = client.getAvailabilityZoneAndRegionServices();
56      this.regions = regions;
57   }
58 
59   @Override
60   public Map<String, Supplier<Set<String>>> get() {
61      Builder<String, Set<String>> map = ImmutableMap.builder();
62      HttpResponseException exception = null;
63      // TODO: this should be parallel
64      for (String region : regions.get()) {
65         try {
66            ImmutableSet<String> zones = ImmutableSet.copyOf(Iterables.transform(client
67                     .describeAvailabilityZonesInRegion(region), new Function<AvailabilityZoneInfo, String>() {
68 
69               @Override
70               public String apply(AvailabilityZoneInfo arg0) {
71                  return arg0.getZone();
72               }
73 
74            }));
75            if (zones.size() > 0)
76               map.put(region, zones);
77         } catch (HttpResponseException e) {
78            // TODO: this should be in retry handler, not here.
79            if (e.getMessage().contains("Unable to tunnel through proxy")) {
80               exception = e;
81               logger.error(e, "Could not describe availability zones in Region: %s", region);
82            } else {
83               throw e;
84            }
85         }
86      }
87      ImmutableMap<String, Set<String>> result = map.build();
88      if (result.isEmpty() && exception != null) {
89         throw exception;
90      }
91      return Maps.transformValues(result, Suppliers2.<Set<String>> ofInstanceFunction());
92   }
93 
94}

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