@Test public void testFindLocation() throws Exception { assertEquals(new SwiftLocationFeature.SwiftRegion("IAD"), new SwiftLocationFeature(session).getLocation( new Path("cdn.duck.sh", EnumSet.of(Path.Type.volume, Path.Type.directory)))); assertEquals(unknown, new SwiftLocationFeature(session).getLocation( new Path("/", EnumSet.of(Path.Type.volume, Path.Type.directory)))); }
@Override public Name getLocation(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return unknown; } if(cache.containsKey(container)) { return cache.get(container); } if(Location.unknown.equals(new SwiftRegion(container.attributes().getRegion()))) { final SwiftRegion region = new SwiftRegion(session.getHost().getRegion()); if(Location.unknown.equals(region)) { final Client client = session.getClient(); for(Region r : client.getRegions()) { try { cache.put(container, new SwiftRegion( client.getContainerInfo(r, container.getName()).getRegion().getRegionId()) ); } catch(ContainerNotFoundException | AuthorizationException e) { log.warn(String.format("Failure finding container %s in region %s", container, r.getRegionId())); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } if(!cache.containsKey(container)) { throw new NotfoundException(container.getAbsolute()); } } else { cache.put(container, region); } } else { final SwiftRegion r = new SwiftRegion(container.attributes().getRegion()); cache.put(container, r); } return cache.get(container); }
SwiftLocationFeature implements Location { @Override public Name getLocation(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return unknown; } if(cache.containsKey(container)) { return cache.get(container); } if(Location.unknown.equals(new SwiftRegion(container.attributes().getRegion()))) { final SwiftRegion region = new SwiftRegion(session.getHost().getRegion()); if(Location.unknown.equals(region)) { final Client client = session.getClient(); for(Region r : client.getRegions()) { try { cache.put(container, new SwiftRegion( client.getContainerInfo(r, container.getName()).getRegion().getRegionId()) ); } catch(ContainerNotFoundException | AuthorizationException e) { log.warn(String.format("Failure finding container %s in region %s", container, r.getRegionId())); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } if(!cache.containsKey(container)) { throw new NotfoundException(container.getAbsolute()); } } else { cache.put(container, region); } } else { final SwiftRegion r = new SwiftRegion(container.attributes().getRegion()); cache.put(container, r); } return cache.get(container); } }
SwiftLocationFeature implements Location { @Override public Name getLocation(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return unknown; } if(cache.containsKey(container)) { return cache.get(container); } if(Location.unknown.equals(new SwiftRegion(container.attributes().getRegion()))) { final SwiftRegion region = new SwiftRegion(session.getHost().getRegion()); if(Location.unknown.equals(region)) { final Client client = session.getClient(); for(Region r : client.getRegions()) { try { cache.put(container, new SwiftRegion( client.getContainerInfo(r, container.getName()).getRegion().getRegionId()) ); } catch(ContainerNotFoundException | AuthorizationException e) { log.warn(String.format("Failure finding container %s in region %s", container, r.getRegionId())); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } if(!cache.containsKey(container)) { throw new NotfoundException(container.getAbsolute()); } } else { cache.put(container, region); } } else { final SwiftRegion r = new SwiftRegion(container.attributes().getRegion()); cache.put(container, r); } return cache.get(container); } SwiftLocationFeature(final SwiftSession session); }
SwiftLocationFeature implements Location { @Override public Name getLocation(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return unknown; } if(cache.containsKey(container)) { return cache.get(container); } if(Location.unknown.equals(new SwiftRegion(container.attributes().getRegion()))) { final SwiftRegion region = new SwiftRegion(session.getHost().getRegion()); if(Location.unknown.equals(region)) { final Client client = session.getClient(); for(Region r : client.getRegions()) { try { cache.put(container, new SwiftRegion( client.getContainerInfo(r, container.getName()).getRegion().getRegionId()) ); } catch(ContainerNotFoundException | AuthorizationException e) { log.warn(String.format("Failure finding container %s in region %s", container, r.getRegionId())); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } if(!cache.containsKey(container)) { throw new NotfoundException(container.getAbsolute()); } } else { cache.put(container, region); } } else { final SwiftRegion r = new SwiftRegion(container.attributes().getRegion()); cache.put(container, r); } return cache.get(container); } SwiftLocationFeature(final SwiftSession session); @Override Set<Name> getLocations(); @Override Name getLocation(final Path file); }
SwiftLocationFeature implements Location { @Override public Name getLocation(final Path file) throws BackgroundException { final Path container = containerService.getContainer(file); if(container.isRoot()) { return unknown; } if(cache.containsKey(container)) { return cache.get(container); } if(Location.unknown.equals(new SwiftRegion(container.attributes().getRegion()))) { final SwiftRegion region = new SwiftRegion(session.getHost().getRegion()); if(Location.unknown.equals(region)) { final Client client = session.getClient(); for(Region r : client.getRegions()) { try { cache.put(container, new SwiftRegion( client.getContainerInfo(r, container.getName()).getRegion().getRegionId()) ); } catch(ContainerNotFoundException | AuthorizationException e) { log.warn(String.format("Failure finding container %s in region %s", container, r.getRegionId())); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } if(!cache.containsKey(container)) { throw new NotfoundException(container.getAbsolute()); } } else { cache.put(container, region); } } else { final SwiftRegion r = new SwiftRegion(container.attributes().getRegion()); cache.put(container, r); } return cache.get(container); } SwiftLocationFeature(final SwiftSession session); @Override Set<Name> getLocations(); @Override Name getLocation(final Path file);  }