From c58e04004edcf641425f3e173985cb0dd193e4fb Mon Sep 17 00:00:00 2001 From: Daniele Kruse <dkruse@cern.ch> Date: Fri, 20 Feb 2015 16:12:06 +0100 Subject: [PATCH] Added tape commands --- xroot_clients/CTACmd.cpp | 5 +- xroot_plugins/XrdProFilesystem.cpp | 122 +++++++++++++++++++++++++++++ xroot_plugins/XrdProFilesystem.hpp | 30 +++++++ 3 files changed, 156 insertions(+), 1 deletion(-) diff --git a/xroot_clients/CTACmd.cpp b/xroot_clients/CTACmd.cpp index 178f5b56ed..1e1b63df15 100644 --- a/xroot_clients/CTACmd.cpp +++ b/xroot_clients/CTACmd.cpp @@ -38,7 +38,10 @@ void CTACmd::usage(std::ostream &os) const throw() { "\t" << m_programName << " lsroute\n" "\t" << m_programName << " mkllib <logical_library_name> <\"comment\">\n" "\t" << m_programName << " rmllib <logical_library_name>\n" - "\t" << m_programName << " lsllib\n" + "\t" << m_programName << " lsllib\n" + "\t" << m_programName << " mktape <vid> <logical_library_name> <tapepool_name> <capacity_in_bytes> <\"comment\">\n" + "\t" << m_programName << " rmtape <vid>\n" + "\t" << m_programName << " lstape\n" "\t" << m_programName << " mkadminuser <uid> <gid>\n" "\t" << m_programName << " rmadminuser <uid> <gid>\n" "\t" << m_programName << " lsadminuser\n" diff --git a/xroot_plugins/XrdProFilesystem.cpp b/xroot_plugins/XrdProFilesystem.cpp index f04f9a0893..3272c9b89d 100644 --- a/xroot_plugins/XrdProFilesystem.cpp +++ b/xroot_plugins/XrdProFilesystem.cpp @@ -815,6 +815,116 @@ int XrdProFilesystem::executeLsllibCommand(const ParsedRequest &req, XrdOucErrIn } } +//------------------------------------------------------------------------------ +// executeMktapeCommand +//------------------------------------------------------------------------------ +int XrdProFilesystem::executeMktapeCommand(const ParsedRequest &req, XrdOucErrInfo &eInfo, const cta::SecurityIdentity &requester) { + if(req.args.size() != 5) { + std::string response = "[ERROR] Wrong number of arguments provided"; + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } + try { + uint64_t capacity; + std::istringstream ss(req.args.at(3)); + ss >> capacity; + m_adminApi.createTape(requester, req.args.at(0), req.args.at(1), req.args.at(2), capacity, req.args.at(4)); + std::ostringstream responseSS; + responseSS << "[OK] Tape " << req.args.at(0) << " of logical library " << req.args.at(1) << " of " << capacity << " bytes of capacity " << " was created in tapepool " << req.args.at(2) << " with comment \"" << req.args.at(4) << "\""; + eInfo.setErrInfo(responseSS.str().length()+1, responseSS.str().c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } catch (...) { + std::string response = "[ERROR] Unknown exception caught!"; + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } +} + +//------------------------------------------------------------------------------ +// executeRmtapeCommand +//------------------------------------------------------------------------------ +int XrdProFilesystem::executeRmtapeCommand(const ParsedRequest &req, XrdOucErrInfo &eInfo, const cta::SecurityIdentity &requester) { + if(req.args.size() != 1) { + std::string response = "[ERROR] Wrong number of arguments provided"; + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } + try { + m_adminApi.deleteTape(requester, req.args.at(0)); + std::ostringstream responseSS; + responseSS << "[OK] Tape " << req.args.at(0) << " removed"; + eInfo.setErrInfo(responseSS.str().length()+1, responseSS.str().c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } catch (...) { + std::string response = "[ERROR] Unknown exception caught!"; + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } +} + +//------------------------------------------------------------------------------ +// executeLstapeCommand +//------------------------------------------------------------------------------ +int XrdProFilesystem::executeLstapeCommand(const ParsedRequest &req, XrdOucErrInfo &eInfo, const cta::SecurityIdentity &requester) const { + if(req.args.size() != 0) { + std::string response = "[ERROR] Wrong number of arguments provided"; + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } + try { + std::list<cta::Tape> tapes = m_adminApi.getTapes(requester); + std::ostringstream responseSS; + responseSS << "[OK] Listing of tapes:"; + for(std::list<cta::Tape>::iterator it = tapes.begin(); it != tapes.end(); it++) { + responseSS << "\n" << it->getVid() + << " " << it->getCapacityInBytes() + << " " << it->getDataOnTapeInBytes() + << " " << it->getLogicalLibraryName() + << " " << it->getTapePoolName() + << " " << it->getCreator().getUid() + << " " << it->getCreator().getGid() + << " " << it->getCreationTime() + << " \"" << it->getComment() << "\""; + } + eInfo.setErrInfo(responseSS.str().length()+1, responseSS.str().c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } catch (...) { + std::string response = "[ERROR] Unknown exception caught!"; + eInfo.setErrInfo(response.length()+1, response.c_str()); + return SFS_DATA; + } +} + //------------------------------------------------------------------------------ // executeMkadminuserCommand //------------------------------------------------------------------------------ @@ -1121,6 +1231,18 @@ int XrdProFilesystem::dispatchRequest(const XrdSfsFSctl &args, XrdOucErrInfo &eI else if(strcmp(req.cmd.c_str(), "/lsllib") == 0) { return executeLsllibCommand(req, eInfo, requester); + } + else if(strcmp(req.cmd.c_str(), "/mktape") == 0) + { + return executeMktapeCommand(req, eInfo, requester); + } + else if(strcmp(req.cmd.c_str(), "/rmtape") == 0) + { + return executeRmtapeCommand(req, eInfo, requester); + } + else if(strcmp(req.cmd.c_str(), "/lstape") == 0) + { + return executeLstapeCommand(req, eInfo, requester); } else if(strcmp(req.cmd.c_str(), "/mkadminuser") == 0) { diff --git a/xroot_plugins/XrdProFilesystem.hpp b/xroot_plugins/XrdProFilesystem.hpp index d2eb74a060..dea9a98032 100644 --- a/xroot_plugins/XrdProFilesystem.hpp +++ b/xroot_plugins/XrdProFilesystem.hpp @@ -267,6 +267,36 @@ protected: */ int executeLsllibCommand(const ParsedRequest &req, XrdOucErrInfo &eInfo, const cta::SecurityIdentity &requester) const; + /** + * Executes the command contained within the request structure + * + * @param req parsed request + * @param eInfo Error information + * @param requester The UserIdentity structure of the requester + * @return SFS_DATA + */ + int executeMktapeCommand(const ParsedRequest &req, XrdOucErrInfo &eInfo, const cta::SecurityIdentity &requester); + + /** + * Executes the command contained within the request structure + * + * @param req parsed request + * @param eInfo Error information + * @param requester The UserIdentity structure of the requester + * @return SFS_DATA + */ + int executeRmtapeCommand(const ParsedRequest &req, XrdOucErrInfo &eInfo, const cta::SecurityIdentity &requester); + + /** + * Executes the command contained within the request structure + * + * @param req parsed request + * @param eInfo Error information + * @param requester The UserIdentity structure of the requester + * @return SFS_DATA + */ + int executeLstapeCommand(const ParsedRequest &req, XrdOucErrInfo &eInfo, const cta::SecurityIdentity &requester) const; + /** * Executes the command contained within the request structure * -- GitLab