Commit 559fbc28 authored by Steven Murray's avatar Steven Murray
Browse files

castor-tape-mediachanger-mount now handles manual mode better

parent 3392ac67
......@@ -27,6 +27,7 @@ set (MEDIA_CHANGER_LIB_SRC_FILES
MmcProxy.cpp
MmcProxyDummy.cpp
MmcProxyLog.cpp
MmcProxyNotSupported.cpp
ScsiLibrarySlot.cpp
TapeLibraryType.cpp)
add_library(castormediachanger ${MEDIA_CHANGER_LIB_SRC_FILES})
......
......@@ -35,6 +35,17 @@ castor::mediachanger::MediaChangerFacade::MediaChangerFacade(
m_rmc(rmc) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::mediachanger::MediaChangerFacade::MediaChangerFacade(
messages::AcsProxy &acs,
legacymsg::RmcProxy &rmc) throw():
m_acs(acs),
m_mmc(m_mmcNotSupported),
m_rmc(rmc) {
}
//------------------------------------------------------------------------------
// mountTapeReadOnly
//------------------------------------------------------------------------------
......
......@@ -24,6 +24,7 @@
#include "castor/legacymsg/RmcProxy.hpp"
#include "castor/mediachanger/GenericLibrarySlot.hpp"
#include "castor/mediachanger/MmcProxy.hpp"
#include "castor/mediachanger/MmcProxyNotSupported.hpp"
#include "castor/messages/AcsProxy.hpp"
#include <unistd.h>
......@@ -51,6 +52,17 @@ public:
MediaChangerFacade(messages::AcsProxy &acs, MmcProxy &mmc,
legacymsg::RmcProxy &rmc) throw();
/**
* Constructor.
*
* Use this constructor when manual media-changers are not to be supported.
*
* @param acs Proxy object representing the CASTOR ACS daemon.
* @param rmc Proxy object representing the rmcd daemon.
*/
MediaChangerFacade(messages::AcsProxy &acs, legacymsg::RmcProxy &rmc)
throw();
/**
* Requests the media changer to mount of the specified tape for read-only
* access into the drive in the specified library slot.
......@@ -98,6 +110,12 @@ private:
*/
legacymsg::RmcProxy &m_rmc;
/**
* The manual media-changer proxy object that is used when manual
* media-changers are not to be supported.
*/
MmcProxyNotSupported m_mmcNotSupported;
}; // class MediaChangerFacade
} // namespace mediachanger
......
/******************************************************************************
*
* 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 "castor/exception/Exception.hpp"
#include "castor/mediachanger/MmcProxyNotSupported.hpp"
//------------------------------------------------------------------------------
// mountTapeReadOnly
//------------------------------------------------------------------------------
void castor::mediachanger::MmcProxyNotSupported::mountTapeReadOnly(
const std::string &vid, const ManualLibrarySlot &librarySlot) {
castor::exception::Exception ex;
ex.getMessage() << "Manual mounting is not supported";
throw ex;
}
//------------------------------------------------------------------------------
// mountTapeReadWrite
//------------------------------------------------------------------------------
void castor::mediachanger::MmcProxyNotSupported::mountTapeReadWrite(
const std::string &vid, const ManualLibrarySlot &librarySlot) {
castor::exception::Exception ex;
ex.getMessage() << "Manual mounting is not supported";
throw ex;
}
//------------------------------------------------------------------------------
// dismountTape
//------------------------------------------------------------------------------
void castor::mediachanger::MmcProxyNotSupported::dismountTape(
const std::string &vid, const ManualLibrarySlot &librarySlot) {
castor::exception::Exception ex;
ex.getMessage() << "Manual dismounting is not supported";
throw ex;
}
/******************************************************************************
*
* 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 "castor/mediachanger/MmcProxy.hpp"
namespace castor {
namespace mediachanger {
/**
* Concrete class implementing a manual media-changer that throws
* "not supported" exceptions.
*/
class MmcProxyNotSupported: public MmcProxy {
public:
/**
* Requests the media changer to mount of the specified tape for read-only
* access into the drive in the specified library slot.
*
* @param vid The volume identifier of the tape.
* @param librarySlot The library slot containing the tape drive.
*/
void mountTapeReadOnly(const std::string &vid,
const ManualLibrarySlot &librarySlot);
/**
* Requests the media changer to mount of the specified tape for read/write
* access into the drive in the specified library slot.
*
* @param vid The volume identifier of the tape.
* @param librarySlot The library slot containing the tape drive.
*/
void mountTapeReadWrite(const std::string &vid,
const ManualLibrarySlot &librarySlot);
/**
* Requests the media changer to dismount of the specified tape from the
* drive in the specifed library slot.
*
* @param vid The volume identifier of the tape.
* @param librarySlot The library slot containing the tape drive.
*/
void dismountTape(const std::string &vid,
const ManualLibrarySlot &librarySlot);
}; // class MmcProxyNotSupported
} // namespace mediachanger
} // namespace castor
......@@ -45,61 +45,25 @@ castor::mediachanger::MountCmd::~MountCmd() throw() {
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int castor::mediachanger::MountCmd::main(const int argc,
char *const *const argv) throw() {
if(parseCmdLine(argc, argv)) {
return 1;
}
void castor::mediachanger::MountCmd::exceptionThrowingMain(const int argc,
char *const *const argv) {
m_cmdLine = MountCmdLine(argc, argv);
// Display the usage message to standard out and exit with success if the
// user requested help
if(m_cmdLine.help) {
usage(m_out);
return 0;
return;
}
// Setup debug mode to be on or off depending on the command-line arguments
m_debugBuf.setDebug(m_cmdLine.debug);
m_dbg << "readonly = " << bool2Str(m_cmdLine.readOnly) << std::endl;
m_dbg << "VID = " << m_cmdLine.vid;
m_dbg << "VID = " << m_cmdLine.vid << std::endl;
m_dbg << "DRIVE_SLOT = " << m_cmdLine.driveLibrarySlot.str() << std::endl;
return mountTape();
}
//------------------------------------------------------------------------------
// parseCmdLine
//------------------------------------------------------------------------------
bool castor::mediachanger::MountCmd::parseCmdLine(const int argc,
char *const *const argv) throw() {
std::ostringstream errorMessage;
try {
m_cmdLine = MountCmdLine(argc, argv);
return false; // Successfully parsed command line
} catch(castor::exception::InvalidArgument &ia) {
errorMessage << "Invalid argument: " << ia.getMessage().str() << std::endl;
errorMessage << std::endl;
usage(errorMessage);
} catch(castor::exception::MissingOperand &mo) {
errorMessage << "Missing operand: " << mo.getMessage().str() << std::endl;
errorMessage << std::endl;
usage(errorMessage);
} catch(castor::exception::Exception &ie) {
errorMessage << "Internal error: " << ie.getMessage().str() << std::endl;
} catch(std::exception &se) {
errorMessage << "Unexpected exception: " << se.what() << std::endl;
} catch(...) {
errorMessage << "Unknown exception" << std::endl;
}
// Reaching here means the command line could not be parsed, an exception has
// been thrown and errorMessage has been set accordingly
m_err << "Aborting: Failed to parse command line: " << errorMessage.str();
return true; // Failed to parse command line
mountTape();
}
//------------------------------------------------------------------------------
......@@ -135,17 +99,10 @@ void castor::mediachanger::MountCmd::usage(std::ostream &os) const throw() {
//------------------------------------------------------------------------------
// mountTape
//------------------------------------------------------------------------------
int castor::mediachanger::MountCmd::mountTape() throw() {
try {
if(m_cmdLine.readOnly) {
m_mc.mountTapeReadOnly(m_cmdLine.vid, m_cmdLine.driveLibrarySlot);
} else {
m_mc.mountTapeReadWrite(m_cmdLine.vid, m_cmdLine.driveLibrarySlot);
}
} catch(castor::exception::Exception &ex) {
m_err << "Aborting: " << ex.getMessage().str() << std::endl;
return 1;
void castor::mediachanger::MountCmd::mountTape() {
if(m_cmdLine.readOnly) {
m_mc.mountTapeReadOnly(m_cmdLine.vid, m_cmdLine.driveLibrarySlot);
} else {
m_mc.mountTapeReadWrite(m_cmdLine.vid, m_cmdLine.driveLibrarySlot);
}
return 0;
}
......@@ -63,7 +63,7 @@ public:
* @param argc The number of command-line arguments.
* @param argv The command-line arguments.
*/
int main(const int argc, char *const *const argv) throw();
void exceptionThrowingMain(const int argc, char *const *const argv);
private:
......@@ -75,15 +75,6 @@ private:
*/
MountCmdLine m_cmdLine;
/**
* Parses the specified command line.
*
* @param argc The number of command-line arguments.
* @param argv The command-line arguments.
* @return true on failure and false on success.
*/
bool parseCmdLine(const int argc, char *const *const argv) throw();
/**
* Writes the command-line usage message of to the specified output stream.
*
......@@ -94,10 +85,8 @@ private:
/**
* Requests the media changer to mount the tape and returns only when the
* operation has terminated.
*
* @return The return value of the command-line tool.
*/
int mountTape() throw();
void mountTape();
}; // class MountCmd
......
......@@ -25,7 +25,7 @@
#include "castor/common/CastorConfiguration.hpp"
#include "castor/exception/Exception.hpp"
#include "castor/legacymsg/RmcProxyTcpIp.hpp"
#include "castor/mediachanger/MmcProxyDummy.hpp"
#include "castor/mediachanger/MmcProxyNotSupported.hpp"
#include "castor/mediachanger/MountCmd.hpp"
#include "castor/messages/AcsProxyZmq.hpp"
#include "castor/messages/SmartZmqContext.hpp"
......@@ -42,7 +42,7 @@
* @param argc The number of command-line arguments including the program name.
* @param argv The command-line arguments.
*/
static int exceptionThrowingMain(const int argc, char *const *const argv);
static void exceptionThrowingMain(const int argc, char *const *const argv);
/**
* Instantiates a ZMQ context.
......@@ -60,7 +60,8 @@ int main(const int argc, char *const *const argv) {
std::string errorMessage;
try {
return exceptionThrowingMain(argc, argv);
exceptionThrowingMain(argc, argv);
return 0;
} catch(castor::exception::Exception &ex) {
errorMessage = ex.getMessage().str();
} catch(std::exception &se) {
......@@ -72,7 +73,7 @@ int main(const int argc, char *const *const argv) {
// Reaching this point means the command has failed, ane exception was throw
// and errorMessage has been set accordingly
std::cerr << "Aborting: " << errorMessage;
std::cerr << "Aborting: " << errorMessage << std::endl;
return 1;
}
......@@ -80,7 +81,7 @@ int main(const int argc, char *const *const argv) {
//------------------------------------------------------------------------------
// exceptionThrowingMain
//------------------------------------------------------------------------------
static int exceptionThrowingMain(const int argc, char *const *const argv) {
static void exceptionThrowingMain(const int argc, char *const *const argv) {
using namespace castor;
const int sizeOfIOThreadPoolForZMQ = 1;
......@@ -88,7 +89,7 @@ static int exceptionThrowingMain(const int argc, char *const *const argv) {
sizeOfIOThreadPoolForZMQ));
messages::AcsProxyZmq acs(acs::ACS_PORT, zmqContext.get());
mediachanger::MmcProxyDummy mmc;
mediachanger::MmcProxyNotSupported mmc;
common::CastorConfiguration &castorConf =
common::CastorConfiguration::getConfig();
......@@ -106,7 +107,7 @@ static int exceptionThrowingMain(const int argc, char *const *const argv) {
mediachanger::MountCmd cmd(std::cin, std::cout, std::cerr, mc);
return cmd.main(argc, argv);
cmd.exceptionThrowingMain(argc, argv);
}
//------------------------------------------------------------------------------
......
......@@ -19,12 +19,10 @@ castor-tape-mediachanger-mount \- mount a volume
.SH DESCRIPTION
\fBcastor-tape-mediachanger-mount\fP mounts the volume with the specfied
\fBVID\fP into the drive located in the specified \fBDRIVE_SLOT\fP within the
tape library. \fBDRIVE_SLOT\fP must be in one of the following three forms:
tape library. \fBDRIVE_SLOT\fP must be in one of the following two forms:
.IP
.B acsACS_NUMBER,LSM_NUMBER,PANEL_NUMBER,TRANSPORT_NUMBER
.IP
.B manual
.IP
.B smc@rmc_host,drive_ordinal
.SH OPTIONS
......
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