@Override public <T> T _getFeature(final Class<T> type) { if(type == DistributionConfiguration.class) { return null; } return super._getFeature(type); } }
@Override public Space get() throws BackgroundException { long used = 0L; try { for(Region region : session.getClient().getRegions()) { final long bytes = session.getClient().getAccountInfo(region).getBytesUsed(); if(log.isInfoEnabled()) { log.info(String.format("Add %d used in region %s", bytes, region)); } used += bytes; } } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory))); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory))); } return new Space(used, Long.MAX_VALUE); } }
@Override protected Map<Path, Distribution> operate(final PasswordCallback callback, final Path file) throws BackgroundException { final DistributionConfiguration feature = session.getFeature(DistributionConfiguration.class); if(null == feature) { return Collections.emptyMap(); } final AttributedList<Path> containers = new SwiftContainerListService(session, new SwiftLocationFeature.SwiftRegion(session.getHost().getRegion())).list(file, new DisabledListProgressListener()); final Map<Path, Distribution> distributions = new ConcurrentHashMap<>(); for(Path container : containers) { for(Distribution.Method method : feature.getMethods(container)) { final Distribution distribution = feature.read(container, method, new DisabledLoginCallback()); if(log.isInfoEnabled()) { log.info(String.format("Cache distribution %s", distribution)); } distributions.put(container, distribution); } } return distributions; } }
@Override public Set<Name> getLocations() { final Set<Name> locations = new LinkedHashSet<Name>(); if(StringUtils.isNotBlank(session.getHost().getRegion())) { locations.add(new SwiftRegion(session.getHost().getRegion())); } else { final List<Region> regions = new ArrayList<Region>(session.getClient().getRegions()); Collections.sort(regions, new Comparator<Region>() { @Override public int compare(final Region r1, final Region r2) { if(r1.isDefault()) { return -1; } if(r2.isDefault()) { return 1; } return 0; } }); for(Region region : regions) { if(StringUtils.isBlank(region.getRegionId())) { // v1 authentication contexts do not have region support continue; } locations.add(new SwiftRegion(region.getRegionId())); } } return locations; }
public Region lookup(final Location.Name location) throws InteroperabilityException { if(!session.isConnected()) { log.warn("Cannot determine region if not connected"); return new Region(location.getIdentifier(), null, null); for(Region region : session.getClient().getRegions()) { if(StringUtils.isBlank(region.getRegionId())) { continue; if(session.getClient().getRegions().isEmpty()) { throw new InteroperabilityException("No region found in authentication context"); for(Region region : session.getClient().getRegions()) { if(region.isDefault()) { log.warn(String.format("Fallback to default region %s", region.getRegionId())); final Region region = session.getClient().getRegions().iterator().next(); log.warn(String.format("Fallback to first region %s", region.getRegionId())); if(null == region.getStorageUrl()) {
@Override public String getHostname() { return session.getHost().getProtocol().getDefaultHostname(); }
@Override @SuppressWarnings("unchecked") public <T> T getFeature(final Class<T> type, final Distribution.Method method) { if(type == Purge.class) { return (T) new SwiftDistributionPurgeFeature(session, regionService); } if(type == Index.class) { return (T) this; } if(type == DistributionLogging.class) { return (T) this; } if(type == IdentityConfiguration.class) { return (T) new DefaultCredentialsIdentityConfiguration(session.getHost()); } if(type == AnalyticsProvider.class) { return (T) new QloudstatAnalyticsProvider(); } return null; }
try { final Map<Region, AccountInfo> accounts = new ConcurrentHashMap<>(); for(Region region : session.getClient().getRegions()) { final AccountInfo info = session.getClient().getAccountInfo(region); if(log.isInfoEnabled()) { log.info(String.format("Signing key is %s", info.getTempUrlKey())); log.debug(String.format("Set acccount temp URL key to %s", key)); session.getClient().updateAccountMetadata(region, Collections.singletonMap("X-Account-Meta-Temp-URL-Key", key)); info.setTempUrlKey(key);
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { return new SwiftContainerListService(session, new SwiftLocationFeature.SwiftRegion(session.getHost().getRegion())).list(directory, listener); } else { return new SwiftObjectListService(session, regionService).list(directory, listener); } }
log.debug(String.format("Write metadata %s for file %s", metadata, file)); session.getClient().updateContainerMetadata(regionService.lookup(file), containerService.getContainer(file).getName(), metadata); log.debug(String.format("Write metadata %s for file %s", metadata, file)); session.getClient().updateObjectMetadata(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), metadata);
list.addAll(new DefaultUrlProvider(session.getHost()).toUrl(file)); list.addAll(new WebUrlProvider(session.getHost()).toUrl(file)); list.add(new DescriptiveUrl( URI.create(region.getStorageUrl(containerService.getContainer(file).getName(), containerService.getKey(file)).toString()), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().name().toUpperCase(Locale.ROOT)) ));
try { if(StringUtils.isNotBlank(configuration.getIndexDocument())) { session.getClient().updateContainerMetadata(regionService.lookup(container), container.getName(), Collections.singletonMap("X-Container-Meta-Web-Index", configuration.getIndexDocument())); = session.getClient().getCDNContainerInfo(regionService.lookup(container), container.getName()); if(log.isDebugEnabled()) { log.debug(String.format("Found existing CDN configuration %s", info)); log.debug(String.format("Enable CDN configuration for %s", container)); session.getClient().cdnEnableContainer(regionService.lookup(container), container.getName()); log.debug(String.format("Update CDN configuration for %s", container)); session.getClient().cdnUpdateContainer(regionService.lookup(container), container.getName(), -1, configuration.isEnabled(), configuration.isLogging());
log.debug(String.format("Creating SLO manifest %s for %s", manifest, file)); session.getClient().createSLOManifestObject(regionService.lookup( containerService.getContainer(file)), containerService.getContainer(file).getName(),
final List<String> keys = container.getValue(); for(List<String> partition : new Partition<String>(keys, PreferencesFactory.get().getInteger("openstack.delete.multiple.partition"))) { session.getClient().deleteObjects(region, container.getKey().getName(), partition); session.getClient().deleteContainer(regionService.lookup(file), containerService.getContainer(file).getName());
final AttributedList<Path> containers = new AttributedList<Path>(); final int limit = preferences.getInteger("openstack.list.container.limit"); final Client client = session.getClient(); for(final Region r : client.getRegions()) { if(region.getIdentifier() != null) {
/** * @return The ETag returned by the server for the uploaded object */ @Override public StorageObject call(final AbstractHttpEntity entity) throws BackgroundException { try { // Previous final HashMap<String, String> headers = new HashMap<>(status.getMetadata()); final String checksum = session.getClient().storeObject( regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), entity, headers, null); if(log.isDebugEnabled()) { log.debug(String.format("Saved object %s with checksum %s", file, checksum)); } final StorageObject stored = new StorageObject(containerService.getKey(file)); stored.setMd5sum(checksum); stored.setSize(status.getLength()); return stored; } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Upload {0} failed", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file); } }
final Path container = containerService.getContainer(file); final Map<String, List<StorageObject>> segments = session.getClient().listObjectSegments(regionService.lookup(container), container.getName(), containerService.getKey(file)); if(null == segments) {
@Override protected Long operate(final PasswordCallback callback, final Path container) throws BackgroundException { try { return session.getClient().getContainerInfo(regionService.lookup(container), container.getName()).getTotalSize(); } catch(GenericException e) { throw new SwiftExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } }
final String checksum = session.getClient().createSLOManifestObject(regionService.lookup( containerService.getContainer(file)), containerService.getContainer(file).getName(),