@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); } }
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);
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()) {
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);
@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; }
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 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); } }
@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 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) {
final SwiftRegion region = new SwiftRegion(session.getHost().getRegion()); if(Location.unknown.equals(region)) { final Client client = session.getClient(); for(Region r : client.getRegions()) { try {
@Override public void invalidate(final Path container, final Distribution.Method method, final List<Path> files, final LoginCallback prompt) throws BackgroundException { try { for(Path file : files) { if(containerService.isContainer(file)) { session.getClient().purgeCDNContainer(regionService.lookup(containerService.getContainer(file)), container.getName(), null); } else { session.getClient().purgeCDNObject(regionService.lookup(containerService.getContainer(file)), container.getName(), containerService.getKey(file), null); } } } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Cannot write CDN configuration", e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot write CDN configuration", e); } } }
final String checksum; try { checksum = session.getClient().storeObject( regionService.lookup(file), containerService.getContainer(segment).getName(), containerService.getKey(segment),
@Override public Map<String, String> getMetadata(final Path file) throws BackgroundException { try { if(containerService.isContainer(file)) { final ContainerMetadata meta = session.getClient().getContainerMetaData(regionService.lookup(file), containerService.getContainer(file).getName()); return meta.getMetaData(); } else { final ObjectMetadata meta = session.getClient().getObjectMetaData(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file)); return meta.getMetaData(); } } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Failure to read attributes of {0}", e, file); } }
try { if(containerService.isContainer(file)) { final ContainerInfo info = session.getClient().getContainerInfo(region, containerService.getContainer(file).getName()); final PathAttributes attributes = new PathAttributes(); return attributes; final ObjectMetadata metadata = session.getClient().getObjectMetaData(region, containerService.getContainer(file).getName(), containerService.getKey(file)); if(file.isDirectory()) {
final HttpRange range = HttpRange.withStatus(status); if(-1 == range.getEnd()) { response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart()); response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file), range.getStart(), range.getLength()); response = session.getClient().getObject(regionService.lookup(file), containerService.getContainer(file).getName(), containerService.getKey(file));
final Path container = containerService.getContainer(directory); do { list = session.getClient().listObjectsStartingWith(regionService.lookup(container), container.getName(), containerService.isContainer(directory) ? StringUtils.EMPTY : containerService.getKey(directory) + Path.DELIMITER, null, limit, marker, Path.DELIMITER);
@Override public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException { try { session.getClient().copyObject(regionService.lookup(source), containerService.getContainer(source).getName(), containerService.getKey(source), containerService.getContainer(target).getName(), containerService.getKey(target)); // Copy original file attributes return new Path(target.getParent(), target.getName(), target.getType(), new PathAttributes(source.attributes())); } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Cannot copy {0}", e, source); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot copy {0}", e, source); } }
@Override public Path mkdir(final Path folder, final String region, final TransferStatus status) throws BackgroundException { try { if(containerService.isContainer(folder)) { // Create container at top level session.getClient().createContainer(regionService.lookup( new SwiftLocationFeature.SwiftRegion(region)), folder.getName()); return new Path(folder.getParent(), folder.getName(), folder.getType(), new SwiftAttributesFinderFeature(session, regionService).find(folder)); } else { status.setMime("application/directory"); status.setLength(0L); final StatusOutputStream<StorageObject> out = writer.write(folder, status, new DisabledConnectionCallback()); new DefaultStreamCloser().close(out); final StorageObject metadata = out.getStatus(); return new Path(folder.getParent(), folder.getName(), folder.getType(), new SwiftAttributesFinderFeature(session, regionService).toAttributes(metadata)); } } catch(GenericException e) { throw new SwiftExceptionMappingService().map("Cannot create folder {0}", e, folder); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map("Cannot create folder {0}", e, folder); } }