diff --git a/xroot_plugins/XrdSsiCtaRequestMessage.cpp b/xroot_plugins/XrdSsiCtaRequestMessage.cpp index 914828b89a75a708c86fe2263e027e8b81ad3e67..a01b76c4a5e8e26a3a27fd12c818937c9fa149c0 100644 --- a/xroot_plugins/XrdSsiCtaRequestMessage.cpp +++ b/xroot_plugins/XrdSsiCtaRequestMessage.cpp @@ -42,8 +42,8 @@ void RequestMessage::process(const cta::xrd::Request &request, cta::xrd::Respons using namespace cta::xrd; case Request::kAdmincmd: - // Validate the Protocol Buffer - validateCmd(request.admincmd()); + // Validate the Protocol Buffer and import options into maps + importOptions(request.admincmd()); // Map the <Cmd, SubCmd> to a method switch(cmd_pair(request.admincmd().cmd(), request.admincmd().subcmd())) { @@ -68,9 +68,10 @@ void RequestMessage::process(const cta::xrd::Request &request, cta::xrd::Respons case cmd_pair(AdminCmd::CMD_GROUPMOUNTRULE, AdminCmd::SUBCMD_ADD): case cmd_pair(AdminCmd::CMD_GROUPMOUNTRULE, AdminCmd::SUBCMD_CH): case cmd_pair(AdminCmd::CMD_GROUPMOUNTRULE, AdminCmd::SUBCMD_RM): - case cmd_pair(AdminCmd::CMD_GROUPMOUNTRULE, AdminCmd::SUBCMD_LS): + case cmd_pair(AdminCmd::CMD_GROUPMOUNTRULE, AdminCmd::SUBCMD_LS): case cmd_pair(AdminCmd::CMD_LISTPENDINGARCHIVES, AdminCmd::SUBCMD_NONE): - case cmd_pair(AdminCmd::CMD_LISTPENDINGRETRIEVES, AdminCmd::SUBCMD_NONE): +goto the_end; + case cmd_pair(AdminCmd::CMD_LISTPENDINGRETRIEVES, AdminCmd::SUBCMD_NONE): processListPendingRetrieves(request.admincmd(), response); break; case cmd_pair(AdminCmd::CMD_LOGICALLIBRARY, AdminCmd::SUBCMD_ADD): case cmd_pair(AdminCmd::CMD_LOGICALLIBRARY, AdminCmd::SUBCMD_CH): case cmd_pair(AdminCmd::CMD_LOGICALLIBRARY, AdminCmd::SUBCMD_RM): @@ -111,6 +112,7 @@ void RequestMessage::process(const cta::xrd::Request &request, cta::xrd::Respons case cmd_pair(AdminCmd::CMD_VERIFY, AdminCmd::SUBCMD_LS): case cmd_pair(AdminCmd::CMD_VERIFY, AdminCmd::SUBCMD_ERR): + the_end: default: throw PbException("Admin command pair <" + AdminCmd_Cmd_Name(request.admincmd().cmd()) + ", " + @@ -267,5 +269,105 @@ void RequestMessage::processDELETE(const cta::eos::Notification ¬ification, c response.set_type(cta::xrd::Response::RSP_SUCCESS); } + + +void RequestMessage::processListPendingRetrieves(const cta::admin::AdminCmd &admincmd, cta::xrd::Response &response) +{ +#if 0 + std::stringstream cmdlineOutput; + std::stringstream help; + log::LogContext lc(m_log); + help << m_requestTokens.at(0) << " lpr/listpendingretrieves [--header/-h] [--vid/-v <vid>] [--extended/-x]" << std::endl; + if (hasOption("-?", "--help")) { + return help.str(); + } +#endif + using namespace cta::admin; + + auto vid = m_option_str.find(OptionString::VID); + //bool extended = m_option_bool.find(OptionBoolean::EXTENDED) != m_option_bool.end(); + + std::map<std::string, std::list<cta::common::dataStructures::RetrieveJob> > result; + + if(vid == m_option_str.end()) { + result = m_scheduler.getPendingRetrieveJobs(m_lc); + } else { + std::list<cta::common::dataStructures::RetrieveJob> list = m_scheduler.getPendingRetrieveJobs(vid->second, m_lc); + + if(list.size() > 0) { + result[vid->second] = list; + } + } + +#if 0 + if(result.size()>0) + { + std::vector<std::vector<std::string>> responseTable; + + if(extended) { + std::vector<std::string> header = {"vid","id","copy no.","fseq","block id","size","user","group","path"}; + if(hasOption("-h", "--header")) responseTable.push_back(header); + for(auto it = result.cbegin(); it != result.cend(); it++) { + for(auto jt = it->second.cbegin(); jt != it->second.cend(); jt++) { + std::vector<std::string> currentRow; + currentRow.push_back(it->first); + currentRow.push_back(std::to_string((unsigned long long)jt->request.archiveFileID)); + cta::common::dataStructures::ArchiveFile file = m_catalogue->getArchiveFileById(jt->request.archiveFileID); + currentRow.push_back(std::to_string((unsigned long long)(jt->tapeCopies.at(it->first).first))); + currentRow.push_back(std::to_string((unsigned long long)(jt->tapeCopies.at(it->first).second.fSeq))); + currentRow.push_back(std::to_string((unsigned long long)(jt->tapeCopies.at(it->first).second.blockId))); + currentRow.push_back(std::to_string((unsigned long long)file.fileSize)); + currentRow.push_back(jt->request.requester.name); + currentRow.push_back(jt->request.requester.group); + currentRow.push_back(jt->request.diskFileInfo.path); + responseTable.push_back(currentRow); + } + } + } else { + std::vector<std::string> header = {"vid","total files","total size"}; + if(hasOption("-h", "--header")) responseTable.push_back(header); + for(auto it = result.cbegin(); it != result.cend(); it++) { + std::vector<std::string> currentRow; + currentRow.push_back(it->first); + currentRow.push_back(std::to_string((unsigned long long)it->second.size())); + uint64_t size=0; + for(auto jt = it->second.cbegin(); jt != it->second.cend(); jt++) { + cta::common::dataStructures::ArchiveFile file = m_catalogue->getArchiveFileById(jt->request.archiveFileID); + size += file.fileSize; + } + currentRow.push_back(std::to_string((unsigned long long)size)); + responseTable.push_back(currentRow); + } + } + cmdlineOutput << formatResponse(responseTable, hasOption("-h", "--header")); + } + + //return cmdlineOutput.str(); +#endif +} + + + +void RequestMessage::importOptions(const cta::admin::AdminCmd &admincmd) +{ + // Validate the Protocol Buffer + validateCmd(admincmd); + + // Import Boolean options + for(auto opt_it = admincmd.option_bool().begin(); opt_it != admincmd.option_bool().end(); ++opt_it) { + m_option_bool.insert(std::make_pair(opt_it->key(), opt_it->value())); + } + + // Import UInt64 options + for(auto opt_it = admincmd.option_uint64().begin(); opt_it != admincmd.option_uint64().end(); ++opt_it) { + m_option_uint64.insert(std::make_pair(opt_it->key(), opt_it->value())); + } + + // Import String options + for(auto opt_it = admincmd.option_str().begin(); opt_it != admincmd.option_str().end(); ++opt_it) { + m_option_str.insert(std::make_pair(opt_it->key(), opt_it->value())); + } +} + }} // namespace cta::xrd diff --git a/xroot_plugins/XrdSsiCtaRequestMessage.hpp b/xroot_plugins/XrdSsiCtaRequestMessage.hpp index 7a9aff437fead47bd7265a93ccf259bd47193034..e55b752ebfab3e65d73421539bba2ac3077ccc1f 100644 --- a/xroot_plugins/XrdSsiCtaRequestMessage.hpp +++ b/xroot_plugins/XrdSsiCtaRequestMessage.hpp @@ -57,11 +57,31 @@ private: notification_event_t processPREPARE; //!< Retrieve file event notification_event_t processDELETE; //!< Delete file event + /*! + * Process AdminCmd events + * + * @param[in] admincmd CTA Admin command request message + * @param[out] response CTA Admin command response message + */ + typedef void admincmd_t(const cta::admin::AdminCmd &admincmd, cta::xrd::Response &response); + + admincmd_t processListPendingRetrieves; + + /*! + * Import Google Protobuf option fields into maps + * + * @param[in] admincmd CTA Admin command request message + */ + void importOptions(const cta::admin::AdminCmd &admincmd); + // Member variables - cta::Scheduler &m_scheduler; //!< Reference to CTA Scheduler - cta::log::LogContext m_lc; //!< CTA Log Context - const char * const m_instance_name; //!< Instance name = XRootD client name + cta::Scheduler &m_scheduler; //!< Reference to CTA Scheduler + cta::log::LogContext m_lc; //!< CTA Log Context + const char * const m_instance_name; //!< Instance name = XRootD client name + std::map<cta::admin::OptionBoolean::Key, bool> m_option_bool; //!< Boolean options + std::map<cta::admin::OptionUInt64::Key, uint64_t> m_option_uint64; //!< UInt64 options + std::map<cta::admin::OptionString::Key, std::string> m_option_str; //!< String options }; }} // namespace cta::xrd diff --git a/xroot_plugins/messages/cta_frontend.proto b/xroot_plugins/messages/cta_frontend.proto index 25ad10765ddfbfd07f0e27d3fe3a4e8866eba3ec..25fb2fbdb3201fbbcccb002ba0b1e865ce58c600 100644 --- a/xroot_plugins/messages/cta_frontend.proto +++ b/xroot_plugins/messages/cta_frontend.proto @@ -39,9 +39,10 @@ message Request { message Response { enum ResponseType { - RSP_SUCCESS = 0; //< Notification was queued successfully - RSP_ERR_PROTOBUF = 1; //< Framework error caused by Google Protocol Buffers layer - RSP_ERR_CTA = 2; //< Server error reported by CTA Frontend + RSP_INVALID = 0; //< Response type was not set + RSP_SUCCESS = 1; //< Notification was queued successfully + RSP_ERR_PROTOBUF = 2; //< Framework error caused by Google Protocol Buffers layer + RSP_ERR_CTA = 3; //< Server error reported by CTA Frontend } ResponseType type = 1; //< Encode the type of this reply string message_txt = 2; //< Text of the reply