use of org.dcache.srm.SRMException in project dcache by dCache.
the class Storage method listDirectory.
@Override
public List<URI> listDirectory(SRMUser user, URI surl, FileMetaData fileMetaData) throws SRMException {
final FsPath path = getPath(surl);
final List<URI> result = new ArrayList<>();
final String base = addTrailingSlash(surl.toString());
Subject subject = asDcacheUser(user).getSubject();
Restriction restriction = asDcacheUser(user).getRestriction();
DirectoryListPrinter printer = new DirectoryListPrinter() {
@Override
public Set<FileAttribute> getRequiredAttributes() {
return EnumSet.noneOf(FileAttribute.class);
}
@Override
public void print(FsPath dir, FileAttributes dirAttr, DirectoryEntry entry) {
result.add(URI.create(base + entry.getName()));
}
};
try {
_listSource.printDirectory(subject, restriction, printer, path, null, Range.<Integer>all());
return result;
} catch (TimeoutCacheException e) {
throw new SRMInternalErrorException("Internal name space timeout", e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("List aborted by administrator", e);
} catch (NotDirCacheException e) {
throw new SRMInvalidPathException("Not a directory", e);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException("No such file or directory", e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied", e);
} catch (CacheException e) {
throw new SRMException(String.format("List failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
}
}
use of org.dcache.srm.SRMException in project dcache by dCache.
the class Storage method listSubdirectoriesRecursivelyForDelete.
/**
* Adds transitive subdirectories of {@code dir} to {@code result}.
*
* @param subject Issuer of rmdir
* @param dir Path to directory
* @param attributes File attributes of {@code dir}
* @param result List that subdirectories are added to
* @throws SRMAuthorizationException if {@code subject} is not authorized to list {@code
* dir} or not authorized to list or delete any of its
* transitive subdirectories.
* @throws SRMNonEmptyDirectoryException if {@code dir} or any of its transitive subdirectories
* contains non-directory entries.
* @throws SRMInternalErrorException in case of transient errors.
* @throws SRMInvalidPathException if {@code dir} is not a directory.
* @throws SRMException in case of other errors.
*/
private void listSubdirectoriesRecursivelyForDelete(Subject subject, Restriction restriction, FsPath dir, FileAttributes attributes, List<FsPath> result) throws SRMException {
List<DirectoryEntry> children = new ArrayList<>();
try (DirectoryStream list = _listSource.list(subject, restriction, dir, null, Range.<Integer>all(), attributesRequiredForRmdir)) {
for (DirectoryEntry child : list) {
FileAttributes childAttributes = child.getFileAttributes();
AccessType canDelete = permissionHandler.canDeleteDir(subject, attributes, childAttributes);
if (canDelete != AccessType.ACCESS_ALLOWED) {
throw new SRMAuthorizationException(dir + "/" + child.getName() + " (permission denied)");
}
if (childAttributes.getFileType() != FileType.DIR) {
throw new SRMNonEmptyDirectoryException(dir + "/" + child.getName() + " (not empty)");
}
children.add(child);
}
} catch (NotDirCacheException e) {
throw new SRMInvalidPathException(dir + " (not a directory)", e);
} catch (FileNotFoundCacheException ignored) {
// Somebody removed the directory before we could.
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException(dir + " (permission denied)", e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
} catch (TimeoutCacheException e) {
throw new SRMInternalErrorException("Name space timeout", e);
} catch (CacheException e) {
throw new SRMException(dir + " (" + e.getMessage() + ")");
}
// Result list uses post-order so directories will be deleted bottom-up.
for (DirectoryEntry child : children) {
FsPath path = dir.child(child.getName());
listSubdirectoriesRecursivelyForDelete(subject, restriction, path, child.getFileAttributes(), result);
result.add(path);
}
}
use of org.dcache.srm.SRMException in project dcache by dCache.
the class Storage method messageArrived.
public void messageArrived(final TransferManagerMessage msg) {
Long callerId = msg.getId();
_log.debug("handleTransferManagerMessage for callerId={}", callerId);
TransferInfo info = callerIdToHandler.remove(callerId);
if (info == null) {
_log.error("TransferInfo for callerId={} not found", callerId);
return;
}
_log.debug("removed TransferInfo for callerId={}", callerId);
_executor.execute(() -> {
if (msg instanceof TransferCompleteMessage) {
info.callbacks.copyComplete();
} else if (msg instanceof TransferFailedMessage) {
Object error = msg.getErrorObject();
if (error instanceof CacheException) {
error = ((CacheException) error).getMessage();
}
SRMException e;
switch(msg.getReturnCode()) {
case CacheException.PERMISSION_DENIED:
e = new SRMAuthorizationException(String.format("Access denied: %s", error));
break;
case CacheException.FILE_NOT_FOUND:
e = new SRMInvalidPathException(String.valueOf(error));
break;
case CacheException.THIRD_PARTY_TRANSFER_FAILED:
e = new SRMException("Transfer failed: " + error);
break;
default:
e = new SRMException(String.format("Transfer failed: %s [%d]", error, msg.getReturnCode()));
}
info.callbacks.copyFailed(e);
}
});
}
use of org.dcache.srm.SRMException in project dcache by dCache.
the class Storage method createDirectory.
@Override
public void createDirectory(SRMUser abstractUser, URI surl) throws SRMException {
_log.debug("Storage.createDirectory");
DcacheUser user = asDcacheUser(abstractUser);
PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
try {
handler.createPnfsDirectory(getPath(surl).toString());
} catch (TimeoutCacheException e) {
throw new SRMInternalErrorException("Internal name space timeout", e);
} catch (NotDirCacheException e) {
throw new SRMInvalidPathException("Parent path is not a directory", e);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException("Parent path does not exist", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException("File exists");
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied");
} catch (CacheException e) {
_log.error("Failed to create directory {}: {}", surl, e.getMessage());
throw new SRMException(String.format("Failed to create directory [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
}
}
use of org.dcache.srm.SRMException in project dcache by dCache.
the class Storage method srmGetSpaceTokens.
@Override
@Nonnull
public String[] srmGetSpaceTokens(SRMUser user, String description) throws SRMException {
_log.trace("srmGetSpaceTokens ({})", description);
if (!_isSpaceManagerEnabled) {
return new String[0];
}
try {
DcacheUser duser = asDcacheUser(user);
long[] tokens = spaceTokens.get(new GetSpaceTokensKey(duser.getSubject().getPrincipals(), description));
if (_log.isTraceEnabled()) {
_log.trace("srmGetSpaceTokens returns: {}", Arrays.toString(tokens));
}
return Arrays.stream(tokens).mapToObj(Long::toString).toArray(String[]::new);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
Throwables.throwIfInstanceOf(cause, SRMException.class);
Throwables.throwIfUnchecked(cause);
throw new RuntimeException(cause);
}
}
Aggregations