@Override public void startRequest(MRCRequest rq) throws Throwable { final removexattrRequest rqArgs = (removexattrRequest) rq.getRequestArgs(); final VolumeManager vMan = master.getVolumeManager(); final FileAccessManager faMan = master.getFileAccessManager(); Path p = new Path(rqArgs.getVolumeName(), rqArgs.getPath()); validateContext(rq); StorageManager sMan = vMan.getStorageManagerByName(p.getComp(0)); PathResolver res = new PathResolver(sMan, p); // check whether the path prefix is searchable faMan.checkSearchPermission( sMan, res, rq.getDetails().userId, rq.getDetails().superUser, rq.getDetails().groupIds); // check whether file exists res.checkIfFileDoesNotExist(); // retrieve and prepare the metadata to return FileMetadata file = res.getFile(); AtomicDBUpdate update = sMan.createAtomicDBUpdate(master, rq); // if the attribute is a system attribute, set it final String attrKey = rqArgs.getName(); // set a system attribute if (attrKey.startsWith("xtreemfs.")) { // check whether the user has privileged permissions to set // system attributes faMan.checkPrivilegedPermissions( sMan, file, rq.getDetails().userId, rq.getDetails().superUser, rq.getDetails().groupIds); MRCHelper.setSysAttrValue( sMan, vMan, faMan, res.getParentDirId(), file, attrKey.substring(9), "", update); } // set a user attribute else { sMan.setXAttr(file.getId(), rq.getDetails().userId, attrKey, null, update); } // update POSIX timestamps int time = (int) (TimeSync.getGlobalTime() / 1000); MRCHelper.updateFileTimes(res.getParentDirId(), file, false, true, false, sMan, time, update); // set the response rq.setResponse(timestampResponse.newBuilder().setTimestampS(time).build()); update.execute(); }
@Override public void startRequest(MRCRequest rq) throws Throwable { final XCap xcap = (XCap) rq.getRequestArgs(); // perform master redirect if necessary due to DB operation if (master.getReplMasterUUID() != null && !master.getReplMasterUUID().equals(master.getConfig().getUUID().toString())) throw new DatabaseException(ExceptionType.REDIRECT); // create a capability object to verify the capability Capability cap = new Capability(xcap, master.getConfig().getCapabilitySecret()); // check whether the capability has a valid signature if (!cap.hasValidSignature()) throw new UserException( POSIXErrno.POSIX_ERROR_EPERM, cap + " does not have a valid signature"); // check whether the capability has expired if (cap.hasExpired() && !renewTimedOutCaps) throw new UserException(POSIXErrno.POSIX_ERROR_EPERM, cap + " has expired"); Capability newCap = new Capability( cap.getFileId(), cap.getAccessMode(), master.getConfig().getCapabilityTimeout(), TimeSync.getGlobalTime() / 1000 + master.getConfig().getCapabilityTimeout(), cap.getClientIdentity(), cap.getEpochNo(), cap.isReplicateOnClose(), cap.getSnapConfig(), cap.getSnapTimestamp(), cap.getTraceConfig().getTraceRequests(), cap.getTraceConfig().getTracingPolicy(), cap.getTraceConfig().getTracingPolicyConfig(), cap.getVoucherSize(), 0L, master.getConfig().getCapabilitySecret()); // set the response rq.setResponse(newCap.getXCap()); finishRequest(rq); }
@Override public void startRequest(MRCRequest rq) throws Throwable { final statvfsRequest rqArgs = (statvfsRequest) rq.getRequestArgs(); final VolumeManager vMan = master.getVolumeManager(); final StorageManager sMan = vMan.getStorageManagerByName(rqArgs.getVolumeName()); StatVFS volumeInfo = getVolumeInfo(master, sMan); // long knownEtag = rqArgs.getKnownEtag(); // StatVFSSet set = new StatVFSSet(); // if (knownEtag != volumeInfo.getEtag()) // set.add(volumeInfo); // set the response rq.setResponse(volumeInfo); finishRequest(rq); }
private void redirect(MRCRequest rq, String uuid) { rq.getRPCRequest().sendRedirect(uuid); }
/** * Execute an operation * * @param operation MRCOperation to execute * @param method StageMethod to serve as the context */ private void execute(MRCOperation op, StageMethod method) { final MRCRequest rq = method.getRq(); final RPCServerRequest rpcRequest = rq.getRPCRequest(); final RPCHeader header = rpcRequest.getHeader(); final RPCHeader.RequestHeader rqHeader = header.getRequestHeader(); try { if (Logging.isDebug()) { StringBuffer params = new StringBuffer(); Map<FieldDescriptor, Object> fieldMap = rq.getRequestArgs() == null ? null : rq.getRequestArgs().getAllFields(); if (fieldMap != null) { int i = 0; for (Entry<FieldDescriptor, Object> entry : fieldMap.entrySet()) { params.append( entry.getKey().getName() + "='" + entry.getValue() + (i == fieldMap.size() - 1 ? "'" : "', ")); i++; } } Logging.logMessage( Logging.LEVEL_DEBUG, this, "parsed request: %s (%s)\n", StatusPage.getOpName(rqHeader.getProcId()), params.toString()); } op.startRequest(rq); } catch (UserException exc) { reportUserError(op, rq, exc, exc.getErrno()); } catch (MRCException exc) { Throwable cause = exc.getCause(); if (cause instanceof DatabaseException && ((DatabaseException) cause).getType() == ExceptionType.NOT_ALLOWED) reportUserError(op, rq, exc, POSIXErrno.POSIX_ERROR_EPERM); else reportServerError(op, rq, exc); } catch (DatabaseException exc) { if (exc.getType() == ExceptionType.NOT_ALLOWED) { reportUserError(op, rq, exc, POSIXErrno.POSIX_ERROR_EPERM); } else if (exc.getType() == ExceptionType.REDIRECT) { try { redirect( rq, exc.getAttachment() != null ? (String) exc.getAttachment() : master.getReplMasterUUID()); } catch (MRCException e) { reportServerError(op, rq, e); } } else reportServerError(op, rq, exc); } catch (Throwable exc) { reportServerError(op, rq, exc); } }
/** * Parse request and execute method * * @param method stagemethod to execute */ private void parseAndExecute(StageMethod method) { final MRCRequest rq = method.getRq(); final RPCServerRequest rpcRequest = rq.getRPCRequest(); final RPCHeader header = rpcRequest.getHeader(); final RPCHeader.RequestHeader rqHeader = header.getRequestHeader(); if (header.getMessageType() != MessageType.RPC_REQUEST) { rq.setError( ErrorType.GARBAGE_ARGS, POSIXErrno.POSIX_ERROR_EIO, "expected RPC request message type but got " + header.getMessageType()); return; } final MRCOperation op = operations.get(rqHeader.getProcId()); if (op == null) { rq.setError( ErrorType.INVALID_PROC_ID, "requested operation (" + rqHeader.getProcId() + ") is not available on this MRC"); master.requestFinished(rq); return; } if (Logging.isDebug()) Logging.logMessage( Logging.LEVEL_DEBUG, Category.stage, this, "operation for request %s: %s", rq.toString(), op.getClass().getSimpleName()); if (statisticsEnabled) { _opCountMap.put(rqHeader.getProcId(), _opCountMap.get(rqHeader.getProcId()) + 1); } // parse request arguments ErrorRecord error = op.parseRequestArgs(rq); if (error != null) { rq.setError(error); master.requestFinished(rq); return; } try { // get the auth data if available Auth auth = header.getRequestHeader().hasAuthData() ? header.getRequestHeader().getAuthData() : null; // get the user credentials org.xtreemfs.foundation.pbrpc.generatedinterfaces.RPC.UserCredentials ctx = op.getUserCredentials(rq); if (ctx != null) try { UserCredentials cred = master .getAuthProvider() .getEffectiveCredentials(ctx, rpcRequest.getConnection().getChannel()); rq.getDetails().superUser = cred.isSuperUser(); rq.getDetails().groupIds = cred.getGroupIDs(); rq.getDetails().userId = cred.getUserID(); rq.getDetails().auth = auth; rq.getDetails().password = auth != null && auth.hasAuthPasswd() ? auth.getAuthPasswd().getPassword() : ""; } catch (AuthenticationException ex) { throw new UserException(POSIXErrno.POSIX_ERROR_EPERM, ex.getMessage()); } } catch (Exception exc) { method .getRq() .setError( ErrorType.INTERNAL_SERVER_ERROR, "could not initialize authentication module", exc); master.requestFinished(method.getRq()); return; } execute(op, method); }
/** * Parse request and execute method * * @param method stagemethod to execute */ private void parseAndExecute(StageMethod method) { final MRCRequest rq = method.getRq(); final RPCServerRequest rpcRequest = rq.getRPCRequest(); final RPCHeader header = rpcRequest.getHeader(); final RPCHeader.RequestHeader rqHeader = header.getRequestHeader(); if (header.getMessageType() != MessageType.RPC_REQUEST) { rq.setError( ErrorType.GARBAGE_ARGS, POSIXErrno.POSIX_ERROR_EIO, "expected RPC request message type but got " + header.getMessageType()); return; } final MRCOperation op = operations.get(rqHeader.getProcId()); if (op == null) { rq.setError( ErrorType.INVALID_PROC_ID, "requested operation (" + rqHeader.getProcId() + ") is not available on this MRC"); master.requestFinished(rq); return; } if (Logging.isDebug()) Logging.logMessage( Logging.LEVEL_DEBUG, Category.stage, this, "operation for request %s: %s", rq.toString(), op.getClass().getSimpleName()); if (statisticsEnabled) { _opCountMap.put(rqHeader.getProcId(), _opCountMap.get(rqHeader.getProcId()) + 1); } // parse request arguments ErrorRecord error = op.parseRequestArgs(rq); if (error != null) { rq.setError(error); master.requestFinished(rq); return; } try { // get the auth data if available Auth auth = header.getRequestHeader().hasAuthData() ? header.getRequestHeader().getAuthData() : null; // get the user credentials org.xtreemfs.foundation.pbrpc.generatedinterfaces.RPC.UserCredentials ctx = op.getUserCredentials(rq); if (ctx != null) try { UserCredentials cred = master .getAuthProvider() .getEffectiveCredentials(ctx, rpcRequest.getConnection().getChannel()); rq.getDetails().superUser = cred.isSuperUser(); rq.getDetails().groupIds = cred.getGroupIDs(); rq.getDetails().userId = cred.getUserID(); rq.getDetails().auth = auth; rq.getDetails().password = auth != null && auth.hasAuthPasswd() ? auth.getAuthPasswd().getPassword() : ""; } catch (AuthenticationException ex) { throw new UserException(POSIXErrno.POSIX_ERROR_EPERM, ex.getMessage()); } } catch (Exception exc) { method .getRq() .setError( ErrorType.INTERNAL_SERVER_ERROR, "could not initialize authentication module", exc); master.requestFinished(method.getRq()); return; } try { if (Logging.isDebug()) { StringBuffer params = new StringBuffer(); Map<FieldDescriptor, Object> fieldMap = rq.getRequestArgs() == null ? null : rq.getRequestArgs().getAllFields(); if (fieldMap != null) { int i = 0; for (Entry<FieldDescriptor, Object> entry : fieldMap.entrySet()) { params.append( entry.getKey().getName() + "='" + entry.getValue() + (i == fieldMap.size() - 1 ? "'" : "', ")); i++; } } Logging.logMessage( Logging.LEVEL_DEBUG, this, "parsed request: %s (%s)\n", StatusPage.getOpName(rqHeader.getProcId()), params.toString()); } op.startRequest(rq); } catch (UserException exc) { reportUserError(op, rq, exc, exc.getErrno()); } catch (MRCException exc) { Throwable cause = exc.getCause(); if (cause instanceof DatabaseException && ((DatabaseException) cause).getType() == ExceptionType.NOT_ALLOWED) reportUserError(op, rq, exc, POSIXErrno.POSIX_ERROR_EPERM); else reportServerError(op, rq, exc); } catch (DatabaseException exc) { if (exc.getType() == ExceptionType.NOT_ALLOWED) { reportUserError(op, rq, exc, POSIXErrno.POSIX_ERROR_EPERM); } else if (exc.getType() == ExceptionType.REDIRECT) { try { redirect( rq, exc.getAttachment() != null ? (String) exc.getAttachment() : master.getReplMasterUUID()); } catch (MRCException e) { reportServerError(op, rq, e); } } else reportServerError(op, rq, exc); } catch (Throwable exc) { reportServerError(op, rq, exc); } }