diff --git a/mediachanger/AcsProxyZmq.cpp b/mediachanger/AcsProxyZmq.cpp index 9a56fc49bd0d8bdfda4bf752738c3f5331eee8e5..20748dd70ebdf3b0fa17cb9b0466584bce57ef62 100644 --- a/mediachanger/AcsProxyZmq.cpp +++ b/mediachanger/AcsProxyZmq.cpp @@ -18,6 +18,7 @@ #include "mediachanger/AcsDismountTape.pb.h" #include "mediachanger/AcsForceDismountTape.pb.h" +#include "mediachanger/AcsLibrarySlot.hpp" #include "mediachanger/AcsMountTapeReadOnly.pb.h" #include "mediachanger/AcsMountTapeReadWrite.pb.h" #include "mediachanger/AcsProxyZmq.hpp" @@ -176,12 +177,11 @@ AcsProxyZmq::AcsProxyZmq(void *const zmqContext, const unsigned short serverPort //------------------------------------------------------------------------------ // mountTapeReadOnly //------------------------------------------------------------------------------ -void AcsProxyZmq::mountTapeReadOnly(const std::string &vid, - const AcsLibrarySlot &librarySlot) { +void AcsProxyZmq::mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) { std::lock_guard<std::mutex> lock(m_mutex); try { - const Frame rqst = createAcsMountTapeReadOnlyFrame(vid, librarySlot); + const Frame rqst = createAcsMountTapeReadOnlyFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot)); sendFrame(m_serverSocket, rqst); MediaChangerReturnValue reply; @@ -205,12 +205,11 @@ void AcsProxyZmq::mountTapeReadOnly(const std::string &vid, //------------------------------------------------------------------------------ // mountTapeReadWrite //------------------------------------------------------------------------------ -void AcsProxyZmq::mountTapeReadWrite(const std::string &vid, - const AcsLibrarySlot &librarySlot) { +void AcsProxyZmq::mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) { std::lock_guard<std::mutex> lock(m_mutex); try { - const Frame rqst = createAcsMountTapeReadWriteFrame(vid, librarySlot); + const Frame rqst = createAcsMountTapeReadWriteFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot)); sendFrame(m_serverSocket, rqst); MediaChangerReturnValue reply; @@ -234,12 +233,11 @@ void AcsProxyZmq::mountTapeReadWrite(const std::string &vid, //------------------------------------------------------------------------------ // dismountTape //------------------------------------------------------------------------------ -void AcsProxyZmq::dismountTape(const std::string &vid, - const AcsLibrarySlot &librarySlot) { +void AcsProxyZmq::dismountTape(const std::string &vid, const LibrarySlot &librarySlot) { std::lock_guard<std::mutex> lock(m_mutex); try { - const Frame rqst = createAcsDismountTapeFrame(vid, librarySlot); + const Frame rqst = createAcsDismountTapeFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot)); sendFrame(m_serverSocket, rqst); MediaChangerReturnValue reply; @@ -263,12 +261,11 @@ void AcsProxyZmq::dismountTape(const std::string &vid, //------------------------------------------------------------------------------ // forceDismountTape //------------------------------------------------------------------------------ -void AcsProxyZmq::forceDismountTape(const std::string &vid, - const AcsLibrarySlot &librarySlot) { +void AcsProxyZmq::forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) { std::lock_guard<std::mutex> lock(m_mutex); try { - const Frame rqst = createAcsForceDismountTapeFrame(vid, librarySlot); + const Frame rqst = createAcsForceDismountTapeFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot)); sendFrame(m_serverSocket, rqst); MediaChangerReturnValue reply; diff --git a/mediachanger/AcsProxyZmq.hpp b/mediachanger/AcsProxyZmq.hpp index 652da4f8130e51a29dd408e1bcf00174a9448c7c..8b8ff4d4539f7226d3d6565b1b2e66c66c6d7ba8 100644 --- a/mediachanger/AcsProxyZmq.hpp +++ b/mediachanger/AcsProxyZmq.hpp @@ -18,8 +18,8 @@ #pragma once -#include "mediachanger/AcsProxy.hpp" #include "mediachanger/Constants.hpp" +#include "mediachanger/MediaChangerProxy.hpp" #include "mediachanger/ZmqSocketMT.hpp" #include <mutex> @@ -30,7 +30,7 @@ namespace mediachanger { /** * Concrete class providing a ZMQ implementation of an AcsProxy. */ -class AcsProxyZmq: public AcsProxy { +class AcsProxyZmq: public MediaChangerProxy { public: /** @@ -49,7 +49,7 @@ public: * @param vid The volume identifier of the tape to be mounted. * @param librarySlot The slot in the library that contains the tape drive. */ - void mountTapeReadOnly(const std::string &vid, const AcsLibrarySlot &librarySlot); + void mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Request the CASTOR ACS daemon to mount the specifed tape for read/write @@ -58,7 +58,7 @@ public: * @param vid The volume identifier of the tape to be mounted. * @param librarySlot The slot in the library that contains the tape drive. */ - void mountTapeReadWrite(const std::string &vid, const AcsLibrarySlot &librarySlot); + void mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Request the CASTOR ACS daemon to dismount the specifed tape from the tape @@ -67,7 +67,7 @@ public: * @param vid The volume identifier of the tape to be mounted. * @param librarySlot The slot in the library that contains the tape drive. */ - void dismountTape(const std::string &vid, const AcsLibrarySlot &librarySlot); + void dismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Request the CASTOR ACS daemon to forcefully dismount the specifed tape @@ -77,7 +77,7 @@ public: * @param vid The volume identifier of the tape to be mounted. * @param librarySlot The slot in the library that contains the tape drive. */ - void forceDismountTape(const std::string &vid, const AcsLibrarySlot &librarySlot); + void forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; private: diff --git a/mediachanger/CMakeLists.txt b/mediachanger/CMakeLists.txt index 9a2661f5b7b374c908a9957aa3683ea7c1005d3b..72358c7e49018bbcecb5446295253dee7c2cc561 100644 --- a/mediachanger/CMakeLists.txt +++ b/mediachanger/CMakeLists.txt @@ -24,7 +24,6 @@ PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles}) set (MEDIACHANGER_LIB_SRC_FILES AcsLibrarySlot.cpp - AcsProxy.cpp AcsProxyZmq.cpp CmdLine.cpp CmdLineTool.cpp @@ -37,16 +36,15 @@ set (MEDIACHANGER_LIB_SRC_FILES LibrarySlotParser.cpp ManualLibrarySlot.cpp MediaChangerFacade.cpp + MediaChangerProxy.cpp MessageHeader.cpp messages.cpp - MmcProxy.cpp MmcProxyLog.cpp MmcProxyNotSupported.cpp ${ProtoSources} RmcMarshal.cpp RmcMarshal.hpp RmcMountMsgBody.cpp - RmcProxy.cpp RmcProxyTcpIp.cpp RmcUnmountMsgBody.cpp ScsiLibrarySlot.cpp diff --git a/mediachanger/MediaChangerFacade.cpp b/mediachanger/MediaChangerFacade.cpp index 7398e60cc7ee15144bbbdd0927c526537ea80ed0..d39e7f2ed5fdd6089a450be20408af9d699efef4 100644 --- a/mediachanger/MediaChangerFacade.cpp +++ b/mediachanger/MediaChangerFacade.cpp @@ -16,13 +16,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "common/exception/Exception.hpp" +#include "common/make_unique.hpp" #include "mediachanger/AcsProxyZmq.hpp" #include "mediachanger/Constants.hpp" #include "mediachanger/MediaChangerFacade.hpp" #include "mediachanger/MmcProxyLog.hpp" #include "mediachanger/RmcProxyTcpIp.hpp" #include "mediachanger/ZmqContextSingleton.hpp" -#include "common/exception/Exception.hpp" namespace cta { namespace mediachanger { @@ -40,39 +41,10 @@ MediaChangerFacade::MediaChangerFacade(log::Logger &log, void *const zmqContext) //------------------------------------------------------------------------------ void MediaChangerFacade::mountTapeReadOnly(const std::string &vid, const LibrarySlot &slot) { try { - const TapeLibraryType libraryType = slot.getLibraryType(); - - // Dispatch the appropriate helper method depending on library slot type - switch(libraryType) { - case TAPE_LIBRARY_TYPE_ACS: - { - AcsProxyZmq acs(m_zmqContext); - return acs.mountTapeReadOnly(vid, dynamic_cast<const AcsLibrarySlot&>(slot)); - } - case TAPE_LIBRARY_TYPE_MANUAL: - { - MmcProxyLog mmc(m_log); - return mmc.mountTapeReadOnly(vid, dynamic_cast<const ManualLibrarySlot&>(slot)); - } - case TAPE_LIBRARY_TYPE_SCSI: - { - RmcProxyTcpIp rmc; - - // SCSI media-changers to not support read-only mounts - return rmc.mountTapeReadWrite(vid, dynamic_cast<const ScsiLibrarySlot&>(slot)); - } - default: - { - // Should never get here - cta::exception::Exception ex; - ex.getMessage() << "Library slot has an unexpected library type"; - throw ex; - } - } + return createMediaChangerProxy(slot.getLibraryType())->mountTapeReadOnly(vid, slot); } catch(cta::exception::Exception &ne) { cta::exception::Exception ex; - ex.getMessage() << "Failed to mount tape for read-only access" - ": vid=" << vid << " slot=" << slot.str() << ": " << + ex.getMessage() << "Failed to mount tape for read-only access: vid=" << vid << " slot=" << slot.str() << ": " << ne.getMessage().str(); throw ex; } @@ -83,37 +55,10 @@ void MediaChangerFacade::mountTapeReadOnly(const std::string &vid, const Library //------------------------------------------------------------------------------ void MediaChangerFacade::mountTapeReadWrite(const std::string &vid, const LibrarySlot &slot) { try { - const TapeLibraryType libraryType = slot.getLibraryType(); - - // Dispatch the appropriate helper method depending on library slot type - switch(libraryType) { - case TAPE_LIBRARY_TYPE_ACS: - { - AcsProxyZmq acs(m_zmqContext); - return acs.mountTapeReadWrite(vid, dynamic_cast<const AcsLibrarySlot&>(slot)); - } - case TAPE_LIBRARY_TYPE_MANUAL: - { - MmcProxyLog mmc(m_log); - return mmc.mountTapeReadWrite(vid, dynamic_cast<const ManualLibrarySlot&>(slot)); - } - case TAPE_LIBRARY_TYPE_SCSI: - { - RmcProxyTcpIp rmc; - return rmc.mountTapeReadWrite(vid, dynamic_cast<const ScsiLibrarySlot&>(slot)); - } - default: - { - // Should never get here - cta::exception::Exception ex; - ex.getMessage() << "Library slot has an unexpected library type"; - throw ex; - } - } + return createMediaChangerProxy(slot.getLibraryType())->mountTapeReadWrite(vid, slot); } catch(cta::exception::Exception &ne) { cta::exception::Exception ex; - ex.getMessage() << "Failed to mount tape for read/write access" - ": vid=" << vid << " slot=" << slot.str() << ": " << + ex.getMessage() << "Failed to mount tape for read/write access: vid=" << vid << " slot=" << slot.str() << ": " << ne.getMessage().str(); throw ex; } @@ -124,37 +69,10 @@ void MediaChangerFacade::mountTapeReadWrite(const std::string &vid, const Librar //------------------------------------------------------------------------------ void MediaChangerFacade::dismountTape(const std::string &vid, const LibrarySlot &slot) { try { - const TapeLibraryType libraryType = slot.getLibraryType(); - - // Dispatch the appropriate helper method depending on library slot type - switch(libraryType) { - case TAPE_LIBRARY_TYPE_ACS: - { - AcsProxyZmq acs(m_zmqContext); - return acs.dismountTape(vid, dynamic_cast<const AcsLibrarySlot&>(slot)); - } - case TAPE_LIBRARY_TYPE_MANUAL: - { - MmcProxyLog mmc(m_log); - return mmc.dismountTape(vid, dynamic_cast<const ManualLibrarySlot&>(slot)); - } - case TAPE_LIBRARY_TYPE_SCSI: - { - RmcProxyTcpIp rmc; - return rmc.dismountTape(vid, dynamic_cast<const ScsiLibrarySlot&>(slot)); - } - default: - { - // Should never get here - cta::exception::Exception ex; - ex.getMessage() << "Library slot has an unexpected library type"; - throw ex; - } - } + return createMediaChangerProxy(slot.getLibraryType())->dismountTape(vid, slot); } catch(cta::exception::Exception &ne) { cta::exception::Exception ex; - ex.getMessage() << "Failed to dismount tape" - ": vid=" << vid << " slot=" << slot.str() << ": " << + ex.getMessage() << "Failed to dismount tape: vid=" << vid << " slot=" << slot.str() << ": " << ne.getMessage().str(); throw ex; } @@ -165,39 +83,33 @@ void MediaChangerFacade::dismountTape(const std::string &vid, const LibrarySlot //------------------------------------------------------------------------------ void MediaChangerFacade::forceDismountTape(const std::string &vid, const LibrarySlot &slot) { try { - const TapeLibraryType libraryType = slot.getLibraryType(); + return createMediaChangerProxy(slot.getLibraryType())->forceDismountTape(vid, slot); + } catch(cta::exception::Exception &ne) { + cta::exception::Exception ex; + ex.getMessage() << "Failed to force dismount tape: vid=" << vid << " slot=" << slot.str() << ": " << + ne.getMessage().str(); + throw ex; + } +} - // Dispatch the appropriate helper method depending on library slot type +//------------------------------------------------------------------------------ +// createMediaChangerProxy +//------------------------------------------------------------------------------ +std::unique_ptr<MediaChangerProxy> MediaChangerFacade::createMediaChangerProxy(const TapeLibraryType libraryType) { + try { switch(libraryType) { case TAPE_LIBRARY_TYPE_ACS: - { - AcsProxyZmq acs(m_zmqContext); - return acs.forceDismountTape(vid, dynamic_cast<const AcsLibrarySlot&>(slot)); - } + return make_unique<AcsProxyZmq>(m_zmqContext); case TAPE_LIBRARY_TYPE_MANUAL: - { - MmcProxyLog mmc(m_log); - return mmc.forceDismountTape(vid, dynamic_cast<const ManualLibrarySlot&>(slot)); - } + return make_unique<MmcProxyLog>(m_log); case TAPE_LIBRARY_TYPE_SCSI: - { - RmcProxyTcpIp rmc; - return rmc.forceDismountTape(vid, dynamic_cast<const ScsiLibrarySlot&>(slot)); - } + return make_unique<RmcProxyTcpIp>(); default: - { - // Should never get here - cta::exception::Exception ex; - ex.getMessage() << "Library slot has an unexpected library type"; - throw ex; - } + // Should never get here + throw exception::Exception("Library slot has an unexpected library type"); } - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to force dismount tape" - ": vid=" << vid << " slot=" << slot.str() << ": " << - ne.getMessage().str(); - throw ex; + } catch(cta::exception::Exception &ex) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } } diff --git a/mediachanger/MediaChangerFacade.hpp b/mediachanger/MediaChangerFacade.hpp index 7fdab7f331e04171388e04f7b540d0c1ba063f59..372bc76fed676c6f03fe4e93ab9d2c54b53699b0 100644 --- a/mediachanger/MediaChangerFacade.hpp +++ b/mediachanger/MediaChangerFacade.hpp @@ -20,8 +20,10 @@ #include "common/log/Logger.hpp" #include "mediachanger/LibrarySlot.hpp" +#include "mediachanger/MediaChangerProxy.hpp" #include "mediachanger/ZmqContextSingleton.hpp" +#include <memory> #include <string> namespace cta { @@ -98,6 +100,14 @@ private: */ void *m_zmqContext; + /** + * Factory method that creates a media changer proxy object based on the + * specified tape library type. + * + * @param libraryType The type of tape library. + */ + std::unique_ptr<MediaChangerProxy> createMediaChangerProxy(const TapeLibraryType libraryType); + }; // class MediaChangerFacade } // namespace mediachanger diff --git a/mediachanger/AcsProxy.cpp b/mediachanger/MediaChangerProxy.cpp similarity index 89% rename from mediachanger/AcsProxy.cpp rename to mediachanger/MediaChangerProxy.cpp index af9265d2ccd5a96b2716e8575e209f0c9cd5543a..d3105be15ed789ac1d4a216324f7d14814431390 100644 --- a/mediachanger/AcsProxy.cpp +++ b/mediachanger/MediaChangerProxy.cpp @@ -16,10 +16,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "mediachanger/AcsProxy.hpp" +#include "mediachanger/MediaChangerProxy.hpp" //----------------------------------------------------------------------------- // destructor //----------------------------------------------------------------------------- -cta::mediachanger::AcsProxy::~AcsProxy() { +cta::mediachanger::MediaChangerProxy::~MediaChangerProxy() { } diff --git a/mediachanger/AcsProxy.hpp b/mediachanger/MediaChangerProxy.hpp similarity index 72% rename from mediachanger/AcsProxy.hpp rename to mediachanger/MediaChangerProxy.hpp index e25cf9ef973ae3714ee7d323f4e71d96fa3d8d56..31e60acc128ca3ad1f97a86e89fe3c14827bf173 100644 --- a/mediachanger/AcsProxy.hpp +++ b/mediachanger/MediaChangerProxy.hpp @@ -18,7 +18,7 @@ #pragma once -#include "mediachanger/AcsLibrarySlot.hpp" +#include "mediachanger/LibrarySlot.hpp" #include <stdint.h> #include <string> @@ -27,19 +27,19 @@ namespace cta { namespace mediachanger { /** - * Abstract class defining the interface to a proxy object representing the - * CASTOR ACS daemon. + * Abstract class defining the interface to a proxy object representing a + * media changer daemon. */ -class AcsProxy { +class MediaChangerProxy { public: /** * Destructor. */ - virtual ~AcsProxy() = 0; + virtual ~MediaChangerProxy() = 0; /** - * Request the CASTOR ACS daemon to mount the specified tape for read-only + * Request the media changer daemon to mount the specified tape for read-only * access into the tape drive in the specified library slot. * * Please note that this method provides a best-effort service because not all @@ -48,28 +48,28 @@ public: * @param vid The volume identifier of the tape to be mounted. * @param librarySlot The slot in the library that contains the tape drive. */ - virtual void mountTapeReadOnly(const std::string &vid, const AcsLibrarySlot &librarySlot) = 0; + virtual void mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) = 0; /** - * Request the CASTOR ACS daemon to mount the specifed tape for read/write + * Request the media changer daemon to mount the specifed tape for read/write * access into the tape drive in the specified library slot. * * @param vid The volume identifier of the tape to be mounted. * @param librarySlot The slot in the library that contains the tape drive. */ - virtual void mountTapeReadWrite(const std::string &vid, const AcsLibrarySlot &librarySlot) = 0; + virtual void mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) = 0; /** - * Request the CASTOR ACS daemon to dismount the specifed tape from the tape - * drive in the specified library slot. + * Request the media changer daemon to dismount the specifed tape from the + * tape drive in the specified library slot. * * @param vid The volume identifier of the tape to be mounted. * @param librarySlot The slot in the library that contains the tape drive. */ - virtual void dismountTape(const std::string &vid, const AcsLibrarySlot &librarySlot) = 0; + virtual void dismountTape(const std::string &vid, const LibrarySlot &librarySlot) = 0; /** - * Request the CASTOR ACS daemon to forcefully dismount the specifed tape + * Request the media changer daemon to forcefully dismount the specifed tape * from the tape drive in the specified library slot. Forcefully means * rewinding and ejecting the tape if necessary. * @@ -79,9 +79,9 @@ public: * @param vid The volume identifier of the tape to be mounted. * @param librarySlot The slot in the library that contains the tape drive. */ - virtual void forceDismountTape(const std::string &vid, const AcsLibrarySlot &librarySlot) = 0; + virtual void forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) = 0; -}; // class AcsProxy +}; // class MediaChangerProxy } // namespace mediachanger } // namespace cta diff --git a/mediachanger/MmcProxy.cpp b/mediachanger/MmcProxy.cpp deleted file mode 100644 index 0c6ec758dcb47a9e2f54d2e166fb88ca3dcc8b73..0000000000000000000000000000000000000000 --- a/mediachanger/MmcProxy.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * The CERN Tape Archive(CTA) project - * Copyright(C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -#include "mediachanger/MmcProxy.hpp" - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::MmcProxy::~MmcProxy() throw() { -} diff --git a/mediachanger/MmcProxy.hpp b/mediachanger/MmcProxy.hpp deleted file mode 100644 index 39ed02c43c15dc1a303cad3c1c5edac1d8fdc57d..0000000000000000000000000000000000000000 --- a/mediachanger/MmcProxy.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The CERN Tape Archive(CTA) project - * Copyright(C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include "mediachanger/ManualLibrarySlot.hpp" - -#include <string> - -namespace cta { -namespace mediachanger { - -/** - * Asbtract class defining the interface to manually operated media-changer. - */ -class MmcProxy { -public: - - /** - * Destructor. - */ - virtual ~MmcProxy() throw() = 0; - - /** - * Requests the media changer to mount of the specified tape for read-only - * access into the drive in the specified library slot. - * - * Please note that this method provides a best-effort service because not all - * media changers support read-only mounts. - * - * @param vid The volume identifier of the tape. - * @param librarySlot The library slot containing the tape drive. - */ - virtual void mountTapeReadOnly(const std::string &vid, - const cta::mediachanger::ManualLibrarySlot &librarySlot) = 0; - - /** - * 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. - */ - virtual void mountTapeReadWrite(const std::string &vid, - const cta::mediachanger::ManualLibrarySlot &librarySlot) = 0; - - /** - * 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. - */ - virtual void dismountTape(const std::string &vid, - const cta::mediachanger::ManualLibrarySlot &librarySlot) = 0; - - /** - * Requests the media changer to forcefully dismount the specified tape from - * the drive in the specifed library slot. Forcefully means rewinding and - * ejecting the tape where necessary. - * - * Please note that this method provides a best-effort service because not all - * media changers support forceful dismounts. - * - * @param vid The volume identifier of the tape. - * @param librarySlot The library slot containing the tape drive. - */ - virtual void forceDismountTape(const std::string &vid, - const cta::mediachanger::ManualLibrarySlot &librarySlot) = 0; - -}; // class MmcProxy - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/MmcProxyLog.cpp b/mediachanger/MmcProxyLog.cpp index 1ce3c69fdfc75908d6299a28fafc44c5193cf22b..4af646656efca36fad087321eee858e0b5c45f38 100644 --- a/mediachanger/MmcProxyLog.cpp +++ b/mediachanger/MmcProxyLog.cpp @@ -16,6 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "mediachanger/ManualLibrarySlot.hpp" #include "mediachanger/MmcProxyLog.hpp" //------------------------------------------------------------------------------ @@ -28,8 +29,7 @@ cta::mediachanger::MmcProxyLog::MmcProxyLog(log::Logger &log) throw(): //------------------------------------------------------------------------------ // mountTapeReadOnly //------------------------------------------------------------------------------ -void cta::mediachanger::MmcProxyLog::mountTapeReadOnly( - const std::string &vid, const ManualLibrarySlot &librarySlot) { +void cta::mediachanger::MmcProxyLog::mountTapeReadOnly( const std::string &vid, const LibrarySlot &librarySlot) { std::list<log::Param> params = { log::Param("TPVID", vid), log::Param("librarySlot", librarySlot.str())}; @@ -40,8 +40,7 @@ void cta::mediachanger::MmcProxyLog::mountTapeReadOnly( //------------------------------------------------------------------------------ // mountTapeReadWrite //------------------------------------------------------------------------------ -void cta::mediachanger::MmcProxyLog::mountTapeReadWrite( - const std::string &vid, const ManualLibrarySlot &librarySlot) { +void cta::mediachanger::MmcProxyLog::mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) { std::list<log::Param> params = { log::Param("TPVID", vid), log::Param("librarySlot", librarySlot.str())}; @@ -52,8 +51,7 @@ void cta::mediachanger::MmcProxyLog::mountTapeReadWrite( //------------------------------------------------------------------------------ // dismountTape //------------------------------------------------------------------------------ -void cta::mediachanger::MmcProxyLog::dismountTape( - const std::string &vid, const ManualLibrarySlot &librarySlot) { +void cta::mediachanger::MmcProxyLog::dismountTape( const std::string &vid, const LibrarySlot &librarySlot) { std::list<log::Param> params = { log::Param("TPVID", vid), log::Param("librarySlot", librarySlot.str())}; @@ -63,8 +61,7 @@ void cta::mediachanger::MmcProxyLog::dismountTape( //------------------------------------------------------------------------------ // forceDismountTape //------------------------------------------------------------------------------ -void cta::mediachanger::MmcProxyLog::forceDismountTape( - const std::string &vid, const ManualLibrarySlot &librarySlot) { +void cta::mediachanger::MmcProxyLog::forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) { std::list<log::Param> params = { log::Param("TPVID", vid), log::Param("librarySlot", librarySlot.str())}; diff --git a/mediachanger/MmcProxyLog.hpp b/mediachanger/MmcProxyLog.hpp index 83d044fdc761185dccd56bb4eaa184a5d0275e15..bf398756da9aad251487725d8f5dc55b19732c4b 100644 --- a/mediachanger/MmcProxyLog.hpp +++ b/mediachanger/MmcProxyLog.hpp @@ -19,7 +19,7 @@ #pragma once #include "common/log/Logger.hpp" -#include "mediachanger/MmcProxy.hpp" +#include "mediachanger/MediaChangerProxy.hpp" namespace cta { namespace mediachanger { @@ -28,7 +28,7 @@ namespace mediachanger { * Concrete class implementing a MmcProxy that simply logs mount and dismount * requests. */ -class MmcProxyLog: public MmcProxy { +class MmcProxyLog: public MediaChangerProxy { public: /** @@ -48,7 +48,7 @@ public: * @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); + void mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to mount the specified tape for read/write @@ -57,7 +57,7 @@ public: * @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); + void mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to dismount the specified tape from the @@ -66,7 +66,7 @@ public: * @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); + void dismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to forcefully dismount the specified tape from @@ -79,7 +79,7 @@ public: * @param vid The volume identifier of the tape. * @param librarySlot The library slot containing the tape drive. */ - void forceDismountTape(const std::string &vid, const ManualLibrarySlot &librarySlot); + void forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; private: diff --git a/mediachanger/MmcProxyNotSupported.cpp b/mediachanger/MmcProxyNotSupported.cpp index 5f6a44a627f5e1466ce6198efabf727e4e56a964..b1cb6396d211b65c61d72173b294e390f65650e6 100644 --- a/mediachanger/MmcProxyNotSupported.cpp +++ b/mediachanger/MmcProxyNotSupported.cpp @@ -16,14 +16,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "mediachanger/ManualLibrarySlot.hpp" #include "mediachanger/MmcProxyNotSupported.hpp" #include "common/exception/Exception.hpp" //------------------------------------------------------------------------------ // mountTapeReadOnly //------------------------------------------------------------------------------ -void cta::mediachanger::MmcProxyNotSupported::mountTapeReadOnly( - const std::string &vid, const ManualLibrarySlot &librarySlot) { +void cta::mediachanger::MmcProxyNotSupported::mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) { cta::exception::Exception ex; ex.getMessage() << "Manual mounting is not supported"; throw ex; @@ -32,8 +32,7 @@ void cta::mediachanger::MmcProxyNotSupported::mountTapeReadOnly( //------------------------------------------------------------------------------ // mountTapeReadWrite //------------------------------------------------------------------------------ -void cta::mediachanger::MmcProxyNotSupported::mountTapeReadWrite( - const std::string &vid, const ManualLibrarySlot &librarySlot) { +void cta::mediachanger::MmcProxyNotSupported::mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) { cta::exception::Exception ex; ex.getMessage() << "Manual mounting is not supported"; throw ex; @@ -42,8 +41,7 @@ void cta::mediachanger::MmcProxyNotSupported::mountTapeReadWrite( //------------------------------------------------------------------------------ // dismountTape //------------------------------------------------------------------------------ -void cta::mediachanger::MmcProxyNotSupported::dismountTape( - const std::string &vid, const ManualLibrarySlot &librarySlot) { +void cta::mediachanger::MmcProxyNotSupported::dismountTape(const std::string &vid, const LibrarySlot &librarySlot) { cta::exception::Exception ex; ex.getMessage() << "Manual dismounting is not supported"; throw ex; @@ -52,8 +50,7 @@ void cta::mediachanger::MmcProxyNotSupported::dismountTape( //------------------------------------------------------------------------------ // forceDismountTape //------------------------------------------------------------------------------ -void cta::mediachanger::MmcProxyNotSupported::forceDismountTape( - const std::string &vid, const ManualLibrarySlot &librarySlot) { +void cta::mediachanger::MmcProxyNotSupported::forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) { cta::exception::Exception ex; ex.getMessage() << "Manual dismounting is not supported"; throw ex; diff --git a/mediachanger/MmcProxyNotSupported.hpp b/mediachanger/MmcProxyNotSupported.hpp index 1cfb660d0004d24b83ea223b1877ce28ea93471d..5942eba13f22bcc17d0e1d92155bf9fdeabeb2b5 100644 --- a/mediachanger/MmcProxyNotSupported.hpp +++ b/mediachanger/MmcProxyNotSupported.hpp @@ -18,7 +18,7 @@ #pragma once -#include "mediachanger/MmcProxy.hpp" +#include "mediachanger/MediaChangerProxy.hpp" namespace cta { namespace mediachanger { @@ -27,7 +27,7 @@ namespace mediachanger { * Concrete class implementing a manual media-changer that throws * "not supported" exceptions. */ -class MmcProxyNotSupported: public MmcProxy { +class MmcProxyNotSupported: public MediaChangerProxy { public: /** @@ -40,8 +40,7 @@ public: * @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); + void mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to mount the specified tape for read/write @@ -50,8 +49,7 @@ public: * @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); + void mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to dismount the specified tape from the @@ -60,8 +58,7 @@ public: * @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); + void dismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to forcefully dismount the specified tape from @@ -74,8 +71,7 @@ public: * @param vid The volume identifier of the tape. * @param librarySlot The library slot containing the tape drive. */ - void forceDismountTape(const std::string &vid, - const ManualLibrarySlot &librarySlot); + void forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; }; // class MmcProxyNotSupported diff --git a/mediachanger/RmcProxy.cpp b/mediachanger/RmcProxy.cpp deleted file mode 100644 index 68f53157a84c980eb87c233147468f6bcf06a156..0000000000000000000000000000000000000000 --- a/mediachanger/RmcProxy.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * The CERN Tape Archive(CTA) project - * Copyright(C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -#include "mediachanger/RmcProxy.hpp" - -namespace cta { -namespace mediachanger { - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -RmcProxy::~RmcProxy() throw() { -} - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/RmcProxy.hpp b/mediachanger/RmcProxy.hpp deleted file mode 100644 index 4e6df6c2ff22825db383de0d5cd0ff98f7f50b2d..0000000000000000000000000000000000000000 --- a/mediachanger/RmcProxy.hpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The CERN Tape Archive(CTA) project - * Copyright(C) 2015 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 3 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, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include "mediachanger/ScsiLibrarySlot.hpp" -#include "common/exception/Exception.hpp" - -#include <string> - -namespace cta { -namespace mediachanger { - -/** - * Abstract class defining the interface to a proxy object representing the - * SCSI media-changer daemon (rmcd). - */ -class RmcProxy { -public: - - /** - * Destructor. - */ - virtual ~RmcProxy() throw() = 0; - - /** - * Requests the media changer to mount the specified tape for read-only - * access into the drive in the specified library slot. - * - * Please note that this method provides a best-effort service because not all - * media changers support read-only mounts. - * - * @param vid The volume identifier of the tape. - * @param librarySlot The library slot containing the tape drive. - */ - virtual void mountTapeReadOnly(const std::string &vid, - const ScsiLibrarySlot &librarySlot) = 0; - - /** - * 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. - */ - virtual void mountTapeReadWrite(const std::string &vid, - const ScsiLibrarySlot &librarySlot) = 0; - - /** - * 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. - */ - virtual void dismountTape(const std::string &vid, - const ScsiLibrarySlot &librarySlot) = 0; - - /** - * Requests the media changer to forcefully dismount the specified tape from - * the drive in the specifed library slot. Forcefully means rewinding and - * ejecting the tape where necessary. - * - * Please note that this method provides a best-effort service because not all - * media changers support forceful dismounts. - * - * @param vid The volume identifier of the tape. - * @param librarySlot The library slot containing the tape drive. - */ - virtual void forceDismountTape(const std::string &vid, - const ScsiLibrarySlot &librarySlot) = 0; - -}; // class RmcProxy - -} // namespace mediachanger -} // namespace cta - diff --git a/mediachanger/RmcProxyTcpIp.cpp b/mediachanger/RmcProxyTcpIp.cpp index cee5b7e17ab1a07434a077c917b542b23bec8741..491590a0955842e1c40de9ace942f334848cdd26 100644 --- a/mediachanger/RmcProxyTcpIp.cpp +++ b/mediachanger/RmcProxyTcpIp.cpp @@ -22,6 +22,7 @@ #include "mediachanger/io.hpp" #include "mediachanger/RmcMarshal.hpp" #include "mediachanger/RmcProxyTcpIp.hpp" +#include "mediachanger/ScsiLibrarySlot.hpp" namespace cta { namespace mediachanger { @@ -47,8 +48,7 @@ RmcProxyTcpIp::~RmcProxyTcpIp() throw() { //------------------------------------------------------------------------------ // mountTapeReadOnly //------------------------------------------------------------------------------ -void RmcProxyTcpIp::mountTapeReadOnly( - const std::string &vid, const mediachanger::ScsiLibrarySlot &librarySlot) { +void RmcProxyTcpIp::mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) { // SCSI libraries do not support read-only mounts mountTapeReadWrite(vid, librarySlot); } @@ -56,14 +56,14 @@ void RmcProxyTcpIp::mountTapeReadOnly( //------------------------------------------------------------------------------ // mountTapeReadWrite //------------------------------------------------------------------------------ -void RmcProxyTcpIp::mountTapeReadWrite( - const std::string &vid, const mediachanger::ScsiLibrarySlot &librarySlot) { +void RmcProxyTcpIp::mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) { try { RmcMountMsgBody rqstBody; rqstBody.uid = geteuid(); rqstBody.gid = getegid(); utils::copyString(rqstBody.vid, vid); - rqstBody.drvOrd = librarySlot.getDrvOrd(); + const ScsiLibrarySlot &scsiLibrarySlot = dynamic_cast<const ScsiLibrarySlot&>(librarySlot); + rqstBody.drvOrd = scsiLibrarySlot.getDrvOrd(); rmcSendRecvNbAttempts(m_maxRqstAttempts, rqstBody); } catch(cta::exception::Exception &ne) { @@ -79,14 +79,14 @@ void RmcProxyTcpIp::mountTapeReadWrite( //------------------------------------------------------------------------------ // dismountTape //------------------------------------------------------------------------------ -void RmcProxyTcpIp::dismountTape(const std::string &vid, - const mediachanger::ScsiLibrarySlot &librarySlot) { +void RmcProxyTcpIp::dismountTape(const std::string &vid, const LibrarySlot &librarySlot) { try { RmcUnmountMsgBody rqstBody; rqstBody.uid = geteuid(); rqstBody.gid = getegid(); utils::copyString(rqstBody.vid, vid); - rqstBody.drvOrd = librarySlot.getDrvOrd(); + const ScsiLibrarySlot &scsiLibrarySlot = dynamic_cast<const ScsiLibrarySlot&>(librarySlot); + rqstBody.drvOrd = scsiLibrarySlot.getDrvOrd(); rqstBody.force = 0; rmcSendRecvNbAttempts(m_maxRqstAttempts, rqstBody); @@ -103,8 +103,7 @@ void RmcProxyTcpIp::dismountTape(const std::string &vid, //------------------------------------------------------------------------------ // forceDismountTape //------------------------------------------------------------------------------ -void RmcProxyTcpIp::forceDismountTape(const std::string &vid, - const mediachanger::ScsiLibrarySlot &librarySlot) { +void RmcProxyTcpIp::forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) { // SCSI libraries do not support forced dismounts dismountTape(vid, librarySlot); } diff --git a/mediachanger/RmcProxyTcpIp.hpp b/mediachanger/RmcProxyTcpIp.hpp index befeb53bd2884c1dd01fd0e2afac60263a400e01..5bdbaefa13b7839a5e98371df16af96487d3c730 100644 --- a/mediachanger/RmcProxyTcpIp.hpp +++ b/mediachanger/RmcProxyTcpIp.hpp @@ -22,9 +22,9 @@ #include "common/utils/utils.hpp" #include "mediachanger/Constants.hpp" #include "mediachanger/io.hpp" +#include "mediachanger/MediaChangerProxy.hpp" #include "mediachanger/MessageHeader.hpp" #include "mediachanger/RmcMountMsgBody.hpp" -#include "mediachanger/RmcProxy.hpp" #include "mediachanger/RmcUnmountMsgBody.hpp" #include <unistd.h> @@ -55,7 +55,7 @@ namespace mediachanger { /** * A concrete implementation of the interface to the rmc daemon. */ -class RmcProxyTcpIp: public RmcProxy { +class RmcProxyTcpIp: public MediaChangerProxy { public: /** @@ -87,7 +87,7 @@ public: * @param vid The volume identifier of the tape. * @param librarySlot The library slot containing the tape drive. */ - void mountTapeReadOnly(const std::string &vid, const ScsiLibrarySlot &librarySlot); + void mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to mount of the specified tape for read/write @@ -96,7 +96,7 @@ public: * @param vid The volume identifier of the tape. * @param librarySlot The library slot containing the tape drive. */ - void mountTapeReadWrite(const std::string &vid, const ScsiLibrarySlot &librarySlot); + void mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to dismount of the specified tape from the @@ -105,7 +105,7 @@ public: * @param vid The volume identifier of the tape. * @param librarySlot The library slot containing the tape drive. */ - void dismountTape(const std::string &vid, const ScsiLibrarySlot &librarySlot); + void dismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; /** * Requests the media changer to forcefully dismount the specified tape from @@ -118,7 +118,7 @@ public: * @param vid The volume identifier of the tape. * @param librarySlot The library slot containing the tape drive. */ - void forceDismountTape(const std::string &vid, const ScsiLibrarySlot &librarySlot); + void forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; protected: