Commit b51c7034 authored by Steven Murray's avatar Steven Murray
Browse files

Continued to refactor tapeserverd - vdqm is now synced with "wait down"

parent a6ef2399
......@@ -118,7 +118,7 @@ bool castor::tape::tapeserver::daemon::AdminAcceptHandler::handleEvent(
std::auto_ptr<AdminConnectionHandler> connectionHandler;
try {
connectionHandler.reset(new AdminConnectionHandler(connection.get(),
m_reactor, m_log, m_vdqm, m_driveCatalogue, m_hostName));
m_reactor, m_log, m_driveCatalogue));
connection.release();
} catch(std::bad_alloc &ba) {
castor::exception::BadAlloc ex;
......
......@@ -49,16 +49,12 @@ castor::tape::tapeserver::daemon::AdminConnectionHandler::AdminConnectionHandler
const int fd,
reactor::ZMQReactor &reactor,
log::Logger &log,
legacymsg::VdqmProxy &vdqm,
DriveCatalogue &driveCatalogue,
const std::string &hostName)
DriveCatalogue &driveCatalogue)
throw():
m_fd(fd),
m_reactor(reactor),
m_log(log),
m_vdqm(vdqm),
m_driveCatalogue(driveCatalogue),
m_hostName(hostName),
m_netTimeout(1) { // Timeout in seconds
}
......@@ -197,12 +193,10 @@ void castor::tape::tapeserver::daemon::AdminConnectionHandler::
switch(body.status) {
case CONF_UP:
m_vdqm.setDriveUp(m_hostName, unitName, driveConfig.dgn);
drive.configureUp();
m_log(LOG_INFO, "Drive configured up", params);
break;
case CONF_DOWN:
m_vdqm.setDriveDown(m_hostName, unitName, driveConfig.dgn);
drive.configureDown();
m_log(LOG_INFO, "Drive configured down", params);
break;
......
......@@ -51,7 +51,6 @@ public:
* @param reactor The reactor to which new Vdqm connection handlers are to
* be registered.
* @param log The object representing the API of the CASTOR logging system.
* @param vdqm Proxy object representing the vdqmd daemon.
* @param driveCatalogue The catalogue of tape drives controlled by the tape
* server daemon.
*/
......@@ -59,9 +58,7 @@ public:
const int fd,
reactor::ZMQReactor &reactor,
log::Logger &log,
legacymsg::VdqmProxy &vdqm,
DriveCatalogue &driveCatalogue,
const std::string &hostName) throw();
DriveCatalogue &driveCatalogue) throw();
/**
* Returns the human-readable name this event handler.
......@@ -200,22 +197,11 @@ private:
*/
log::Logger &m_log;
/**
* Proxy object representing the vdqmd daemon.
*/
legacymsg::VdqmProxy &m_vdqm;
/**
* The catalogue of tape drives controlled by the tape server daemon.
*/
DriveCatalogue &m_driveCatalogue;
/**
* The name of the host on which tape daemon is running. This name is
* needed to fill in messages to be sent to the vdqmd daemon.
*/
const std::string m_hostName;
/**
* The timeout in seconds to be applied when performing network read and
* write operations.
......
......@@ -31,18 +31,19 @@
castor::tape::tapeserver::daemon::DriveCatalogueCleanerSession *
castor::tape::tapeserver::daemon::DriveCatalogueCleanerSession::create(
log::Logger &log,
ProcessForkerProxy &processForker,
const int netTimeout,
const tape::utils::DriveConfig &driveConfig,
ProcessForkerProxy &processForker,
const std::string &vid,
const unsigned short rmcPort,
const time_t assignmentTime) {
const pid_t pid = forkCleanerSession(processForker, driveConfig, vid,
rmcPort);
const pid_t pid = processForker.forkCleaner(driveConfig, vid, rmcPort);
return new DriveCatalogueCleanerSession(
pid,
log,
netTimeout,
pid,
driveConfig,
vid,
assignmentTime);
......@@ -53,29 +54,17 @@ castor::tape::tapeserver::daemon::DriveCatalogueCleanerSession *
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::DriveCatalogueCleanerSession::
DriveCatalogueCleanerSession(
const pid_t pid,
log::Logger &log,
const int netTimeout,
const pid_t pid,
const tape::utils::DriveConfig &driveConfig,
const std::string &vid,
const time_t assignmentTime) throw():
m_pid(pid),
m_log(log),
DriveCatalogueSession(log, netTimeout, pid, driveConfig),
m_vid(vid),
m_assignmentTime(assignmentTime) {
}
//------------------------------------------------------------------------------
// forkCleanerSession
//------------------------------------------------------------------------------
pid_t castor::tape::tapeserver::daemon::DriveCatalogueCleanerSession::
forkCleanerSession(ProcessForkerProxy &processForker,
const tape::utils::DriveConfig &driveConfig,
const std::string &vid,
const unsigned short rmcPort) {
return processForker.forkCleaner(driveConfig, vid, rmcPort);
}
//------------------------------------------------------------------------------
// sessionSucceeded
//------------------------------------------------------------------------------
......
......@@ -45,8 +45,10 @@ public:
* should only be created using the static create() method.
*
* @param log Object representing the API of the CASTOR logging system.
* @param processForker Proxy object representing the ProcessForker.
* @param netTimeout Timeout in seconds to be used when performing network
* I/O.
* @param driveConfig The configuration of the tape drive.
* @param processForker Proxy object representing the ProcessForker.
* @param vid The volume identifier ofthe tape associated with the tape
* drive. If the volume identifier is not known then this parameter should
* be set to the empty string.
......@@ -57,8 +59,9 @@ public:
*/
static DriveCatalogueCleanerSession *create(
log::Logger &log,
ProcessForkerProxy &processForker,
const int netTimeout,
const tape::utils::DriveConfig &driveConfig,
ProcessForkerProxy &processForker,
const std::string &vid,
const unsigned short rmcPort,
const time_t assignmentTime);
......@@ -122,8 +125,10 @@ protected:
* is protected so that unit tests can go around this restriction for sole
* purpose of unit testing.
*
* @param pid Process identifier of the session.
* @param log Object representing the API of the CASTOR logging system.
* @param netTimeout Timeout in seconds to be used when performing network
* I/O.
* @param pid The process identifier of the session.
* @param driveConfig The configuration of the tape drive.
* @param vid The volume identifier ofthe tape associated with the tape
* drive. If the volume identifier is not known then this parameter should
......@@ -132,24 +137,15 @@ protected:
* drive.
*/
DriveCatalogueCleanerSession(
const pid_t pid,
log::Logger &log,
const int netTimeout,
const pid_t pid,
const tape::utils::DriveConfig &driveConfig,
const std::string &vid,
const time_t assignmentTime) throw();
private:
/**
* The process identifier of the session.
*/
const pid_t m_pid;
/**
* Object representing the API of the CASTOR logging system.
*/
log::Logger &m_log;
/**
* The volume identifier of the tape associated with the tape drive. If the
* volume identifier was not known when the cleaner session was created then
......@@ -162,23 +158,6 @@ private:
*/
const time_t m_assignmentTime;
/**
* Forks a cleaner session.
*
* @param processForker Proxy object representing the ProcessForker.
* @param driveConfig The configuration of the tape drive.
* @param vid The volume identifier ofthe tape associated with the tape
* drive. If the volume identifier is not known then this parameter should
* be set to the empty string.
* @param rmcPort The TCP/IP port on which the rmcd daemon is listening.
* @return The process identifier of the session.
*/
static pid_t forkCleanerSession(
ProcessForkerProxy &processForker,
const tape::utils::DriveConfig &driveConfig,
const std::string &vid,
const unsigned short rmcPort);
}; // class DriveCatalogueCleanerSession
} // namespace daemon
......
......@@ -404,6 +404,7 @@ void castor::tape::tapeserver::daemon::DriveCatalogueEntry::configureUp() {
throw ex;
}
}
m_vdqm.setDriveUp(m_hostName, m_config.unitName, m_config.dgn);
}
//-----------------------------------------------------------------------------
......@@ -465,11 +466,17 @@ void castor::tape::tapeserver::daemon::DriveCatalogueEntry::receivedVdqmJob(
common::CastorConfiguration::getConfig().getConfEntInt("RMC", "PORT",
(unsigned short)RMC_PORT, &m_log);
DriveCatalogueTransferSession *const transferSession =
DriveCatalogueTransferSession::create(m_log, m_config,
m_dataTransferConfig, job, rmcPort, m_processForker, m_vdqm,
m_hostName);
DriveCatalogueTransferSession::create(
m_log,
m_netTimeout,
m_config,
job,
m_dataTransferConfig,
rmcPort,
m_processForker);
m_session = dynamic_cast<DriveCatalogueSession *>(transferSession);
transferSession->assignDriveInVdqm();
m_vdqm.assignDrive(m_hostName, m_config.unitName, job.dgn,
job.volReqId, m_session->getPid());
}
break;
default:
......@@ -517,8 +524,14 @@ void castor::tape::tapeserver::daemon::DriveCatalogueEntry::receivedLabelJob(
const unsigned short rmcPort =
common::CastorConfiguration::getConfig().getConfEntInt("RMC", "PORT",
(unsigned short)RMC_PORT, &m_log);
m_session = DriveCatalogueLabelSession::create(m_netTimeout, m_log,
m_processForker, m_config, job, rmcPort, labelCmdConnection);
m_session = DriveCatalogueLabelSession::create(
m_log,
m_netTimeout,
m_config,
m_processForker,
job,
rmcPort,
labelCmdConnection);
}
break;
default:
......@@ -545,8 +558,9 @@ void castor::tape::tapeserver::daemon::DriveCatalogueEntry::createCleaner(
(unsigned short)RMC_PORT, &m_log);
m_session = DriveCatalogueCleanerSession::create(
m_log,
m_processForker,
m_netTimeout,
m_config,
m_processForker,
vid,
rmcPort,
assignmentTime);
......@@ -566,9 +580,11 @@ void castor::tape::tapeserver::daemon::DriveCatalogueEntry::
switch(m_state) {
case DRIVE_STATE_RUNNING:
m_state = DRIVE_STATE_UP;
m_vdqm.setDriveUp(m_hostName, m_config.unitName, m_config.dgn);
break;
case DRIVE_STATE_WAITDOWN:
m_state = DriveCatalogueEntry::DRIVE_STATE_DOWN;
m_vdqm.setDriveDown(m_hostName, m_config.unitName, m_config.dgn);
break;
default:
{
......@@ -619,6 +635,8 @@ void castor::tape::tapeserver::daemon::DriveCatalogueEntry::sessionFailed() {
}
}
m_vdqm.setDriveDown(m_hostName, m_config.unitName, m_config.dgn);
// Wrap the session in an auto pointer to gaurantee it is deleted even in the
// event of an exception
std::auto_ptr<DriveCatalogueSession> session(m_session);
......
......@@ -30,21 +30,20 @@
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::DriveCatalogueLabelSession *
castor::tape::tapeserver::daemon::DriveCatalogueLabelSession::create(
const int netTimeout,
log::Logger &log,
ProcessForkerProxy &processForker,
const int netTimeout,
const tape::utils::DriveConfig &driveConfig,
ProcessForkerProxy &processForker,
const castor::legacymsg::TapeLabelRqstMsgBody &labelJob,
const unsigned short rmcPort,
const int labelCmdConnection) {
const pid_t pid = forkLabelSession(processForker, driveConfig, labelJob,
rmcPort);
const pid_t pid = processForker.forkLabel(driveConfig, labelJob, rmcPort);
return new DriveCatalogueLabelSession(
pid,
netTimeout,
log,
netTimeout,
pid,
driveConfig,
labelJob,
labelCmdConnection);
......@@ -55,39 +54,18 @@ castor::tape::tapeserver::daemon::DriveCatalogueLabelSession *
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::DriveCatalogueLabelSession::
DriveCatalogueLabelSession(
const pid_t pid,
const int netTimeout,
log::Logger &log,
const int netTimeout,
const pid_t pid,
const tape::utils::DriveConfig &driveConfig,
const castor::legacymsg::TapeLabelRqstMsgBody &labelJob,
const int labelCmdConnection) throw():
m_pid(pid),
DriveCatalogueSession(log, netTimeout, pid, driveConfig),
m_assignmentTime(time(0)),
m_netTimeout(netTimeout),
m_log(log),
m_driveConfig(driveConfig),
m_labelJob(labelJob),
m_labelCmdConnection(labelCmdConnection) {
}
//------------------------------------------------------------------------------
// forkLabelSession
//------------------------------------------------------------------------------
pid_t castor::tape::tapeserver::daemon::DriveCatalogueLabelSession::
forkLabelSession(ProcessForkerProxy &processForker,
const tape::utils::DriveConfig &driveConfig,
const castor::legacymsg::TapeLabelRqstMsgBody &labelJob,
const unsigned short rmcPort) {
try {
return processForker.forkLabel(driveConfig, labelJob, rmcPort);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to fork label session: unitName=" <<
driveConfig.unitName << ": " << ne.getMessage().str();
throw ex;
}
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
......
......@@ -46,11 +46,11 @@ public:
* Except in the case of unit testing, a DriveCatalogueLabelSession object
* should only be created using the static create() method.
*
* @param log Object representing the API of the CASTOR logging system.
* @param netTimeout Timeout in seconds to be used when performing network
* I/O.
* @param log Object representing the API of the CASTOR logging system.
* @param processForker Proxy object representing the ProcessForker.
* @param driveConfig The configuration of the tape drive.
* @param processForker Proxy object representing the ProcessForker.
* @param labelJob The label job received from the castor-tape-label
* command-line tool.
* @param rmcPort The TCP/IP port on which the rmcd daemon is listening.
......@@ -59,10 +59,10 @@ public:
* @return A newly created DriveCatalogueSession object.
*/
static DriveCatalogueLabelSession *create(
const int netTimeout,
log::Logger &log,
ProcessForkerProxy &processForker,
const int netTimeout,
const tape::utils::DriveConfig &driveConfig,
ProcessForkerProxy &processForker,
const castor::legacymsg::TapeLabelRqstMsgBody &labelJob,
const unsigned short rmcPort,
const int labelCmdConnection);
......@@ -137,10 +137,10 @@ protected:
* is protected so that unit tests can go around this restriction for sole
* purpose of unit testing.
*
* @param pid The process ID of the session.
* @param log Object representing the API of the CASTOR logging system.
* @param netTimeout Timeout in seconds to be used when performing network
* I/O.
* @param log Object representing the API of the CASTOR logging system.
* @param pid The process ID of the session.
* @param driveConfig The configuration of the tape drive.
* @param labelJob The label job received from the castor-tape-label
* command-line tool.
......@@ -148,40 +148,20 @@ protected:
* the tape labeling command-line tool castor-tape-label.
*/
DriveCatalogueLabelSession(
const pid_t pid,
const int netTimeout,
log::Logger &log,
const int netTimeout,
const pid_t pid,
const tape::utils::DriveConfig &driveConfig,
const castor::legacymsg::TapeLabelRqstMsgBody &labelJob,
const int labelCmdConnection) throw();
private:
/**
* The process ID of the session.
*/
const pid_t m_pid;
/**
* The time at which the tape drive was assigned a data transfer job.
*/
const time_t m_assignmentTime;
/**
* Timeout in seconds to be used when performing network I/O.
*/
const int m_netTimeout;
/**
* Object representing the API of the CASTOR logging system.
*/
log::Logger &m_log;
/**
* The configuration of the tape drive.
*/
tape::utils::DriveConfig m_driveConfig;
/**
* The label job received from the castor-tape-label command-line tool.
*/
......@@ -193,21 +173,6 @@ private:
*/
const int m_labelCmdConnection;
/**
* Uses the ProcessForker to fork a label-session.
*
* @param processForker Proxy object representing the ProcessForker.
* @param driveConfig The configuration of the tape drive.
* @param labelJob The label job received from the castor-tape-label
* command-line tool.
* @param rmcPort The TCP/IP port on which the rmcd daemon is listening.
* @return The process identifier of the session.
*/
static pid_t forkLabelSession(ProcessForkerProxy &processForker,
const tape::utils::DriveConfig &driveConfig,
const castor::legacymsg::TapeLabelRqstMsgBody &labelJob,
const unsigned short rmcPort);
}; // class DriveCatalogueLabelSession
} // namespace daemon
......
......@@ -23,6 +23,21 @@
#include "castor/tape/tapeserver/daemon/DriveCatalogueSession.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::DriveCatalogueSession::
DriveCatalogueSession(
log::Logger &log,
const int netTimeout,
const pid_t pid,
const tape::utils::DriveConfig &driveConfig) throw():
m_log(log),
m_netTimeout(netTimeout),
m_pid(pid),
m_driveConfig(driveConfig) {
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
......
......@@ -23,6 +23,9 @@
#pragma once
#include "castor/log/Logger.hpp"
#include "castor/tape/utils/DriveConfig.hpp"
#include <string>
#include <sys/types.h>
#include <unistd.h>
......@@ -89,7 +92,49 @@ public:
* @return True if a tape is in the process of being mounted.
*/
virtual bool tapeIsBeingMounted() const throw() = 0;
protected:
/**
* Protected constructor.
*
* Except in the case of unit testing a DriveCatalogueTransferSession object
* should only be created using the static create() method. This constructor
* is protected so that unit tests can go around this restriction for sole
* purpose of unit testing.
*
* @param log Object representing the API of the CASTOR logging system.
* @param netTimeout Timeout in seconds to be used when performing network
* I/O.
* @param pid The process identifier of the session.
* @param driveConfig The configuration of the tape drive.
*/
DriveCatalogueSession(
log::Logger &log,
const int netTimeout,
const pid_t pid,
const tape::utils::DriveConfig &driveConfig) throw();
/**
* Object representing the API of the CASTOR logging system.
*/
log::Logger &m_log;
/**
* Timeout in seconds to be used when performing network I/O.
*/
const int m_netTimeout;
/**
* The process identifier of the session.
*/
const pid_t m_pid;
/**
* The configuration of the tape drive.
*/
const tape::utils::DriveConfig &m_driveConfig;
}; // class DriveCatalogueSession
} // namespace daemon
......
......@@ -33,26 +33,24 @@
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::DriveCatalogueTransferSession*
castor::tape::tapeserver::daemon::DriveCatalogueTransferSession::create(
log::Logger &log,
const tape::utils::DriveConfig &driveConfig,
const DataTransferSession::CastorConf &dataTransferConfig,
const legacymsg::RtcpJobRqstMsgBody &vdqmJob,
const unsigned short rmcPort,
ProcessForkerProxy &processForker,
legacymsg::VdqmProxy &vdqm,
const std::string &hostName) {
log::Logger &log,
const int netTimeout,
const tape::utils::DriveConfig &driveConfig,
const legacymsg::RtcpJobRqstMsgBody &vdqmJob,
const DataTransferSession::CastorConf &dataTransferConfig,
const unsigned short rmcPort,
ProcessForkerProxy &processForker) {
const pid_t pid = forkTransferSession(processForker, driveConfig, vdqmJob,
const pid_t pid = processForker.forkDataTransfer(driveConfig, vdqmJob,
dataTransferConfig, rmcPort);
return new DriveCatalogueTransferSession(
pid,
log,
netTimeout,
pid,
driveConfig,
dataTransferConfig,
vdqmJob,
vdqm,
hostName);
vdqmJob);
}
//------------------------------------------------------------------------------
......@@ -60,43 +58,18 @@ castor::tape::tapeserver::daemon::DriveCatalogueTransferSession*
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::DriveCatalogueTransferSession::