Skip to content
Snippets Groups Projects
Commit 01af991b authored by Steven Murray's avatar Steven Murray
Browse files

Added MediaChangerProxy::verifyVidAndLibrarySlot

parent ad814aae
Branches
Tags
No related merge requests found
......@@ -50,6 +50,9 @@ castor::legacymsg::RmcProxyTcpIp::~RmcProxyTcpIp() throw() {
//------------------------------------------------------------------------------
void castor::legacymsg::RmcProxyTcpIp::mountTapeReadOnly(
const std::string &vid, const mediachanger::TapeLibrarySlot &librarySlot) {
verifyVidAndLibrarySlot(vid, mediachanger::TAPE_LIBRARY_TYPE_SCSI,
librarySlot);
// SCSI does not support read-only mounts
mountTapeReadWrite(vid, librarySlot);
}
......@@ -59,38 +62,35 @@ void castor::legacymsg::RmcProxyTcpIp::mountTapeReadOnly(
//------------------------------------------------------------------------------
void castor::legacymsg::RmcProxyTcpIp::mountTapeReadWrite(
const std::string &vid, const mediachanger::TapeLibrarySlot &librarySlot) {
// Verify parameters
if(vid.empty()) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to mount tape: VID is an empty string";
throw ex;
}
if(CA_MAXVIDLEN < vid.length()) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to mount tape: VID is too long"
": vid=" << vid << " maxLen=" << CA_MAXVIDLEN << " actualLen=" <<
vid.length();
throw ex;
}
try {
verifyVidAndLibrarySlot(vid, mediachanger::TAPE_LIBRARY_TYPE_SCSI,
librarySlot);
// Dispatch the appropriate helper method depending on library slot type
switch(librarySlot.getLibraryType()) {
case mediachanger::TAPE_LIBRARY_TYPE_ACS:
mountTapeAcs(vid, librarySlot.str());
break;
case mediachanger::TAPE_LIBRARY_TYPE_MANUAL:
mountTapeManual(vid);
break;
case mediachanger::TAPE_LIBRARY_TYPE_SCSI:
mountTapeScsi(vid, librarySlot.str());
break;
default:
{
castor::exception::Exception ex;
ex.getMessage() << "Failed to mount tape: Unexpected library slot type"
": vid=" << vid << " librarySlot=" << librarySlot.str();
throw ex;
// Dispatch the appropriate helper method depending on library slot type
switch(librarySlot.getLibraryType()) {
case mediachanger::TAPE_LIBRARY_TYPE_ACS:
mountTapeAcs(vid, librarySlot.str());
break;
case mediachanger::TAPE_LIBRARY_TYPE_MANUAL:
mountTapeManual(vid);
break;
case mediachanger::TAPE_LIBRARY_TYPE_SCSI:
mountTapeScsi(vid, librarySlot.str());
break;
default:
{
castor::exception::Exception ex;
ex.getMessage() << "Unexpected library type"
": vid=" << vid << " librarySlot=" << librarySlot.str();
throw ex;
}
}
} catch(castor::exception::Exception &ne) {
castor::exception::Exception ex;
ex.getMessage() <<
"Failed to mount tape in SCSI library for read/write access:" <<
ne.getMessage().str();
throw ex;
}
}
......@@ -173,18 +173,8 @@ void castor::legacymsg::RmcProxyTcpIp::mountTapeScsi(const std::string &vid,
//------------------------------------------------------------------------------
void castor::legacymsg::RmcProxyTcpIp::dismountTape(const std::string &vid,
const mediachanger::TapeLibrarySlot &librarySlot) {
// Verify parameters
if(vid.empty()) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to unmount tape: VID is an empty string";
throw ex;
}
if(CA_MAXVIDLEN < vid.length()) {
castor::exception::Exception ex;
ex.getMessage() << "Failed to nmount tape: VID is too long"
": vid=" << vid << " maxLen=" << CA_MAXVIDLEN << " actualLen=" << vid.length();
throw ex;
}
verifyVidAndLibrarySlot(vid, mediachanger::TAPE_LIBRARY_TYPE_SCSI,
librarySlot);
// Dispatch the appropriate helper method depending on library slot type
switch(librarySlot.getLibraryType()) {
......
......@@ -19,10 +19,44 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/exception/Exception.hpp"
#include "castor/mediachanger/MediaChangerProxy.hpp"
#include "h/Castor_limits.h"
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::mediachanger::MediaChangerProxy::~MediaChangerProxy() {
}
//------------------------------------------------------------------------------
// verifyVidAndLibrarySlot
//------------------------------------------------------------------------------
void castor::mediachanger::MediaChangerProxy::verifyVidAndLibrarySlot(
const std::string &vid,
const mediachanger::TapeLibraryType expectedLibraryType,
const mediachanger::TapeLibrarySlot librarySlot) {
// Verify VID
if(vid.empty()) {
castor::exception::Exception ex;
ex.getMessage() << "VID is an empty string";
throw ex;
}
if(CA_MAXVIDLEN < vid.length()) {
castor::exception::Exception ex;
ex.getMessage() << "VID is too long"
": vid=" << vid << " maxLen=" << CA_MAXVIDLEN << " actualLen=" <<
vid.length();
throw ex;
}
// Verify library slot
const TapeLibraryType actualLibraryType = librarySlot.getLibraryType();
if(expectedLibraryType != actualLibraryType) {
castor::exception::Exception ex;
ex.getMessage() << "Incompatible library type: expected=" <<
mediachanger::tapeLibraryTypeToString(expectedLibraryType) << " actual=" <<
mediachanger::tapeLibraryTypeToString(actualLibraryType);
throw ex;
}
}
......@@ -69,6 +69,23 @@ public:
virtual void dismountTape(const std::string &vid,
const TapeLibrarySlot &librarySlot) = 0;
protected:
/**
* Verifies the specified tape volume-identifier and tape library-slot.
*
* This method throws a castor::exception::Exception if the verfication fails.
*
* @param vid The volume identifier of the tape.
* @param expectedLibraryType Expected tape-library type.
* @param librarySlot The slot in the tape loibrary that contains the tape
* drive.
*/
void verifyVidAndLibrarySlot(
const std::string &vid,
const mediachanger::TapeLibraryType expectedLibraryType,
const mediachanger::TapeLibrarySlot librarySlot);
}; // class MediaChangerProxy
} // namespace mediachanger
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment