Skip to content
Snippets Groups Projects
Commit 6e927274 authored by Anastasia Karachaliou's avatar Anastasia Karachaliou
Browse files

Main event loop of acsd daemon running

parent 9d261cd2
No related branches found
No related tags found
No related merge requests found
......@@ -197,7 +197,7 @@ void AcsProxy::mountTapeReadOnly(const std::string &vid, const LibrarySlot &libr
} catch(cta::exception::Exception &ne) {
cta::exception::Exception ex;
ex.getMessage() <<
"Failed to request CASTOR ACS daemon to mount tape for read only access: "
"Failed to request CTA ACS daemon to mount tape for read only access: "
<< librarySlot.str() << ": " << ne.getMessage().str();
throw ex;
}
......@@ -225,7 +225,7 @@ void AcsProxy::mountTapeReadWrite(const std::string &vid, const LibrarySlot &lib
} catch(cta::exception::Exception &ne) {
cta::exception::Exception ex;
ex.getMessage() <<
"Failed to request CASTOR ACS daemon to mount tape for read/write "
"Failed to request CTA ACS daemon to mount tape for read/write "
"access: " << librarySlot.str() << ": " << ne.getMessage().str();
throw ex;
}
......@@ -253,7 +253,7 @@ void AcsProxy::dismountTape(const std::string &vid, const LibrarySlot &librarySl
} catch(cta::exception::Exception &ne) {
cta::exception::Exception ex;
ex.getMessage() <<
"Failed to request CASTOR ACS daemon to dismount tape: " <<
"Failed to request CTA ACS daemon to dismount tape: " <<
librarySlot.str() << ": " << ne.getMessage().str();
throw ex;
}
......@@ -281,7 +281,7 @@ void AcsProxy::forceDismountTape(const std::string &vid, const LibrarySlot &libr
} catch(cta::exception::Exception &ne) {
cta::exception::Exception ex;
ex.getMessage() <<
"Failed to request CASTOR ACS daemon to force dismount tape: " <<
"Failed to request CTA ACS daemon to force dismount tape: " <<
librarySlot.str() << ": " << ne.getMessage().str();
throw ex;
}
......
......@@ -112,9 +112,7 @@ std::string cta::mediachanger::acs::daemon::AcsDaemon::getHostName() const {
int AcsDaemon::main() throw() {
try {
exceptionThrowingMain(m_argc, m_argv);
} catch (cta::exception::Exception &ex) {
// Write the error to standard error
std::cerr << std::endl << "Aborting: " << ex.getMessage().str() << std::endl
......@@ -138,15 +136,15 @@ void AcsDaemon::exceptionThrowingMain(
logStartOfDaemon(argc, argv);
AcsdCmdLine Commandline(argc,argv); //parse command line
setCommandLineHasBeenParsed(Commandline.foreground);
const std::string runAsStagerSuperuser = m_config.daemonUserName.value();;
const std::string runAsStagerSupergroup = m_config.daemonGroupName.value();;
daemonizeIfNotRunInForegroundAndSetUserAndGroup(runAsStagerSuperuser, runAsStagerSupergroup);
setDumpable();
const std::string runAsStagerSuperuser = m_config.daemonUserName.value();;
const std::string runAsStagerSupergroup = m_config.daemonGroupName.value();;
daemonizeIfNotRunInForegroundAndSetUserAndGroup(runAsStagerSuperuser, runAsStagerSupergroup);
setDumpable();
blockSignals();
initZmqContext();
setUpReactor();
// mainEventLoop();
blockSignals();
initZmqContext();
setUpReactor();
mainEventLoop();
}
......@@ -272,7 +270,7 @@ void AcsDaemon::createAndRegisterAcsMessageHandler() {
throw ex;
}
}
/*
//------------------------------------------------------------------------------
// mainEventLoop
//------------------------------------------------------------------------------
......@@ -373,9 +371,9 @@ bool AcsDaemon::handlePendingSignals() throw() {
break;
}
}
return continueMainEventLoop;
}
*/
}}}}
......@@ -138,27 +138,27 @@ protected:
/**
* The main event loop of the daemon.
*/
///// void mainEventLoop();
void mainEventLoop();
/**
* Handles any pending events.
*
* @return True if the main event loop should continue, else false.
*/
/////// bool handleEvents();
bool handleEvents();
/**
* Handles any pending signals.
*
* @return True if the main event loop should continue, else false.
*/
////// bool handlePendingSignals() throw();
bool handlePendingSignals() throw();
/**
* Handles any pending Acs requests.
*
*/
////// void handlePendingRequests();
void handlePendingRequests();
/**
* The argc of main().
......
......@@ -147,7 +147,7 @@ bool cta::mediachanger::acs::daemon::AcsMessageHandler::handleEvent(
/*bool exceptionOccurred = false;*/
try {
//m_acsPendingRequests.checkAndAddRequest(address, empty, rqst, m_socket);
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);
......@@ -177,7 +177,7 @@ bool cta::mediachanger::acs::daemon::AcsMessageHandler::handleEvent(
cta::mediachanger::sendFrame(m_socket, reply);
} catch(castor::exception::Exception &ex) {
std::list<log::Param> params = {log::Param("message", ex.getMessage().str())};
log::write(LOG_ERR, "AcsMessageHandler failed to send reply to client", params);
m_log(LOG_ERR, "AcsMessageHandler failed to send reply to client", params);
}
}
*/
......
......@@ -24,13 +24,12 @@
#include "AcsPendingRequests.hpp"
#include "mediachanger/acs/AcsImpl.hpp"
#include "mediachanger/acs/AcsRequest.hpp"
/////#include "mediachanger/acs/daemon/AcsDismountTape.hpp"
//#include "castor/acs/AcsRequestDismountTape.hpp"
//////#include "AcsRequestDismountTape.hpp"
#include "mediachanger/acs/daemon/AcsDismountTape.hpp"
#include "AcsRequestDismountTape.hpp"
#include "common/Constants.hpp"
//#include "messages/Constants.hpp"
#include "mediachanger/Constants.hpp"
//#include "mediachanger/acs/Constants.hpp"
#include "mediachanger/acs/daemon/Constants.hpp"
#include "common/log/log.hpp"
#include "mediachanger/messages.hpp"
#include "mediachanger/Frame.hpp"
......@@ -179,7 +178,7 @@ void cta::mediachanger::acs::daemon::AcsPendingRequests::handleToDeleteRequests(
}
}
}
/*
//-----------------------------------------------------------------------------
// checkAndAddRequest
//-----------------------------------------------------------------------------
......@@ -192,7 +191,7 @@ void cta::mediachanger::acs::daemon::AcsPendingRequests::checkAndAddRequest(
};
m_log(LOG_DEBUG, "AcsPendingRequests::checkAndAddRequest", params);
const mediachanger::MsgType msgType = (mediachanger::MsgType)rqst.header.msgtype();
const cta::mediachanger::acs::daemon::MsgType msgType = (cta::mediachanger::acs::daemon::MsgType)rqst.header.msgtype();
switch(msgType) {
case mediachanger::MSG_TYPE_ACSMOUNTTAPEREADONLY:
case mediachanger::MSG_TYPE_ACSMOUNTTAPEREADWRITE:
......@@ -208,7 +207,7 @@ void cta::mediachanger::acs::daemon::AcsPendingRequests::checkAndAddRequest(
break;
default:
{
const std::string msgTypeStr = (std::string)mediachanger::msgTypeToString(msgType);
const std::string msgTypeStr = cta::mediachanger::acs::daemon::msgTypeToString(msgType);
cta::exception::Exception ex;
ex.getMessage() << "Failed to check request"
": Unexpected request type: msgType=" << msgType << " msgTypeStr=" <<
......@@ -256,7 +255,7 @@ void cta::mediachanger::acs::daemon::AcsPendingRequests::checkAndAddRequestDismo
cta::mediachanger::acs::AcsRequest * acsRequestDismountTape =
new AcsRequestDismountTape(vid, acs, lsm, panel, drive,
//new AcsRequestDismountTape AcsRequestDismountTape(vid, acs, lsm, panel, drive,
m_ctaConf, socket, address, empty, seqNo);
m_ctaConf, socket, address, empty, m_log, seqNo);
acsRequestDismountTape->setStateToExecute();
m_acsRequestList.push_back(acsRequestDismountTape);
......@@ -335,4 +334,4 @@ SEQ_NO cta::mediachanger::acs::daemon::AcsPendingRequests::getSequenceNumber() c
" allocated maximum seqNo=\""<<maxSeqNo<<"\"";
m_log(LOG_ERR, ex.getMessage().str());
throw ex;
}*/
}
......@@ -23,14 +23,12 @@
#pragma once
//#include "daemon/AcsdConfiguration.hpp"
#include "AcsdConfiguration.hpp"
//#include "daemon/AcsDaemonConfig.hpp"
#include "common/log/log.hpp"
#include "common/log/SyslogLogger.hpp"
#include "mediachanger/acs/AcsRequest.hpp"
/////#include "mediachanger/acs/AcsImpl.hpp"
/////#include "mediachanger/messages.hpp"
#include "mediachanger/acs/AcsImpl.hpp"
#include "mediachanger/messages.hpp"
#include "mediachanger/Frame.hpp"
#include "mediachanger/ZmqMsg.hpp"
#include "mediachanger/ZmqSocket.hpp"
......@@ -113,16 +111,11 @@ public:
* @param rqst ZMQ message with CASTOR frame.
* @param socket ZMQ socket to use.
*/
/*
* void checkAndAddRequest(messages::ZmqMsg &address,
messages::ZmqMsg &empty,
const messages::Frame &rqst,
messages::ZmqSocketST &socket);
*/
///// void checkAndAddRequest(mediachanger::ZmqMsg &address,
///// mediachanger::ZmqMsg &empty,
///// const mediachanger:: Frame &rqst,
///// mediachanger::ZmqSocketST &socket);
void checkAndAddRequest(mediachanger::ZmqMsg &address,
mediachanger::ZmqMsg &empty,
const mediachanger:: Frame &rqst,
mediachanger::ZmqSocketST &socket);
/**
* Performs dismount specific checks for the incoming request and add it to
......@@ -133,10 +126,10 @@ public:
* @param rqst ZMQ message with CASTOR frame.
* @param socket ZMQ socket to use.
*/
///// void checkAndAddRequestDismountTape(mediachanger::ZmqMsg &address,
///// mediachanger::ZmqMsg &empty,
///// const mediachanger::Frame &rqst,
///// mediachanger::ZmqSocketST &socket);
void checkAndAddRequestDismountTape(mediachanger::ZmqMsg &address,
mediachanger::ZmqMsg &empty,
const mediachanger::Frame &rqst,
mediachanger::ZmqSocketST &socket);
/**
* Find and return free sequence number for the ACS request.
......@@ -144,7 +137,7 @@ public:
* @return The value of free sequence number for the ACS request. Throws
* exception if the is no free sequence number.
*/
///// SEQ_NO getSequenceNumber() const;
SEQ_NO getSequenceNumber() const;
/**
* Sets the type of the response and the response message in the ACS request
......@@ -168,8 +161,8 @@ public:
* @param panel The panel value of the ACS request.
* @param drive The drive value of the ACS request.
*/
///// void checkRequest(const std::string &vid, const uint32_t acs,
///// const uint32_t lsm, const uint32_t panel, const uint32_t drive) const ;
void checkRequest(const std::string &vid, const uint32_t acs,
const uint32_t lsm, const uint32_t panel, const uint32_t drive) const ;
private:
......
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* 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
*****************************************************************************/
#include "AcsRequestDismountTape.hpp"
#include "common/exception/DismountFailed.hpp"
#include "common/log/log.hpp"
//-----------------------------------------------------------------------------
// constructor
//-----------------------------------------------------------------------------
cta::mediachanger::acs::daemon::AcsRequestDismountTape::AcsRequestDismountTape(
const std::string &vid, const uint32_t acs,
const uint32_t lsm, const uint32_t panel, const uint32_t drive,
const AcsdConfiguration &ctaConf,
mediachanger::ZmqSocketST &socket,
mediachanger::ZmqMsg &address,
mediachanger::ZmqMsg &empty,
log::Logger &log,
const SEQ_NO seqNo):
AcsRequest(socket, address, empty, seqNo, vid, acs, lsm, panel, drive),
m_ctaConf(ctaConf),
m_acsDismountTape(vid, acs, lsm, panel, drive, m_acs, log, ctaConf),
m_lastTimeLibraryQueried(0),
m_log(log),
m_timeAcsCommandStarted(0) {
}
//-----------------------------------------------------------------------------
// tick
//-----------------------------------------------------------------------------
void cta::mediachanger::acs::daemon::AcsRequestDismountTape::tick() {
try {
if (isToExecute()) {
m_log(LOG_DEBUG,"AcsRequestDismountTape::tick isToExecute");
m_acsDismountTape.asyncExecute(getSeqNo());
setStateIsRunning();
m_timeAcsCommandStarted = time(0);
}
const time_t now = time(0);
const time_t secsSinceLastQuery = now - m_lastTimeLibraryQueried;
const bool firstQueryOrTimeExceeded = (unsigned int)secsSinceLastQuery >
m_ctaConf.QueryInterval.value();
if(isRunning() && firstQueryOrTimeExceeded) {
if(isResponseFinalAndSuccess()) {
setStateCompleted();
m_log(LOG_DEBUG,
"AcsRequestDismountTape::tick ACS_REQUEST_COMPLETED");
} else {
m_log(LOG_DEBUG,"AcsRequestDismountTape::tick "
"firstQueryOrTimeExceeded()");
m_lastTimeLibraryQueried = time(0);
}
}
const time_t secsSinceCommandStarted = now - m_timeAcsCommandStarted;
const bool acsCommandTimeExceeded = (unsigned int)secsSinceCommandStarted >
m_ctaConf.CmdTimeout.value();
if(isRunning() && acsCommandTimeExceeded) {
cta::exception::RequestFailed ex;
ex.getMessage() << "ACS command timed out after " <<
secsSinceCommandStarted << " seconds";
throw ex;
}
} catch (cta::exception::Exception &ex) {
setStateFailed(ECANCELED, ex.getMessage().str());
m_log(LOG_ERR,"Failed to handle the ACS dismount tape request: "
+ ex.getMessage().str());
} catch(std::exception &se) {
setStateFailed(ECANCELED, se.what());
m_log(LOG_ERR, se.what());
} catch(...) {
setStateFailed(ECANCELED, "Caught an unknown exception");
m_log(LOG_ERR, "Caught an unknown exception");
}
}
//------------------------------------------------------------------------------
// isResponseFinalAndSuccess
//------------------------------------------------------------------------------
bool cta::mediachanger::acs::daemon::AcsRequestDismountTape::isResponseFinalAndSuccess() const {
if (RT_FINAL == m_responseType ) {
const ACS_DISMOUNT_RESPONSE *const msg =
(ACS_DISMOUNT_RESPONSE *)m_responseMsg;
if(STATUS_SUCCESS != msg->dismount_status) {
cta::exception::DismountFailed ex;
ex.getMessage() << "Status of dismount response is not success: " <<
acs_status(msg->dismount_status);
throw ex;
}
return true;
}
return false;
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* 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
*****************************************************************************/
#pragma once
#include "mediachanger/acs/daemon/AcsdConfiguration.hpp"
#include "mediachanger/acs/daemon/AcsDismountTape.hpp"
#include "mediachanger/acs/AcsImpl.hpp"
#include "mediachanger/acs/AcsRequest.hpp"
namespace cta {
namespace mediachanger {
namespace acs {
namespace daemon {
/**
* Concrete class providing a dismount tape implementation of an AcsRequest
* abstract class.
*/
class AcsRequestDismountTape: public cta::mediachanger::acs::AcsRequest {
public:
/**
* Constructor.
*
* @param vid The vid of the ACS request.
* @param acs The acs value of the ACS request.
* @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 socket ZMQ socket to use.
* @param address ZMQ message with client address.
* @param empty ZMQ empty message.
* @param seqNo Sequence number for the ACS request.
*/
AcsRequestDismountTape(
const std::string &vid,
const uint32_t acs,
const uint32_t lsm,
const uint32_t panel,
const uint32_t drive,
const AcsdConfiguration &ctaConf,
mediachanger::ZmqSocketST &socket,
mediachanger::ZmqMsg &address,
mediachanger::ZmqMsg &empty,
cta::log::Logger& log,
const SEQ_NO seqNo);
/**
* Perform any time related actions with the request to CASTOR ACS daemon.
*
* This method does not have to be called at any time precise interval.
*/
void tick();
/**
* Checks the status of the response from the dismount response message buffer
* and the type of the response. Throws exception if the type of the response
* is RT_FINAL but the status is not success.
*
* @return true if the type of response RT_FINAL and the response status
* is STATUS_SUCCESS.
*/
bool isResponseFinalAndSuccess() const;
private:
/**
* The CASTOR configuration parameters for the CASTOR ACS daemon.
*/
const AcsdConfiguration m_ctaConf;
/**
* The object representing the class for tape dismount through ACS API.
*/
AcsDismountTape m_acsDismountTape;
/**
* The ACLS C-API wrapper.
*/
AcsImpl m_acs;
/**
* The time when the ACS library queried last time.
*/
time_t m_lastTimeLibraryQueried;
cta::log::Logger &m_log;
/**
* The time at which ACS command was started.
*/
time_t m_timeAcsCommandStarted;
}; // class AcsRequestDismountTape
} // namespace daemon
} // namespace acs
} // namespace mediachanger
} // namespace cta
......@@ -27,8 +27,7 @@ set (ACS_DAEMON_SRC_FILES
AcsMountTapeReadOnly.cpp
AcsForceDismountTape.cpp
Constants.cpp
#AcsRequestDismountTape.cpp
#AcsLibraryInteraction.cpp
AcsRequestDismountTape.cpp
)
add_executable (cta-acsd ${ACS_DAEMON_SRC_FILES})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment