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

Replaced DriveCatalogueEntry::toBeCleaned() by createCleaner()

parent 8aafa0f4
......@@ -60,7 +60,15 @@ castor::tape::tapeserver::daemon::DriveCatalogueEntry::DriveCatalogueEntry(
//------------------------------------------------------------------------------
castor::tape::tapeserver::daemon::DriveCatalogueEntry::~DriveCatalogueEntry()
throw() {
deleteSession();
}
//------------------------------------------------------------------------------
// deleteSession
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::DriveCatalogueEntry::deleteSession() {
delete m_session;
m_session = NULL;
}
//-----------------------------------------------------------------------------
......@@ -524,63 +532,42 @@ void castor::tape::tapeserver::daemon::DriveCatalogueEntry::receivedLabelJob(
}
//-----------------------------------------------------------------------------
// toBeCleaned
// createCleaner
//-----------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::DriveCatalogueEntry::toBeCleaned() {
switch(m_state) {
case DRIVE_STATE_RUNNING:
case DRIVE_STATE_WAITDOWN:
{
// Get the vid and assignment time of the crashed tape session
std::string vid;
try {
vid = getSession().getVid();
} catch(...) {
vid = "";
}
time_t assignmentTime = 0;
try {
getSession().getAssignmentTime();
} catch(...) {
assignmentTime = 0;
}
// Free the catalogue representation of the crashed tape session setting
// the sesison pointer to NULL to prevent the destructor from perfroming
// a double delete
delete(m_session);
m_session = NULL;
void castor::tape::tapeserver::daemon::DriveCatalogueEntry::createCleaner() {
try {
const DriveCatalogueSession &session = getSession();
const std::string vid = session.getVid();
const time_t assignmentTime = session.getAssignmentTime();
// Create a cleaner session in the catalogue
m_state = DRIVE_STATE_RUNNING;
m_sessionType = SESSION_TYPE_CLEANER;
const unsigned short rmcPort =
common::CastorConfiguration::getConfig().getConfEntInt("RMC", "PORT",
(unsigned short)RMC_PORT, &m_log);
m_session = DriveCatalogueCleanerSession::create(
m_log,
m_processForker,
m_config,
vid,
rmcPort,
assignmentTime);
}
break;
default:
{
castor::exception::Exception ex;
ex.getMessage() << "Failed to clean drive"
": Drive is not running a tape session: state=" <<
drvState2Str(m_state);
throw ex;
}
deleteSession();
// Create a cleaner session in the catalogue
m_state = DRIVE_STATE_RUNNING;
m_sessionType = SESSION_TYPE_CLEANER;
const unsigned short rmcPort =
common::CastorConfiguration::getConfig().getConfEntInt("RMC", "PORT",
(unsigned short)RMC_PORT, &m_log);
m_session = DriveCatalogueCleanerSession::create(
m_log,
m_processForker,
m_config,
vid,
rmcPort,
assignmentTime);
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to create cleaner session: " <<
ne.getMessage().str();
throw ex;
}
}
//-----------------------------------------------------------------------------
// sessionSucceeded
//-----------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::DriveCatalogueEntry::sessionSucceeded() {
void castor::tape::tapeserver::daemon::DriveCatalogueEntry::
sessionSucceeded() {
switch(m_state) {
case DRIVE_STATE_RUNNING:
m_state = DRIVE_STATE_UP;
......
......@@ -188,6 +188,13 @@ public:
*/
~DriveCatalogueEntry() throw();
/**
* If there is a catalogue session associated with the tape drive then this
* method deletes it and sets the member variable pointing to it to NULL in
* order to prevent double deletions.
*/
void deleteSession();
/**
* Gets the configuration of the tape-drive.
*
......@@ -277,12 +284,9 @@ public:
const int labelCmdConnection);
/**
* Moves the state of tape drive to DRIVE_STATE_SESSIONRUNNING and sets the
* current session type to SESSION_TYPE_CLEANER.
*
* This method will accept any drive state.
*/
void toBeCleaned();
* Creates a cleaner session to eject any tape left in the tape drive.
*/
void createCleaner();
/**
* Moves the state of the tape drive to DRIVE_STATE_UP if the
......@@ -495,35 +499,53 @@ private:
uint16_t getAsnForTapeStatDriveEntry() const throw();
/**
* Returns the value of the asnTime field of a TapeStatDriveEntry to be used
* in a TapeStatReplyMsgBody.
* Determines the value of the asnTime field of a TapeStatDriveEntry to be
* used in a TapeStatReplyMsgBody.
*/
uint32_t getAsnTimeForTapeStatDriveEntry() const throw();
/**
* Returns the value of the mode field of a TapeStatDriveEntry to be used
* Determines the value of the mode field of a TapeStatDriveEntry to be used
* in a TapeStatReplyMsgBody.
*
* @return The value of the mode field if known else WRITE_DISABLE.
*/
uint16_t getModeForTapeStatDriveEntry() const throw();
/**
* Returns the value of the lblCode field of a TapeStatDriveEntry to be used
* in a TapeStatReplyMsgBody.
* Determines the value of the lblCode field of a TapeStatDriveEntry to be
* used in a TapeStatReplyMsgBody.
*
* @return Always "aul" because this is the only tape format supported by
* CASTOR.
*/
std::string getLblCodeForTapeStatDriveEntry() const throw();
/**
* Returns the value of the tobeMounted field of a TapeStatDriveEntry to be
* Determines the value of the tobeMounted field of a TapeStatDriveEntry to be
* used in a TapeStatReplyMsgBody.
*
* @return The value of the tobeMounted filed if known, else 0.
*/
uint16_t getToBeMountedForTapeStatDriveEntry() const throw();
/**
* Returns the value of the vid field of a TapeStatDriveEntry to be used
* Determines the value of the vid field of a TapeStatDriveEntry to be used
* in a TapeStatReplyMsgBody.
*
* @return The volume indenfier if known else the empty string.
*/
std::string getVidForTapeStatDriveEntry() const throw();
/**
* Tries to determine the volume identifier of the tape currently associated
* with the tape drive.
*
* @return The volume identifier of the tape or the empty string if it was
* not possible to determine.
*/
std::string getVidForCleaner() const throw();
/**
* Returns the value of the vsn field of a TapeStatDriveEntry to be used
* in a TapeStatReplyMsgBody.
......
......@@ -209,7 +209,13 @@ std::string castor::tape::tapeserver::daemon::DriveCatalogueTransferSession::
case TRANSFERSTATE_RUNNING:
return m_vid;
default:
return "";
{
castor::exception::Exception ex;
ex.getMessage() << "Failed to get VID from catalogue transfer-session"
": Catalogue transfer-session is in an incompatible state: "
" state=" << transferStateToStr(m_state);
throw ex;
}
}
}
......
......@@ -84,11 +84,13 @@ public:
/**
* Gets the time at which the tape drive was assigned a data transfer job.
*
* @return The assignment time as the number of seconds since the Epoch.
*/
time_t getAssignmentTime() const throw();
/**
* vdqmJob getter method
* Get the vdqm job received from the vdqmd daemon.
*
* @return vdqm job received from the vdqmd daemon
*/
......@@ -113,9 +115,10 @@ public:
/**
* Gets the volume identifier of the tape associated with the tape drive.
*
* This method throws a castor::exception::Exception if the volume identifer
* is not yet known.
*
* @return The volume identifier of the tape associated with the tape drive.
* If the volume indentifier is not known then this method returns the empty
* string.
*/
std::string getVid() const;
......
......@@ -228,7 +228,7 @@ void castor::tape::tapeserver::daemon::ProcessForkerConnectionHandler::
try {
drive.sessionFailed();
m_log(LOG_WARNING, "Data-transfer session failed", params);
drive.toBeCleaned();
drive.createCleaner();
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to handle crashed data-transfer session: " <<
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment