use of org.dcache.xrootd.protocol.messages.StatResponse in project dcache by dCache.
the class XrootdPoolRequestHandler method doOnStat.
/**
* In third-party requests where dCache is the destination, the client may ask for a size
* update. This can be provided by checking channel size.
* <p>
* Otherwise, stat is not supported on the pool and should be issued to the door.
*
* @param ctx Received from the netty pipeline
* @param msg The actual request
*/
@Override
protected XrootdResponse<StatRequest> doOnStat(ChannelHandlerContext ctx, StatRequest msg) throws XrootdException {
switch(msg.getTarget()) {
case PATH:
_log.debug("Request to stat {}; redirecting to door.", msg);
return redirectToDoor(ctx, msg);
case FHANDLE:
int fd = msg.getFhandle();
FileDescriptor descriptor = getDescriptor(fd);
if (descriptor instanceof TpcWriteDescriptor) {
_log.debug("Request to stat {} is for third-party transfer.", msg);
return ((TpcWriteDescriptor) descriptor).handleStat(msg);
} else {
try {
_log.debug("Request to stat open file fhandle={}", fd);
return new StatResponse(msg, stat(descriptor.getChannel()));
} catch (IOException e) {
throw new XrootdException(kXR_IOError, e.getMessage());
}
}
default:
throw new XrootdException(kXR_NotFile, "Unexpected stat target");
}
}
use of org.dcache.xrootd.protocol.messages.StatResponse in project dcache by dCache.
the class TpcWriteDescriptor method handleStat.
public synchronized XrootdResponse<StatRequest> handleStat(StatRequest msg) throws XrootdException {
if (client.getError() != null) {
return new ErrorResponse<>(msg, client.getErrno(), client.getError());
}
int fd = msg.getFhandle();
NettyMoverChannel channel = getChannel();
FileStatus fileStatus;
try {
fileStatus = new FileStatus(fd, channel.size(), XrootdPoolRequestHandler.DEFAULT_FILESTATUS_FLAGS, channel.getFileAttributes().getModificationTime() / 1000);
} catch (IOException e) {
String error = String.format("Failed to get channel " + "info for %s: %s.", msg, e.toString());
throw new XrootdException(kXR_IOError, error);
}
return new StatResponse(msg, fileStatus);
}
use of org.dcache.xrootd.protocol.messages.StatResponse in project dcache by dCache.
the class XrootdRedirectHandler method doOnStat.
@Override
protected XrootdResponse<StatRequest> doOnStat(ChannelHandlerContext ctx, StatRequest req) throws XrootdException {
try {
String path = req.getPath();
LoginSessionInfo loginSessionInfo = sessionInfo();
InetSocketAddress client = getSourceAddress();
return new StatResponse(req, _door.getFileStatus(createFullPath(path), loginSessionInfo.getSubject(), loginSessionInfo.getRestriction(), client.getAddress().getHostAddress()));
} catch (FileNotFoundCacheException e) {
throw xrootdException(e.getRc(), "No such file");
} 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.protocol.messages.StatResponse in project dcache by dCache.
the class AccessLogHandler method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof XrootdResponse<?> && logger.isErrorEnabled()) {
XrootdResponse<?> response = (XrootdResponse<?>) msg;
XrootdRequest request = response.getRequest();
NetLoggerBuilder.Level level;
if (response instanceof ErrorResponse) {
level = ERROR;
} else if (request instanceof WriteRequest || request instanceof ReadRequest || request instanceof ReadVRequest) {
level = DEBUG;
} else {
level = INFO;
}
if (level == ERROR || level == INFO && logger.isInfoEnabled() || level == DEBUG && logger.isDebugEnabled()) {
NetLoggerBuilder log = new NetLoggerBuilder(level, "org.dcache.xrootd.request").omitNullValues();
log.add("session", CDC.getSession());
log.add("request", getRequestId(request));
if (request instanceof PathRequest) {
log.add("path", (Strings.emptyToNull(((PathRequest) request).getPath())));
log.add("opaque", (Strings.emptyToNull(((PathRequest) request).getOpaque())));
if (request instanceof OpenRequest) {
if (!((OpenRequest) request).isReadOnly()) {
int mode = ((OpenRequest) request).getUMask();
if (mode == 0) {
log.add("mode", "0");
} else {
log.add("mode", "0" + Integer.toOctalString(mode));
}
}
log.add("options", "0x" + Integer.toHexString(((OpenRequest) request).getOptions()));
} else if (request instanceof LocateRequest) {
log.add("options", "0x" + Integer.toHexString(((LocateRequest) request).getOptions()));
} else if (request instanceof MkDirRequest) {
log.add("options", "0x" + Integer.toHexString(((MkDirRequest) request).getOptions()));
} else if (request instanceof StatRequest) {
if (((StatRequest) request).getTarget() == Target.FHANDLE) {
log.add("handle", ((StatRequest) request).getFhandle());
}
log.add("vfs", ((StatRequest) request).isVfsSet());
}
} else if (request instanceof CloseRequest) {
log.add("handle", ((CloseRequest) request).getFileHandle());
} else if (request instanceof LoginRequest) {
log.add("username", ((LoginRequest) request).getUserName());
log.add("capver", ((LoginRequest) request).getClientProtocolVersion());
log.add("pid", ((LoginRequest) request).getPID());
log.add("token", emptyToNull(((LoginRequest) request).getToken()));
} else if (request instanceof MvRequest) {
log.add("source", ((MvRequest) request).getSourcePath());
log.add("target", ((MvRequest) request).getTargetPath());
} else if (request instanceof PrepareRequest) {
log.add("options", "0x" + Integer.toHexString(((PrepareRequest) request).getOptions()));
if (((PrepareRequest) request).getPathList().length == 1) {
log.add("path", ((PrepareRequest) request).getPathList()[0]);
} else {
log.add("files", ((PrepareRequest) request).getPathList().length);
}
} else if (request instanceof QueryRequest) {
log.add("reqcode", getQueryReqCode(request));
int fhandle = ((QueryRequest) request).getFhandle();
if (fhandle != 0) {
log.add("fhandle", fhandle);
}
log.add("args", Strings.emptyToNull(((QueryRequest) request).getArgs()));
} else if (request instanceof StatxRequest) {
if (((StatxRequest) request).getPaths().length == 1) {
log.add("path", ((StatxRequest) request).getPaths()[0]);
} else {
log.add("files", ((StatxRequest) request).getPaths().length);
}
} else if (request instanceof SetRequest) {
final String APPID_PREFIX = "appid ";
final int APPID_PREFIX_LENGTH = APPID_PREFIX.length();
final int APPID_MSG_LENGTH = 80;
String data = ((SetRequest) request).getData();
if (data.startsWith(APPID_PREFIX)) {
log.add("appid", data.substring(APPID_PREFIX_LENGTH, Math.min(APPID_PREFIX_LENGTH + APPID_MSG_LENGTH, data.length())));
}
} else if (request instanceof EndSessionRequest) {
log.add("sessionId", ((EndSessionRequest) request).getSessionId());
} else if (request instanceof SyncRequest) {
log.add("handle", ((SyncRequest) request).getFileHandle());
}
log.add("response", getStatusCode(response));
if (response instanceof ErrorResponse) {
log.add("error.code", getErrorCode((ErrorResponse) response));
log.add("error.msg", ((ErrorResponse) response).getErrorMessage());
} else if (response instanceof RedirectResponse) {
log.add("host", ((RedirectResponse) response).getHost());
log.add("port", ((RedirectResponse) response).getPort());
log.add("token", emptyToNull(((RedirectResponse) response).getToken()));
} else if (response instanceof StatResponse) {
log.add("flags", ((StatResponse) response).getFlags());
log.add("modtime", Instant.ofEpochSecond(((StatResponse) response).getModificationTime()));
log.add("size", ((StatResponse) response).getSize());
} else if (response instanceof LoginResponse) {
log.add("sessionId", ((LoginResponse) response).getSessionId());
log.add("sec", emptyToNull(((LoginResponse) response).getSec()));
} else if (response instanceof OpenResponse) {
log.add("handle", ((OpenResponse) response).getFileHandle());
FileStatus fs = ((OpenResponse) response).getFileStatus();
if (fs != null) {
log.add("flags", fs.getFlags());
log.add("modtime", Instant.ofEpochSecond(fs.getModificationTime()));
log.add("size", fs.getSize());
}
}
log.toLogger(logger);
}
}
ctx.write(msg, promise);
}
Aggregations