From 4bf816b09d8fbf97be6dceb708d428a7a882bdb7 Mon Sep 17 00:00:00 2001
From: Cedric CAFFY <cedric.caffy@cern.ch>
Date: Thu, 18 Jul 2019 13:31:32 +0200
Subject: [PATCH] The repack buffer URL option is not mandatory anymore If this
 option is used, then the bufferURL provided to the repack request will be the
 one specified. Otherwise, the repack buffer URL will be the one from the
 cta-frontend-xrootd.conf file

---
 cmdline/CtaAdminCmdParse.hpp               |  2 +-
 xroot_plugins/XrdSsiCtaRequestMessage.cpp  | 15 ++++++++++++---
 xroot_plugins/XrdSsiCtaRequestMessage.hpp  |  2 ++
 xroot_plugins/XrdSsiCtaServiceProvider.cpp |  6 ++++++
 xroot_plugins/XrdSsiCtaServiceProvider.hpp |  3 +++
 xroot_plugins/cta-frontend-xrootd.conf     |  3 +++
 6 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/cmdline/CtaAdminCmdParse.hpp b/cmdline/CtaAdminCmdParse.hpp
index ae2528e6fe..ef521e133b 100644
--- a/cmdline/CtaAdminCmdParse.hpp
+++ b/cmdline/CtaAdminCmdParse.hpp
@@ -488,7 +488,7 @@ const std::map<cmd_key_t, cmd_val_t> cmdOptions = {
    {{ AdminCmd::CMD_MOUNTPOLICY,          AdminCmd::SUBCMD_LS    }, { }},
    /*----------------------------------------------------------------------------------------------------*/
    {{ AdminCmd::CMD_REPACK,               AdminCmd::SUBCMD_ADD   },
-      { opt_vid.optional(), opt_vidfile.optional(), opt_bufferurl, opt_justmove.optional(), opt_justaddcopies.optional() }},
+      { opt_vid.optional(), opt_vidfile.optional(), opt_bufferurl.optional(), opt_justmove.optional(), opt_justaddcopies.optional() }},
    {{ AdminCmd::CMD_REPACK,               AdminCmd::SUBCMD_RM    }, { opt_vid }},
    {{ AdminCmd::CMD_REPACK,               AdminCmd::SUBCMD_LS    }, { opt_vid.optional() }},
    {{ AdminCmd::CMD_REPACK,               AdminCmd::SUBCMD_ERR   }, { opt_vid }},
diff --git a/xroot_plugins/XrdSsiCtaRequestMessage.cpp b/xroot_plugins/XrdSsiCtaRequestMessage.cpp
index 3452ad4f47..75f4d2ac42 100644
--- a/xroot_plugins/XrdSsiCtaRequestMessage.cpp
+++ b/xroot_plugins/XrdSsiCtaRequestMessage.cpp
@@ -1070,10 +1070,19 @@ void RequestMessage::processRepack_Add(cta::xrd::Response &response)
    }
    
    auto buff = getOptional(OptionString::BUFFERURL);
-   if (buff)
+   if (buff){
+     //The buffer is provided by the user
      bufferURL = buff.value();
-   else
-     throw cta::exception::UserError("Must specify the buffer URL using --bufferurl option.");
+   }
+   else {
+     //Buffer is not provided by the user, try to get the one from the configuration file
+     if(m_repackBufferURL){
+       bufferURL = m_repackBufferURL.value();
+     } else {
+       //Buffer is neither provided by the user, neither provided by the frontend configuration file, exception
+       throw cta::exception::UserError("Must specify the buffer URL using --bufferurl option or using the frontend configuration file.");
+     }
+   }
 
    // Expand, repack, or both ?
    cta::common::dataStructures::RepackInfo::Type type;
diff --git a/xroot_plugins/XrdSsiCtaRequestMessage.hpp b/xroot_plugins/XrdSsiCtaRequestMessage.hpp
index 0d08dbcfc1..89eb5e68a2 100644
--- a/xroot_plugins/XrdSsiCtaRequestMessage.hpp
+++ b/xroot_plugins/XrdSsiCtaRequestMessage.hpp
@@ -36,6 +36,7 @@ public:
     m_scheddb  (service->getSchedDb()),
     m_catalogue(service->getCatalogue()),
     m_scheduler(service->getScheduler()),
+    m_repackBufferURL(service->getRepackBufferURL()),	    
     m_lc       (service->getLogContext()) {
       m_cliIdentity.username = client.name;
       m_cliIdentity.host     = client.host;
@@ -264,6 +265,7 @@ private:
   cta::OStoreDBWithAgent                               &m_scheddb;            //!< Reference to CTA ObjectStore
   cta::catalogue::Catalogue                            &m_catalogue;          //!< Reference to CTA Catalogue
   cta::Scheduler                                       &m_scheduler;          //!< Reference to CTA Scheduler
+  optional<std::string>				        m_repackBufferURL;    //!< Repack buffer URL
   cta::log::LogContext                                  m_lc;                 //!< CTA Log Context
   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
diff --git a/xroot_plugins/XrdSsiCtaServiceProvider.cpp b/xroot_plugins/XrdSsiCtaServiceProvider.cpp
index f490969036..e8729af8e7 100644
--- a/xroot_plugins/XrdSsiCtaServiceProvider.cpp
+++ b/xroot_plugins/XrdSsiCtaServiceProvider.cpp
@@ -147,6 +147,12 @@ void XrdSsiCtaServiceProvider::ExceptionThrowingInit(XrdSsiLogger *logP, XrdSsiC
    } catch (std::bad_cast &) {
       // If not, never mind
    }
+   
+   //Initialize the repack buffer URL
+   auto repackBufferURLConf = config.getOptionValueStr("cta.repack.repack_buffer_url");
+   if(repackBufferURLConf.first){
+     m_repackBufferURL = repackBufferURLConf.second;
+   }
   
    // Start the heartbeat thread for the agent object. The thread is guaranteed to have started before we call the unique_ptr deleter
    auto aht = new cta::objectstore::AgentHeartbeatThread(m_backendPopulator->getAgentReference(), *m_backend, *m_log);
diff --git a/xroot_plugins/XrdSsiCtaServiceProvider.hpp b/xroot_plugins/XrdSsiCtaServiceProvider.hpp
index 34ba96f57d..4f200a2082 100644
--- a/xroot_plugins/XrdSsiCtaServiceProvider.hpp
+++ b/xroot_plugins/XrdSsiCtaServiceProvider.hpp
@@ -103,6 +103,8 @@ public:
     * Get the log context for this Service
     */
    cta::log::LogContext getLogContext() const { return cta::log::LogContext(*m_log); }
+   
+   cta::optional<std::string> getRepackBufferURL() const { return m_repackBufferURL; }
 
 private:
    /*!
@@ -138,6 +140,7 @@ private:
    std::unique_ptr<cta::catalogue::Catalogue>          m_catalogue;           //!< CTA catalogue of tapes and tape files
    std::unique_ptr<cta::Scheduler>                     m_scheduler;           //!< The scheduler
    std::unique_ptr<cta::log::Logger>                   m_log;                 //!< The logger
+   cta::optional<std::string>		               m_repackBufferURL;     //!< The repack buffer URL
    UniquePtrAgentHeartbeatThread                       m_agentHeartbeat;      //!< Agent heartbeat thread
 
    static constexpr const char* const LOG_SUFFIX = "XrdSsiCtaServiceProvider";    //!< Identifier for log messages
diff --git a/xroot_plugins/cta-frontend-xrootd.conf b/xroot_plugins/cta-frontend-xrootd.conf
index 25159c3b77..2aaac02d3c 100644
--- a/xroot_plugins/cta-frontend-xrootd.conf
+++ b/xroot_plugins/cta-frontend-xrootd.conf
@@ -17,6 +17,9 @@ cta.log.url file:/var/log/cta/cta-frontend.log
 # CTA XRootD SSI/Protobuf log level
 cta.log.ssi warning
 
+# CTA Repack buffer URL
+cta.repack.repack_buffer_url root://ctaeos//eos/ctaeos/repack
+
 #
 # XRootD/SSI options
 #
-- 
GitLab