diff --git a/cmdline/CtaAdminCmd.cpp b/cmdline/CtaAdminCmd.cpp index cdf8a8f792c0aabd253bf8afad47d32a810bb2aa..0d50ea1369827f4ddd70273ae87f6ab4cebc944a 100644 --- a/cmdline/CtaAdminCmd.cpp +++ b/cmdline/CtaAdminCmd.cpp @@ -60,9 +60,9 @@ void IStreamBuffer<cta::xrd::Data>::DataCallback(cta::xrd::Data record) const { case Data::kAfItemFieldNumber : switch(record.af_item().type()) { - case ArchiveFileItem::ARCHIVEFILE_LS: CtaAdminCmd::printAfLsItem(record.af_item()); break; - case ArchiveFileItem::LISTPENDINGARCHIVES: CtaAdminCmd::printLpaItem (record.af_item()); break; - case ArchiveFileItem::LISTPENDINGRETRIEVES: CtaAdminCmd::printLprItem (record.af_item()); break; + case ArchiveFileItem::ARCHIVEFILE_LS: CtaAdminCmd::printAfLsItem(record.af_item()); break; + case ArchiveFileItem::LISTPENDINGARCHIVES: CtaAdminCmd::printLpaItem (record.af_item()); break; + case ArchiveFileItem::LISTPENDINGRETRIEVES: CtaAdminCmd::printLprItem (record.af_item()); break; default: throw std::runtime_error("Not implemented/received invalid stream data from CTA Frontend."); } @@ -70,8 +70,9 @@ void IStreamBuffer<cta::xrd::Data>::DataCallback(cta::xrd::Data record) const case Data::kAfSummaryItemFieldNumber : switch(record.af_summary_item().type()) { - case ArchiveFileSummaryItem::LISTPENDINGARCHIVES: CtaAdminCmd::printLpaSummaryItem(record.af_summary_item()); break; - case ArchiveFileSummaryItem::LISTPENDINGRETRIEVES: CtaAdminCmd::printLprSummaryItem(record.af_summary_item()); break; + case ArchiveFileSummaryItem::ARCHIVEFILE_LS: CtaAdminCmd::printAfLsSummaryItem(record.af_summary_item()); break; + case ArchiveFileSummaryItem::LISTPENDINGARCHIVES: CtaAdminCmd::printLpaSummaryItem (record.af_summary_item()); break; + case ArchiveFileSummaryItem::LISTPENDINGRETRIEVES: CtaAdminCmd::printLprSummaryItem (record.af_summary_item()); break; default: throw std::runtime_error("Not implemented/received invalid stream data from CTA Frontend."); } @@ -196,6 +197,7 @@ void CtaAdminCmd::send() const // Print streaming response header switch(response.show_header()) { case HeaderType::ARCHIVEFILE_LS: printAfLsHeader(); break; + case HeaderType::ARCHIVEFILE_LS_SUMMARY: printAfLsSummaryHeader(); break; case HeaderType::LISTPENDINGARCHIVES: printLpaHeader(); break; case HeaderType::LISTPENDINGARCHIVES_SUMMARY: printLpaSummaryHeader(); break; case HeaderType::LISTPENDINGRETRIEVES: printLprHeader(); break; @@ -404,6 +406,21 @@ void CtaAdminCmd::printAfLsItem(const cta::admin::ArchiveFileItem &af_item) << std::endl; } +void CtaAdminCmd::printAfLsSummaryHeader() +{ + std::cout << TEXT_RED + << std::setfill(' ') << std::setw(13) << std::right << "total files" << ' ' + << std::setfill(' ') << std::setw(12) << std::right << "total size" << ' ' + << TEXT_NORMAL << std::endl; +} + +void CtaAdminCmd::printAfLsSummaryItem(const cta::admin::ArchiveFileSummaryItem &af_summary_item) +{ + std::cout << std::setfill(' ') << std::setw(13) << std::right << af_summary_item.total_files() << ' ' + << std::setfill(' ') << std::setw(12) << std::right << af_summary_item.total_size() << ' ' + << std::endl; +} + void CtaAdminCmd::printLpaHeader() { std::cout << TEXT_RED diff --git a/cmdline/CtaAdminCmd.hpp b/cmdline/CtaAdminCmd.hpp index 931d3197bd2289b129c33bc5649eaaa99885db51..2d003d88a9a5957e8bd1c270a1a07994bab367a6 100644 --- a/cmdline/CtaAdminCmd.hpp +++ b/cmdline/CtaAdminCmd.hpp @@ -39,6 +39,8 @@ public: // "archivefile ls" command static void printAfLsHeader(); static void printAfLsItem(const ArchiveFileItem &af_item); + static void printAfLsSummaryHeader(); + static void printAfLsSummaryItem(const ArchiveFileSummaryItem &af_item); // "listpendingarchives" command static void printLpaHeader(); diff --git a/xroot_plugins/XrdCtaArchiveFileLs.hpp b/xroot_plugins/XrdCtaArchiveFileLs.hpp index ef3b3ea03a70469b98e4593a225397749ba800b8..3e6f6c31671eaf80d1829d0b929b03ef697a308c 100644 --- a/xroot_plugins/XrdCtaArchiveFileLs.hpp +++ b/xroot_plugins/XrdCtaArchiveFileLs.hpp @@ -31,8 +31,9 @@ namespace cta { namespace xrd { class ArchiveFileLsStream : public XrdSsiStream { public: - ArchiveFileLsStream(cta::catalogue::ArchiveFileItor archiveFileItor) : + ArchiveFileLsStream(bool is_extended, cta::catalogue::ArchiveFileItor archiveFileItor) : XrdSsiStream(XrdSsiStream::isActive), + m_isExtended(is_extended), m_archiveFileItor(std::move(archiveFileItor)) { XrdSsiPb::Log::Msg(XrdSsiPb::Log::DEBUG, LOG_SUFFIX, "ArchiveFileLsStream() constructor"); @@ -75,6 +76,22 @@ public: streambuf = new XrdSsiPb::OStreamBuffer<cta::xrd::Data>(dlen); +#if 0 + if(has_flag(OptionBoolean::SUMMARY)) { + // Probably we should use a data response here, to prevent timeouts while calculating the summary statistics + cta::common::dataStructures::ArchiveFileSummary summary = m_catalogue.getTapeFileSummary(searchCriteria); + std::vector<std::vector<std::string>> responseTable; + std::vector<std::string> header = { "total number of files","total size" }; + std::vector<std::string> row = {std::to_string(static_cast<unsigned long long>(summary.totalFiles)), + std::to_string(static_cast<unsigned long long>(summary.totalBytes))}; + if(has_flag(OptionBoolean::SHOW_HEADER)) responseTable.push_back(header); + responseTable.push_back(row); + std::stringstream cmdlineOutput; + cmdlineOutput << formatResponse(responseTable); + response.set_message_txt(cmdlineOutput.str()); + } +#endif + for(bool is_buffer_full = false; m_archiveFileItor.hasMore() && !is_buffer_full; ) { const cta::common::dataStructures::ArchiveFile archiveFile = m_archiveFileItor.next(); @@ -135,7 +152,8 @@ public: } private: - catalogue::ArchiveFileItor m_archiveFileItor; + bool m_isExtended; //!< Summary or extended listing? + catalogue::ArchiveFileItor m_archiveFileItor; //!< Iterator across files which have been archived static constexpr const char* const LOG_SUFFIX = "ArchiveFileLsStream"; //!< Identifier for log messages }; diff --git a/xroot_plugins/XrdSsiCtaRequestMessage.cpp b/xroot_plugins/XrdSsiCtaRequestMessage.cpp index 62d34d1bfbdbdbcf5332cd25fa0e9c79d99ef43f..163bfd9697d04cc477c4225e945558e6d8e0c24e 100644 --- a/xroot_plugins/XrdSsiCtaRequestMessage.cpp +++ b/xroot_plugins/XrdSsiCtaRequestMessage.cpp @@ -841,26 +841,13 @@ void RequestMessage::processArchiveFile_Ls(const cta::admin::AdminCmd &admincmd, } } - if(has_flag(OptionBoolean::SUMMARY)) { - // Probably we should use a data response here, to prevent timeouts while calculating the summary statistics - cta::common::dataStructures::ArchiveFileSummary summary = m_catalogue.getTapeFileSummary(searchCriteria); - std::vector<std::vector<std::string>> responseTable; - std::vector<std::string> header = { "total number of files","total size" }; - std::vector<std::string> row = {std::to_string(static_cast<unsigned long long>(summary.totalFiles)), - std::to_string(static_cast<unsigned long long>(summary.totalBytes))}; - if(has_flag(OptionBoolean::SHOW_HEADER)) responseTable.push_back(header); - responseTable.push_back(row); - std::stringstream cmdlineOutput; - cmdlineOutput << formatResponse(responseTable); - response.set_message_txt(cmdlineOutput.str()); - } else { - // Create a XrdSsi stream object to return the results - stream = new ArchiveFileLsStream(m_catalogue.getArchiveFiles(searchCriteria)); + // Create a XrdSsi stream object to return the results + stream = new ArchiveFileLsStream(has_flag(OptionBoolean::EXTENDED), m_catalogue.getArchiveFiles(searchCriteria)); - // Should the client print headers? - if(has_flag(OptionBoolean::SHOW_HEADER)) { - response.set_show_header(cta::admin::HeaderType::ARCHIVEFILE_LS); - } + // Should the client display column headers? + if(has_flag(OptionBoolean::SHOW_HEADER)) { + response.set_show_header(has_flag(OptionBoolean::SUMMARY) ? HeaderType::ARCHIVEFILE_LS_SUMMARY + : HeaderType::ARCHIVEFILE_LS); } response.set_type(cta::xrd::Response::RSP_SUCCESS); @@ -1224,11 +1211,8 @@ void RequestMessage::processListPendingArchives(const cta::admin::AdminCmd &admi // Should the client display column headers? if(has_flag(OptionBoolean::SHOW_HEADER)) { - if(has_flag(OptionBoolean::EXTENDED)) { - response.set_show_header(HeaderType::LISTPENDINGARCHIVES); - } else { - response.set_show_header(HeaderType::LISTPENDINGARCHIVES_SUMMARY); - } + response.set_show_header(has_flag(OptionBoolean::EXTENDED) ? HeaderType::LISTPENDINGARCHIVES + : HeaderType::LISTPENDINGARCHIVES_SUMMARY); } response.set_type(cta::xrd::Response::RSP_SUCCESS); @@ -1250,11 +1234,8 @@ void RequestMessage::processListPendingRetrieves(const cta::admin::AdminCmd &adm // Should the client display column headers? if(has_flag(OptionBoolean::SHOW_HEADER)) { - if(has_flag(OptionBoolean::EXTENDED)) { - response.set_show_header(HeaderType::LISTPENDINGRETRIEVES); - } else { - response.set_show_header(HeaderType::LISTPENDINGRETRIEVES_SUMMARY); - } + response.set_show_header(has_flag(OptionBoolean::EXTENDED) ? HeaderType::LISTPENDINGRETRIEVES + : HeaderType::LISTPENDINGRETRIEVES_SUMMARY); } response.set_type(cta::xrd::Response::RSP_SUCCESS); diff --git a/xrootd-ssi-protobuf-interface b/xrootd-ssi-protobuf-interface index 36cf1ea86e6f6cd0843a9a90521b36c3948d2937..a0852801beb2802954596389b5a7126999c9c1c6 160000 --- a/xrootd-ssi-protobuf-interface +++ b/xrootd-ssi-protobuf-interface @@ -1 +1 @@ -Subproject commit 36cf1ea86e6f6cd0843a9a90521b36c3948d2937 +Subproject commit a0852801beb2802954596389b5a7126999c9c1c6