@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 public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { final OAuthTokens tokens = authorizationService.authorize(host, prompt, cancel); try { if(log.isInfoEnabled()) { log.info(String.format("Attempt authentication with %s", tokens)); } client.authenticate(new HubicAuthenticationRequest(tokens.getAccessToken()), new HubicAuthenticationResponseHandler()); } catch(GenericException e) { throw new SwiftExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
throw new SwiftExceptionMappingService().map("Failure to write attributes of {0}", e, file);
throw new SwiftExceptionMappingService().map(e);
throw new SwiftExceptionMappingService().map("Cannot write CDN configuration", e);
throw new SwiftExceptionMappingService().map("Listing directory {0} failed", e, directory);
/** * @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); } } }
throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file);
throw new SwiftExceptionMappingService().map("Upload {0} failed", e, file);
throw new SwiftExceptionMappingService().map("Cannot read CDN configuration", e);
throw new SwiftExceptionMappingService().map("Listing directory {0} failed", e, directory);
throw new SwiftExceptionMappingService().map("Failure to read attributes of {0}", e, file);
@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); } } }
@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 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); } }
@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); } }
throw new SwiftExceptionMappingService().map("Download {0} failed", e, file);