Skip to content
Snippets Groups Projects
Commit ab6350d5 authored by Michael Davis's avatar Michael Davis
Browse files

[EOS-CTA] Moves Service intialisation into the ServiceProvider class

parent 317d2e49
Branches
Tags
No related merge requests found
......@@ -16,25 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <memory>
#include "common/dataStructures/ArchiveRequest.hpp"
#include "common/exception/Exception.hpp"
#include "XrdSsiPbDebug.hpp" // for Json output
#ifdef XRDSSI_DEBUG
#include "XrdSsiPbDebug.hpp"
#endif
#include "XrdSsiPbException.hpp"
#include "XrdSsiPbResource.hpp"
#include "XrdSsiPbRequestProc.hpp"
#include "eos/messages/eos_messages.pb.h"
#include "common/Configuration.hpp"
#include "common/dataStructures/ArchiveRequest.hpp"
#include "common/log/StdoutLogger.hpp"
#include "scheduler/Scheduler.hpp"
#include "objectstore/BackendFactory.hpp"
#include "objectstore/BackendPopulator.hpp"
#include "catalogue/CatalogueFactory.hpp"
#include "rdbms/Login.hpp"
#include "scheduler/OStoreDB/OStoreDBWithAgent.hpp"
#include "common/make_unique.hpp"
#include "XrdSsiCtaServiceProvider.hpp"
......@@ -62,30 +55,20 @@ void RequestProc<eos::wfe::Notification, eos::wfe::Response, eos::wfe::Alert>::E
{
try
{
getClient(m_resource);
// Instantiate the scheduler
const cta::rdbms::Login catalogueLogin = cta::rdbms::Login::parseFile("/etc/cta/cta_catalogue_db.conf");
const uint64_t nbConns = 10;
const uint64_t nbArchiveFileListingConns = 2;
// Perform a capability query on the XrdSsiProviderServer object: it must be a XrdSsiCtaServiceProvider
std::unique_ptr<cta::catalogue::Catalogue> my_catalogue = cta::catalogue::CatalogueFactory::create(catalogueLogin, nbConns, nbArchiveFileListingConns);
cta::common::Configuration ctaConf("/etc/cta/cta-frontend.conf");
std::string backend_str = ctaConf.getConfEntString("ObjectStore", "BackendPath", nullptr);
XrdSsiCtaServiceProvider *cta_service_ptr;
if(!(cta_service_ptr = dynamic_cast<XrdSsiCtaServiceProvider *>(XrdSsiProviderServer)))
{
throw cta::exception::Exception("XRootD Service is not a CTA Service");
}
std::unique_ptr<cta::objectstore::Backend> backend(cta::objectstore::BackendFactory::createBackend(backend_str));
cta::objectstore::BackendPopulator backendPopulator(*backend, "Frontend");
cta::OStoreDBWithAgent scheddb(*backend, backendPopulator.getAgentReference());
#ifdef XRDSSI_DEBUG
// Output message in Json format
cta::Scheduler *scheduler = new cta::Scheduler(*my_catalogue, scheddb, 5, 2*1000*1000);
cta::log::StdoutLogger log("ctafrontend");
cta::log::LogContext lc(log);
// Output message in Json format (for debugging)
std::cerr << "Received message:" << std::endl;
OutputJsonString(std::cerr, &m_request);
#endif
// Unpack message
......@@ -113,31 +96,32 @@ void RequestProc<eos::wfe::Notification, eos::wfe::Response, eos::wfe::Alert>::E
// Queue the request
uint64_t archiveFileId = scheduler->queueArchive(client_username, request, lc);
uint64_t archiveFileId = cta_service_ptr->getScheduler().queueArchive(client_username, request, cta_service_ptr->getLogContext());
// Temporary hack to send back archiveFileId (deprecated)
std::string result_str = "<eos::wfe::path::fxattr:sys.archiveFileId>" + std::to_string(archiveFileId);
std::cout << result_str << std::endl;
#ifdef XRDSSI_DEBUG
std::cerr << result_str << std::endl;
#endif
m_metadata.set_message_txt(result_str);
// Set metadata
m_metadata.set_type(eos::wfe::Response::RSP_SUCCESS);
// Temporary hack to send back archiveFileId (deprecated)
m_metadata.set_message_txt(result_str);
}
catch(std::exception &ex)
{
// Send a log message
#ifdef XRDSSI_DEBUG
// Serialize and send a log message
eos::wfe::Alert alert_msg;
alert_msg.set_audience(eos::wfe::Alert::EOSLOG);
alert_msg.set_message_txt("Something bad happened");
// Serialize and send the alert message
Alert(alert_msg);
#endif
// Set the response
m_metadata.set_type(eos::wfe::Response::RSP_ERR_CTA);
......
#ifdef XRDSSI_DEBUG
#include <iostream>
#endif
#include <XrdSsi/XrdSsiProvider.hh>
#include "XrdSsiPbAlert.hpp"
#include "XrdSsiPbService.hpp"
#include "eos/messages/eos_messages.pb.h"
/*!
* The Service Provider class.
* @project The CERN Tape Archive (CTA)
* @brief XRootD Service Provider class implementation
* @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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Instantiate a Service to process client requests.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class XrdSsiCtaServiceProvider : public XrdSsiProvider
{
public:
XrdSsiCtaServiceProvider() {
#ifdef XRDSSI_DEBUG
std::cout << "[DEBUG] XrdSsiCtaServiceProvider() constructor" << std::endl;
#endif
}
virtual ~XrdSsiCtaServiceProvider() {
#ifdef XRDSSI_DEBUG
std::cout << "[DEBUG] ~XrdSsiCtaServiceProvider() destructor" << std::endl;
#include <iostream>
#endif
}
//! Initialize the object for its intended use. This is always called before any other method.
bool Init(XrdSsiLogger *logP, XrdSsiCluster *clsP, const std::string cfgFn, const std::string parms,
int argc, char **argv) override;
#include "common/make_unique.hpp"
//! Called exactly once after initialisation to obtain an instance of an XrdSsiService object
#include "rdbms/Login.hpp"
#include "catalogue/CatalogueFactory.hpp"
#include "common/Configuration.hpp"
#include "scheduler/OStoreDB/OStoreDBWithAgent.hpp"
#include "objectstore/BackendFactory.hpp"
#include "objectstore/BackendPopulator.hpp"
#include "common/log/StdoutLogger.hpp"
XrdSsiService *GetService(XrdSsiErrInfo &eInfo, const std::string &contact, int oHold=256) override;
//! Determine resource availability. Can be called any time the client asks for the resource status.
#include "XrdSsiPbAlert.hpp"
#include "XrdSsiPbService.hpp"
#include "eos/messages/eos_messages.pb.h"
XrdSsiProvider::rStat QueryResource(const char *rName, const char *contact=0) override;
};
#include "XrdSsiCtaServiceProvider.hpp"
......@@ -68,7 +59,26 @@ bool XrdSsiCtaServiceProvider::Init(XrdSsiLogger *logP, XrdSsiCluster *clsP, con
std::cout << "[DEBUG] Called Init(" << cfgFn << "," << parms << ")" << std::endl;
#endif
// do some initialisation
const cta::rdbms::Login catalogueLogin = cta::rdbms::Login::parseFile("/etc/cta/cta_catalogue_db.conf");
const uint64_t nbConns = 10;
const uint64_t nbArchiveFileListingConns = 2;
std::unique_ptr<cta::catalogue::Catalogue> my_catalogue = cta::catalogue::CatalogueFactory::create(catalogueLogin, nbConns, nbArchiveFileListingConns);
cta::common::Configuration ctaConf("/etc/cta/cta-frontend.conf");
std::string backend_str = ctaConf.getConfEntString("ObjectStore", "BackendPath", nullptr);
std::unique_ptr<cta::objectstore::Backend> backend(cta::objectstore::BackendFactory::createBackend(backend_str));
cta::objectstore::BackendPopulator backendPopulator(*backend, "Frontend");
cta::OStoreDBWithAgent scheddb(*backend, backendPopulator.getAgentReference());
// Instantiate the scheduler
m_scheduler_ptr = cta::make_unique<cta::Scheduler>(*my_catalogue, scheddb, 5, 2*1000*1000);
// Instantiate the logger
cta::log::StdoutLogger log("ctafrontend");
m_log_context_ptr = cta::make_unique<cta::log::LogContext>(log);
return true;
}
......
/*!
* @project The CERN Tape Archive (CTA)
* @brief XRootD Service Provider class
* @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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __XRD_SSI_CTA_SERVICE_PROVIDER_H
#define __XRD_SSI_CTA_SERVICE_PROVIDER_H
#include <XrdSsi/XrdSsiProvider.hh>
#include "scheduler/Scheduler.hpp"
/*!
* Global pointer to the Service Provider object.
*/
extern XrdSsiProvider *XrdSsiProviderServer;
/*!
* Instantiates a Service to process client requests.
*/
class XrdSsiCtaServiceProvider : public XrdSsiProvider
{
public:
XrdSsiCtaServiceProvider() {
#ifdef XRDSSI_DEBUG
std::cout << "[DEBUG] XrdSsiCtaServiceProvider() constructor" << std::endl;
#endif
}
virtual ~XrdSsiCtaServiceProvider() {
#ifdef XRDSSI_DEBUG
std::cout << "[DEBUG] ~XrdSsiCtaServiceProvider() destructor" << std::endl;
#endif
}
/*!
* Initialize the object for its intended use. This is always called before any other method.
*/
bool Init(XrdSsiLogger *logP, XrdSsiCluster *clsP, const std::string cfgFn, const std::string parms,
int argc, char **argv) override;
/*!
* Called exactly once after initialisation to obtain an instance of an XrdSsiService object
*/
XrdSsiService *GetService(XrdSsiErrInfo &eInfo, const std::string &contact, int oHold=256) override;
/*!
* Determine resource availability. Can be called any time the client asks for the resource status.
*/
XrdSsiProvider::rStat QueryResource(const char *rName, const char *contact=0) override;
/*!
* Get a reference to the Log Context for this Service
*/
cta::log::LogContext &getLogContext() { return *m_log_context_ptr; }
/*!
* Get a reference to the Scheduler for this Service
*/
cta::Scheduler &getScheduler() { return *m_scheduler_ptr; }
private:
std::unique_ptr<cta::log::LogContext> m_log_context_ptr; //!< Log Context for this Service
std::unique_ptr<cta::Scheduler> m_scheduler_ptr; //!< Scheduler for this Service
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment