EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.location.config]

COVERAGE SUMMARY FOR SOURCE FILE [ProvideZonesViaProperties.java]

nameclass, %method, %block, %line, %
ProvideZonesViaProperties.java0%   (0/1)0%   (0/2)0%   (0/64)0%   (0/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ProvideZonesViaProperties0%   (0/1)0%   (0/2)0%   (0/64)0%   (0/11)
ProvideZonesViaProperties (Injector, Set): void 0%   (0/1)0%   (0/9)0%   (0/4)
get (): Map 0%   (0/1)0%   (0/55)0%   (0/7)

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.location.config;
20 
21import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION;
22 
23import java.util.Map;
24import java.util.Set;
25 
26import javax.inject.Inject;
27import javax.inject.Singleton;
28 
29import org.jclouds.location.Region;
30import org.jclouds.location.Zone;
31 
32import com.google.common.base.Splitter;
33import com.google.common.collect.ImmutableMap;
34import com.google.common.collect.ImmutableMap.Builder;
35import com.google.inject.ConfigurationException;
36import com.google.inject.Injector;
37import com.google.inject.Key;
38import com.google.inject.name.Names;
39 
40/**
41 * 
42 * looks for properties bound to the naming convention jclouds.location.region.{@code regionId}.zones
43 * 
44 * @author Adrian Cole
45 */
46@Singleton
47public class ProvideZonesViaProperties implements javax.inject.Provider<Map<String, String>> {
48 
49   private final Injector injector;
50   private final Set<String> regions;
51 
52   @Inject
53   ProvideZonesViaProperties(Injector injector, @Region Set<String> regions) {
54      this.injector = injector;
55      this.regions = regions;
56   }
57 
58   @Singleton
59   @Zone
60   @Override
61   public Map<String, String> get() {
62      try {
63         Builder<String, String> zones = ImmutableMap.<String, String> builder();
64         for (String region : regions) {
65            for (String zone : Splitter.on(',').split(
66                  injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGION + "." + region + ".zones"))))) {
67               zones.put(zone, region);
68            }
69         }
70         return zones.build();
71      } catch (ConfigurationException e) {
72         // this happens if regions property isn't set
73         // services not run by AWS may not have zones, so this is ok.
74         return ImmutableMap.<String, String> of();
75      }
76   }
77}

[all classes][org.jclouds.location.config]
EMMA 2.0.5312 (C) Vladimir Roubtsov