Commit 60b1fe88 authored by Steven Murray's avatar Steven Murray
Browse files

Added castor::mediachanger::MediaChangerProxy

parent 85f0440c
......@@ -27,6 +27,7 @@ add_subdirectory (legacymsg)
if (${COMPILE_SERVER} STREQUAL "1")
add_subdirectory (db)
add_subdirectory (gc)
add_subdirectory (mediachanger)
add_subdirectory (messages)
add_subdirectory (rh)
add_subdirectory (scheduler)
......
......@@ -83,6 +83,9 @@ set (CASTOR_LEGACYMSG_LIB_SRC_FILES
VmgrTapeMountedMsgBody.cpp)
add_library (castorlegacymsg SHARED ${CASTOR_LEGACYMSG_LIB_SRC_FILES})
CastorSetLibraryVersions (castorlegacymsg)
target_link_libraries (castorlegacymsg castorclient castorcommon)
target_link_libraries (castorlegacymsg
castorclient
castorcommon
castormediachangerclient)
install (TARGETS castorlegacymsg LIBRARY DESTINATION ${CASTOR_DEST_LIB_DIR}
NAMELINK_SKIP)
......@@ -22,7 +22,7 @@
#pragma once
#include "castor/exception/Exception.hpp"
#include "castor/tape/utils/TapeLibrarySlot.hpp"
#include "castor/mediachanger/MediaChangerProxy.hpp"
#include <string>
......@@ -32,54 +32,43 @@ namespace legacymsg {
/**
* Proxy class representing the remote media-changer daemon.
*/
class RmcProxy {
class RmcProxy: public mediachanger::MediaChangerProxy {
public:
/**
* Enumeration of the possible mount access-modes.
*/
enum MountMode {
MOUNT_MODE_READONLY,
MOUNT_MODE_READWRITE};
/**
* Returns the string representation of the specified mount access-mode.
* Destructor.
*/
const char *mountMode2Str(const MountMode m) throw() {
switch(m) {
case MOUNT_MODE_READONLY: return "read only";
case MOUNT_MODE_READWRITE: return "read/write";
default: return "unknown";
}
}
virtual ~RmcProxy() throw() = 0;
/**
* Destructor.
* 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.
*/
virtual ~RmcProxy() throw() = 0;
virtual void mountTapeReadOnly(const std::string &vid,
const mediachanger::TapeLibrarySlot &librarySlot) = 0;
/**
* Asks the remote media-changer daemon to mount the specified tape into the
* drive in the specified library slot.
* 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 tape library slot containing the tape drive.
* @param mode The access mode in which the specified tape should be mounted.
* Please note that the value of this parameter is honored in a best effort
* fashion. If the library and drive combination do not support specifying
* the access mode, then this parameter will be ignored.
* @param librarySlot The library slot containing the tape drive.
*/
virtual void mountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot, const MountMode mode) = 0;
virtual void mountTapeReadWrite(const std::string &vid,
const mediachanger::TapeLibrarySlot &librarySlot) = 0;
/**
* Asks the remote media-changer daemon to unmount the specified tape from the
* drive in the specified library slot.
* 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 tape library slot containing the tape drive.
* @param librarySlot The library slot containing the tape drive.
*/
virtual void unmountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot) = 0;
virtual void dismountTape(const std::string &vid,
const mediachanger::TapeLibrarySlot &librarySlot) = 0;
}; // class RmcProxy
......
......@@ -46,10 +46,19 @@ castor::legacymsg::RmcProxyTcpIp::~RmcProxyTcpIp() throw() {
}
//------------------------------------------------------------------------------
// mountTape
// mountTapeReadOnly
//------------------------------------------------------------------------------
void castor::legacymsg::RmcProxyTcpIp::mountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot, const MountMode mode) {
void castor::legacymsg::RmcProxyTcpIp::mountTapeReadOnly(
const std::string &vid, const mediachanger::TapeLibrarySlot &librarySlot) {
// SCSI does not support read-only mounts
mountTapeReadWrite(vid, librarySlot);
}
//------------------------------------------------------------------------------
// mountTapeReadWrite
//------------------------------------------------------------------------------
void castor::legacymsg::RmcProxyTcpIp::mountTapeReadWrite(
const std::string &vid, const mediachanger::TapeLibrarySlot &librarySlot) {
// Verify parameters
if(vid.empty()) {
castor::exception::Exception ex;
......@@ -66,13 +75,13 @@ void castor::legacymsg::RmcProxyTcpIp::mountTape(const std::string &vid,
// Dispatch the appropriate helper method depending on library slot type
switch(librarySlot.getLibraryType()) {
case tape::utils::TAPE_LIBRARY_TYPE_ACS:
case mediachanger::TAPE_LIBRARY_TYPE_ACS:
mountTapeAcs(vid, librarySlot.str());
break;
case tape::utils::TAPE_LIBRARY_TYPE_MANUAL:
case mediachanger::TAPE_LIBRARY_TYPE_MANUAL:
mountTapeManual(vid);
break;
case tape::utils::TAPE_LIBRARY_TYPE_SCSI:
case mediachanger::TAPE_LIBRARY_TYPE_SCSI:
mountTapeScsi(vid, librarySlot.str());
break;
default:
......@@ -160,10 +169,10 @@ void castor::legacymsg::RmcProxyTcpIp::mountTapeScsi(const std::string &vid,
}
//------------------------------------------------------------------------------
// unmountTape
// dismountTape
//------------------------------------------------------------------------------
void castor::legacymsg::RmcProxyTcpIp::unmountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot) {
void castor::legacymsg::RmcProxyTcpIp::dismountTape(const std::string &vid,
const mediachanger::TapeLibrarySlot &librarySlot) {
// Verify parameters
if(vid.empty()) {
castor::exception::Exception ex;
......@@ -179,13 +188,13 @@ void castor::legacymsg::RmcProxyTcpIp::unmountTape(const std::string &vid,
// Dispatch the appropriate helper method depending on library slot type
switch(librarySlot.getLibraryType()) {
case tape::utils::TAPE_LIBRARY_TYPE_ACS:
case mediachanger::TAPE_LIBRARY_TYPE_ACS:
unmountTapeAcs(vid, librarySlot.str());
break;
case tape::utils::TAPE_LIBRARY_TYPE_MANUAL:
case mediachanger::TAPE_LIBRARY_TYPE_MANUAL:
unmountTapeManual(vid);
break;
case tape::utils::TAPE_LIBRARY_TYPE_SCSI:
case mediachanger::TAPE_LIBRARY_TYPE_SCSI:
unmountTapeScsi(vid, librarySlot.str());
break;
default:
......
......@@ -56,28 +56,34 @@ public:
~RmcProxyTcpIp() throw();
/**
* Asks the remote media-changer daemon to mount the specified tape into the
* drive in the specified library slot.
* 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 tape library slot containing the tape drive.
* @param mode The access mode in which the specified tape should be mounted.
* Please note that the value of this parameter is honored in a best effort
* fashion. If the library and drive combination do not support specifying
* the access mode, then this parameter will be ignored.
* @param librarySlot The library slot containing the tape drive.
*/
void mountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot, const MountMode mode);
void mountTapeReadOnly(const std::string &vid,
const mediachanger::TapeLibrarySlot &librarySlot);
/**
* Asks the remote media-changer daemon to unmount the specified tape from the
* drive in the specified library slot.
* 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 mediachanger::TapeLibrarySlot &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 tape library slot containing the tape drive.
* @param librarySlot The library slot containing the tape drive.
*/
void unmountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot);
void dismountTape(const std::string &vid,
const mediachanger::TapeLibrarySlot &librarySlot);
protected:
......
#
# castor/tape/rmc/CMakeLists.txt
#
# 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
#
cmake_minimum_required (VERSION 2.6)
set (MEDIA_CHANGER_CLIENT_LIB_SRC_FILES
MediaChangerProxy.cpp
MediaChangerProxyDummy.cpp
TapeLibrarySlot.cpp
TapeLibraryType.cpp)
add_library(castormediachangerclient
${MEDIA_CHANGER_CLIENT_LIB_SRC_FILES})
......@@ -19,18 +19,10 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/RmcProxyDummy.hpp"
#include "castor/legacymsg/RmcProxyDummyFactory.hpp"
#include "castor/mediachanger/MediaChangerProxy.hpp"
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::legacymsg::RmcProxyDummyFactory::~RmcProxyDummyFactory() throw() {
}
//------------------------------------------------------------------------------
// create
//------------------------------------------------------------------------------
castor::legacymsg::RmcProxy *castor::legacymsg::RmcProxyDummyFactory::create() {
return new RmcProxyDummy();
castor::mediachanger::MediaChangerProxy::~MediaChangerProxy() {
}
......@@ -21,35 +21,56 @@
#pragma once
#include "castor/legacymsg/RmcProxyFactory.hpp"
#include "castor/mediachanger/TapeLibrarySlot.hpp"
#include <string>
namespace castor {
namespace legacymsg {
namespace mediachanger {
/**
* Concrete factory for creating objects of type RmcProxyDummy.
* Abstract class that defines the inteface to a media-changer proxy.
*/
class RmcProxyDummyFactory: public RmcProxyFactory {
class MediaChangerProxy {
public:
/**
* Destructor.
*/
~RmcProxyDummyFactory() throw();
virtual ~MediaChangerProxy() = 0;
/**
* 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.
*/
virtual void mountTapeReadOnly(const std::string &vid,
const TapeLibrarySlot &librarySlot) = 0;
/**
* Creates an object of type RmcProxyDummy on the heap and returns a pointer
* to it.
* Requests the media changer to mount of the specified tape for read/write
* access into the drive in the specified library slot.
*
* Please note that it is the responsibility of the caller to deallocate the
* proxy object from the heap.
* @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 TapeLibrarySlot &librarySlot) = 0;
/**
* Requests the media changer to mount of the specified tape for read/write
* access into the drive in the specified library slot.
*
* @return A pointer to the newly created object.
* @param vid The volume identifier of the tape.
* @param librarySlot The library slot containing the tape drive.
*/
RmcProxy *create();
virtual void dismountTape(const std::string &vid,
const TapeLibrarySlot &librarySlot) = 0;
}; // class RmcProxyDummyFactory
}; // class MediaChangerProxy
} // namespace legacymsg
} // namespace mediachanger
} // namespace castor
......@@ -19,24 +19,31 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/RmcProxyDummy.hpp"
#include "castor/mediachanger/MediaChangerProxyDummy.hpp"
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::legacymsg::RmcProxyDummy::~RmcProxyDummy() throw() {
castor::mediachanger::MediaChangerProxyDummy::~MediaChangerProxyDummy() {
}
//------------------------------------------------------------------------------
// mountTape
// mountTapeReadOnly
//------------------------------------------------------------------------------
void castor::legacymsg::RmcProxyDummy::mountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot, const MountMode mode) {
void castor::mediachanger::MediaChangerProxyDummy::mountTapeReadOnly(
const std::string &vid, const TapeLibrarySlot &librarySlot) {
}
//------------------------------------------------------------------------------
// unmountTape
// mountTapeReadWrite
//------------------------------------------------------------------------------
void castor::legacymsg::RmcProxyDummy::unmountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot) {
void castor::mediachanger::MediaChangerProxyDummy::mountTapeReadWrite(
const std::string &vid, const TapeLibrarySlot &librarySlot) {
}
//------------------------------------------------------------------------------
// dismountTape
//------------------------------------------------------------------------------
void castor::mediachanger::MediaChangerProxyDummy::dismountTape(
const std::string &vid, const TapeLibrarySlot &librarySlot) {
}
......@@ -21,50 +21,54 @@
#pragma once
#include "castor/legacymsg/RmcProxy.hpp"
#include "castor/mediachanger/MediaChangerProxy.hpp"
#include <string>
namespace castor {
namespace legacymsg {
namespace mediachanger {
/**
* A dummy rmc proxy.
*
* The main goal of this class is to facilitate the development of unit tests.
* Concrete class that implementd a dummy a media-changer proxy.
*/
class RmcProxyDummy: public RmcProxy {
class MediaChangerProxyDummy: public MediaChangerProxy {
public:
/**
* Destructor.
*/
~RmcProxyDummy() throw();
~MediaChangerProxyDummy();
/**
* 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 TapeLibrarySlot &librarySlot);
/**
* Asks the remote media-changer daemon to mount the specified tape into the
* drive in the specified library slot.
* 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 tape library slot containing the tape drive.
* @param mode The access mode in which the specified tape should be mounted.
* Please note that the value of this parameter is honored in a best effort
* fashion. If the library and drive combination do not support specifying
* the access mode, then this parameter will be ignored.
* @param librarySlot The library slot containing the tape drive.
*/
void mountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot, const MountMode mode);
void mountTapeReadWrite(const std::string &vid,
const TapeLibrarySlot &librarySlot);
/**
* Asks the remote media-changer daemon to unmount the specified tape from the
* drive in the specified library slot.
* 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 tape library slot containing the tape drive.
* @param librarySlot The library slot containing the tape drive.
*/
void unmountTape(const std::string &vid,
const tape::utils::TapeLibrarySlot &librarySlot);
void dismountTape(const std::string &vid, const TapeLibrarySlot &librarySlot);
}; // class RmcProxyDummy
}; // class MediaChangerProxy
} // namespace legacymsg
} // namespace mediachanger
} // namespace castor
......@@ -22,19 +22,19 @@
*****************************************************************************/
#include "castor/exception/Exception.hpp"
#include "castor/tape/utils/TapeLibrarySlot.hpp"
#include "castor/mediachanger/TapeLibrarySlot.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::utils::TapeLibrarySlot::TapeLibrarySlot():
castor::mediachanger::TapeLibrarySlot::TapeLibrarySlot():
m_libraryType(TAPE_LIBRARY_TYPE_NONE) {
}
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::utils::TapeLibrarySlot::TapeLibrarySlot(const std::string &str):
castor::mediachanger::TapeLibrarySlot::TapeLibrarySlot(const std::string &str):
m_str(str),
m_libraryType(getLibraryTypeOfSlot(str)) {
}
......@@ -42,7 +42,7 @@ castor::tape::utils::TapeLibrarySlot::TapeLibrarySlot(const std::string &str):
//------------------------------------------------------------------------------
// getLibrarySlotType
//------------------------------------------------------------------------------
castor::tape::utils::TapeLibraryType castor::tape::utils::TapeLibrarySlot::
castor::mediachanger::TapeLibraryType castor::mediachanger::TapeLibrarySlot::
getLibraryTypeOfSlot(const std::string &slot) {
if(0 == slot.find("acs@")) return TAPE_LIBRARY_TYPE_ACS;
if(0 == slot.find("manual@")) return TAPE_LIBRARY_TYPE_MANUAL;
......@@ -57,14 +57,14 @@ castor::tape::utils::TapeLibraryType castor::tape::utils::TapeLibrarySlot::
//------------------------------------------------------------------------------
// str
//------------------------------------------------------------------------------
const std::string &castor::tape::utils::TapeLibrarySlot::str() const throw() {
const std::string &castor::mediachanger::TapeLibrarySlot::str() const throw() {
return m_str;
}
//------------------------------------------------------------------------------
// getLibraryType
//------------------------------------------------------------------------------
castor::tape::utils::TapeLibraryType
castor::tape::utils::TapeLibrarySlot::getLibraryType() const throw() {
castor::mediachanger::TapeLibraryType
castor::mediachanger::TapeLibrarySlot::getLibraryType() const throw() {
return m_libraryType;
}
......@@ -23,13 +23,12 @@
#pragma once
#include "castor/tape/utils/TapeLibraryType.hpp"
#include "castor/mediachanger/TapeLibraryType.hpp"
#include <string>
namespace castor {
namespace tape {
namespace utils {
namespace mediachanger {
/**
* Class representing a slot in a tape library.
......@@ -89,6 +88,5 @@ private:
}; // class TapeLibrarySlot
} // namespace utils
} // namespace tape
} // namespace mediachanger
} // namespace castor
......@@ -22,14 +22,14 @@
*****************************************************************************/
#include "castor/exception/Exception.hpp"
#include "castor/tape/utils/TapeLibrarySlot.hpp"
#include "castor/mediachanger/TapeLibrarySlot.hpp"
#include <gtest/gtest.h>
#include <memory>
namespace unitTests {
class castor_tape_utils_TapeLibrarySlotTest : public ::testing::Test {
class castor_mediachanger_TapeLibrarySlotTest : public ::testing::Test {
protected:
virtual void SetUp() {
......@@ -39,40 +39,40 @@ protected:
}
};
TEST_F(castor_tape_utils_TapeLibrarySlotTest, getLibraryTypeNone) {
using namespace castor::tape::utils;
TEST_F(castor_mediachanger_TapeLibrarySlotTest, getLibraryTypeNone) {
using namespace castor::mediachanger;
TapeLibrarySlot slot;
ASSERT_EQ(TAPE_LIBRARY_TYPE_NONE, slot.getLibraryType());
}
TEST_F(castor_tape_utils_TapeLibrarySlotTest, getLibraryTypeAcs) {
using namespace castor::tape::utils;
TEST_F(castor_mediachanger_TapeLibrarySlotTest, getLibraryTypeAcs) {
using namespace castor::mediachanger;
TapeLibrarySlot slot("acs@rmc_host,1,2,3,4");
ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, slot.getLibraryType());
}
TEST_F(castor_tape_utils_TapeLibrarySlotTest, getLibraryTypeManual) {
using namespace castor::tape::utils;
TEST_F(castor_mediachanger_TapeLibrarySlotTest, getLibraryTypeManual) {
using namespace castor::mediachanger;
TapeLibrarySlot slot("manual@opaque_drive_id");
ASSERT_EQ(TAPE_LIBRARY_TYPE_MANUAL, slot.getLibraryType());
}
TEST_F(castor_tape_utils_TapeLibrarySlotTest, getLibraryTypeScsi) {
using namespace castor::tape::utils;
TEST_F(castor_mediachanger_TapeLibrarySlotTest, getLibraryTypeScsi) {
using namespace castor::mediachanger;
TapeLibrarySlot slot("smc@rmc_host,1");
ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, slot.getLibraryType());
}
TEST_F(castor_tape_utils_TapeLibrarySlotTest, getLibraryTypeNonsense) {
using namespace castor::tape::utils;
TEST_F(castor_mediachanger_TapeLibrarySlotTest, getLibraryTypeNonsense) {
using namespace castor::mediachanger;