diff --git a/xroot_plugins/CMakeLists.txt b/xroot_plugins/CMakeLists.txt index 029f25cb3e484e4504d1eb917525389e0e607591..910390150e08336690292c4a277c77edbede297c 100644 --- a/xroot_plugins/CMakeLists.txt +++ b/xroot_plugins/CMakeLists.txt @@ -40,7 +40,7 @@ add_subdirectory(messages) add_definitions(-DXRDSSI_DEBUG) include_directories(../xroot_ssi_pb) -add_library(XrdSsiCta MODULE XrdSsiCtaServiceProvider.cpp XrdSsiCtaRequestProc.cpp XrdSsiCtaEos.cpp) +add_library(XrdSsiCta MODULE XrdSsiCtaServiceProvider.cpp XrdSsiCtaRequestProc.cpp XrdSsiCtaRequestMessage.cpp) target_link_libraries(XrdSsiCta XrdSsi-4 XrdSsiLib XrdCtaMessages ctascheduler ctacommon ctaobjectstore ctacatalogue) set_target_properties(XrdSsiCta PROPERTIES INSTALL_RPATH ${PROTOBUF3_RPATH}) diff --git a/xroot_plugins/XrdSsiCtaEos.cpp b/xroot_plugins/XrdSsiCtaRequestMessage.cpp similarity index 78% rename from xroot_plugins/XrdSsiCtaEos.cpp rename to xroot_plugins/XrdSsiCtaRequestMessage.cpp index df9e7715170ebcb79d84694fba4384f2d20d1e45..639d73ed49e201034a64d7eb83eff005c9e29dcd 100644 --- a/xroot_plugins/XrdSsiCtaEos.cpp +++ b/xroot_plugins/XrdSsiCtaRequestMessage.cpp @@ -19,37 +19,39 @@ #include "XrdSsiPbException.hpp" using XrdSsiPb::PbException; -#include "xroot_plugins/messages/cta_frontend.pb.h" -#include "XrdSsiCtaEos.hpp" +#include "XrdSsiCtaRequestMessage.hpp" -#if 0 -#include "common/dataStructures/ArchiveRequest.hpp" -#include "common/exception/Exception.hpp" -#ifdef XRDSSI_DEBUG -#include "XrdSsiPbDebug.hpp" -#endif -#include "XrdSsiPbResource.hpp" -#include "XrdSsiPbRequestProc.hpp" -#include "xroot_plugins/messages/cta_frontend.pb.h" +namespace cta { namespace xrd { -#include "XrdSsiCtaServiceProvider.hpp" -#endif +void RequestMessage::process(const cta::xrd::Request &request, cta::xrd::Response &response) +{ + // Branch on the Request payload type + switch(request.request_case()) + { + using namespace cta::xrd; + case Request::kAdmincmd: + case Request::kNotification: processNotification(request.notification(), response); break; + case Request::REQUEST_NOT_SET: throw PbException("Request message has not been set."); + default: throw PbException("Unrecognized Request message. " + "Possible Protocol Buffer version mismatch between client and server."); + } +} -namespace cta { namespace frontend { -void EosNotificationRequest::process(const cta::eos::Notification ¬ification, cta::xrd::Response &response) + +void RequestMessage::processNotification(const cta::eos::Notification ¬ification, cta::xrd::Response &response) { switch(notification.wf().event()) { using namespace cta::eos; - case Workflow::CLOSEW: requestProcCLOSEW (notification, response); break; - case Workflow::PREPARE: requestProcPREPARE(notification, response); break; - case Workflow::DELETE: requestProcDELETE (notification, response); break; + case Workflow::CLOSEW: processCLOSEW (notification, response); break; + case Workflow::PREPARE: processPREPARE(notification, response); break; + case Workflow::DELETE: processDELETE (notification, response); break; default: throw PbException("Workflow Event type " + std::to_string(notification.wf().event()) + " is not supported."); @@ -58,8 +60,7 @@ void EosNotificationRequest::process(const cta::eos::Notification ¬ification, - -void EosNotificationRequest::requestProcCLOSEW(const cta::eos::Notification ¬ification, cta::xrd::Response &response) +void RequestMessage::processCLOSEW(const cta::eos::Notification ¬ification, cta::xrd::Response &response) { // Unpack message @@ -102,7 +103,7 @@ void EosNotificationRequest::requestProcCLOSEW(const cta::eos::Notification ¬ -void EosNotificationRequest::requestProcPREPARE(const cta::eos::Notification ¬ification, cta::xrd::Response &response) +void RequestMessage::processPREPARE(const cta::eos::Notification ¬ification, cta::xrd::Response &response) { // Unpack message @@ -140,7 +141,7 @@ void EosNotificationRequest::requestProcPREPARE(const cta::eos::Notification &no -void EosNotificationRequest::requestProcDELETE(const cta::eos::Notification ¬ification, cta::xrd::Response &response) +void RequestMessage::processDELETE(const cta::eos::Notification ¬ification, cta::xrd::Response &response) { // Unpack message @@ -174,12 +175,12 @@ void EosNotificationRequest::requestProcDELETE(const cta::eos::Notification ¬ cta::log::ScopedParamContainer params(m_lc); params.add("fileId", request.archiveFileID).add("catalogueTime", t.secs()); - m_lc.log(cta::log::INFO, "In requestProcDELETE(): deleted archive file."); + m_lc.log(cta::log::INFO, "In processDELETE(): deleted archive file."); // Set response type response.set_type(cta::xrd::Response::RSP_SUCCESS); } -}} // namespace cta::frontend +}} // namespace cta::xrd diff --git a/xroot_plugins/XrdSsiCtaEos.hpp b/xroot_plugins/XrdSsiCtaRequestMessage.hpp similarity index 70% rename from xroot_plugins/XrdSsiCtaEos.hpp rename to xroot_plugins/XrdSsiCtaRequestMessage.hpp index 31fb07ac5d07933ad745a7113c7e18668236a8e8..b4cb54b8debc8dbced169b3784b5bf78b6aff3df 100644 --- a/xroot_plugins/XrdSsiCtaEos.hpp +++ b/xroot_plugins/XrdSsiCtaRequestMessage.hpp @@ -1,6 +1,6 @@ /*! * @project The CERN Tape Archive (CTA) - * @brief XRootD EOS Notification handler + * @brief CTA Frontend Message handler * @copyright Copyright 2017 CERN * @license This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,16 +21,17 @@ #include <XrdSsi/XrdSsiEntity.hh> #include "XrdSsiCtaServiceProvider.hpp" +#include "xroot_plugins/messages/cta_frontend.pb.h" -namespace cta { namespace frontend { +namespace cta { namespace xrd { /*! - * EOS Notification handler class + * CTA Frontend Request Message class */ -class EosNotificationRequest +class RequestMessage { public: - EosNotificationRequest(const XrdSsiEntity &client, const XrdSsiCtaServiceProvider *service) : + RequestMessage(const XrdSsiEntity &client, const XrdSsiCtaServiceProvider *service) : m_scheduler(service->getScheduler()), m_lc(service->getLogContext()), m_instance_name(client.name) {} @@ -38,19 +39,27 @@ public: /*! * Process the Notification request * - * @param[in] notification Notification request message from EOS WFE + * @param[in] request * @param[out] response Response message to return to EOS */ - void process(const cta::eos::Notification ¬ification, cta::xrd::Response &response); + void process(const cta::xrd::Request &request, cta::xrd::Response &response); private: + /*! + * Process the EOS WFE Notification message type + * + * @param[in] notification Notification request message from EOS WFE + * @param[out] response Response message to return to EOS + */ + void processNotification(const cta::eos::Notification ¬ification, cta::xrd::Response &response); + /*! * Process the CLOSEW workflow event * * @param[in] notification Notification request message from EOS WFE * @param[out] response Response message to return to EOS */ - void requestProcCLOSEW(const cta::eos::Notification ¬ification, cta::xrd::Response &response); + void processCLOSEW(const cta::eos::Notification ¬ification, cta::xrd::Response &response); /*! * Process the PREPARE workflow event @@ -58,7 +67,7 @@ private: * @param[in] notification Notification request message from EOS WFE * @param[out] response Response message to return to EOS */ - void requestProcPREPARE(const cta::eos::Notification ¬ification, cta::xrd::Response &response); + void processPREPARE(const cta::eos::Notification ¬ification, cta::xrd::Response &response); /*! * Process the DELETE workflow event @@ -66,7 +75,7 @@ private: * @param[in] notification Notification request message from EOS WFE * @param[out] response Response message to return to EOS */ - void requestProcDELETE(const cta::eos::Notification ¬ification, cta::xrd::Response &response); + void processDELETE(const cta::eos::Notification ¬ification, cta::xrd::Response &response); // Member variables @@ -75,4 +84,4 @@ private: const char * const m_instance_name; //< Instance name = XRootD client name }; -}} // namespace cta::frontend +}} // namespace cta::xrd diff --git a/xroot_plugins/XrdSsiCtaRequestProc.cpp b/xroot_plugins/XrdSsiCtaRequestProc.cpp index e4c4feef329ffd2e9898e895730ad7560fb8837a..468feaa25de6a792ec70808f027ada8b3b8a6eb1 100644 --- a/xroot_plugins/XrdSsiCtaRequestProc.cpp +++ b/xroot_plugins/XrdSsiCtaRequestProc.cpp @@ -24,10 +24,9 @@ #endif #include "XrdSsiPbException.hpp" #include "XrdSsiPbRequestProc.hpp" -#include "xroot_plugins/messages/cta_frontend.pb.h" #include "XrdSsiCtaServiceProvider.hpp" -#include "XrdSsiCtaEos.hpp" +#include "XrdSsiCtaRequestMessage.hpp" @@ -67,12 +66,16 @@ void RequestProc<cta::xrd::Request, cta::xrd::Response, cta::xrd::Alert>::Execut OutputJsonString(std::cerr, &m_request); #endif - // Process EOS Request - //const cta::eos::Notification ¬ification = m_request.notification(); + cta::xrd::RequestMessage request_msg(*(m_resource.client), cta_service_ptr); + request_msg.process(m_request, m_metadata); + } + catch(PbException &ex) + { + // Set the response - cta::frontend::EosNotificationRequest eos_rq(*(m_resource.client), cta_service_ptr); - eos_rq.process(m_request.notification(), m_metadata); + m_metadata.set_type(cta::xrd::Response::RSP_ERR_PROTOBUF); + m_metadata.set_message_txt(ex.what()); } catch(std::exception &ex) {