diff --git a/cmdline/EosCtaApi.h b/cmdline/EosCtaApi.h index 0c140cf478864e251f5aa2f9f83dc2151e8199c2..fd0a6aad876cd77957b64423a9bd939973cc0aa9 100644 --- a/cmdline/EosCtaApi.h +++ b/cmdline/EosCtaApi.h @@ -19,7 +19,7 @@ #ifndef __EOS_CTA_API_H #define __EOS_CTA_API_H -#include "XrdSsiPbServiceClientSide.h" //!< XRootD SSI/Protocol Buffer Service bindings (client side) +#include "XrdSsiPbServiceClientSide.hpp" //!< XRootD SSI/Protocol Buffer Service, client-side bindings #include "eos/messages/eos_messages.pb.h" //!< Auto-generated message types from .proto file /*! diff --git a/cmdline/EosCtaStub.cpp b/cmdline/EosCtaStub.cpp index 96bda7dc68e36baf8acd4b8eae4cc8a123b4fa8e..490645fee408b2b015d112e56a1fee91b09b4f94 100644 --- a/cmdline/EosCtaStub.cpp +++ b/cmdline/EosCtaStub.cpp @@ -21,10 +21,10 @@ #include <iostream> #include <sstream> #include <cryptopp/base64.h> -#include <google/protobuf/util/json_util.h> #include "common/dataStructures/FrontendReturnCode.hpp" -#include "XrdSsiPbDebug.h" + +#include "XrdSsiPbDebug.hpp" #include "EosCtaApi.h" @@ -283,6 +283,19 @@ int exceptionThrowingMain(int argc, const char *const *const argv) XrdSsiPb::OutputJsonString(myout, &response); } + // Handle responses + + switch(response.type()) + { + using namespace eos::wfe; + + case Response::RSP_SUCCESS: myout << response.message_txt() << std::endl; break; + case Response::RSP_ERR_PROTOBUF: throw XrdSsiPb::PbException(response.message_txt()); + case Response::RSP_ERR_CTA: throw std::runtime_error(response.message_txt()); + // ... define other response types in the protocol buffer (e.g. user error) + default: throw XrdSsiPb::PbException("Invalid response type."); + } + // Delete all global objects allocated by libprotobuf google::protobuf::ShutdownProtobufLibrary(); @@ -303,12 +316,16 @@ int main(int argc, const char **argv) { try { return exceptionThrowingMain(argc, argv); + } catch (XrdSsiPb::PbException &ex) { + std::cerr << "Error in Google Protocol Buffers: " << ex.what() << std::endl; + } catch (XrdSsiPb::XrdSsiException &ex) { + std::cerr << "Error from XRootD SSI Framework: " << ex.what() << std::endl; } catch (std::exception &ex) { - std::cerr << "Failed to execute the command. Reason: " << ex.what() << std::endl; - return cta::common::dataStructures::FrontendReturnCode::ctaErrorNoRetry; + std::cerr << "Caught exception: " << ex.what() << std::endl; } catch (...) { - std::cerr << "Failed to execute the command for an unknown reason" << std::endl; - return cta::common::dataStructures::FrontendReturnCode::ctaErrorNoRetry; + std::cerr << "Caught an unknown exception" << std::endl; } + + return cta::common::dataStructures::FrontendReturnCode::ctaErrorNoRetry; } diff --git a/eos/messages/eos_messages.proto b/eos/messages/eos_messages.proto index 6c247277b78181e90eda257c8e3f79d4ce125de0..c9180ce5ffe06f9bf869432b3f5816b755044558 100644 --- a/eos/messages/eos_messages.proto +++ b/eos/messages/eos_messages.proto @@ -111,8 +111,8 @@ message Response { RSP_ERR_PROTOBUF = 1; //< Framework error caused by Google Protocol Buffers layer RSP_ERR_CTA = 2; //< Server error reported by CTA Frontend } - ResponseType rsp_type = 1; //< Encode the type of this reply - Alert alert_msg = 2; //< Text of the reply + ResponseType type = 1; //< Encode the type of this reply + string message_txt = 2; //< Text of the reply } diff --git a/xroot_plugins/XrdSsiCtaRequestProc.cpp b/xroot_plugins/XrdSsiCtaRequestProc.cpp index d7d85166d9039d1bc46f05d82b7654c7a26755b2..edcdd956b211d62bf9bb9ca582448462fb4eb0f0 100644 --- a/xroot_plugins/XrdSsiCtaRequestProc.cpp +++ b/xroot_plugins/XrdSsiCtaRequestProc.cpp @@ -19,9 +19,9 @@ #include <iostream> #include <memory> -#include "XrdSsiPbDebug.h" // for Json output -#include "XrdSsiPbException.h" -#include "XrdSsiPbRequestProc.h" +#include "XrdSsiPbDebug.hpp" // for Json output +#include "XrdSsiPbException.hpp" +#include "XrdSsiPbRequestProc.hpp" #include "eos/messages/eos_messages.pb.h" #include "common/Configuration.hpp" @@ -102,13 +102,12 @@ void RequestProc<eos::wfe::Notification, eos::wfe::Response, eos::wfe::Alert>::E // Set metadata - m_metadata.set_rsp_type(eos::wfe::Response::RSP_SUCCESS); + m_metadata.set_type(eos::wfe::Response::RSP_SUCCESS); } catch(std::exception &ex) { - m_metadata.set_rsp_type(eos::wfe::Response::RSP_ERR_CTA); - m_metadata.mutable_alert_msg()->set_audience(eos::wfe::Alert::EOSLOG); - m_metadata.mutable_alert_msg()->set_message_txt(ex.what()); + m_metadata.set_type(eos::wfe::Response::RSP_ERR_CTA); + m_metadata.set_message_txt(ex.what()); } #if 0 @@ -186,14 +185,14 @@ void RequestProc<eos::wfe::Notification, eos::wfe::Response, eos::wfe::Alert>:: { // Set metadata - m_metadata.set_rsp_type(eos::wfe::Response::RSP_ERR_CTA); + m_metadata.set_type(eos::wfe::Response::RSP_ERR_CTA); //switch(err_num) //{ //case PB_PARSE_ERR: m_metadata.mutable_exception()->set_code(eos::wfe::Exception::PB_PARSE_ERR); //} - m_metadata.mutable_alert_msg()->set_message_txt(err_text); + m_metadata.set_message_txt(err_text); // Output message in Json format (for debugging) diff --git a/xroot_plugins/XrdSsiCtaService.h b/xroot_plugins/XrdSsiCtaService.h index 10c98a658ac44c2490cf7ef7ed9c406845af39b3..f6da04910845e4b38d3f78195c7c1861bd39d3cb 100644 --- a/xroot_plugins/XrdSsiCtaService.h +++ b/xroot_plugins/XrdSsiCtaService.h @@ -4,7 +4,7 @@ #include <unistd.h> // for debugging #include <XrdSsi/XrdSsiService.hh> -#include "XrdSsiPbRequestProc.h" +#include "XrdSsiPbRequestProc.hpp" @@ -61,7 +61,7 @@ void XrdSsiCtaService<RequestType, MetadataType, AlertType>::ProcessRequest(XrdS // Tell the framework we are done with the request object // WE NEED TO ENSURE THAT FINISHED() HAS BEEN CALLED BEFORE UNBIND - sleep(1); + sleep(1); // remove unistd.h #ifdef XRDSSI_DEBUG std::cout << "[DEBUG] XrdSsiCtaService::ProcessRequest(): Calling UnBindRequest()" << std::endl; #endif diff --git a/xroot_plugins/XrdSsiCtaServiceProvider.cpp b/xroot_plugins/XrdSsiCtaServiceProvider.cpp index c6208e304f0613c21e9143e368f37c11317287a0..e14a96a6a58e36acfb9af8c068109ebfb7c0c572 100644 --- a/xroot_plugins/XrdSsiCtaServiceProvider.cpp +++ b/xroot_plugins/XrdSsiCtaServiceProvider.cpp @@ -2,7 +2,7 @@ #include <iostream> #endif -#include "XrdSsiPbAlert.h" +#include "XrdSsiPbAlert.hpp" #include "XrdSsiCtaService.h" #include "XrdSsiCtaServiceProvider.h" #include "eos/messages/eos_messages.pb.h" diff --git a/xroot_ssi_pb/XrdSsiPbAlert.h b/xroot_ssi_pb/XrdSsiPbAlert.hpp similarity index 98% rename from xroot_ssi_pb/XrdSsiPbAlert.h rename to xroot_ssi_pb/XrdSsiPbAlert.hpp index 28f39d0516fbd260eed2f93d8dd705d078495a29..a8f285a7954ad6364b06d76fb323fca58ca15a5b 100644 --- a/xroot_ssi_pb/XrdSsiPbAlert.h +++ b/xroot_ssi_pb/XrdSsiPbAlert.hpp @@ -20,7 +20,7 @@ #define __XRD_SSI_PB_ALERT_H #include <XrdSsi/XrdSsiRespInfo.hh> -#include "XrdSsiPbException.h" +#include "XrdSsiPbException.hpp" namespace XrdSsiPb { diff --git a/xroot_ssi_pb/XrdSsiPbDebug.h b/xroot_ssi_pb/XrdSsiPbDebug.hpp similarity index 100% rename from xroot_ssi_pb/XrdSsiPbDebug.h rename to xroot_ssi_pb/XrdSsiPbDebug.hpp diff --git a/xroot_ssi_pb/XrdSsiPbException.h b/xroot_ssi_pb/XrdSsiPbException.hpp similarity index 74% rename from xroot_ssi_pb/XrdSsiPbException.h rename to xroot_ssi_pb/XrdSsiPbException.hpp index b9f56f2690574536619dbeb99eb84dc40f3ef2a7..2f1eaad5a5cd47c8cf34ba13bc2c983f8fea0610 100644 --- a/xroot_ssi_pb/XrdSsiPbException.h +++ b/xroot_ssi_pb/XrdSsiPbException.hpp @@ -28,15 +28,10 @@ namespace XrdSsiPb { * Framework exception thrown by Google Protocol Buffers layer */ -class PbException : public std::exception -{ +class PbException : public std::runtime_error { public: - PbException(const std::string &err_msg) : m_err_msg(err_msg) {} - - const char* what() const noexcept { return m_err_msg.c_str(); } - -private: - std::string m_err_msg; + PbException(const char *err_msg) : std::runtime_error(err_msg) {} + PbException(const std::string &err_msg) : std::runtime_error(err_msg) {} }; @@ -45,11 +40,12 @@ private: * Framework exception thrown by XRootD/SSI layer */ -class XrdSsiException : public PbException +class XrdSsiException : public std::runtime_error { public: - XrdSsiException(const std::string &err_msg) : PbException(err_msg) {} - XrdSsiException(const XrdSsiErrInfo &eInfo) : PbException(eInfo.Get()) {} + XrdSsiException(const char *err_msg) : std::runtime_error(err_msg) {} + XrdSsiException(const std::string &err_msg) : std::runtime_error(err_msg) {} + XrdSsiException(const XrdSsiErrInfo &eInfo) : std::runtime_error(eInfo.Get()) {} }; } // namespace XrdSsiPb diff --git a/xroot_ssi_pb/XrdSsiPbRequest.h b/xroot_ssi_pb/XrdSsiPbRequest.hpp similarity index 100% rename from xroot_ssi_pb/XrdSsiPbRequest.h rename to xroot_ssi_pb/XrdSsiPbRequest.hpp diff --git a/xroot_ssi_pb/XrdSsiPbRequestProc.h b/xroot_ssi_pb/XrdSsiPbRequestProc.hpp similarity index 98% rename from xroot_ssi_pb/XrdSsiPbRequestProc.h rename to xroot_ssi_pb/XrdSsiPbRequestProc.hpp index 57e80d491bda93a96970faea154dcc8b4f5eef57..6d2d4005956e749df48d66bf31051a46157ca639 100644 --- a/xroot_ssi_pb/XrdSsiPbRequestProc.h +++ b/xroot_ssi_pb/XrdSsiPbRequestProc.hpp @@ -20,8 +20,8 @@ #define __XRD_SSI_PB_REQUEST_PROC_H #include <XrdSsi/XrdSsiResponder.hh> -#include "XrdSsiPbException.h" -#include "XrdSsiPbAlert.h" +#include "XrdSsiPbException.hpp" +#include "XrdSsiPbAlert.hpp" namespace XrdSsiPb { diff --git a/xroot_ssi_pb/XrdSsiPbServiceClientSide.h b/xroot_ssi_pb/XrdSsiPbServiceClientSide.hpp similarity index 99% rename from xroot_ssi_pb/XrdSsiPbServiceClientSide.h rename to xroot_ssi_pb/XrdSsiPbServiceClientSide.hpp index 245073bbe0626990610af83b1879287d68a22432..ab824816abfbb282b491b29ac3ce40c8752ac6d7 100644 --- a/xroot_ssi_pb/XrdSsiPbServiceClientSide.h +++ b/xroot_ssi_pb/XrdSsiPbServiceClientSide.hpp @@ -23,8 +23,8 @@ #include <XrdSsi/XrdSsiProvider.hh> #include <XrdSsi/XrdSsiService.hh> -#include "XrdSsiPbException.h" -#include "XrdSsiPbRequest.h" +#include "XrdSsiPbException.hpp" +#include "XrdSsiPbRequest.hpp"