Commit 0a792db7 authored by Anastasia Karachaliou's avatar Anastasia Karachaliou
Browse files

setupReactor running in AcsDaemon

parent 319f4dc5
......@@ -81,6 +81,7 @@ set (COMMON_LIB_SRC_FILES
exception/DatabaseConstraintError.cpp
exception/DatabasePrimaryKeyError.cpp
exception/DismountFailed.cpp
exception/ForceDismountFailed.cpp
exception/Errnum.cpp
exception/Exception.cpp
exception/InvalidArgument.cpp
......
/******************************************************************************
*
* 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 "ForceDismountFailed.hpp"
//#include "serrno.h"
// -----------------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------------
cta::exception::ForceDismountFailed::ForceDismountFailed():
cta::exception::Exception() {
//cta::exception::Exception(ETFDISMOUNTFAILED) {
}
/******************************************************************************
*
* 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 "Exception.hpp"
namespace cta {
namespace exception {
/**
* Failed to dismount volume.
*/
class ForceDismountFailed : public cta::exception::Exception {
public:
/**
* Constructor
*/
ForceDismountFailed();
}; // class ForceDismountFailed
} // namespace exception
} // namespace cta
/******************************************************************************
*
* 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.
*
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/exception/Exception.hpp"
#include "castor/log/log.hpp"
/**
* The logger to be used by the CASTOR logging systsem.
*/
static cta::log::Logger *s_logger = NULL;
//------------------------------------------------------------------------------
// init
//------------------------------------------------------------------------------
void cta::log::init(cta::log::Logger *logger) {
if(s_logger) {
throw cta::exception::Exception("Failed to initialise logging system"
": Logging system already initialised");
}
s_logger = logger;
}
//------------------------------------------------------------------------------
// shutdown
//------------------------------------------------------------------------------
void cta::log::shutdown() {
delete s_logger;
s_logger = NULL;
}
//------------------------------------------------------------------------------
// instance
//------------------------------------------------------------------------------
cta::log::Logger &cta::log::instance() {
if(NULL == s_logger) {
throw cta::exception::Exception("Failed to get CASTOR logger"
": Logger does not exist");
}
return *s_logger;
}
//------------------------------------------------------------------------------
// prepareForFork
//------------------------------------------------------------------------------
void cta::log::prepareForFork() {
try {
instance().prepareForFork();
} catch(cta::exception::Exception &ex) {
throw cta::exception::Exception(
std::string("Failed to prepare logger for call to fork(): ") +
ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// write
//------------------------------------------------------------------------------
void cta::log::write(
const int priority,
const std::string &msg,
const std::list<cta::log::Param> &params) {
if(s_logger) (*s_logger)(priority, msg, params);
}
//------------------------------------------------------------------------------
// write
//------------------------------------------------------------------------------
void cta::log::write(
const int priority,
const std::string &msg,
const std::string &rawParams,
const struct timeval &timeStamp,
const std::string &progName,
const int pid) {
const std::list<Param> params;
if(s_logger) (*s_logger)(priority, msg, params, rawParams, timeStamp,
progName, pid);
}
//------------------------------------------------------------------------------
// getProgramName
//------------------------------------------------------------------------------
std::string cta::log::getProgramName() {
if(s_logger) {
return (*s_logger).getProgramName();
} else {
return "";
}
}
//------------------------------------------------------------------------------
// operator<<
//------------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& out, const Cuuid_t& uuid) {
char uuidstr[CUUID_STRING_LEN + 1];
memset(uuidstr, '\0', CUUID_STRING_LEN + 1);
Cuuid2string(uuidstr, CUUID_STRING_LEN + 1, &uuid);
out << uuidstr;
return out;
}
// 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
syntax = "proto2";
package cta.mediachanger;
message Exception {
// The error code
required uint32 code = 1;
// The error message
required string message = 2;
}
// 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
syntax = "proto2";
package cta.mediachanger;
message ReturnValue {
required uint32 value = 1;
}
......@@ -18,28 +18,28 @@
*/
#include "AcsLibraryInteraction.hpp"
#include "../../log.hpp"
#include "common/log/log.hpp"
#include <stdlib.h>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::acs::AcsLibraryInteraction::AcsLibraryInteraction(
Acs &acs) throw(): m_acs(acs) {
cta::mediachanger::acs::AcsLibraryInteraction::AcsLibraryInteraction(
Acs &acs, cta::log::Logger& log) throw(): m_acs(acs), m_log(log) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
cta::acs::AcsLibraryInteraction::~AcsLibraryInteraction() throw() {
cta::mediachanger::acs::AcsLibraryInteraction::~AcsLibraryInteraction() throw() {
}
//------------------------------------------------------------------------------
// requestResponsesUntilFinal
//------------------------------------------------------------------------------
void cta::acs::AcsLibraryInteraction::requestResponsesUntilFinal(
void cta::mediachanger::acs::AcsLibraryInteraction::requestResponsesUntilFinal(
const SEQ_NO requestSeqNumber,
ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)],
const int queryInterval, const int timeout) const
......@@ -56,7 +56,7 @@ void cta::acs::AcsLibraryInteraction::requestResponsesUntilFinal(
elapsedTime += time(NULL) - startTime;
if(RT_ACKNOWLEDGE == responseType) {
log::write(LOG_DEBUG,"Received RT_ACKNOWLEDGE");
m_log(LOG_DEBUG,"Received RT_ACKNOWLEDGE");
}
if(elapsedTime >= timeout) {
......@@ -66,13 +66,13 @@ void cta::acs::AcsLibraryInteraction::requestResponsesUntilFinal(
}
} while(RT_FINAL != responseType);
log::write(LOG_DEBUG,"Received RT_FINAL");
m_log(LOG_DEBUG,"Received RT_FINAL");
}
//------------------------------------------------------------------------------
// requestResponse
//------------------------------------------------------------------------------
ACS_RESPONSE_TYPE cta::acs::AcsLibraryInteraction::requestResponse(
ACS_RESPONSE_TYPE cta::mediachanger::acs::AcsLibraryInteraction::requestResponse(
const int timeout, const SEQ_NO requestSeqNumber,
ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const
{
......@@ -82,7 +82,7 @@ ACS_RESPONSE_TYPE cta::acs::AcsLibraryInteraction::requestResponse(
std::stringstream dbgMsg;
dbgMsg << "Calling Acs::response() for requestSeqNumber=" << requestSeqNumber;
log::write(LOG_DEBUG, dbgMsg.str());
m_log(LOG_DEBUG, dbgMsg.str());
const STATUS s = m_acs.response(timeout, responseSeqNumber, reqId,
responseType, buf);
......@@ -91,7 +91,7 @@ ACS_RESPONSE_TYPE cta::acs::AcsLibraryInteraction::requestResponse(
dbgMsg << "Acs::response() for requestSeqNumber=" << requestSeqNumber <<
" returned responseSeqNumber=" << responseSeqNumber << " and status " <<
acs_status(s);
log::write(LOG_DEBUG,dbgMsg.str());
m_log(LOG_DEBUG,dbgMsg.str());
switch(s) {
case STATUS_SUCCESS:
......@@ -109,7 +109,7 @@ ACS_RESPONSE_TYPE cta::acs::AcsLibraryInteraction::requestResponse(
//------------------------------------------------------------------------------
// checkSeqNumber
//------------------------------------------------------------------------------
void cta::acs::AcsLibraryInteraction::checkResponseSeqNumber(
void cta::mediachanger::acs::AcsLibraryInteraction::checkResponseSeqNumber(
const SEQ_NO requestSeqNumber, const SEQ_NO responseSeqNumber) const
{
if(requestSeqNumber != responseSeqNumber) {
......@@ -123,7 +123,7 @@ void cta::acs::AcsLibraryInteraction::checkResponseSeqNumber(
//------------------------------------------------------------------------------
// volumeStatusAsString
//------------------------------------------------------------------------------
std::string cta::acs::AcsLibraryInteraction::volumeStatusAsString(
std::string cta::mediachanger::acs::AcsLibraryInteraction::volumeStatusAsString(
const QU_VOL_STATUS &s) const throw() {
std::ostringstream os;
......
......@@ -20,6 +20,7 @@
#include "common/exception/Mismatch.hpp"
#include "common/exception/RequestFailed.hpp"
#include "common/log/log.hpp"
#include "Acs.hpp"
#include <string>
......@@ -30,6 +31,7 @@ extern "C" {
}
namespace cta {
namespace mediachanger {
namespace acs {
/**
......@@ -44,7 +46,7 @@ public:
*
* @param acs Wrapper around the ACSLS C-API.
*/
AcsLibraryInteraction(Acs &acs) throw();
AcsLibraryInteraction(Acs &acs, cta::log::Logger &log) throw();
/**
* Pure-virtual destructor to guarantee this class is abstract.
......@@ -108,10 +110,11 @@ protected:
* Wrapper around the ACSLS C-API.
*/
Acs &m_acs;
log::Logger &m_log;
}; // class AcsLibraryInteraction
} // namespace acs
} // namespace mediachanger
} // namespace cta
......@@ -34,11 +34,11 @@ add_library(CtaAcsDaemon
#AcsDismountTape.cpp
#AcsForceDismountTape.cpp
AcsImpl.cpp
#AcsLibraryInteraction.cpp
#AcsMessageHandler.cpp
#AcsMountTapeReadOnly.cpp
#AcsMountTapeReadWrite.cpp
AcsRequest.cpp
AcsLibraryInteraction.cpp
#AcsRequestDismountTape.cpp
#${ProtoSources}
)
......
......@@ -48,7 +48,7 @@ namespace cta { namespace mediachanger { namespace acs { namespace daemon {
AcsDaemon::AcsDaemon(
const int argc,
char **const argv,
cta::log::Logger& log,
cta::log::Logger& log,
cta::mediachanger::reactor::ZMQReactor &reactor,
const AcsdConfiguration &config):
cta::server::Daemon(log),
......@@ -140,12 +140,12 @@ void AcsDaemon::exceptionThrowingMain(
const std::string runAsStagerSuperuser = "ACSD";
const std::string runAsStagerSupergroup = "CTA";
daemonizeIfNotRunInForegroundAndSetUserAndGroup(runAsStagerSuperuser, runAsStagerSupergroup);
//daemonizeIfNotRunInForegroundAndSetUserAndGroup(runAsStagerSuperuser, runAsStagerSupergroup);
setDumpable();
blockSignals();
initZmqContext();
//setUpReactor();
setUpReactor();
// mainEventLoop();
}
......@@ -242,24 +242,24 @@ void AcsDaemon::blockSignals() const {
//------------------------------------------------------------------------------
// setUpReactor
//------------------------------------------------------------------------------
/*void AcsDaemon::setUpReactor() {
void AcsDaemon::setUpReactor() {
createAndRegisterAcsMessageHandler();
}
*/
//------------------------------------------------------------------------------
// createAndRegisterAcsMessageHandler
//------------------------------------------------------------------------------
/*void AcsDaemon::createAndRegisterAcsMessageHandler() {
void AcsDaemon::createAndRegisterAcsMessageHandler() {
try {
std::unique_ptr<AcsMessageHandler> handler;
try {
handler.reset(new AcsMessageHandler(m_reactor, m_hostName, m_log, m_zmqContext,
m_config, m_acsPendingRequests));
handler.reset(new AcsMessageHandler(m_log, m_reactor, m_zmqContext, m_hostName,
m_config, m_acsPendingRequests)); //create event handler for communicating with the acs daemon
} catch(std::bad_alloc &ba) {
cta::exception::BadAlloc ex;
ex.getMessage() <<
"Failed to create event handler for communicating with "
"the CASTOR ACS daemon: " << ba.what();
"the CTA ACS daemon: " << ba.what();
throw ex;
}
m_reactor.registerHandler(handler.get());
......@@ -272,7 +272,7 @@ void AcsDaemon::blockSignals() const {
throw ex;
}
}
/*
//------------------------------------------------------------------------------
// mainEventLoop
//------------------------------------------------------------------------------
......
......@@ -128,12 +128,12 @@ protected:
/**
* Sets up the reactor.
*/
////// void setUpReactor();
void setUpReactor();
/**
* Creates the handler to handle messages for the acs Zmq requests.
*/
///// void createAndRegisterAcsMessageHandler();
void createAndRegisterAcsMessageHandler();
/**
* The main event loop of the daemon.
......
......@@ -56,7 +56,7 @@ int main(const int argc, char **const argv) {
logger(LOG_INFO, "started ACSD in CTA");
} catch(cta::exception::Exception &ex) {
std::cerr <<
"Failed to instantiate object representing CASTOR logging system: " <<
"Failed to instantiate object representing CTA logging system: " <<
ex.getMessage().str() << std::endl;
return 1;
}
......
/******************************************************************************
*
* 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 "AcsDismountTape.hpp"
#include "common/exception/DismountFailed.hpp"
#include "common/log/log.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
//cta::mediachanger::acs::daemon::acs::daemon::AcsDismountTape::AcsDismountTape(
cta::mediachanger::acs::daemon::AcsDismountTape::AcsDismountTape(
const std::string &vid,
const uint32_t acs,
const uint32_t lsm,
const uint32_t panel,
const uint32_t drive,
Acs &acsWrapper,
log::Logger& log,
const AcsdConfiguration &ctaConf):
cta::mediachanger::acs::AcsLibraryInteraction(acsWrapper, log),
m_volId(acsWrapper.str2Volid(vid)),
m_driveId(acsWrapper.alpd2DriveId(acs,lsm,panel,drive)),
m_acsWrapper(acsWrapper),
m_log(log),
m_ctaConf(ctaConf) {
}
//------------------------------------------------------------------------------
// execute
//------------------------------------------------------------------------------
void cta::mediachanger::acs::daemon::AcsDismountTape::execute() const {
//void cta::mediachanger::acs::daemon::AcsDismountTape::execute() const {
syncDismount();
}
//------------------------------------------------------------------------------
// 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);
}
//------------------------------------------------------------------------------
// 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)];
try {
sendDismountRequest(requestSeqNumber);
requestResponsesUntilFinal(requestSeqNumber, buf,
m_ctaConf.QueryInterval.value(),
m_ctaConf.CmdTimeout.value());
processDismountResponse(buf);
} catch(cta::exception::Exception &ex) {
cta::exception::DismountFailed df;
df.getMessage() << "Failed to dismount volume " <<
m_volId.external_label << ": " << ex.getMessage().str();
throw df;
}
}
//------------------------------------------------------------------------------
// asyncDismount
//------------------------------------------------------------------------------
void cta::mediachanger::acs::daemon::AcsDismountTape::asyncDismount(const SEQ_NO seqNo) const
{
try {
sendDismountRequest(seqNo);
} catch(cta::exception::Exception &ex) {
cta::exception::DismountFailed df;
df.getMessage() << "Failed to send dismount request to ACS " <<
m_volId.external_label << ": " << ex.getMessage().str();
throw df;
}
}
//------------------------------------------------------------------------------
// sendDismountRequest
//------------------------------------------------------------------------------
void cta::mediachanger::acs::daemon::AcsDismountTape::sendDismountRequest(
const SEQ_NO seqNumber) const {
const LOCKID lockId = 0; // No lock
const BOOLEAN force = FALSE;
std::stringstream dbgMsg;
dbgMsg << "Calling Acs::dismount() with seqNumber=" << seqNumber;
m_log(LOG_DEBUG, dbgMsg.str());
const STATUS s = m_acsWrapper.dismount(seqNumber, lockId, m_volId,