diff --git a/cmake/Findzeromq.cmake b/cmake/Findzeromq.cmake deleted file mode 100644 index 2798a9e4819896e96a6dae10a2fe6c47237707eb..0000000000000000000000000000000000000000 --- a/cmake/Findzeromq.cmake +++ /dev/null @@ -1,28 +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/>. - -# This module will set the following variables: -# ZEROMQ_FOUND -# ZEROMQ_INCLUDE_DIRS - -find_path (ZEROMQ_INCLUDE_DIRS - zmq.h - PATHS /usr/include - NO_DEFAULT_PATH) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(zeromq DEFAULT_MSG - ZEROMQ_INCLUDE_DIRS) diff --git a/cta.spec.in b/cta.spec.in index b2a406fa929e589ef0ac88881b935f99e876f176..1822e4336725d67c5961822a82a763fd9b4a8949 100644 --- a/cta.spec.in +++ b/cta.spec.in @@ -51,7 +51,6 @@ BuildRequires: gmock-devel >= 1.5.0 gtest-devel >= 1.5.0 BuildRequires: sqlite-devel >= 3.6 BuildRequires: libcap-devel >= 2.16 BuildRequires: binutils-devel >= 2.20 -BuildRequires: zeromq-devel >= 4.0 BuildRequires: openssl-devel >= 1.0.1e BuildRequires: cryptopp-devel >= 5.6.2 BuildRequires: libuuid-devel >= 2.17 @@ -207,7 +206,6 @@ Requires: mariadb-libs Requires: postgresql-libs # Explicity require protobuf3 to avoid clash with eos-protobuf3 Requires: protobuf3 -Requires: zeromq Requires: cta-lib-common = %{version}-%{release} %description -n cta-lib CERN Tape Archive: diff --git a/mediachanger/AcsDismountTape.proto b/mediachanger/AcsDismountTape.proto deleted file mode 100644 index a519b6a276949afaddfd19ee0cd9029d1bc26e7d..0000000000000000000000000000000000000000 --- a/mediachanger/AcsDismountTape.proto +++ /dev/null @@ -1,26 +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/>. -// -syntax = "proto2"; -package cta.mediachanger; - -message AcsDismountTape { - required string vid = 1; - required uint32 acs = 2; - required uint32 lsm = 3; - required uint32 panel = 4; - required uint32 drive = 5; -} diff --git a/mediachanger/AcsForceDismountTape.proto b/mediachanger/AcsForceDismountTape.proto deleted file mode 100644 index 37c38cfb55253c4949f89070a54562ebeaeeeecf..0000000000000000000000000000000000000000 --- a/mediachanger/AcsForceDismountTape.proto +++ /dev/null @@ -1,26 +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/>. -// -syntax = "proto2"; -package cta.mediachanger; - -message AcsForceDismountTape { - required string vid = 1; - required uint32 acs = 2; - required uint32 lsm = 3; - required uint32 panel = 4; - required uint32 drive = 5; -} diff --git a/mediachanger/AcsLibrarySlot.cpp b/mediachanger/AcsLibrarySlot.cpp deleted file mode 100644 index e21a6961839660e4b15baed1d3f0cd6187abf086..0000000000000000000000000000000000000000 --- a/mediachanger/AcsLibrarySlot.cpp +++ /dev/null @@ -1,99 +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/AcsLibrarySlot.hpp" - -#include <sstream> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::AcsLibrarySlot::AcsLibrarySlot(): - LibrarySlot(TAPE_LIBRARY_TYPE_ACS), - m_acs(0), - m_lsm(0), - m_panel(0), - m_drive(0) { - m_str = librarySlotToString(0, 0, 0, 0); -} - -//------------------------------------------------------------------------------ -// librarySlotToString -//------------------------------------------------------------------------------ -std::string cta::mediachanger::AcsLibrarySlot::librarySlotToString( - const uint32_t acs, const uint32_t lsm, const uint32_t panel, - const uint32_t drive) const { - std::ostringstream oss; - oss << "acs" << acs << "," << lsm << "," << panel << "," << drive; - return oss.str(); -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::AcsLibrarySlot::AcsLibrarySlot(const uint32_t acs, - const uint32_t lsm, const uint32_t panel, const uint32_t drive): - LibrarySlot(TAPE_LIBRARY_TYPE_ACS), - m_acs(acs), - m_lsm(lsm), - m_panel(panel), - m_drive(drive) { - m_str = librarySlotToString(acs, lsm, panel, drive); -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::AcsLibrarySlot::~AcsLibrarySlot() { -} - -//------------------------------------------------------------------------------ -// clone -//------------------------------------------------------------------------------ -cta::mediachanger::LibrarySlot *cta::mediachanger::AcsLibrarySlot:: - clone() { - return new AcsLibrarySlot(*this); -} - -//------------------------------------------------------------------------------ -// getAcs -//------------------------------------------------------------------------------ -uint32_t cta::mediachanger::AcsLibrarySlot::getAcs() const { - return m_acs; -} - -//------------------------------------------------------------------------------ -// getLsm -//------------------------------------------------------------------------------ -uint32_t cta::mediachanger::AcsLibrarySlot::getLsm() const { - return m_lsm; -} - -//------------------------------------------------------------------------------ -// getPanel -//------------------------------------------------------------------------------ -uint32_t cta::mediachanger::AcsLibrarySlot::getPanel() const { - return m_panel; -} - -//------------------------------------------------------------------------------ -// getDrive -//------------------------------------------------------------------------------ -uint32_t cta::mediachanger::AcsLibrarySlot::getDrive() const { - return m_drive; -} diff --git a/mediachanger/AcsLibrarySlot.hpp b/mediachanger/AcsLibrarySlot.hpp deleted file mode 100644 index cb37af492cd7d7f95a8293520f141441c59a21a5..0000000000000000000000000000000000000000 --- a/mediachanger/AcsLibrarySlot.hpp +++ /dev/null @@ -1,128 +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 "common/exception/InvalidArgument.hpp" -#include "mediachanger/LibrarySlot.hpp" - -#include <stdint.h> - -namespace cta { -namespace mediachanger { - -/** - * Class reprsenting a slot in an ACS tape-library. - */ -class AcsLibrarySlot: public LibrarySlot { -public: - - /** - * Default constructor that sets all integer members to 0. - */ - AcsLibrarySlot(); - - /** - * Constructor. - * - * @param acs The acs component of the library slot. - * @param lsm The lsm component of the library slot. - * @param panel The panel component of the library slot. - * @param drive The drive component of the library slot. - */ - AcsLibrarySlot(const uint32_t acs, const uint32_t lsm, - const uint32_t panel, const uint32_t drive); - - /** - * Destructor. - */ - ~AcsLibrarySlot(); - - /** - * Creates a clone of this object. - * - * @return The clone. - */ - LibrarySlot *clone(); - - /** - * Gets the acs component of the library slot. - * - * @return the acs component of the library slot. - */ - uint32_t getAcs() const; - - /** - * Gets the lsm component of the library slot. - * - * @return the lsm component of the library slot. - */ - uint32_t getLsm() const; - - /** - * Gets the panel component of the library slot. - * - * @return the panel component of the library slot. - */ - uint32_t getPanel() const; - - /** - * Gets the drive component of the library slot. - * - * @return the drive component of the library slot. - */ - uint32_t getDrive() const; - -private: - - /** - * The acs component of the library slot. - */ - uint32_t m_acs; - - /** - * The lsm component of the library slot. - */ - uint32_t m_lsm; - - /** - * The panel component of the library slot. - */ - uint32_t m_panel; - - /** - * The drive component of the library slot. - */ - uint32_t m_drive; - - /** - * Returns the string representation of the specified ACS library slot. - * - * @param acs The acs component of the library slot. - * @param lsm The lsm component of the library slot. - * @param panel The panel component of the library slot. - * @param drive The drive component of the library slot. - * @return The string representation. - */ - std::string librarySlotToString(const uint32_t acs, const uint32_t lsm, - const uint32_t panel, const uint32_t drive) const; - -}; // class AcsProxy - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/AcsMountTapeReadOnly.proto b/mediachanger/AcsMountTapeReadOnly.proto deleted file mode 100644 index 4b811dbed5c58d7e3be68f6732c7e9fea48fb00c..0000000000000000000000000000000000000000 --- a/mediachanger/AcsMountTapeReadOnly.proto +++ /dev/null @@ -1,26 +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/>. -// -syntax = "proto2"; -package cta.mediachanger; - -message AcsMountTapeReadOnly { - required string vid = 1; - required uint32 acs = 2; - required uint32 lsm = 3; - required uint32 panel = 4; - required uint32 drive = 5; -} diff --git a/mediachanger/AcsMountTapeReadWrite.proto b/mediachanger/AcsMountTapeReadWrite.proto deleted file mode 100644 index 78491e39407cf0ed4f0649068cdb3e20457ae813..0000000000000000000000000000000000000000 --- a/mediachanger/AcsMountTapeReadWrite.proto +++ /dev/null @@ -1,26 +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/>. -// -syntax = "proto2"; -package cta.mediachanger; - -message AcsMountTapeReadWrite { - required string vid = 1; - required uint32 acs = 2; - required uint32 lsm = 3; - required uint32 panel = 4; - required uint32 drive = 5; -} diff --git a/mediachanger/AcsProxy.cpp b/mediachanger/AcsProxy.cpp deleted file mode 100644 index fb7d6ffac0561be9e7242822a5778a39858c0284..0000000000000000000000000000000000000000 --- a/mediachanger/AcsProxy.cpp +++ /dev/null @@ -1,302 +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 "common/threading/MutexLocker.hpp" -#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/AcsProxy.hpp" -#include "mediachanger/Constants.hpp" -#include "mediachanger/MediaChangerReturnValue.pb.h" -#include "mediachanger/messages.hpp" -#include "mediachanger/ZmqContextSingleton.hpp" -#include "mediachanger/ZmqSocketST.hpp" - -namespace cta { -namespace mediachanger { - -namespace { - -/** - * Creates a frame containing an AcsMountTapeReadOnly message. - * - * @param vid The tape to be mounted. - * @param librarySlot The slot in the library that contains the tape drive. - * @return The frame. - */ -Frame createAcsMountTapeReadOnlyFrame(const std::string &vid, const AcsLibrarySlot &librarySlot) { - try { - Frame frame; - - frame.header = protoTapePreFillHeader(); - frame.header.set_msgtype(MSG_TYPE_ACSMOUNTTAPEREADONLY); - frame.header.set_bodysignature("PIPO"); - - AcsMountTapeReadOnly body; - body.set_vid(vid); - body.set_acs(librarySlot.getAcs()); - body.set_lsm(librarySlot.getLsm()); - body.set_panel(librarySlot.getPanel()); - body.set_drive(librarySlot.getDrive()); - frame.serializeProtocolBufferIntoBody(body); - - return frame; - - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to create AcsMountTapeReadOnly frame: " << - ne.getMessage().str(); - throw ex; - } -} - -/** - * Creates a frame containing a AcsMountTapeReadWrite message. - * - * @param vid The tape to be mounted. - * @param librarySlot The slot in the library that contains the tape drive. - * @return The frame. - */ -Frame createAcsMountTapeReadWriteFrame(const std::string &vid, const AcsLibrarySlot &librarySlot) { - try { - Frame frame; - - frame.header = protoTapePreFillHeader(); - frame.header.set_msgtype(MSG_TYPE_ACSMOUNTTAPEREADWRITE); - frame.header.set_bodysignature("PIPO"); - - AcsMountTapeReadWrite body; - body.set_vid(vid); - body.set_acs(librarySlot.getAcs()); - body.set_lsm(librarySlot.getLsm()); - body.set_panel(librarySlot.getPanel()); - body.set_drive(librarySlot.getDrive()); - frame.serializeProtocolBufferIntoBody(body); - - return frame; - - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to create AcsMountTapeReadWrite frame: " << - ne.getMessage().str(); - throw ex; - } -} - -/** - * Creates a frame containing an AcsDismountTape message. - * - * @param vid The tape to be dismounted. - * @param librarySlot The slot in the library that contains the tape drive. - * @return The frame. - */ -Frame createAcsDismountTapeFrame(const std::string &vid, const AcsLibrarySlot &librarySlot) { - try { - Frame frame; - - frame.header = protoTapePreFillHeader(); - frame.header.set_msgtype(MSG_TYPE_ACSDISMOUNTTAPE); - frame.header.set_bodysignature("PIPO"); - - AcsDismountTape body; - body.set_vid(vid); - body.set_acs(librarySlot.getAcs()); - body.set_lsm(librarySlot.getLsm()); - body.set_panel(librarySlot.getPanel()); - body.set_drive(librarySlot.getDrive()); - frame.serializeProtocolBufferIntoBody(body); - - return frame; - - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to create AcsDismountTape frame: " << - ne.getMessage().str(); - throw ex; - } -} - -/** - * Creates a frame containing an AcsForceDismountTape message. - * - * @param vid The tape to be dismounted. - * @param librarySlot The slot in the library that contains the tape drive. - * @return The frame. - */ -Frame createAcsForceDismountTapeFrame(const std::string &vid, const AcsLibrarySlot &librarySlot) { - try { - Frame frame; - - frame.header = protoTapePreFillHeader(); - frame.header.set_msgtype(MSG_TYPE_ACSFORCEDISMOUNTTAPE); - frame.header.set_bodysignature("PIPO"); - - AcsForceDismountTape body; - body.set_vid(vid); - body.set_acs(librarySlot.getAcs()); - body.set_lsm(librarySlot.getLsm()); - body.set_panel(librarySlot.getPanel()); - body.set_drive(librarySlot.getDrive()); - frame.serializeProtocolBufferIntoBody(body); - - return frame; - - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to create AcsForceDismountTape frame: " << - ne.getMessage().str(); - throw ex; - } -} - -} // anonyous namespace - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -AcsProxy::AcsProxy(const unsigned short serverPort): - m_serverPort(serverPort) { -} - -//------------------------------------------------------------------------------ -// mountTapeReadOnly -//------------------------------------------------------------------------------ -void AcsProxy::mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) { - threading::MutexLocker locker(m_mutex); - - try { - const Frame rqst = createAcsMountTapeReadOnlyFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot)); - sendFrame(serverSocketInstance(), rqst); - - MediaChangerReturnValue reply; - recvTapeReplyOrEx(serverSocketInstance(), reply); - if(0 != reply.value()) { - // Should never get here - cta::exception::Exception ex; - ex.getMessage() << "Received an unexpected return value" - ": expected=0 actual=" << reply.value(); - throw ex; - } - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << - "Failed to request CTA ACS daemon to mount tape for read only access: " - << librarySlot.str() << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// mountTapeReadWrite -//------------------------------------------------------------------------------ -void AcsProxy::mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) { - threading::MutexLocker locker(m_mutex); - - try { - const Frame rqst = createAcsMountTapeReadWriteFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot)); - sendFrame(serverSocketInstance(), rqst); - - MediaChangerReturnValue reply; - recvTapeReplyOrEx(serverSocketInstance(), reply); - if(0 != reply.value()) { - // Should never get here - cta::exception::Exception ex; - ex.getMessage() << "Received an unexpected return value" - ": expected=0 actual=" << reply.value(); - throw ex; - } - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << - "Failed to request CTA ACS daemon to mount tape for read/write " - "access: " << librarySlot.str() << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// dismountTape -//------------------------------------------------------------------------------ -void AcsProxy::dismountTape(const std::string &vid, const LibrarySlot &librarySlot) { - threading::MutexLocker locker(m_mutex); - - try { - const Frame rqst = createAcsDismountTapeFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot)); - sendFrame(serverSocketInstance(), rqst); - - MediaChangerReturnValue reply; - recvTapeReplyOrEx(serverSocketInstance(), reply); - if(0 != reply.value()) { - // Should never get here - cta::exception::Exception ex; - ex.getMessage() << "Received an unexpected return value" - ": expected=0 actual=" << reply.value(); - throw ex; - } - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << - "Failed to request CTA ACS daemon to dismount tape: " << - librarySlot.str() << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// forceDismountTape -//------------------------------------------------------------------------------ -void AcsProxy::forceDismountTape(const std::string &vid, const LibrarySlot &librarySlot) { - threading::MutexLocker locker(m_mutex); - - try { - const Frame rqst = createAcsForceDismountTapeFrame(vid, dynamic_cast<const AcsLibrarySlot&>(librarySlot)); - sendFrame(serverSocketInstance(), rqst); - - MediaChangerReturnValue reply; - recvTapeReplyOrEx(serverSocketInstance(), reply); - if(0 != reply.value()) { - // Should never get here - cta::exception::Exception ex; - ex.getMessage() << "Received an unexpected return value" - ": expected=0 actual=" << reply.value(); - throw ex; - } - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << - "Failed to request CTA ACS daemon to force dismount tape: " << - librarySlot.str() << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// serverSocketInstance -//------------------------------------------------------------------------------ -ZmqSocket &AcsProxy::serverSocketInstance() { - if(nullptr == m_serverSocket) { - m_serverSocket.reset(new ZmqSocketST(ZmqContextSingleton::instance(), ZMQ_REQ)); - connectZmqSocketToLocalhost(*m_serverSocket, m_serverPort); - } - return *m_serverSocket; -} - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/AcsProxy.hpp b/mediachanger/AcsProxy.hpp deleted file mode 100644 index ad22beaaa379f06842a4e803ff58ace2ead1769f..0000000000000000000000000000000000000000 --- a/mediachanger/AcsProxy.hpp +++ /dev/null @@ -1,116 +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 "common/threading/Mutex.hpp" -#include "mediachanger/Constants.hpp" -#include "mediachanger/MediaChangerProxy.hpp" -#include "mediachanger/ZmqSocket.hpp" - -#include <memory> - -namespace cta { -namespace mediachanger { - -/** - * A ZMQ media changer proxy. - */ -class AcsProxy: public MediaChangerProxy { -public: - - /** - * Constructor. - * - * @param serverPort The TCP/IP port on which the CASTOR ACS daemon is - * listening for ZMQ messages. - */ - AcsProxy(const unsigned short serverPort = ACS_PORT); - - /** - * Request the CASTOR ACS daemon to mount the specified tape for read-only - * 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. - */ - void mountTapeReadOnly(const std::string &vid, const LibrarySlot &librarySlot) override; - - /** - * Request the CASTOR ACS 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. - */ - void mountTapeReadWrite(const std::string &vid, const LibrarySlot &librarySlot) override; - - /** - * Request the CASTOR ACS 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. - */ - void dismountTape(const std::string &vid, const LibrarySlot &librarySlot) override; - - /** - * Request the CASTOR ACS 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. - * - * @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 LibrarySlot &librarySlot) override; - -private: - - /** - * Mutex used to implement a critical section around the enclosed - * ZMQ socket. - */ - threading::Mutex m_mutex; - - /** - * The TCP/IP port on which the CASTOR ACS daemon is listening for ZMQ - * messages. - */ - const unsigned short m_serverPort; - - /** - * Socket connecting this proxy to the daemon it represents. - */ - std::unique_ptr<ZmqSocket> m_serverSocket; - - /** - * Returns the socket instance connecting this proxy to the daemon it - * represents. This method instantiates a socket and connects it if - * a socket does not already exist. - * - * Please note that a lock MUST be taken on m_mutex before calling this - * method. - * - * @return The socket connecting this proxy the daemon it represents. - */ - ZmqSocket &serverSocketInstance(); - -}; // class AcsProxy - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/CMakeLists.txt b/mediachanger/CMakeLists.txt index af98f8fab7f0a364c6b3cc5efec0a7c024855166..876d9870320f4f8d87b08dbfce4ec39489745b19 100644 --- a/mediachanger/CMakeLists.txt +++ b/mediachanger/CMakeLists.txt @@ -18,23 +18,12 @@ cmake_minimum_required (VERSION 2.6) add_subdirectory(castorrmc) find_package(openssl REQUIRED) find_package(Protobuf3 REQUIRED) -find_package(zeromq REQUIRED) - -file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.proto") -PROTOBUF3_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles}) -include_directories (${PROTOBUF3_INCLUDE_DIRS}) -add_library(ctamediachangerprotobuf ${ProtoSources}) -target_link_libraries (ctamediachangerprotobuf - ${PROTOBUF3_LIBRARIES}) set (MEDIACHANGER_LIB_SRC_FILES - AcsLibrarySlot.cpp - AcsProxy.cpp CmdLine.cpp CmdLineTool.cpp CommonMarshal.cpp DebugBuf.cpp - Frame.cpp io.cpp IpAndPort.cpp LibrarySlot.cpp @@ -43,7 +32,6 @@ set (MEDIACHANGER_LIB_SRC_FILES MediaChangerFacade.cpp MediaChangerProxy.cpp MessageHeader.cpp - messages.cpp MmcProxy.cpp RmcMarshal.cpp RmcMarshal.hpp @@ -51,12 +39,7 @@ set (MEDIACHANGER_LIB_SRC_FILES RmcProxy.cpp RmcUnmountMsgBody.cpp ScsiLibrarySlot.cpp - TapeLibraryType.cpp - ZmqContextSingleton.cpp - ZmqMsg.cpp - ZmqSocket.cpp - ZmqSocketST.cpp - ZmqSocketMT.cpp) + TapeLibraryType.cpp) add_library (ctamediachanger SHARED ${MEDIACHANGER_LIB_SRC_FILES}) @@ -65,14 +48,11 @@ set_property(TARGET ctamediachanger PROPERTY VERSION "${CTA_LIBVERSION}") target_link_libraries (ctamediachanger ctacommon - ctamediachangerprotobuf - ssl - zmq) + ssl) install (TARGETS ctamediachanger DESTINATION usr/${CMAKE_INSTALL_LIBDIR}) set (MEDIACHANGER_UNIT_TESTS_LIB_SRC_FILES - AcsLibrarySlotTest.cpp DismountCmdLine.cpp DismountCmdLineTest.cpp IoTest.cpp diff --git a/mediachanger/DismountCmdLineTest.cpp b/mediachanger/DismountCmdLineTest.cpp index 79c9207a1be5e27c8d380e515722901bc64fee64..7503f50c849f3d410e5103e53cad6194d2916669 100644 --- a/mediachanger/DismountCmdLineTest.cpp +++ b/mediachanger/DismountCmdLineTest.cpp @@ -66,117 +66,83 @@ protected: } }; -TEST_F(cta_mediachanger_DismountCmdLineTest, acs) { - using namespace cta::mediachanger; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("cta-mediachanger-dismount"); - args->argv[1] = dupString("vid"); - args->argv[2] = dupString("acs1,2,3,4"); - args->argv[3] = NULL; - - std::unique_ptr<DismountCmdLine> cmdLine; - ASSERT_NO_THROW(cmdLine.reset(new DismountCmdLine(args->argc, args->argv))); - - ASSERT_FALSE(cmdLine->getHelp()); - ASSERT_FALSE(cmdLine->getDebug()); - ASSERT_FALSE(cmdLine->getForce()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine->getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs1,2,3,4"), - cmdLine->getDriveLibrarySlot().str()); -} - TEST_F(cta_mediachanger_DismountCmdLineTest, copy_constructor) { using namespace cta::mediachanger; - Argcv *args = new Argcv(); + Argcv *args= new Argcv(); m_argsList.push_back(args); args->argc = 3; - args->argv = new char *[4]; + args->argv = new char *[4]; args->argv[0] = dupString("cta-mediachanger-dismount"); args->argv[1] = dupString("vid"); - args->argv[2] = dupString("acs1,2,3,4"); + args->argv[2] = dupString("smc1"); args->argv[3] = NULL; DismountCmdLine cmdLine1(args->argc, args->argv); ASSERT_FALSE(cmdLine1.getHelp()); ASSERT_FALSE(cmdLine1.getDebug()); ASSERT_FALSE(cmdLine1.getForce()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine1.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs1,2,3,4"), + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine1.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc1"), cmdLine1.getDriveLibrarySlot().str()); DismountCmdLine cmdLine2(cmdLine1); ASSERT_FALSE(cmdLine2.getHelp()); ASSERT_FALSE(cmdLine2.getDebug()); ASSERT_FALSE(cmdLine2.getForce()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine2.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs1,2,3,4"), - cmdLine2.getDriveLibrarySlot().str()); + ASSERT_EQ(std::string("smc1"), cmdLine2.getDriveLibrarySlot().str()); } TEST_F(cta_mediachanger_DismountCmdLineTest, assignment) { using namespace cta::mediachanger; - Argcv *args1 = new Argcv(); + Argcv *args1= new Argcv(); m_argsList.push_back(args1); args1->argc = 3; - args1->argv = new char *[4]; + args1->argv = new char *[4]; args1->argv[0] = dupString("cta-mediachanger-dismount"); args1->argv[1] = dupString("vid"); - args1->argv[2] = dupString("acs1,2,3,4"); + args1->argv[2] = dupString("smc1"); args1->argv[3] = NULL; DismountCmdLine cmdLine1(args1->argc, args1->argv); ASSERT_FALSE(cmdLine1.getHelp()); ASSERT_FALSE(cmdLine1.getDebug()); ASSERT_FALSE(cmdLine1.getForce()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine1.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs1,2,3,4"), - cmdLine1.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine1.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc1"), cmdLine1.getDriveLibrarySlot().str()); - Argcv *args2 = new Argcv(); + Argcv *args2= new Argcv(); m_argsList.push_back(args2); args2->argc = 3; - args2->argv = new char *[4]; + args2->argv = new char *[4]; args2->argv[0] = dupString("cta-mediachanger-dismount"); args2->argv[1] = dupString("vid"); - args2->argv[2] = dupString("acs5,6,7,8"); + args2->argv[2] = dupString("smc2"); args2->argv[3] = NULL; DismountCmdLine cmdLine2(args2->argc, args2->argv); ASSERT_FALSE(cmdLine2.getHelp()); ASSERT_FALSE(cmdLine2.getDebug()); ASSERT_FALSE(cmdLine2.getForce()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine2.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs5,6,7,8"), - cmdLine2.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine2.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc2"), cmdLine2.getDriveLibrarySlot().str()); cmdLine1 = cmdLine2; ASSERT_FALSE(cmdLine1.getHelp()); ASSERT_FALSE(cmdLine1.getDebug()); ASSERT_FALSE(cmdLine1.getForce()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine1.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs5,6,7,8"), - cmdLine1.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine1.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc2"), cmdLine1.getDriveLibrarySlot().str()); ASSERT_FALSE(cmdLine2.getHelp()); ASSERT_FALSE(cmdLine2.getDebug()); ASSERT_FALSE(cmdLine2.getForce()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine2.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs5,6,7,8"), - cmdLine2.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine2.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc2"), cmdLine2.getDriveLibrarySlot().str()); } TEST_F(cta_mediachanger_DismountCmdLineTest, scsi) { diff --git a/mediachanger/DismountCmdMain.cpp b/mediachanger/DismountCmdMain.cpp index 10552fc7add2c6013ab9fc205c8c02440e4275b6..af7dcd301b2ed92a1db294b60f24595831743a44 100644 --- a/mediachanger/DismountCmdMain.cpp +++ b/mediachanger/DismountCmdMain.cpp @@ -23,9 +23,7 @@ #include "mediachanger/DismountCmdLine.hpp" #include <exception> -#include <google/protobuf/stubs/common.h> #include <iostream> -#include <zmq.h> /** * An exception throwing version of main(). @@ -46,7 +44,6 @@ int main(const int argc, char *const *const argv) { try { const int rc = exceptionThrowingMain(argc, argv); - google::protobuf::ShutdownProtobufLibrary(); return rc; } catch(cta::exception::Exception &ex) { errorMessage = ex.getMessage().str(); @@ -60,7 +57,6 @@ int main(const int argc, char *const *const argv) { // and errorMessage has been set accordingly std::cerr << "Aborting: " << errorMessage << std::endl; - google::protobuf::ShutdownProtobufLibrary(); return 1; } diff --git a/mediachanger/Exception.proto b/mediachanger/Exception.proto deleted file mode 100644 index fd88601083069582cf39247d4df76ebee674a35b..0000000000000000000000000000000000000000 --- a/mediachanger/Exception.proto +++ /dev/null @@ -1,27 +0,0 @@ -// 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 -syntax = "proto2"; -package cta.mediachanger; - -message Exception { - // The error code - required uint32 code = 1; - - // The error message - required string message = 2; -} diff --git a/mediachanger/Frame.cpp b/mediachanger/Frame.cpp deleted file mode 100644 index f125a09fe5121ac1cf574ac79cf0bafc2b55272d..0000000000000000000000000000000000000000 --- a/mediachanger/Frame.cpp +++ /dev/null @@ -1,132 +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 "common/exception/Exception.hpp" -#include "common/utils/utils.hpp" -#include "mediachanger/Constants.hpp" -#include "mediachanger/Frame.hpp" -#include "mediachanger/messages.hpp" - -//------------------------------------------------------------------------------ -// checkHashValueOfBody -//------------------------------------------------------------------------------ -void cta::mediachanger::Frame::checkHashValueOfBody() const { - const std::string bodyHash = cta::mediachanger::computeSHA1Base64(body); - if(bodyHash != header.bodyhashvalue()){ - cta::exception::Exception ex; - ex.getMessage() << "Hash value of frame body does match the value stored" - " in the header: header.bodyhashvalue=" << header.bodyhashvalue() << - " bodyHash=" << bodyHash; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// serialiseHeaderToZmqMsg -//------------------------------------------------------------------------------ -void cta::mediachanger::Frame::serializeHeaderToZmqMsg(ZmqMsg &msg) const { - try { - if(!header.IsInitialized()) { - cta::exception::Exception ex; - ex.getMessage() << "Frame header is not initialized"; - throw ex; - } - - if(header.ByteSize() != (int)msg.size()) { - cta::exception::Exception ex; - ex.getMessage() << "Size of frame header does not match that of ZMQ" - " message: header.ByteSize()=" << header.ByteSize() << " msg.size()=" - << msg.size(); - throw ex; - } - - if(!header.SerializeToArray(msg.getData(), header.ByteSize())) { - cta::exception::Exception ex; - ex.getMessage() << "header.SerializeToArray() returned false"; - throw ex; - } - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to serialize frame header to ZMQ message: " << - ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// parseZmqMsgIntoHeader -//------------------------------------------------------------------------------ -void cta::mediachanger::Frame::parseZmqMsgIntoHeader(const ZmqMsg &msg) { - if(!header.ParseFromArray(msg.getData(), msg.size())) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to parse ZMQ message into frame header: " - "header.ParseFromArray() returned false"; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// serializeProtocolBufferIntoBody -//------------------------------------------------------------------------------ -void cta::mediachanger::Frame::serializeProtocolBufferIntoBody( - const google::protobuf::Message &protocolBuffer) { - try { - if(!protocolBuffer.SerializeToString(&body)) { - cta::exception::Exception ex; - ex.getMessage() << "SerializeToString() returned false"; - throw ex; - } - - calcAndSetHashValueOfBody(); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Frame failed to serialize protocol buffer " << - demangledNameOf(protocolBuffer) << " into frame body: " - << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// parseBodyIntoProtocolBuffer -//------------------------------------------------------------------------------ -void cta::mediachanger::Frame::parseBodyIntoProtocolBuffer( - google::protobuf::Message &protocolBuffer) const { - if(!protocolBuffer.ParseFromString(body)) { - cta::exception::Exception ex; - ex.getMessage() << "Frame failed to parse contents of enclosed ZMQ" - " message into protocol buffer " << - demangledNameOf(protocolBuffer) - << ": ParseFromString() returned false"; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// calcAndSetHashValueOfBody -//------------------------------------------------------------------------------ -void cta::mediachanger::Frame::calcAndSetHashValueOfBody() { - try { - header.set_bodyhashvalue(computeSHA1Base64(body)); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Frame failed to calculate the hash value of the frame" - "body and store it in the header: " << ne.getMessage().str(); - throw ex; - } -} diff --git a/mediachanger/Frame.hpp b/mediachanger/Frame.hpp deleted file mode 100644 index cb6281036225325ce781f173816cf668b8e044f8..0000000000000000000000000000000000000000 --- a/mediachanger/Frame.hpp +++ /dev/null @@ -1,111 +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/MediaChangerHeader.pb.h" -#include "mediachanger/ZmqMsg.hpp" - -#include <cxxabi.h> -#include <string> - -namespace cta { -namespace mediachanger { - -/** - * Structure representing a message frame. - */ -struct Frame { - /** - * The header of the frame. - */ - MediaChangerHeader header; - - /** - * The body of the frame. - */ - std::string body; - - /** - * Checks the hash value field of the header against the body of the frame. - */ - void checkHashValueOfBody() const; - - /** - * Serializes the frame header to the specified ZMQ message. - * - * Please note that the specified size of the specified ZMQ message must - * match that of the header. - * - * @param msg Output parameter: The ZMQ message. - */ - void serializeHeaderToZmqMsg(ZmqMsg &msg) const; - - /** - * Parses the specified ZMQ message into the frame header. - * - * @param msg The ZMQ message. - */ - void parseZmqMsgIntoHeader(const ZmqMsg &msg); - - /** - * Serializes the specified protocol buffer into the frame body, calculates - * it hash value and stores the has value in the frame header. - * - * @param protocolBuffer The protocol buffer. - */ - void serializeProtocolBufferIntoBody( - const google::protobuf::Message &protocolBuffer); - - /** - * Parses the body into the specified protocol buffer. - * - * @param pb Output parameter: The protocol buffer to be written to. - */ - void parseBodyIntoProtocolBuffer(google::protobuf::Message &protocolBuffer) - const; - -private: - - /** - * Calculates the hash value of the frame body and records the result in the - * frame header. - */ - void calcAndSetHashValueOfBody(); - - /** - * Determines the demangled type name of the specified object. - * - * @param t The object. - * @return The demangled type name. - */ - template <class T> static std::string demangledNameOf(const T&t) { - std::string responseType = typeid(t).name(); - int status = -1; - char * demangled = abi::__cxa_demangle(responseType.c_str(), NULL, NULL, &status); - if (!status) { - responseType = demangled; - } - free(demangled); - - return responseType; - } -}; // struct Frame - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/LibrarySlot.cpp b/mediachanger/LibrarySlot.cpp index 800c4201079e7522eeaed7e1519ce61175a73ac0..f6eddb8e599b246524c177857179ddfe9156cba6 100644 --- a/mediachanger/LibrarySlot.cpp +++ b/mediachanger/LibrarySlot.cpp @@ -38,7 +38,6 @@ cta::mediachanger::LibrarySlot::~LibrarySlot() { //------------------------------------------------------------------------------ cta::mediachanger::TapeLibraryType cta::mediachanger::LibrarySlot:: 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; if(0 == slot.find("smc")) return TAPE_LIBRARY_TYPE_SCSI; diff --git a/mediachanger/LibrarySlotParser.cpp b/mediachanger/LibrarySlotParser.cpp index 4311b66003d18f104cc11e7f0bb9498c5a1b6cd3..edeec616a0089291d0905f2d98412a3bd9dc21d6 100644 --- a/mediachanger/LibrarySlotParser.cpp +++ b/mediachanger/LibrarySlotParser.cpp @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "common/exception/Exception.hpp" #include "common/utils/utils.hpp" -#include "mediachanger/AcsLibrarySlot.hpp" #include "mediachanger/LibrarySlotParser.hpp" #include "mediachanger/ManualLibrarySlot.hpp" #include "mediachanger/ScsiLibrarySlot.hpp" @@ -50,7 +50,6 @@ cta::mediachanger::LibrarySlot *cta::mediachanger::LibrarySlotParser:: //------------------------------------------------------------------------------ cta::mediachanger::TapeLibraryType cta::mediachanger::LibrarySlotParser:: getLibrarySlotType(const std::string &str) { - if(isAcs(str)) return TAPE_LIBRARY_TYPE_ACS; if(isManual(str)) return TAPE_LIBRARY_TYPE_MANUAL; if(isScsi(str)) return TAPE_LIBRARY_TYPE_SCSI; @@ -59,14 +58,6 @@ cta::mediachanger::TapeLibraryType cta::mediachanger::LibrarySlotParser:: throw ex; } -//------------------------------------------------------------------------------ -// isAcs -//------------------------------------------------------------------------------ -bool cta::mediachanger::LibrarySlotParser::isAcs(const std::string &str) - { - return 0 == str.find("acs"); -} - //------------------------------------------------------------------------------ // isManual //------------------------------------------------------------------------------ @@ -90,7 +81,6 @@ cta::mediachanger::LibrarySlot *cta::mediachanger::LibrarySlotParser:: parse(const TapeLibraryType libraryType, const std::string &str) { switch(libraryType) { - case TAPE_LIBRARY_TYPE_ACS: return parseAcsLibrarySlot(str); case TAPE_LIBRARY_TYPE_MANUAL: return parseManualLibrarySlot(str); case TAPE_LIBRARY_TYPE_SCSI: return parseScsiLibrarySlot(str); default: @@ -104,94 +94,6 @@ cta::mediachanger::LibrarySlot *cta::mediachanger::LibrarySlotParser:: } } -//------------------------------------------------------------------------------ -// parseAcsLibrarySlot -//------------------------------------------------------------------------------ -cta::mediachanger::AcsLibrarySlot *cta::mediachanger::LibrarySlotParser:: - parseAcsLibrarySlot(const std::string &str) { - const std::string errMsg("Failed to construct AcsLibrarySlot"); - std::vector<std::string> components; - utils::splitString(str, ',', components); - if(4 != components.size()) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": Invalid number of components" - ": expected=4, actual=" << components.size(); - throw ex; - } - - // check for acs in the beginning - const std::string &acsWithACS_NUMBERStr = components[0]; - if(0 != acsWithACS_NUMBERStr.find("acs")) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": Invalid tape library-slot format" - ": expected=acsACS_NUMBER, actual=" << acsWithACS_NUMBERStr; - throw ex; - } - - const std::string::size_type indexOfACS_NUMBER = 3; // skip acs - const std::string &acsStr = acsWithACS_NUMBERStr.substr(indexOfACS_NUMBER); - const std::string &lsmStr = components[1]; - const std::string &panStr = components[2]; - const std::string &drvStr = components[3]; - - // Each of the 4 components must be between 1 and than 3 characters long - if(1 > acsStr.length() || 3 < acsStr.length()) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": Invalid ACS_NUMBER string length" - ": expected=1..3, actual=" << acsStr.length(); - throw ex; - } - if(1 > lsmStr.length() || 3 < lsmStr.length()) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": Invalid LSM_NUMBER string length" - ": expected=1..3, actual=" << lsmStr.length(); - throw ex; - } - if(1 > panStr.length() || 3 < panStr.length()) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": Invalid PANEL_NUMBER string length" - ": expected=1..3, actual=" << panStr.length(); - throw ex; - } - if(1 > drvStr.length() || 3 < drvStr.length()) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": Invalid TRANSPORT_NUMBER string length" - ": expected=1..3, actual=" << drvStr.length(); - throw ex; - } - - if(!utils::isValidUInt(acsStr)) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": ACS_NUMBER must be an unsigned integer:" - " value=" << acsStr; - throw ex; - } - if(!utils::isValidUInt(lsmStr)) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": LSM_NUMBER must be an unsigned integer:" - " value=" << lsmStr; - throw ex; - } - if(!utils::isValidUInt(panStr)) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": PANEL_NUMBER must be an unsigned integer:" - " value=" << panStr; - throw ex; - } - if(!utils::isValidUInt(drvStr)) { - cta::exception::InvalidArgument ex; - ex.getMessage() << errMsg << ": TRANSPORT_NUMBER must be an unsigned" - " integer: value=" << drvStr; - throw ex; - } - - return new AcsLibrarySlot( - atoi(acsStr.c_str()), - atoi(lsmStr.c_str()), - atoi(panStr.c_str()), - atoi(drvStr.c_str())); -} - //------------------------------------------------------------------------------ // parseManualLibrarySlot //------------------------------------------------------------------------------ diff --git a/mediachanger/LibrarySlotParser.hpp b/mediachanger/LibrarySlotParser.hpp index 0bf9a5168e962e012530ef9daf47a65e545d4bfc..b8dbd5a681fbc5ea74b0b48e25f264c8247c7b9e 100644 --- a/mediachanger/LibrarySlotParser.hpp +++ b/mediachanger/LibrarySlotParser.hpp @@ -19,7 +19,6 @@ #pragma once #include "mediachanger/LibrarySlot.hpp" -#include "mediachanger/AcsLibrarySlot.hpp" #include "mediachanger/ManualLibrarySlot.hpp" #include "mediachanger/ScsiLibrarySlot.hpp" @@ -66,14 +65,6 @@ private: static cta::mediachanger::TapeLibraryType getLibrarySlotType( const std::string &str); - /** - * Returns true if the type of the specified tape library slot is ACS. - * - * @param str The string representation of the tape library slot. - * @return True if the type if the library slot is ACS. - */ - static bool isAcs(const std::string &str); - /** * Returns true if the type of the specified tape library slot is manual. * @@ -102,14 +93,6 @@ private: const cta::mediachanger::TapeLibraryType libraryType, const std::string &str); - /** - * Parses the specified string representation of an ACS library slot. - * - * @param str The string representation of the tape library slot. - */ - static cta::mediachanger::AcsLibrarySlot *parseAcsLibrarySlot( - const std::string &str); - /** * Parses the specified string representation of a manual library slot. * diff --git a/mediachanger/LibrarySlotParserTest.cpp b/mediachanger/LibrarySlotParserTest.cpp index 1c949f0076f4c6e8ac7b1e11275838edf43464ff..fc4720709a4d5587e8888a066d648c1bff2ac568 100644 --- a/mediachanger/LibrarySlotParserTest.cpp +++ b/mediachanger/LibrarySlotParserTest.cpp @@ -34,15 +34,6 @@ protected: } }; -TEST_F(cta_mediachanger_LibrarySlotParserTest, acs) { - using namespace cta::mediachanger; - - std::unique_ptr<LibrarySlot> slot; - ASSERT_NO_THROW(slot.reset(LibrarySlotParser::parse("acs1,2,3,4"))); - ASSERT_NE((LibrarySlot*)0, slot.get()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, slot->getLibraryType()); -} - TEST_F(cta_mediachanger_LibrarySlotParserTest, manual) { using namespace cta::mediachanger; diff --git a/mediachanger/MediaChangerExceptionMsg.proto b/mediachanger/MediaChangerExceptionMsg.proto deleted file mode 100644 index ef8201b16997681e5279b7bbce1362626e64cd86..0000000000000000000000000000000000000000 --- a/mediachanger/MediaChangerExceptionMsg.proto +++ /dev/null @@ -1,26 +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/>. -// -syntax = "proto2"; -package cta.mediachanger; - -message MediaChangerExceptionMsg { - // The error code - required uint32 code = 1; - - // The error message - required string message = 2; -} diff --git a/mediachanger/MediaChangerFacade.cpp b/mediachanger/MediaChangerFacade.cpp index b6b8d2a08c17cc46a1824fc0ed4bff1a5c4d2710..9a686409da434bd87ca276a7b8e95c3d3b25487b 100644 --- a/mediachanger/MediaChangerFacade.cpp +++ b/mediachanger/MediaChangerFacade.cpp @@ -91,8 +91,6 @@ void MediaChangerFacade::forceDismountTape(const std::string &vid, const Library MediaChangerProxy &MediaChangerFacade::getProxy(const TapeLibraryType libraryType) { try { switch(libraryType) { - case TAPE_LIBRARY_TYPE_ACS: - return m_acsProxy; case TAPE_LIBRARY_TYPE_MANUAL: return m_mmcProxy; case TAPE_LIBRARY_TYPE_SCSI: diff --git a/mediachanger/MediaChangerFacade.hpp b/mediachanger/MediaChangerFacade.hpp index 63eae5442005363bba9dcc914343e16c05e058b4..eac2cd3a2a8c83332b1b413025b2affdd8799c43 100644 --- a/mediachanger/MediaChangerFacade.hpp +++ b/mediachanger/MediaChangerFacade.hpp @@ -19,7 +19,6 @@ #pragma once #include "common/log/Logger.hpp" -#include "mediachanger/AcsProxy.hpp" #include "mediachanger/LibrarySlot.hpp" #include "mediachanger/MediaChangerProxy.hpp" #include "mediachanger/MmcProxy.hpp" @@ -91,11 +90,6 @@ public: private: - /** - * ACS media changer proxy. - */ - AcsProxy m_acsProxy; - /** * Manual media changer proxy. */ diff --git a/mediachanger/MediaChangerHeader.proto b/mediachanger/MediaChangerHeader.proto deleted file mode 100644 index ecaf3534765d3c43dc0ef0db2eb5e246b32dff93..0000000000000000000000000000000000000000 --- a/mediachanger/MediaChangerHeader.proto +++ /dev/null @@ -1,39 +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/>. -// -syntax = "proto2"; -package cta.mediachanger; - -message MediaChangerHeader { - required uint32 magic = 1; - - //see castor::messages::protocolType's anonymous enum for values - required uint32 protocoltype = 2; - - //see castor::messages::protocolVersion's anonymous enum for values - required uint32 protocolversion = 3; - - //see castor::messages::msgType's anonymous enum for values - required uint32 msgtype = 4; - - //will it be hardcoded to SHA1 ? - required string bodyhashtype = 5; - required string bodyhashValue = 6; - - - required string bodysignaturetype= 7; - required string bodysignature = 8; -} diff --git a/mediachanger/MediaChangerReturnValue.proto b/mediachanger/MediaChangerReturnValue.proto deleted file mode 100644 index b2a3272294235e99a2274bd396f499a8a5f72e24..0000000000000000000000000000000000000000 --- a/mediachanger/MediaChangerReturnValue.proto +++ /dev/null @@ -1,22 +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/>. -// -syntax = "proto2"; -package cta.mediachanger; - -message MediaChangerReturnValue { - required uint32 value = 1; -} diff --git a/mediachanger/MountCmdLineTest.cpp b/mediachanger/MountCmdLineTest.cpp index a2a970d9e5f03f5476f2e49c0807568c2fe95cc4..8977692add55916d178ef7f9139ed4b0cae6591c 100644 --- a/mediachanger/MountCmdLineTest.cpp +++ b/mediachanger/MountCmdLineTest.cpp @@ -66,30 +66,6 @@ protected: } }; -TEST_F(cta_mediachanger_MountCmdLineTest, acs) { - using namespace cta::mediachanger; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("cta-mediachanger-mount"); - args->argv[1] = dupString("vid"); - args->argv[2] = dupString("acs1,2,3,4"); - args->argv[3] = NULL; - - std::unique_ptr<MountCmdLine> cmdLine; - ASSERT_NO_THROW(cmdLine.reset(new MountCmdLine(args->argc, args->argv))); - - ASSERT_FALSE(cmdLine->getHelp()); - ASSERT_FALSE(cmdLine->getDebug()); - ASSERT_FALSE(cmdLine->getReadOnly()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine->getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs1,2,3,4"), - cmdLine->getDriveLibrarySlot().str()); -} - TEST_F(cta_mediachanger_MountCmdLineTest, copy_constructor) { using namespace cta::mediachanger; @@ -99,26 +75,22 @@ TEST_F(cta_mediachanger_MountCmdLineTest, copy_constructor) { args->argv = new char *[4]; args->argv[0] = dupString("cta-mediachanger-mount"); args->argv[1] = dupString("vid"); - args->argv[2] = dupString("acs1,2,3,4"); + args->argv[2] = dupString("smc1"); args->argv[3] = NULL; MountCmdLine cmdLine1(args->argc, args->argv); ASSERT_FALSE(cmdLine1.getHelp()); ASSERT_FALSE(cmdLine1.getDebug()); ASSERT_FALSE(cmdLine1.getReadOnly()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine1.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs1,2,3,4"), - cmdLine1.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine1.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc1"), cmdLine1.getDriveLibrarySlot().str()); MountCmdLine cmdLine2(cmdLine1); ASSERT_FALSE(cmdLine2.getHelp()); ASSERT_FALSE(cmdLine2.getDebug()); ASSERT_FALSE(cmdLine2.getReadOnly()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine2.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs1,2,3,4"), - cmdLine2.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine2.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc1"), cmdLine2.getDriveLibrarySlot().str()); } TEST_F(cta_mediachanger_MountCmdLineTest, assignment) { @@ -130,17 +102,15 @@ TEST_F(cta_mediachanger_MountCmdLineTest, assignment) { args1->argv = new char *[4]; args1->argv[0] = dupString("cta-mediachanger-mount"); args1->argv[1] = dupString("vid"); - args1->argv[2] = dupString("acs1,2,3,4"); + args1->argv[2] = dupString("smc1"); args1->argv[3] = NULL; MountCmdLine cmdLine1(args1->argc, args1->argv); ASSERT_FALSE(cmdLine1.getHelp()); ASSERT_FALSE(cmdLine1.getDebug()); ASSERT_FALSE(cmdLine1.getReadOnly()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine1.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs1,2,3,4"), - cmdLine1.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine1.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc1"), cmdLine1.getDriveLibrarySlot().str()); Argcv *args2 = new Argcv(); m_argsList.push_back(args2); @@ -148,35 +118,29 @@ TEST_F(cta_mediachanger_MountCmdLineTest, assignment) { args2->argv = new char *[4]; args2->argv[0] = dupString("cta-mediachanger-mount"); args2->argv[1] = dupString("vid"); - args2->argv[2] = dupString("acs5,6,7,8"); + args2->argv[2] = dupString("smc2"); args2->argv[3] = NULL; MountCmdLine cmdLine2(args2->argc, args2->argv); ASSERT_FALSE(cmdLine2.getHelp()); ASSERT_FALSE(cmdLine2.getDebug()); ASSERT_FALSE(cmdLine2.getReadOnly()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine2.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs5,6,7,8"), - cmdLine2.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine2.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc2"), cmdLine2.getDriveLibrarySlot().str()); cmdLine1 = cmdLine2; ASSERT_FALSE(cmdLine1.getHelp()); ASSERT_FALSE(cmdLine1.getDebug()); ASSERT_FALSE(cmdLine1.getReadOnly()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine1.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs5,6,7,8"), - cmdLine1.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine1.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc2"), cmdLine1.getDriveLibrarySlot().str()); ASSERT_FALSE(cmdLine2.getHelp()); ASSERT_FALSE(cmdLine2.getDebug()); ASSERT_FALSE(cmdLine2.getReadOnly()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_ACS, - cmdLine2.getDriveLibrarySlot().getLibraryType()); - ASSERT_EQ(std::string("acs5,6,7,8"), - cmdLine2.getDriveLibrarySlot().str()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine2.getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(std::string("smc2"), cmdLine2.getDriveLibrarySlot().str()); } TEST_F(cta_mediachanger_MountCmdLineTest, scsi) { @@ -197,8 +161,7 @@ TEST_F(cta_mediachanger_MountCmdLineTest, scsi) { ASSERT_FALSE(cmdLine->getHelp()); ASSERT_FALSE(cmdLine->getDebug()); ASSERT_FALSE(cmdLine->getReadOnly()); - ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, - cmdLine->getDriveLibrarySlot().getLibraryType()); + ASSERT_EQ(TAPE_LIBRARY_TYPE_SCSI, cmdLine->getDriveLibrarySlot().getLibraryType()); } } // namespace unitTests diff --git a/mediachanger/MountCmdMain.cpp b/mediachanger/MountCmdMain.cpp index fa88e77fe9c7b821e2fcbeba54029db466c7ec60..cab8f62b1e5f6d92460e569ea39e00fcee6803bb 100644 --- a/mediachanger/MountCmdMain.cpp +++ b/mediachanger/MountCmdMain.cpp @@ -23,9 +23,7 @@ #include "mediachanger/MountCmdLine.hpp" #include <exception> -#include <google/protobuf/stubs/common.h> #include <iostream> -#include <zmq.h> /** * An exception throwing version of main(). @@ -45,7 +43,6 @@ int main(const int argc, char *const *const argv) { try { const int rc = exceptionThrowingMain(argc, argv); - google::protobuf::ShutdownProtobufLibrary(); return rc; } catch(cta::exception::Exception &ex) { errorMessage = ex.getMessage().str(); @@ -59,7 +56,6 @@ int main(const int argc, char *const *const argv) { // and errorMessage has been set accordingly std::cerr << "Aborting: " << errorMessage << std::endl; - google::protobuf::ShutdownProtobufLibrary(); return 1; } diff --git a/mediachanger/ReturnValue.proto b/mediachanger/ReturnValue.proto deleted file mode 100644 index 4f34c3ffbaab132f1f81ebc51caf90ccaa1dfd67..0000000000000000000000000000000000000000 --- a/mediachanger/ReturnValue.proto +++ /dev/null @@ -1,23 +0,0 @@ -// 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 -syntax = "proto2"; -package cta.mediachanger; - -message ReturnValue { - required uint32 value = 1; -} diff --git a/mediachanger/TapeLibraryType.cpp b/mediachanger/TapeLibraryType.cpp index dfd0f90d89ac437a0b00b901ce81a31d5a7b2b7c..1b5166463faf877ca020186217efce2b5e861f1c 100644 --- a/mediachanger/TapeLibraryType.cpp +++ b/mediachanger/TapeLibraryType.cpp @@ -25,7 +25,6 @@ const char *cta::mediachanger::tapeLibraryTypeToString( const TapeLibraryType libraryType) { switch(libraryType) { case TAPE_LIBRARY_TYPE_NONE : return "NONE"; - case TAPE_LIBRARY_TYPE_ACS : return "ACS"; case TAPE_LIBRARY_TYPE_MANUAL: return "MANUAL"; case TAPE_LIBRARY_TYPE_SCSI : return "SCSI"; default : return "UNKNOWN"; diff --git a/mediachanger/TapeLibraryType.hpp b/mediachanger/TapeLibraryType.hpp index 4b9a752ad35d9db213f57398ee1e046114ab53d8..be7d1fd1c2993a0307aff0eff68bd4c32e57d13c 100644 --- a/mediachanger/TapeLibraryType.hpp +++ b/mediachanger/TapeLibraryType.hpp @@ -26,7 +26,6 @@ namespace mediachanger { */ enum TapeLibraryType { TAPE_LIBRARY_TYPE_NONE, - TAPE_LIBRARY_TYPE_ACS, TAPE_LIBRARY_TYPE_MANUAL, TAPE_LIBRARY_TYPE_SCSI}; diff --git a/mediachanger/ZmqContextSingleton.cpp b/mediachanger/ZmqContextSingleton.cpp deleted file mode 100644 index c429fcc9b99a7d6a6b33818851199e94c75d0e31..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqContextSingleton.cpp +++ /dev/null @@ -1,68 +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 "ZmqContextSingleton.hpp" -#include "common/exception/Exception.hpp" -#include "common/threading/MutexLocker.hpp" -#include "common/utils/utils.hpp" - -#include <zmq.h> - -namespace cta { -namespace mediachanger { - -//------------------------------------------------------------------------------ -// s_mutex -//------------------------------------------------------------------------------ -threading::Mutex ZmqContextSingleton::s_mutex; - -//------------------------------------------------------------------------------ -// s_instance -//------------------------------------------------------------------------------ -void *ZmqContextSingleton::s_instance = nullptr; - -//------------------------------------------------------------------------------ -// instance -//------------------------------------------------------------------------------ -void *ZmqContextSingleton::instance() { - try { - threading::MutexLocker locker(s_mutex); - - if(nullptr == s_instance) { - const int sizeOfIOThreadPoolForZMQ = 1; - s_instance = zmq_init(sizeOfIOThreadPoolForZMQ); - const int savedErrno = errno; - - if(nullptr == s_instance) { - const std::string message = utils::errnoToString(savedErrno); - exception::Exception ex; - ex.getMessage() << "Call to zmq_init(sizeOfIOThreadPoolForZMQ=" << sizeOfIOThreadPoolForZMQ << ") failed: " << - message; - throw ex; - } - } - return s_instance; - } catch(exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } catch(std::exception &se) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + se.what()); - } -} - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/ZmqContextSingleton.hpp b/mediachanger/ZmqContextSingleton.hpp deleted file mode 100644 index dd9653200ed19d3841059e008d7adb2d907ab48b..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqContextSingleton.hpp +++ /dev/null @@ -1,77 +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 "common/threading/Mutex.hpp" - -#include <memory> - -namespace cta { -namespace mediachanger { - -/** - * A singleton version of a ZMQ context. - * - * Please note that this class INTENTIONALLY does NOT terminate the ZMQ context - * because ZMQ sends an abort on exit when cleaned up this way under some - * circumstances, so we purposely do not clean up the context (zmq_term) and - * leave a resource leak, which in our use case is a one-off situation per - * process. - */ -class ZmqContextSingleton { -public: - - /** - * Returns the single instance of the ZMQ context. - */ - static void *instance(); - - /** - * It should not be possible to make instances of this class. - */ - ZmqContextSingleton() = delete; - - /** - * It should not be possible to copy instances of this class. - */ - ZmqContextSingleton(const ZmqContextSingleton &) = delete; - - /** - * It should not be possible to assign instances of this class. - */ - void operator=(const ZmqContextSingleton &) = delete; - -private: - - /** - * Mutex used to implement a critical region around the implementation of the - * instance() method. - */ - static threading::Mutex s_mutex; - - /** - * The single instance of a ZMQ context. A value of NULL means the ZMQ - * context has not yet been created. - */ - static void *s_instance; - -}; // class ZmqContextSingleton - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/ZmqMsg.cpp b/mediachanger/ZmqMsg.cpp deleted file mode 100644 index 1a75d2c3200e9e848163669b4e9f4857836b3847..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqMsg.cpp +++ /dev/null @@ -1,90 +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/messages.hpp" -#include "mediachanger/ZmqMsg.hpp" - -#include <errno.h> -#include <unistd.h> - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::ZmqMsg::ZmqMsg() { - if(zmq_msg_init(&m_zmqMsg)) { - const int savedErrno = errno; - cta::exception::Exception ex; - ex.getMessage() << "zmq_msg_init() failed: " << zmqErrnoToStr(savedErrno); - throw ex; - } -} - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::ZmqMsg::ZmqMsg(const size_t msgSize) { - if(zmq_msg_init_size(&m_zmqMsg, msgSize)) { - const int savedErrno = errno; - cta::exception::Exception ex; - ex.getMessage() << "zmq_msg_init_size() failed: " << - zmqErrnoToStr(savedErrno); - throw ex; - } -} - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -cta::mediachanger::ZmqMsg::~ZmqMsg() { - zmq_msg_close(&m_zmqMsg); -} - -//----------------------------------------------------------------------------- -// getZmqMsg -//----------------------------------------------------------------------------- -zmq_msg_t &cta::mediachanger::ZmqMsg::getZmqMsg() { - return m_zmqMsg; -} - -//----------------------------------------------------------------------------- -// getData -//----------------------------------------------------------------------------- -const void* cta::mediachanger::ZmqMsg::getData() const { - return zmq_msg_data(const_cast<zmq_msg_t*>(&m_zmqMsg)); -} - -//----------------------------------------------------------------------------- -// getData -//----------------------------------------------------------------------------- -void* cta::mediachanger::ZmqMsg::getData() { - return zmq_msg_data(&m_zmqMsg); -} - -//----------------------------------------------------------------------------- -// size -//----------------------------------------------------------------------------- -size_t cta::mediachanger::ZmqMsg::size() const { - return zmq_msg_size(const_cast<zmq_msg_t*>(&m_zmqMsg)); -} - -//----------------------------------------------------------------------------- -// more -//----------------------------------------------------------------------------- -bool cta::mediachanger::ZmqMsg::more() const { - return zmq_msg_more(const_cast<zmq_msg_t*>(&m_zmqMsg)); -} diff --git a/mediachanger/ZmqMsg.hpp b/mediachanger/ZmqMsg.hpp deleted file mode 100644 index 0e1345689a45569fbdbfb1bc2b8b5cd9e0386e6d..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqMsg.hpp +++ /dev/null @@ -1,109 +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 "common/exception/NotAnOwner.hpp" - -#include <stdio.h> -#include <zmq.h> - - -namespace cta { -namespace mediachanger { - -/** - * C++ wrapper around a ZMQ message. - */ -class ZmqMsg { - -public: - - /** - * Constructor. - */ - ZmqMsg(); - - /** - * Constructor. - * - * @param msgSize The size of the ZMQ message. - */ - ZmqMsg(const size_t msgSize); - - /** - * Destructor. - * - * Calls zmq_msg_close(). - */ - ~ZmqMsg(); - - /** - * Returns the enclosed ZMQ message. - * - * @return The underlying ZMQ message. - */ - zmq_msg_t &getZmqMsg(); - - /** - * Gives read access to the data of the enclosed ZMQ message. - * - * @return A pointer to the beginning of the data - */ - const void* getData() const; - - /** - * Gives read/write access to the data of the enclosed ZMQ message. - * - * @return A pointer to the beginning of the data - */ - void* getData(); - - /** - * Gets the size of the enclosed ZMQ message. - * - * @return The size of the ZMQ message. - */ - size_t size() const; - - /** - * Returns true if the enclosed ZMQ message is part of a multi-part message - * and there are more parts to receive. - */ - bool more() const; - -private: - - /** - * The enclosed ZMQ message. - */ - zmq_msg_t m_zmqMsg; - - /** - * Private copy-constructor to prevent users from trying to create a new - * copy of an object of this class. - * - * Not implemented so that it cannot be called - */ - ZmqMsg(const ZmqMsg &obj); - -}; // class ZmqMsg - -} // namespace mediachanger -} // namespace cta - diff --git a/mediachanger/ZmqSocket.cpp b/mediachanger/ZmqSocket.cpp deleted file mode 100644 index 85a21f57a338efbbd0712bb86bf539e06f3228e3..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqSocket.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 "ZmqSocket.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::ZmqSocket::ZmqSocket() { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::ZmqSocket::~ZmqSocket() { -} diff --git a/mediachanger/ZmqSocket.hpp b/mediachanger/ZmqSocket.hpp deleted file mode 100644 index 1ec46edbf00b91cce2d0a257d002aef397eb7b98..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqSocket.hpp +++ /dev/null @@ -1,118 +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 "ZmqMsg.hpp" - -#include <string> -#include <zmq.h> - -namespace cta { -namespace mediachanger { - -/** - * Abstract C++ class that defines the interace of a wrapper around a ZMQ - * socket. - */ -class ZmqSocket { -public: - /** - * Constructor. - */ - ZmqSocket(); - - /** - * Destructor. - */ - virtual ~ZmqSocket() = 0; - - /** - * Closes the ZMQ socket. - */ - virtual void close() = 0; - - /** - * Binds the ZMQ socket to the specified endpoint. - * - * @param endpoint The endpoint to bind to. - */ - virtual void bind(const std::string &endpoint) = 0; - - /** - * Connects the socket to the spedicied endpoint. - * - * @param endpoint The endpoint to connect to. - */ - virtual void connect(const std::string &endpoint) = 0; - - /** - * Sends the specified ZMQ message over the socket. - * - * @param msg The ZMQ messge to be sent. - * @param flags See manual page of zmq_msg_send(). - */ - virtual void send(ZmqMsg &msg, const int flags = 0) = 0; - - /** - * Sends the specified ZMQ message over the socket. - * - * @param msg The ZMQ messge to be sent. - * @param flags See manual page of zmq_msg_send(). - */ - virtual void send(zmq_msg_t *const msg, const int flags = 0) = 0; - - /** - * Receives a ZMQ mesage from the socket. - * - * @param msg Output parameter: The received ZMQ messge. - * @param flags See manual page of zmq_msg_send(). - */ - virtual void recv(ZmqMsg &msg, const int flags = 0) = 0; - - /** - * Receives a ZMQ mesage from the socket. - * - * @param msg Output parameter: The received ZMQ messge. - * @param flags See manual page of zmq_msg_send(). - */ - virtual void recv(zmq_msg_t *const msg, const int flags = 0) = 0; - - /** - * Returns the ZMQ socket wrappeed by this class. - * - * @return The ZMQ socket wrappeed by this class. - */ - virtual void *getZmqSocket() const = 0; - -private: - - /** - * Copy constructor made private to prevent copies. - */ - ZmqSocket(const ZmqSocket&); - - /** - * Assignment operator made private to prevent assignments. - */ - void operator=(const ZmqSocket &); - -}; // class ZmqSocket - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/ZmqSocketMT.cpp b/mediachanger/ZmqSocketMT.cpp deleted file mode 100644 index a29f3f38284d5a9d0beb54e73b52b6feca0c92d6..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqSocketMT.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/****************************************************************************** - * - * 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 "common/exception/Exception.hpp" -#include "common/threading/MutexLocker.hpp" -#include "common/threading/Mutex.hpp" -#include "ZmqSocketMT.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::ZmqSocketMT::ZmqSocketMT(void *const zmqContext, - const int socketType): m_socket(zmqContext, socketType) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::ZmqSocketMT::~ZmqSocketMT() { - try { - close(); - } catch(...) { - // Ignore any exceptions because this is a destructor. - } -} - -//------------------------------------------------------------------------------ -// close -//------------------------------------------------------------------------------ -void cta::mediachanger::ZmqSocketMT::close() { - cta::threading::MutexLocker lock(cta::threading::Mutex &m_mutex); - m_socket.close(); -} - -//------------------------------------------------------------------------------ -// bind -//------------------------------------------------------------------------------ -void cta::mediachanger::ZmqSocketMT::bind (const std::string &endpoint) { - cta::threading::MutexLocker lock(cta::threading::Mutex &m_mutex); - m_socket.bind(endpoint); -} - -//------------------------------------------------------------------------------ -// connect -//------------------------------------------------------------------------------ -void cta::mediachanger::ZmqSocketMT::connect(const std::string &endpoint) { - cta::threading::MutexLocker lock(cta::threading::Mutex &m_mutex); - m_socket.connect(endpoint); -} - -//------------------------------------------------------------------------------ -// send -//------------------------------------------------------------------------------ -void cta::mediachanger::ZmqSocketMT::send(ZmqMsg &msg, const int flags) { - cta::threading::MutexLocker lock(cta::threading::Mutex &m_mutex); - m_socket.send(msg, flags); -} - -//------------------------------------------------------------------------------ -// send -//------------------------------------------------------------------------------ -void cta::mediachanger::ZmqSocketMT::send(zmq_msg_t *const msg, - const int flags) { - cta::threading::MutexLocker lock(cta::threading::Mutex &m_mutex); - m_socket.send(msg, flags); -} - -//------------------------------------------------------------------------------ -// recv -//------------------------------------------------------------------------------ -void cta::mediachanger::ZmqSocketMT::recv(ZmqMsg &msg, const int flags) { - cta::threading::MutexLocker lock(cta::threading::Mutex &m_mutex); - m_socket.recv(msg, flags); -} - -//------------------------------------------------------------------------------ -// recv -//------------------------------------------------------------------------------ -void cta::mediachanger::ZmqSocketMT::recv(zmq_msg_t *const msg, int flags) { - cta::threading::MutexLocker lock(cta::threading::Mutex &m_mutex); - m_socket.recv(msg, flags); -} - -//------------------------------------------------------------------------------ -// getZmqSocket -//------------------------------------------------------------------------------ -void *cta::mediachanger::ZmqSocketMT::getZmqSocket() const { - return m_socket.getZmqSocket(); -} diff --git a/mediachanger/ZmqSocketMT.hpp b/mediachanger/ZmqSocketMT.hpp deleted file mode 100644 index 476a663df0f1001f53394a047c25ed3490d39ecd..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqSocketMT.hpp +++ /dev/null @@ -1,138 +0,0 @@ -/****************************************************************************** - * - * 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 "common/threading/Mutex.hpp" -#include "ZmqSocket.hpp" -#include "ZmqSocketST.hpp" - -#include <pthread.h> -#include <string> -#include <zmq.h> - -namespace cta { -namespace mediachanger { - -/** - * A "Multi-Threaded" ZMQ socket. - * - * This concrete C++ class wraps a ZMQ socket and provides a thread safe - * interface by acting as a monitor. If a single-threaded use is required then - * the ZmqSocketST class should be used instead. - * - * Please note that the getZmqSocket() method is not thread safe. - */ -class ZmqSocketMT: public ZmqSocket { -public: - - /** - * Constructor. - * - * @param zmqContext The ZMQ context. - * @param socketType The type of the ZMQ socket. - */ - ZmqSocketMT(void *const zmqContext, const int socketType); - - /** - * Destructor. - */ - ~ZmqSocketMT(); - - /** - * Closes the ZMQ socket. - */ - void close(); - - /** - * Binds the ZMQ socket to the specified endpoint. - * - * @param endpoint The endpoint to bind to. - */ - void bind(const std::string &endpoint); - - /** - * Connects the socket to the spedicied endpoint. - * - * @param endpoint The endpoint to connect to. - */ - void connect(const std::string &endpoint); - - /** - * Sends the specified ZMQ message over the socket. - * - * @param msg The ZMQ messge to be sent. - * @param flags See manual page of zmq_msg_send(). - */ - void send(ZmqMsg &msg, const int flags = 0); - - /** - * Sends the specified ZMQ message over the socket. - * - * @param msg The ZMQ messge to be sent. - * @param flags See manual page of zmq_msg_send(). - */ - void send(zmq_msg_t *const msg, const int flags = 0); - - /** - * Receives a ZMQ mesage from the socket. - * - * @param msg Output parameter: The received ZMQ messge. - * @param flags See manual page of zmq_msg_send(). - */ - void recv(ZmqMsg &msg, const int flags = 0); - - /** - * Receives a ZMQ mesage from the socket. - * - * @param msg Output parameter: The received ZMQ messge. - * @param flags See manual page of zmq_msg_send(). - */ - void recv(zmq_msg_t *const msg, const int flags = 0); - - /** - * Returns the ZMQ socket wrappeed by this class. - * - * Please note that the getZmqSocket() method is not thread safe. - * - * @return The ZMQ socket wrappeed by this class. - */ - void *getZmqSocket() const; - -private: - - /** - * Mutex used to implement a critical section around the enclosed - * ZMQ socket. - */ - cta::threading::Mutex m_mutex; - - /** - * The non thread-safe socket to be protected. - */ - ZmqSocketST m_socket; - -}; // class ZmqSocketMT - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/ZmqSocketST.cpp b/mediachanger/ZmqSocketST.cpp deleted file mode 100644 index 664c63142588d920ad0ec91469bdc17bc17e562e..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqSocketST.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/****************************************************************************** - * - * 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 "common/exception/Exception.hpp" -#include "messages.hpp" -#include "ZmqSocketST.hpp" -#include "ZmqSocket.hpp" - -namespace cta { -namespace mediachanger { -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -ZmqSocketST::ZmqSocketST(void *const zmqContext, const int socketType) { - m_zmqSocket = zmq_socket (zmqContext, socketType); - if (NULL == m_zmqSocket) { - const int savedErrno = errno; - cta::exception::Exception ex; - ex.getMessage() << "zmq_socket() failed: " << zmqErrnoToStr(savedErrno); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -ZmqSocketST::~ZmqSocketST() { - try { - close(); - } catch(...) { - // Ignore any exceptions because this is a destructor. - } -} - -//------------------------------------------------------------------------------ -// close -//------------------------------------------------------------------------------ -void ZmqSocketST::close() { - if(m_zmqSocket == NULL) { - return; - } - - if(zmq_close(m_zmqSocket)) { - const int savedErrno = errno; - cta::exception::Exception ex; - ex.getMessage() << "zmq_close() failed: " << zmqErrnoToStr(savedErrno); - throw ex; - } - m_zmqSocket = NULL; -} - -//------------------------------------------------------------------------------ -// bind -//------------------------------------------------------------------------------ -void ZmqSocketST::bind (const std::string &endpoint) { - if(zmq_bind(m_zmqSocket, endpoint.c_str())) { - const int savedErrno = errno; - cta::exception::Exception ex; - ex.getMessage() << "zmq_bind failed(): " << zmqErrnoToStr(savedErrno); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// connect -//------------------------------------------------------------------------------ -void ZmqSocketST::connect(const std::string &endpoint) { - if(zmq_connect(m_zmqSocket, endpoint.c_str())) { - const int savedErrno = errno; - cta::exception::Exception ex; - ex.getMessage() << "zmq_connect() failed: " << zmqErrnoToStr(savedErrno); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// send -//------------------------------------------------------------------------------ -void ZmqSocketST::send(ZmqMsg &msg, const int flags) { - send(&msg.getZmqMsg(), flags); -} - -//------------------------------------------------------------------------------ -// send -//------------------------------------------------------------------------------ -void ZmqSocketST::send(zmq_msg_t *const msg, const int flags) { - if(-1 == zmq_msg_send(msg, m_zmqSocket, flags)) { - const int savedErrno = errno; - cta::exception::Exception ex; - ex.getMessage() << "zmq_msg_send() failed: " << zmqErrnoToStr(savedErrno); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// recv -//------------------------------------------------------------------------------ -void ZmqSocketST::recv(ZmqMsg &msg, const int flags) { - recv(&msg.getZmqMsg(), flags); -} - -//------------------------------------------------------------------------------ -// recv -//------------------------------------------------------------------------------ -void ZmqSocketST::recv(zmq_msg_t *const msg, int flags) { - if(-1 == zmq_msg_recv (msg, m_zmqSocket, flags)) { - const int savedErrno = errno; - cta::exception::Exception ex; - ex.getMessage() << "zmq_msg_recv() failed: " << zmqErrnoToStr(savedErrno); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// getZmqSocket -//------------------------------------------------------------------------------ -void *ZmqSocketST::getZmqSocket() const { - return m_zmqSocket; -} - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/ZmqSocketST.hpp b/mediachanger/ZmqSocketST.hpp deleted file mode 100644 index 598fca1f0d37e880aa62ae3fea820997651043c8..0000000000000000000000000000000000000000 --- a/mediachanger/ZmqSocketST.hpp +++ /dev/null @@ -1,135 +0,0 @@ -/****************************************************************************** - * - * 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/messages/ZmqSocket.hpp" -//#include "ZmqSocket.hpp" -#include "mediachanger/ZmqMsg.hpp" - -namespace cta { -namespace mediachanger { - -/** - - * A "Single-Threaded" ZMQ socket. - * - * This concrete C++ class wraps a ZMQ socket. This class is intended for - * single-thread use. If a multi-threaded use is required then the ZmqSocketMT - * class should be used instead. - */ -class ZmqSocketST: public ZmqSocket { -public: - - /** - * Constructor. - * - * @param zmqContext The ZMQ context. - * @param socketType The type of the ZMQ socket. - */ - ZmqSocketST(void *const zmqContext, const int socketType); - - /** - * Destructor. - */ - ~ZmqSocketST(); - - /** - * Closes the ZMQ socket. - */ - void close(); - - /** - * Binds the ZMQ socket to the specified endpoint. - * - * @param endpoint The endpoint to bind to. - */ - void bind(const std::string &endpoint); - - /** - * Connects the socket to the spedicied endpoint. - * - * @param endpoint The endpoint to connect to. - */ - void connect(const std::string &endpoint); - - /** - * Sends the specified ZMQ message over the socket. - * - * @param msg The ZMQ messge to be sent. - * @param flags See manual page of zmq_msg_send(). - */ - void send(ZmqMsg &msg, const int flags = 0); - - /** - * Sends the specified ZMQ message over the socket. - * - * @param msg The ZMQ messge to be sent. - * @param flags See manual page of zmq_msg_send(). - */ - void send(zmq_msg_t *const msg, const int flags = 0); - - /** - * Receives a ZMQ mesage from the socket. - * - * @param msg Output parameter: The received ZMQ messge. - * @param flags See manual page of zmq_msg_send(). - */ - void recv(ZmqMsg &msg, const int flags = 0); - - /** - * Receives a ZMQ mesage from the socket. - * - * @param msg Output parameter: The received ZMQ messge. - * @param flags See manual page of zmq_msg_send(). - */ - void recv(zmq_msg_t *const msg, const int flags = 0); - - /** - * Returns the ZMQ socket wrappeed by this class. - * - * @return The ZMQ socket wrappeed by this class. - */ - void *getZmqSocket() const; - -private: - - /** - * The ZMQ socket. - */ - void *m_zmqSocket; - - /** - * Copy constructor made private to prevent copies. - */ - ZmqSocketST(const ZmqSocketST&); - - /** - * Assignment operator made private to prevent assignments. - */ - void operator=(const ZmqSocketST &); - -}; // class ZmqSocketST - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/messages.cpp b/mediachanger/messages.cpp deleted file mode 100644 index e2fd5a7ffc31c4c87e0916afef8bd50559d0ee0c..0000000000000000000000000000000000000000 --- a/mediachanger/messages.cpp +++ /dev/null @@ -1,286 +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/MediaChangerExceptionMsg.pb.h" -#include "mediachanger/messages.hpp" -#include "common/utils/strerror_r_wrapper.hpp" - -#include <string> -#include <string.h> -#include <zmq.h> - -namespace cta { -namespace mediachanger { - -//------------------------------------------------------------------------------ -// sendFrame -//------------------------------------------------------------------------------ -void sendFrame(ZmqSocket &socket, const Frame &frame) { - try { - // Prepare header - ZmqMsg header(frame.header.ByteSize()); - frame.serializeHeaderToZmqMsg(header); - - // Prepare body - ZmqMsg body(frame.body.length()); - memcpy(body.getData(), frame.body.c_str(), body.size()); - - // Send header and body as a two part ZMQ message - socket.send(header, ZMQ_SNDMORE); - socket.send(body, 0); - - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to send message frame: " << - ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// recvFrame -//------------------------------------------------------------------------------ -Frame recvFrame(ZmqSocket &socket) { - try { - ZmqMsg header; - try { - socket.recv(header); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to receive header of message frame: " << - ne.getMessage().str(); - throw ex; - } - - if(!header.more()){ - cta::exception::Exception ex; - ex.getMessage() << "No message body after receiving the header"; - throw ex; - } - - Frame frame; - frame.parseZmqMsgIntoHeader(header); - - ZmqMsg body; - try { - socket.recv(body); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to receive body of message frame: " << - ne.getMessage().str(); - throw ex; - } - - frame.body = std::string((const char *)body.getData(), body.size()); - - frame.checkHashValueOfBody(); - - return frame; - - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to receive message frame: " << - ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// connectZmqSocketToLocalhost -//------------------------------------------------------------------------------ -void connectZmqSocketToLocalhost(ZmqSocket &socket, - const int port) { - std::string bindingAdress("tcp://127.0.0.1:"); - bindingAdress += std::to_string(port); - socket.connect(bindingAdress.c_str()); -} - -//------------------------------------------------------------------------------ -// preFillHeader -//------------------------------------------------------------------------------ -MediaChangerHeader protoTapePreFillHeader() { - return genericPreFillHeader<TPMAGIC, PROTOCOL_TYPE_TAPE, - PROTOCOL_VERSION_1>(); -} - -//------------------------------------------------------------------------------ -// computeSHA1Base64 -//------------------------------------------------------------------------------ -std::string computeSHA1Base64(const std::string &data) { - return computeSHA1Base64(data.c_str(), data.length()); -} - -//------------------------------------------------------------------------------ -// computeSHA1Base64 -//------------------------------------------------------------------------------ -std::string computeSHA1Base64( - const google::protobuf::Message& msg) { - std::string buffer; - msg.SerializeToString(&buffer); - if (!msg.SerializeToString(&buffer)) { - throw cta::exception::Exception(std::string("In mediachanger::computeSHA1Base64(): could not serialize: ")+ - msg.InitializationErrorString()); - } - return computeSHA1Base64(buffer.c_str(),buffer.size()); -} - -//------------------------------------------------------------------------------ -// computeSHA1Base64 -//------------------------------------------------------------------------------ -std::string computeSHA1Base64(void const* const data, - const int len){ - // Create a context and hash the data - EVP_MD_CTX ctx; - EVP_MD_CTX_init(&ctx); - EVP_SignInit(&ctx, EVP_sha1()); - if (!EVP_SignUpdate(&ctx,data, len)) { - EVP_MD_CTX_cleanup(&ctx); - throw cta::exception::Exception("cant compute SHA1"); - } - unsigned char md_value[EVP_MAX_MD_SIZE]; - unsigned int md_len; - EVP_DigestFinal_ex(&ctx, md_value, &md_len); - // cleanup context - EVP_MD_CTX_cleanup(&ctx); - - // base64 encode - BIO *b64 = BIO_new(BIO_f_base64()); - BIO *bmem = BIO_new(BIO_s_mem()); - if (NULL == b64 || NULL == bmem) { - throw cta::exception::Exception("cant set up the environnement for computing the SHA1 in base64"); - } - b64 = BIO_push(b64, bmem); - BIO_write(b64, md_value, md_len); - (void)BIO_flush(b64); - BUF_MEM* bptr; - BIO_get_mem_ptr(b64, &bptr); - - std::string ret(bptr->data,bptr->length); - BIO_free(bmem); - BIO_free(b64); - - return ret; -} - -//----------------------------------------------------------------------------- -// recvReplyOrEx -//----------------------------------------------------------------------------- -void recvTapeReplyOrEx(ZmqSocket& socket, - google::protobuf::Message &body) { - recvReplyOrEx(socket, body, TPMAGIC, PROTOCOL_TYPE_TAPE, PROTOCOL_VERSION_1); -} - -//----------------------------------------------------------------------------- -// recvReplyOrEx -//----------------------------------------------------------------------------- -void recvReplyOrEx(ZmqSocket& socket, - google::protobuf::Message &body, - const uint32_t magic, const uint32_t protocolType, - const uint32_t protocolVersion) { - const Frame frame = recvFrame(socket); - - // Check the magic number - if(magic != frame.header.magic()) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to receive message" - ": Unexpected magic number: excpected=" << magic << " actual= " << - frame.header.magic(); - throw ex; - } - - // Check the protocol type - if(protocolType != frame.header.protocoltype()) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to receive message" - ": Unexpected protocol type: excpected=" << protocolType << " actual= " - << frame.header.protocoltype(); - throw ex; - } - - // Check the protocol version - if(protocolVersion != frame.header.protocolversion()) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to receive message" - ": Unexpected protocol version: excpected=" << protocolVersion << - " actual= " << frame.header.protocolversion(); - throw ex; - } - - // If an exception message was received - if(MSG_TYPE_EXCEPTION == frame.header.msgtype()) { - // Convert it into a C++ exception and throw it - MediaChangerExceptionMsg exMsg; - frame.parseBodyIntoProtocolBuffer(exMsg); - cta::exception::Exception ex; - ex.getMessage() << exMsg.message(); - throw ex; - } - - frame.parseBodyIntoProtocolBuffer(body); -} - -//------------------------------------------------------------------------------ -// zmqErrnoToStr -//------------------------------------------------------------------------------ -std::string zmqErrnoToStr(const int zmqErrno) { - switch(zmqErrno) { - // Translate the values that are specific to ZMQ - case EFSM: - return "Operation cannot be accomplished in current state"; - case ENOCOMPATPROTO: - return "The protocol is not compatible with the socket type"; - case ETERM: - return "Context was terminated"; - case EMTHREAD: - return "No thread available"; - - // Translate the values that are not specific to ZMQ - default: - { - char errorCStr[100]; - const int rc = strerror_r_wrapper(zmqErrno, errorCStr, sizeof(errorCStr)); - - // If strerror_r_wrapper() failed to translate - if(rc) { - std::ostringstream oss; - oss << "Failed to translate ZMQ errno"; - - switch(errno) { - case EINVAL: - oss << ": Unknown ZMQ errno"; - break; - case ERANGE: - oss << ": strerror_r_wrapper() given too small a buffer"; - break; - default: - oss << ": Unknown reason"; - } - - oss << ": zmqErrno=" << zmqErrno; - return oss.str(); - } - - // strerror_r_wrapper() succeeded to translate - errorCStr[sizeof(errorCStr) -1] = '\0'; // Being paranoid - return errorCStr; - } - } -} - -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/messages.hpp b/mediachanger/messages.hpp deleted file mode 100644 index 265fc283f9f6c1b5decd2727597ea4f9b5379ee7..0000000000000000000000000000000000000000 --- a/mediachanger/messages.hpp +++ /dev/null @@ -1,159 +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 "common/exception/Exception.hpp" -#include "mediachanger/Constants.hpp" -#include "mediachanger/Frame.hpp" -#include "mediachanger/MediaChangerHeader.pb.h" -#include "mediachanger/ZmqMsg.hpp" -#include "mediachanger/ZmqSocket.hpp" - -#include <openssl/rsa.h> -#include <openssl/evp.h> -#include <openssl/err.h> -#include <openssl/pem.h> - -namespace cta { -namespace mediachanger { - -/** - * Sends the specified message frame over the specified socket. - * - * @param socket The ZMQ socket. - * @param frame The message frame. - */ -void sendFrame(ZmqSocket &socket, const Frame &frame); - -/** - * Receives a message frame from the specified socket. - * - * @param socket The ZMQ socket. - * @return The message frame. - */ -Frame recvFrame(ZmqSocket &socket); - -/** - * Function to compute inn Base64 the SHA1 of a given buffer - * @param data The data - * @param len, the length of the buffer - * @return the base64 sha1 of the serialized buffer - */ -std::string computeSHA1Base64(const std::string &data); - -/** - * Function to compute inn Base64 the SHA1 of a given ProtoBuff message. - * All fields must be set because we are going to serialize the message. - * @param msg - * @return the base64 sha1 of the serialized body - */ -std::string computeSHA1Base64(const google::protobuf::Message& msg); - -/** - * Function to compute inn Base64 the SHA1 of a given buffer - * @param data The data - * @param len, the length of the buffer - * @return the base64 sha1 of the serialized buffer - */ -std::string computeSHA1Base64(void const* const data, const int len); - -/** - * Connects the specified ZMQ socket to localhost on the given TCP/IP port. - * - * @param socket The ZMQ socket. - * @param port The TCP/IP port. - */ -void connectZmqSocketToLocalhost(ZmqSocket &socket, const int port); - -/** - * Header factory which pre fill several fields - * magic(TPMAGIC) - * protocoltype(protocolType); - * protocolversion(protocolVersion; - * bodyhashtype("SHA1"); - * bodysignaturetype("SHA1"); - * After, the only fields left are reqtype, bodyhashvalue and bodyhashsignature - * @return The header - */ -template <int magic, int protocolType, int protocolVersion> MediaChangerHeader genericPreFillHeader() { - MediaChangerHeader header; - header.set_magic(magic); - header.set_protocoltype(protocolType); - header.set_protocolversion(protocolVersion); - header.set_bodyhashtype("SHA1"); - header.set_bodysignaturetype("SHA1"); - return header; -} - -/** - * Return genericPreFillHeader() with - * protocolType = <protocolType::Tape - * protocolVersion = protocolVersion::prototype - * @return - */ -MediaChangerHeader protoTapePreFillHeader(); - -/** - * Receives either a good-day reply-message or an exception message from the - * specified ZMQ socket. - * - * If a good-day reply-message is read from the socket then it's body is parsed - * into the specified Google protocol-buffer. - * - * If an exception message is read from the socket then it is converted into a - * a C++ exception and thrown. - * - * @param socket The ZMQ socket. - * @param body Output parameter: The body of the good-day reply-message in the - * form of a Google protocol-buffer. - */ -void recvTapeReplyOrEx(ZmqSocket& socket, google::protobuf::Message &body); - -/** - * Receives either a good-day reply-message or an exception message from the - * specified ZMQ socket. - * - * If a good-day reply-message is read from the socket then it's body is parsed - * into the specified Google protocol-buffer. - * - * If an exception message is read from the socket then it is converted into a - * a C++ exception and thrown. - * - * @param socket The ZMQ socket. - * @param body Output parameter: The body of the good-day reply-message in the - * form of a Google protocol-buffer. - * @param magic The expected magic number of the message. - * @param protocolType The expected protocol type of the message. - * @param protocolVersion The expected protocol version of the message. - */ -void recvReplyOrEx(ZmqSocket& socket, - google::protobuf::Message &body, - const uint32_t magic, const uint32_t protocolType, - const uint32_t protocolVersion); - -/** - * Returns the string representation of the specified ZMQ errno. - * - * This method does not throw an exception if the specified errno is unknown. - * Instead the method returns a string explaining that the errno is unknown. - */ -std::string zmqErrnoToStr(const int zmqErrno); - -} // namespace mediachanger -} // namespace cta diff --git a/tapeserver/castor/messages/CMakeLists.txt b/tapeserver/castor/messages/CMakeLists.txt index 95be800c7eb623f3b4c57cbd2df63be79407a261..7d9200889addf0c23dc4c383afbe32b01a37113b 100644 --- a/tapeserver/castor/messages/CMakeLists.txt +++ b/tapeserver/castor/messages/CMakeLists.txt @@ -22,7 +22,6 @@ include_directories(${PROJECT_BINARY_DIR}/tapeserver) find_package(openssl REQUIRED) find_package(Protobuf3 REQUIRED) -find_package(zeromq REQUIRED) file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.proto") PROTOBUF3_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})