use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.
the class XrootdRedirectHandler method doOnStatx.
@Override
protected XrootdResponse<StatxRequest> doOnStatx(ChannelHandlerContext ctx, StatxRequest req) throws XrootdException {
if (req.getPaths().length == 0) {
throw new XrootdException(kXR_ArgMissing, "no paths specified");
}
try {
FsPath[] paths = new FsPath[req.getPaths().length];
for (int i = 0; i < paths.length; i++) {
paths[i] = createFullPath(req.getPaths()[i]);
}
LoginSessionInfo loginSessionInfo = sessionInfo();
Subject subject = loginSessionInfo.getSubject();
Restriction restriction = loginSessionInfo.getRestriction();
return new StatxResponse(req, _door.getMultipleFileStatuses(paths, subject, restriction));
} catch (TimeoutCacheException e) {
throw xrootdException(e.getRc(), "Internal timeout");
} catch (PermissionDeniedCacheException e) {
throw xrootdException(e);
} catch (CacheException e) {
throw xrootdException(e.getRc(), String.format("Failed to open file (%s [%d])", e.getMessage(), e.getRc()));
}
}
use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.
the class XrootdRedirectHandler method doOnDirList.
@Override
protected XrootdResponse<DirListRequest> doOnDirList(ChannelHandlerContext ctx, DirListRequest request) throws XrootdException {
try {
String listPath = request.getPath();
if (listPath.isEmpty()) {
throw new XrootdException(kXR_ArgMissing, "no source path specified");
}
_log.info("Listing directory {}", listPath);
FsPath fullListPath = createFullPath(listPath);
if (!_door.isReadAllowed(fullListPath)) {
throw new PermissionDeniedCacheException("Permission denied.");
}
LoginSessionInfo loginSessionInfo = sessionInfo();
Subject subject = loginSessionInfo.getSubject();
Restriction restriction = loginSessionInfo.getRestriction();
if (request.isDirectoryStat()) {
_door.listPath(fullListPath, subject, restriction, new StatListCallback(request, subject, restriction, fullListPath, ctx), _door.getRequiredAttributesForFileStatus());
} else {
_door.listPath(fullListPath, subject, restriction, new ListCallback(request, ctx), EnumSet.noneOf(FileAttribute.class));
}
return null;
} catch (PermissionDeniedCacheException e) {
throw xrootdException(e);
}
}
use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.
the class AbstractXrootdRequestHandler method selectChecksum.
protected QueryResponse selectChecksum(ChecksumInfo info, Set<Checksum> checksums, QueryRequest msg) throws XrootdException {
if (!checksums.isEmpty()) {
/**
* xrdcp expects lower case names for checksum algorithms
* https://github.com/xrootd/xrootd/issues/459
* TODO: remove toLowerCase() call when above issue is addressed
*/
Optional<String> type = info.getType();
if (type.isPresent()) {
Optional<Checksum> result = checksums.stream().filter((c) -> type.get().equalsIgnoreCase(c.getType().getName())).findFirst();
if (result.isPresent()) {
Checksum checksum = result.get();
return new QueryResponse(msg, checksum.getType().getName().toLowerCase() + " " + checksum.getValue());
}
throw new XrootdException(kXR_Unsupported, "Checksum exists, " + "but not of the requested type.");
}
Checksum checksum = Checksums.preferredOrder().min(checksums);
return new QueryResponse(msg, checksum.getType().getName().toLowerCase() + " " + checksum.getValue());
}
throw new XrootdException(kXR_Unsupported, "No checksum available " + "for this file.");
}
use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.
the class XrootdPoolRequestHandler method doOnOpen.
/**
* Obtains the right mover channel using an opaque token in the request. The mover channel is
* wrapped by a file descriptor. The file descriptor is stored for subsequent access.
* <p>
* In the case that this is a write request as destination in a third party copy, a third-party
* client is started. The client issues login, open and read requests to the source server, and
* writes the responses to the file descriptor.
* <p>
* The third-party client also sends a sync response back to the client when the transfer has
* completed.
*/
@Override
protected XrootdResponse<OpenRequest> doOnOpen(ChannelHandlerContext ctx, OpenRequest msg) throws XrootdException {
try {
Map<String, String> opaqueMap = getOpaqueMap(msg.getOpaque());
UUID uuid = getUuid(opaqueMap);
if (uuid == null) {
_log.info("Request to open {} contains no UUID.", msg.getPath());
throw new XrootdException(kXR_NotAuthorized, "Request lacks the " + UUID_PREFIX + " property.");
}
enforceClientTlsIfDestinationRequiresItForTpc(opaqueMap);
NettyTransferService<XrootdProtocolInfo>.NettyMoverChannel file = _server.openFile(uuid, false);
if (file == null) {
_log.info("No mover found for {} with UUID {}.", msg.getPath(), uuid);
return redirectToDoor(ctx, msg, () -> {
throw new XrootdException(kXR_NotAuthorized, UUID_PREFIX + " is no longer valid.");
});
}
/*
* Stop any timer in case this is a reconnect.
*/
_server.cancelReconnectTimeoutForMover(uuid);
_log.debug("doOnOpen, called cancel on reconnect timers for {}", uuid);
XrootdProtocolInfo protocolInfo = file.getProtocolInfo();
try {
FileDescriptor descriptor;
boolean isWrite = file.getIoMode().contains(StandardOpenOption.WRITE);
if (msg.isNew() && !isWrite) {
throw new XrootdException(kXR_FileNotOpen, "File exists.");
} else if (msg.isDelete() && !isWrite) {
throw new XrootdException(kXR_Unsupported, "File exists.");
/*
* Some clients express only kXR_delete when then intend to write
* so we need to consider delete as a write request here.
*/
} else if ((msg.isNew() || msg.isReadWrite() || msg.isDelete()) && isWrite) {
boolean posc = (msg.getOptions() & kXR_posc) == kXR_posc || protocolInfo.getFlags().contains(XrootdProtocolInfo.Flags.POSC);
if (opaqueMap.containsKey("tpc.src")) {
_log.debug("Request to open {} is as third-party destination.", msg);
XrootdTpcInfo tpcInfo = new XrootdTpcInfo(opaqueMap);
tpcInfo.setDelegatedProxy(protocolInfo.getDelegatedCredential());
tpcInfo.setUid(protocolInfo.getTpcUid());
tpcInfo.setGid(protocolInfo.getTpcGid());
descriptor = new TpcWriteDescriptor(file, posc, ctx, _server, opaqueMap.get("org.dcache.xrootd.client"), tpcInfo, tlsSessionInfo);
} else {
descriptor = new WriteDescriptor(file, posc);
}
} else {
descriptor = new ReadDescriptor(file);
}
FileStatus stat = msg.isRetStat() ? stat(file) : null;
int fd = addDescriptor(descriptor);
_redirectingDoor = protocolInfo.getDoorAddress();
file = null;
_hasOpenedFiles = true;
return new OpenResponse(msg, fd, null, null, stat);
} finally {
if (file != null) {
file.release();
}
}
} catch (ParseException e) {
throw new XrootdException(kXR_ArgInvalid, e.getMessage());
} catch (IOException e) {
throw new XrootdException(kXR_IOError, e.getMessage());
}
}
use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.
the class XrootdPoolRequestHandler method doOnQuery.
@Override
protected XrootdResponse<QueryRequest> doOnQuery(ChannelHandlerContext ctx, QueryRequest msg) throws XrootdException {
switch(msg.getReqcode()) {
case kXR_Qconfig:
StringBuilder s = new StringBuilder();
for (String name : msg.getArgs().split(" ")) {
switch(name) {
case "bind_max":
s.append(0);
break;
case "readv_ior_max":
s.append(_maxFrameSize - ReadVResponse.READ_LIST_HEADER_SIZE);
break;
case "readv_iov_max":
s.append(READV_IOV_MAX);
break;
case "version":
s.append("dCache ").append(Version.of(XrootdPoolRequestHandler.class).getVersion());
break;
case "tpc":
/**
* Indicate support for third-party copy by responding
* with the protocol version.
*/
s.append(XrootdProtocol.TPC_VERSION);
break;
case "tpcdlg":
s.append("gsi");
break;
default:
s.append(_queryConfig.getOrDefault(name, name));
break;
}
s.append('\n');
}
return new QueryResponse(msg, s.toString());
case kXR_Qcksum:
String opaque = msg.getOpaque();
if (opaque == null) {
return redirectToDoor(ctx, msg);
}
UUID uuid = getUuid(getOpaqueMap(opaque));
if (uuid == null) {
/* The spec isn't clear about whether the path includes the opaque information or not.
* Thus we cannot rely on there being a uuid and without the uuid we cannot lookup the
* file attributes in the pool.
*/
return redirectToDoor(ctx, msg);
}
FileAttributes attributes = _server.getFileAttributes(uuid);
if (attributes == null) {
return redirectToDoor(ctx, msg);
}
if (attributes.isUndefined(FileAttribute.CHECKSUM)) {
throw new XrootdException(kXR_Unsupported, "No checksum available for this file.");
}
return selectChecksum(new ChecksumInfo(msg.getPath(), opaque), attributes.getChecksums(), msg);
default:
return unsupported(ctx, msg);
}
}
Aggregations