From 68c6e3c1df40f110df13fb9330df146470eb2e95 Mon Sep 17 00:00:00 2001 From: Anastasia Karachaliou <anastasia.karachaliou@cern.ch> Date: Thu, 31 May 2018 17:23:51 +0200 Subject: [PATCH] code refactoring in acsd daemon --- mediachanger/acs/daemon/AcsDaemon.hpp | 12 +++---- mediachanger/acs/daemon/AcsDaemonMain.cpp | 3 +- mediachanger/acs/daemon/AcsDismountTape.cpp | 4 --- mediachanger/acs/daemon/AcsDismountTape.hpp | 4 +-- .../acs/daemon/AcsForceDismountTape.cpp | 1 - .../acs/daemon/AcsForceDismountTape.hpp | 6 ++-- mediachanger/acs/daemon/AcsMessageHandler.cpp | 35 +++---------------- mediachanger/acs/daemon/AcsMessageHandler.hpp | 12 +++---- .../acs/daemon/AcsMountTapeReadOnly.hpp | 2 +- .../acs/daemon/AcsMountTapeReadWrite.hpp | 2 +- .../acs/daemon/AcsPendingRequests.cpp | 1 - .../acs/daemon/AcsPendingRequests.hpp | 16 ++++----- mediachanger/acs/daemon/AcsRequest.hpp | 2 +- .../acs/daemon/AcsRequestDismountTape.hpp | 6 ++-- mediachanger/acs/daemon/AcsdConfiguration.hpp | 9 +++-- mediachanger/acs/daemon/Constants.cpp | 25 ++++++------- 16 files changed, 49 insertions(+), 91 deletions(-) diff --git a/mediachanger/acs/daemon/AcsDaemon.hpp b/mediachanger/acs/daemon/AcsDaemon.hpp index c2fd312bb3..b6f61f4e1f 100644 --- a/mediachanger/acs/daemon/AcsDaemon.hpp +++ b/mediachanger/acs/daemon/AcsDaemon.hpp @@ -35,7 +35,7 @@ namespace acs { namespace daemon { /** - * CASTOR ACS daemon responsible for mounting and dismounting tapes for ACS. + * CTA ACS daemon responsible for mounting and dismounting tapes for ACS. */ class AcsDaemon : public server::Daemon { @@ -48,8 +48,8 @@ public: * @param stdOut Stream representing standard out. * @param stdErr Stream representing standard error. * @param reactor The reactor responsible for dispatching the I/O requests to - * the CASTOR ACS daemon. - * @param config The CASTOR configuration parameters used by the CASTOR ACS + * the CTA ACS daemon. + * @param config The CTA configuration parameters used by the CTA ACS * daemon. */ AcsDaemon( @@ -168,7 +168,7 @@ protected: log::Logger &m_log; /** * The reactor responsible for dispatching the file-descriptor event-handlers - * of the CASTOR ACS daemon. + * of the CTA ACS daemon. */ cta::mediachanger::reactor::ZMQReactor &m_reactor; @@ -188,12 +188,12 @@ protected: void *m_zmqContext; /** - * The CASTOR configuration parameters used by the CASTOR ACS daemon. + * The CTA configuration parameters used by the CTA ACS daemon. */ const AcsdConfiguration m_config; /** - * The object to handle requests to the CASTOR ACS daemon. + * The object to handle requests to the CTA ACS daemon. */ AcsPendingRequests m_acsPendingRequests; diff --git a/mediachanger/acs/daemon/AcsDaemonMain.cpp b/mediachanger/acs/daemon/AcsDaemonMain.cpp index d71206f487..0f603570ca 100644 --- a/mediachanger/acs/daemon/AcsDaemonMain.cpp +++ b/mediachanger/acs/daemon/AcsDaemonMain.cpp @@ -18,8 +18,7 @@ #include "common/log/log.hpp" #include "common/log/SyslogLogger.hpp" -//#include "common/processCap/ProcessCap.hpp" -#include "../Constants.hpp" +#include "mediachanger/acs/Constants.hpp" #include "AcsDaemon.hpp" #include "AcsdCmdLine.hpp" #include "mediachanger/reactor/ZMQReactor.hpp" diff --git a/mediachanger/acs/daemon/AcsDismountTape.cpp b/mediachanger/acs/daemon/AcsDismountTape.cpp index 63619ea315..99354c573a 100644 --- a/mediachanger/acs/daemon/AcsDismountTape.cpp +++ b/mediachanger/acs/daemon/AcsDismountTape.cpp @@ -23,7 +23,6 @@ //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -//cta::mediachanger::acs::daemon::acs::daemon::AcsDismountTape::AcsDismountTape( cta::mediachanger::acs::daemon::AcsDismountTape::AcsDismountTape( const std::string &vid, const uint32_t acs, @@ -45,7 +44,6 @@ cta::mediachanger::acs::daemon::AcsDismountTape::AcsDismountTape( // execute //------------------------------------------------------------------------------ void cta::mediachanger::acs::daemon::AcsDismountTape::execute() const { -//void cta::mediachanger::acs::daemon::AcsDismountTape::execute() const { syncDismount(); } @@ -53,7 +51,6 @@ void cta::mediachanger::acs::daemon::AcsDismountTape::execute() const { // asyncExecute //------------------------------------------------------------------------------ void cta::mediachanger::acs::daemon::AcsDismountTape::asyncExecute(const SEQ_NO seqNo) const { -//void cta::mediachanger::acs::daemon::AcsDismountTape::asyncExecute(const SEQ_NO seqNo) const { asyncDismount(seqNo); } @@ -61,7 +58,6 @@ void cta::mediachanger::acs::daemon::AcsDismountTape::asyncExecute(const SEQ_NO //------------------------------------------------------------------------------ // syncDismount //------------------------------------------------------------------------------ -//void cta::mediachanger::acs::daemon::AcsDismountTape::syncDismount() const { void cta::mediachanger::acs::daemon::AcsDismountTape::syncDismount() const { const SEQ_NO requestSeqNumber = 1; ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; diff --git a/mediachanger/acs/daemon/AcsDismountTape.hpp b/mediachanger/acs/daemon/AcsDismountTape.hpp index 6ff5046df4..bca01954a1 100644 --- a/mediachanger/acs/daemon/AcsDismountTape.hpp +++ b/mediachanger/acs/daemon/AcsDismountTape.hpp @@ -93,7 +93,7 @@ protected: void sendDismountRequest(const SEQ_NO seqNumber) const; /** - * Throws castor::exception::DismountFailed if the mount was not + * Throws cta::exception::DismountFailed if the mount was not * successful. * * @param buf The mount-response message. @@ -118,7 +118,7 @@ protected: log::Logger &m_log; /** - * The configuration parameters for the CASTOR ACS daemon. + * The configuration parameters for the CTA ACS daemon. */ const mediachanger::acs::daemon::AcsdConfiguration m_ctaConf; diff --git a/mediachanger/acs/daemon/AcsForceDismountTape.cpp b/mediachanger/acs/daemon/AcsForceDismountTape.cpp index ddae8b9a80..439b3b5e1f 100644 --- a/mediachanger/acs/daemon/AcsForceDismountTape.cpp +++ b/mediachanger/acs/daemon/AcsForceDismountTape.cpp @@ -20,7 +20,6 @@ #include "common/exception/ForceDismountFailed.hpp" #include "common/log/log.hpp" #include "common/log/SyslogLogger.hpp" -//#include "common/exception/DismountFailed.hpp" //------------------------------------------------------------------------------ // constructor diff --git a/mediachanger/acs/daemon/AcsForceDismountTape.hpp b/mediachanger/acs/daemon/AcsForceDismountTape.hpp index 893edc3d3a..0b92ec273c 100644 --- a/mediachanger/acs/daemon/AcsForceDismountTape.hpp +++ b/mediachanger/acs/daemon/AcsForceDismountTape.hpp @@ -19,7 +19,7 @@ #pragma once #include "mediachanger/acs/Acs.hpp" -#include "AcsdConfiguration.hpp" +#include "mediachanger/acs/daemon/AcsdConfiguration.hpp" #include "mediachanger/acs/AcsLibraryInteraction.hpp" #include "common/log/log.hpp" #include "common/log/SyslogLogger.hpp" @@ -95,7 +95,7 @@ protected: void sendForceDismountRequest(const SEQ_NO seqNumber) const; /** - * Throws castor::exception::DismountFailed if the mount was not + * Throws cta::exception::DismountFailed if the mount was not * successful. * * @param buf The mount-response message. @@ -121,7 +121,7 @@ protected: log::Logger &m_log; /** - * The configuration parameters for the CASTOR ACS daemon. + * The configuration parameters for the CTA ACS daemon. */ const AcsdConfiguration m_ctaConf; diff --git a/mediachanger/acs/daemon/AcsMessageHandler.cpp b/mediachanger/acs/daemon/AcsMessageHandler.cpp index 3107000d04..4388a97ff9 100644 --- a/mediachanger/acs/daemon/AcsMessageHandler.cpp +++ b/mediachanger/acs/daemon/AcsMessageHandler.cpp @@ -17,9 +17,7 @@ */ #include "common/Constants.hpp" -//#include "messages/Constants.hpp" #include "mediachanger/acs/daemon/Constants.hpp" -//#include "mediachanger/acs/Constants.hpp" #include "AcsMessageHandler.hpp" #include "AcsDismountTape.hpp" #include "AcsForceDismountTape.hpp" @@ -38,13 +36,12 @@ #include "mediachanger/Exception.pb.h" #include "mediachanger/reactor/ZMQPollEventHandler.hpp" #include "mediachanger/reactor/ZMQReactor.hpp" -//#include "mediachanger/ZmqSocketST.hpp" #include "mediachanger/ZmqSocket.hpp" #include "errno.h" #include <iostream> -//#include <sstream> #include <unistd.h> + //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ @@ -141,44 +138,21 @@ bool cta::mediachanger::acs::daemon::AcsMessageHandler::handleEvent( // From this point on any exception thrown should be converted into an // Exception message and sent back to the client cta::mediachanger::Frame reply; - /*bool exceptionOccurred = false;*/ try { - ///////m_acsPendingRequests.checkAndAddRequest(address, empty, rqst, m_socket); // if there are any problems we need to send the replay to the client. - reply = dispatchMsgHandler(rqst); } catch(cta::exception::Exception &ex) { - reply = createExceptionFrame(ECANCELED, ex.getMessage().str()); //TBD we have to get rid of code inside the Exception - /*exceptionOccurred=true;*/ + reply = createExceptionFrame(ECANCELED, ex.getMessage().str()); m_log(LOG_ERR, ex.getMessage().str()); } catch(std::exception &se) { - reply = createExceptionFrame(ECANCELED, se.what()); //TBD - /*exceptionOccurred=true;*/ + reply = createExceptionFrame(ECANCELED, se.what()); m_log(LOG_ERR, se.what()); } catch(...) { - reply = createExceptionFrame(ECANCELED, "Caught an unknown exception"); //TBD - /*exceptionOccurred=true;*/ + reply = createExceptionFrame(ECANCELED, "Caught an unknown exception"); m_log(LOG_ERR, "Caught an unknown exception"); } -/* - if (exceptionOccurred) { - // Send the reply to the client if we were not able to add request to the - // list - try { - //we need to prepend our frames the same way we received them - // ie identity + empty frames - m_socket.send(address,ZMQ_SNDMORE); - m_socket.send(empty,ZMQ_SNDMORE); - cta::mediachanger::sendFrame(m_socket, reply); - } catch(castor::exception::Exception &ex) { - std::list<log::Param> params = {log::Param("message", ex.getMessage().str())}; - m_log(LOG_ERR, "AcsMessageHandler failed to send reply to client", params); - } - } -*/ - // Send the reply to the client try { //we need to prepend our frames the same way we received them @@ -403,7 +377,6 @@ cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsMessageHandler:: log::Param("panel", panel), log::Param("drive", drive)}; m_log(LOG_INFO, "Force dismount tape", params); - // m_log(LOG_INFO, "Force dismount tape",vid); cta::mediachanger::acs::AcsImpl acsWrapper; cta::mediachanger::acs::daemon::AcsForceDismountTape acsForceDismountTape(vid, acs, lsm, diff --git a/mediachanger/acs/daemon/AcsMessageHandler.hpp b/mediachanger/acs/daemon/AcsMessageHandler.hpp index 7ef0c56b46..5499085642 100644 --- a/mediachanger/acs/daemon/AcsMessageHandler.hpp +++ b/mediachanger/acs/daemon/AcsMessageHandler.hpp @@ -18,11 +18,8 @@ #pragma once - -//#include "common/log/Logger.hpp" #include "mediachanger/acs/Constants.hpp" #include "mediachanger/Frame.hpp" -//#include "mediachanger/ZmqSocketST.hpp" #include "mediachanger/ZmqSocket.hpp" #include "mediachanger/reactor/ZMQReactor.hpp" #include "AcsDaemon.hpp" @@ -30,6 +27,7 @@ #include "AcsPendingRequests.hpp" #include "common/log/SyslogLogger.hpp" #include "mediachanger/reactor/ZMQPollEventHandler.hpp" + namespace cta { namespace mediachanger { namespace acs { @@ -155,7 +153,7 @@ private: log::Logger &m_log; /** - * The reactor to which new CASTOR ACS daemon connection handlers are to + * The reactor to which new CTA ACS daemon connection handlers are to * be registered. */ cta::mediachanger::reactor::ZMQReactor &m_reactor; @@ -166,18 +164,18 @@ private: cta::mediachanger::ZmqSocketST m_socket; /** - * The name of the host on which CASTOR ACS daemon is running. + * The name of the host on which CTA ACS daemon is running. */ const std::string m_hostName; /** - * The configuration parameters for the CASTOR ACS daemon. + * The configuration parameters for the CTA ACS daemon. */ const acs::daemon::AcsdConfiguration m_ctaConf; /** - * The object to handle requests to the CASTOR ACS daemon. + * The object to handle requests to the CTA ACS daemon. */ AcsPendingRequests &m_acsPendingRequests; diff --git a/mediachanger/acs/daemon/AcsMountTapeReadOnly.hpp b/mediachanger/acs/daemon/AcsMountTapeReadOnly.hpp index 7fc0733387..51019d3041 100644 --- a/mediachanger/acs/daemon/AcsMountTapeReadOnly.hpp +++ b/mediachanger/acs/daemon/AcsMountTapeReadOnly.hpp @@ -130,7 +130,7 @@ protected: Acs &m_acsWrapper; log::Logger& m_log; /** - * The configuration parameters for the CASTOR ACS daemon. + * The configuration parameters for the CTA ACS daemon. */ const AcsdConfiguration m_ctaConf; diff --git a/mediachanger/acs/daemon/AcsMountTapeReadWrite.hpp b/mediachanger/acs/daemon/AcsMountTapeReadWrite.hpp index fef0482775..a2d4230644 100644 --- a/mediachanger/acs/daemon/AcsMountTapeReadWrite.hpp +++ b/mediachanger/acs/daemon/AcsMountTapeReadWrite.hpp @@ -130,7 +130,7 @@ protected: log::Logger& m_log; /** - * The configuration parameters for the CASTOR ACS daemon. + * The configuration parameters for the CTA ACS daemon. */ const AcsdConfiguration m_ctaConf; diff --git a/mediachanger/acs/daemon/AcsPendingRequests.cpp b/mediachanger/acs/daemon/AcsPendingRequests.cpp index 1c445178a7..fedb852155 100644 --- a/mediachanger/acs/daemon/AcsPendingRequests.cpp +++ b/mediachanger/acs/daemon/AcsPendingRequests.cpp @@ -22,7 +22,6 @@ #include "mediachanger/acs/daemon/AcsDismountTape.hpp" #include "AcsRequestDismountTape.hpp" #include "common/Constants.hpp" -//#include "messages/Constants.hpp" #include "mediachanger/Constants.hpp" #include "mediachanger/acs/daemon/Constants.hpp" #include "common/log/log.hpp" diff --git a/mediachanger/acs/daemon/AcsPendingRequests.hpp b/mediachanger/acs/daemon/AcsPendingRequests.hpp index c9ce59683a..8031001f65 100644 --- a/mediachanger/acs/daemon/AcsPendingRequests.hpp +++ b/mediachanger/acs/daemon/AcsPendingRequests.hpp @@ -18,7 +18,7 @@ #pragma once -#include "AcsdConfiguration.hpp" +#include "mediachanger/acs/daemon/AcsdConfiguration.hpp" #include "common/log/log.hpp" #include "common/log/SyslogLogger.hpp" #include "mediachanger/acs/daemon/AcsRequest.hpp" @@ -38,7 +38,7 @@ namespace daemon { /** * Class responsible for keeping track of the Acs requests controlled by - * the CASTOR ACS daemon. + * the CTA ACS daemon. */ class AcsPendingRequests { public: @@ -46,7 +46,7 @@ public: /** * Constructor. * - * @param castorConf The configuration for the CASTOR ACS daemon. + * @param ctaConf The configuration for the CTA ACS daemon. */ AcsPendingRequests(const AcsdConfiguration &ctaConf, cta::log::Logger &); @@ -64,7 +64,7 @@ public: void tick(); /** - * Requests to the CASTOR ACS daemon might have several states. + * Requests to the CTA ACS daemon might have several states. * * ACS_REQUEST_TO_EXECUTE - is initial state. When request arrives from a * client it is set to be asynchronous executed to ACS Library. @@ -103,7 +103,7 @@ public: * * @param address ZMQ message with client address. * @param empty ZMQ empty message. - * @param rqst ZMQ message with CASTOR frame. + * @param rqst ZMQ message with CTA frame. * @param socket ZMQ socket to use. */ @@ -118,7 +118,7 @@ public: * * @param address ZMQ message with client address. * @param empty ZMQ empty message. - * @param rqst ZMQ message with CASTOR frame. + * @param rqst ZMQ message with CTA frame. * @param socket ZMQ socket to use. */ void checkAndAddRequestDismountTape(mediachanger::ZmqMsg &address, @@ -162,8 +162,8 @@ public: private: /** - * The object representing castor configuration parameters for - * the CASTOR ACS daemon. + * The object representing cta configuration parameters for + * the CTA ACS daemon. */ const AcsdConfiguration m_ctaConf; diff --git a/mediachanger/acs/daemon/AcsRequest.hpp b/mediachanger/acs/daemon/AcsRequest.hpp index 662bd0a6d2..52b22b9499 100644 --- a/mediachanger/acs/daemon/AcsRequest.hpp +++ b/mediachanger/acs/daemon/AcsRequest.hpp @@ -64,7 +64,7 @@ public: virtual ~AcsRequest() = 0; /** - * Perform any time related actions with the request to CASTOR ACS daemon. + * Perform any time related actions with the request to CTA ACS daemon. * * This method does not have to be called at any time precise interval. */ diff --git a/mediachanger/acs/daemon/AcsRequestDismountTape.hpp b/mediachanger/acs/daemon/AcsRequestDismountTape.hpp index b8c0c0bae0..7ec284f6e4 100644 --- a/mediachanger/acs/daemon/AcsRequestDismountTape.hpp +++ b/mediachanger/acs/daemon/AcsRequestDismountTape.hpp @@ -42,7 +42,7 @@ public: * @param lsm The lsm value of the ACS request. * @param panel The panel value of the ACS request. * @param drive The drive value of the ACS request. - * @param castorConf The configuration for the CASTOR ACS daemon. + * @param ctaConf The configuration for the CTA ACS daemon. * @param socket ZMQ socket to use. * @param address ZMQ message with client address. * @param empty ZMQ empty message. @@ -62,7 +62,7 @@ public: const SEQ_NO seqNo); /** - * Perform any time related actions with the request to CASTOR ACS daemon. + * Perform any time related actions with the request to CTA ACS daemon. * * This method does not have to be called at any time precise interval. */ @@ -81,7 +81,7 @@ public: private: /** - * The CASTOR configuration parameters for the CASTOR ACS daemon. + * The CTA configuration parameters for the CTA ACS daemon. */ const AcsdConfiguration m_ctaConf; diff --git a/mediachanger/acs/daemon/AcsdConfiguration.hpp b/mediachanger/acs/daemon/AcsdConfiguration.hpp index 9aec0f89eb..61f70f714e 100644 --- a/mediachanger/acs/daemon/AcsdConfiguration.hpp +++ b/mediachanger/acs/daemon/AcsdConfiguration.hpp @@ -24,7 +24,6 @@ #include "common/log/DummyLogger.hpp" #include "common/exception/Exception.hpp" #include "common/SourcedParameter.hpp" -#include "../../../tapeserver/daemon/FetchReportOrFlushLimits.hpp" #include "Tpconfig.hpp" #include "mediachanger/acs/Constants.hpp" #include "common/ConfigurationFile.hpp" @@ -59,7 +58,7 @@ private: * functions (just unconditionally log things). */ static cta::log::DummyLogger gDummyLogger; } ; -} -} -} -} // namespace cta::mediachanger::acs::daemon +} // namespace daemon +} // namespace acs +} // namespace mediachanger +} // namespace cta diff --git a/mediachanger/acs/daemon/Constants.cpp b/mediachanger/acs/daemon/Constants.cpp index 99ae3d9bc1..2b2feef15f 100644 --- a/mediachanger/acs/daemon/Constants.cpp +++ b/mediachanger/acs/daemon/Constants.cpp @@ -1,25 +1,20 @@ -/****************************************************************************** +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN * - * This file is part of the Castor project. - * See http://castor.web.cern.ch/castor + * 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. * - * Copyright (C) 2003 CERN - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * * - * @author Castor Dev team, castor-dev@cern.ch - *****************************************************************************/ + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ #include "Constants.hpp" -- GitLab