EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.s3.blobstore.functions]

COVERAGE SUMMARY FOR SOURCE FILE [LocationFromBucketLocation.java]

nameclass, %method, %block, %line, %
LocationFromBucketLocation.java0%   (0/2)0%   (0/5)0%   (0/140)0%   (0/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class LocationFromBucketLocation0%   (0/1)0%   (0/3)0%   (0/124)0%   (0/22)
<static initializer> 0%   (0/1)0%   (0/8)0%   (0/1)
LocationFromBucketLocation (S3Client, Supplier): void 0%   (0/1)0%   (0/28)0%   (0/6)
apply (BucketMetadata): Location 0%   (0/1)0%   (0/88)0%   (0/15)
     
class LocationFromBucketLocation$10%   (0/1)0%   (0/2)0%   (0/16)0%   (0/2)
LocationFromBucketLocation$1 (LocationFromBucketLocation, String): void 0%   (0/1)0%   (0/9)0%   (0/1)
apply (Location): boolean 0%   (0/1)0%   (0/7)0%   (0/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.s3.blobstore.functions;
20 
21import java.util.NoSuchElementException;
22import java.util.Set;
23 
24import javax.annotation.Resource;
25import javax.inject.Inject;
26import javax.inject.Singleton;
27 
28import org.jclouds.s3.S3Client;
29import org.jclouds.s3.domain.BucketMetadata;
30import org.jclouds.blobstore.ContainerNotFoundException;
31import org.jclouds.collect.Memoized;
32import org.jclouds.domain.Location;
33import org.jclouds.logging.Logger;
34 
35import com.google.common.base.Function;
36import com.google.common.base.Predicate;
37import com.google.common.base.Supplier;
38import com.google.common.collect.Iterables;
39 
40/**
41 * @author Adrian Cole
42 */
43@Singleton
44public class LocationFromBucketLocation implements Function<BucketMetadata, Location> {
45   private final Location onlyLocation;
46   private final Supplier<Set<? extends Location>> locations;
47   private final S3Client client;
48 
49   @Resource
50   protected Logger logger = Logger.NULL;
51 
52   @Inject
53   LocationFromBucketLocation(S3Client client, @Memoized Supplier<Set<? extends Location>> locations) {
54      this.client = client;
55      this.onlyLocation = locations.get().size() == 1 ? Iterables.get(locations.get(), 0) : null;
56      this.locations = locations;
57   }
58 
59   public Location apply(BucketMetadata from) {
60      if (onlyLocation != null)
61         return onlyLocation;
62      try {
63         Set<? extends Location> locations = this.locations.get();
64         final String region = client.getBucketLocation(from.getName());
65         assert region != null : String.format("could not get region for %s", from.getName());
66         if (region != null) {
67            try {
68               return Iterables.find(locations, new Predicate<Location>() {
69 
70                  @Override
71                  public boolean apply(Location input) {
72                     return input.getId().equalsIgnoreCase(region.toString());
73                  }
74 
75               });
76            } catch (NoSuchElementException e) {
77               logger.error("could not get location for region %s in %s", region, locations);
78            }
79         } else {
80            logger.error("could not get region for %s", from.getName());
81         }
82      } catch (ContainerNotFoundException e) {
83         logger.error(e, "could not get region for %s, as service suggests the bucket doesn't exist", from.getName());
84      }
85      return null;
86   }
87}

[all classes][org.jclouds.s3.blobstore.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov