Skip to content
Snippets Groups Projects
Commit d9e08436 authored by Daniele Kruse's avatar Daniele Kruse
Browse files

added the pid filed in the DriveEntry and added overloaded functions taking pid as arguments

parent 03182b33
Branches
Tags
No related merge requests found
......@@ -390,7 +390,8 @@ void castor::tape::tapeserver::daemon::DriveCatalogue::configureDown(
// tapeSessionStarted
//-----------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::DriveCatalogue::tapeSessionStarted(
const std::string &unitName, const legacymsg::RtcpJobRqstMsgBody &job)
const std::string &unitName, const legacymsg::RtcpJobRqstMsgBody &job,
const pid_t sessionPid)
throw(castor::exception::Exception) {
DriveMap::iterator itor = m_drives.find(unitName);
if(m_drives.end() == itor) {
......@@ -417,6 +418,21 @@ void castor::tape::tapeserver::daemon::DriveCatalogue::tapeSessionStarted(
itor->second.state = DRIVE_STATE_RUNNING;
itor->second.job = job;
itor->second.pid = sessionPid;
}
//-----------------------------------------------------------------------------
// getUnitName
//-----------------------------------------------------------------------------
std::string castor::tape::tapeserver::daemon::DriveCatalogue::getUnitName(
const pid_t sessionPid) throw(castor::exception::Exception) {
for(DriveMap::iterator i = m_drives.begin(); i!=m_drives.end(); i++) {
if(sessionPid == i->second.pid) return i->first;
}
castor::exception::Internal ex;
ex.getMessage() << "Failed to find the unit name of the tape drive on which "
<< "the session with pid==" << sessionPid << " is running.";
throw ex;
}
//-----------------------------------------------------------------------------
......@@ -488,3 +504,19 @@ void castor::tape::tapeserver::daemon::DriveCatalogue::tapeSessionFailed(
itor->second.state = DRIVE_STATE_DOWN;
}
//-----------------------------------------------------------------------------
// tapeSessionSucceeded
//-----------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::DriveCatalogue::tapeSessionSucceeded(
const pid_t pid) throw(castor::exception::Exception) {
tapeSessionSucceeded(getUnitName(pid));
}
//-----------------------------------------------------------------------------
// tapeSessionFailed
//-----------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::DriveCatalogue::tapeSessionFailed(
const pid_t pid) throw(castor::exception::Exception) {
tapeSessionFailed(getUnitName(pid));
}
......@@ -114,6 +114,14 @@ public:
*/
void populateCatalogue(const utils::TpconfigLines &lines)
throw(castor::exception::Exception);
/**
* Returns the unit name of the drive on which the given process is running
* @param sessionPid
* @return the unit name of the drive on which the given process is running
*/
std::string getUnitName(const pid_t sessionPid)
throw(castor::exception::Exception);
/**
* Returns an unordered list of the unit names of all of the tape drives
......@@ -215,9 +223,10 @@ public:
*
* @param unitName The unit name of the tape drive.
* @param job The job received from the vdqmd daemon.
* @param sessionPid The pid of the child process responsible for the tape session
*/
void tapeSessionStarted(const std::string &unitName,
const legacymsg::RtcpJobRqstMsgBody &job)
const legacymsg::RtcpJobRqstMsgBody &job, const pid_t sessionPid)
throw(castor::exception::Exception);
/**
......@@ -243,6 +252,14 @@ public:
*/
void tapeSessionSucceeded(const std::string &unitName)
throw(castor::exception::Exception);
/**
* Same as above but one can use with the pid of the child process instead of
* the unit name
* @param pid of the child process handling the session
*/
void tapeSessionSucceeded(const pid_t pid)
throw(castor::exception::Exception);
/**
* Moves the state of the specified tape drive from DRIVE_STATE_RUNNING to
......@@ -255,6 +272,14 @@ public:
*/
void tapeSessionFailed(const std::string &unitName)
throw(castor::exception::Exception);
/**
* Same as above but one can use with the pid of the child process instead of
* the unit name
* @param pid of the child process handling the session
*/
void tapeSessionFailed(const pid_t pid)
throw(castor::exception::Exception);
private:
......@@ -300,6 +325,12 @@ private:
* member variable is undefined.
*/
legacymsg::RtcpJobRqstMsgBody job;
/**
* The pid of the child process handling the tape session running on the
* tape drive.
*/
pid_t pid;
/**
* Default constructor that initializes all strings to the empty string,
......
......@@ -286,7 +286,7 @@ TEST_F(castor_tape_tapeserver_daemon_DriveCatalogueTest, completeFSTN) {
castor::utils::copyString(job.dgn, "DGN");
castor::utils::copyString(job.driveUnit, "UNIT");
castor::utils::copyString(job.clientUserName, "USER");
ASSERT_NO_THROW(catalogue.tapeSessionStarted("UNIT", job));
ASSERT_NO_THROW(catalogue.tapeSessionStarted("UNIT", job, 1234));
ASSERT_EQ(DriveCatalogue::DRIVE_STATE_RUNNING,
catalogue.getState("UNIT"));
ASSERT_EQ(job.volReqId, catalogue.getJob("UNIT").volReqId);
......@@ -330,7 +330,7 @@ TEST_F(castor_tape_tapeserver_daemon_DriveCatalogueTest, dgnMismatchStart) {
castor::utils::copyString(job.dgn, "DGN2");
castor::utils::copyString(job.driveUnit, "UNIT");
castor::utils::copyString(job.clientUserName, "USER");
ASSERT_THROW(catalogue.tapeSessionStarted("UNIT", job),
ASSERT_THROW(catalogue.tapeSessionStarted("UNIT", job, 1234),
castor::exception::Exception);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment