private Location getLocation(BucketMetadata from) { try { Set<? extends Location> locations = this.locations.get(); final String region = client.getBucketLocation(from.getName()); assert region != null : String.format("could not get region for %s", from.getName()); if (region != null) { try { return Iterables.find(locations, new Predicate<Location>() { @Override public boolean apply(Location input) { return input.getId().equalsIgnoreCase(region.toString()); } }); } catch (NoSuchElementException e) { logger.error("could not get location for region %s in %s", region, locations); } } else { logger.error("could not get region for %s", from.getName()); } } catch (ContainerNotFoundException e) { logger.error(e, "could not get region for %s, as service suggests the bucket doesn't exist", from.getName()); } return null; } }
public StorageMetadata apply(BucketMetadata from) { MutableStorageMetadata to = new MutableStorageMetadataImpl(); to.setName(from.getName()); to.setType(StorageType.CONTAINER); to.setLocation(onlyLocation != null ? onlyLocation : getLocation(from)); return to; }