From 4c59ede551dd82b48b85fc7074bc55fcf712f476 Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Tue, 5 Mar 2019 13:47:25 +0100 Subject: [PATCH] Removed support for Oracle tape libraries --- CMakeLists.txt | 8 - cmake/Findstk.cmake | 38 -- cta.spec.in | 48 -- mediachanger/CMakeLists.txt | 4 - mediachanger/acs/Acs.cpp | 77 --- mediachanger/acs/Acs.hpp | 168 ------- mediachanger/acs/AcsCmd.cpp | 115 ----- mediachanger/acs/AcsCmd.hpp | 122 ----- mediachanger/acs/AcsCmdLine.cpp | 178 ------- mediachanger/acs/AcsCmdLine.hpp | 137 ------ mediachanger/acs/AcsCmdLineTest.cpp | 139 ------ mediachanger/acs/AcsDaemonConfig.cpp | 57 --- mediachanger/acs/AcsDaemonConfig.hpp | 75 --- mediachanger/acs/AcsDebugBuf.cpp | 69 --- mediachanger/acs/AcsDebugBuf.hpp | 95 ---- mediachanger/acs/AcsDismountCmd.cpp | 128 ----- mediachanger/acs/AcsDismountCmd.hpp | 105 ----- mediachanger/acs/AcsDismountCmdLine.cpp | 180 ------- mediachanger/acs/AcsDismountCmdLine.hpp | 114 ----- mediachanger/acs/AcsDismountCmdMain.cpp | 69 --- mediachanger/acs/AcsImpl.cpp | 78 --- mediachanger/acs/AcsImpl.hpp | 119 ----- mediachanger/acs/AcsLibraryInteraction.cpp | 160 ------- mediachanger/acs/AcsLibraryInteraction.hpp | 120 ----- mediachanger/acs/AcsMountCmd.cpp | 131 ------ mediachanger/acs/AcsMountCmd.hpp | 101 ---- mediachanger/acs/AcsMountCmdLine.cpp | 175 ------- mediachanger/acs/AcsMountCmdLine.hpp | 111 ----- mediachanger/acs/AcsMountCmdMain.cpp | 69 --- mediachanger/acs/AcsQueryDriveCmd.cpp | 161 ------- mediachanger/acs/AcsQueryDriveCmd.hpp | 115 ----- mediachanger/acs/AcsQueryDriveCmdLine.cpp | 174 ------- mediachanger/acs/AcsQueryDriveCmdLine.hpp | 118 ----- mediachanger/acs/AcsQueryDriveCmdMain.cpp | 60 --- mediachanger/acs/AcsQueryVolumeCmd.cpp | 190 -------- mediachanger/acs/AcsQueryVolumeCmd.hpp | 116 ----- mediachanger/acs/AcsQueryVolumeCmdLine.cpp | 147 ------ mediachanger/acs/AcsQueryVolumeCmdLine.hpp | 101 ---- mediachanger/acs/AcsQueryVolumeCmdMain.cpp | 68 --- mediachanger/acs/CMakeLists.txt | 155 ------ mediachanger/acs/CmdLineTool.cpp | 41 -- mediachanger/acs/CmdLineTool.hpp | 94 ---- mediachanger/acs/Constants.hpp | 62 --- mediachanger/acs/acsd.init | 111 ----- mediachanger/acs/acsd.man | 66 --- mediachanger/acs/cta-acs-dismount.1cta | 68 --- mediachanger/acs/cta-acs-mount.1cta | 69 --- mediachanger/acs/cta-acs-querydrive.1cta | 65 --- mediachanger/acs/cta-acs-queryvolume.1cta | 62 --- mediachanger/acs/cta-acsd.1cta | 117 ----- mediachanger/acs/daemon/AcsDaemon.cpp | 384 --------------- mediachanger/acs/daemon/AcsDaemon.hpp | 228 --------- mediachanger/acs/daemon/AcsDaemonMain.cpp | 100 ---- mediachanger/acs/daemon/AcsDismountTape.cpp | 142 ------ mediachanger/acs/daemon/AcsDismountTape.hpp | 130 ----- .../acs/daemon/AcsForceDismountTape.cpp | 142 ------ .../acs/daemon/AcsForceDismountTape.hpp | 133 ------ mediachanger/acs/daemon/AcsMessageHandler.cpp | 444 ------------------ mediachanger/acs/daemon/AcsMessageHandler.hpp | 187 -------- .../acs/daemon/AcsMountTapeReadOnly.cpp | 213 --------- .../acs/daemon/AcsMountTapeReadOnly.hpp | 142 ------ .../acs/daemon/AcsMountTapeReadWrite.cpp | 216 --------- .../acs/daemon/AcsMountTapeReadWrite.hpp | 142 ------ .../acs/daemon/AcsPendingRequests.cpp | 331 ------------- .../acs/daemon/AcsPendingRequests.hpp | 196 -------- mediachanger/acs/daemon/AcsRequest.cpp | 283 ----------- mediachanger/acs/daemon/AcsRequest.hpp | 317 ------------- .../acs/daemon/AcsRequestDismountTape.cpp | 112 ----- .../acs/daemon/AcsRequestDismountTape.hpp | 113 ----- mediachanger/acs/daemon/AcsdCmdLine.cpp | 135 ------ mediachanger/acs/daemon/AcsdCmdLine.hpp | 73 --- mediachanger/acs/daemon/AcsdCmdLineTest.cpp | 156 ------ mediachanger/acs/daemon/AcsdConfiguration.cpp | 54 --- mediachanger/acs/daemon/AcsdConfiguration.hpp | 64 --- mediachanger/acs/daemon/CMakeLists.txt | 62 --- mediachanger/acs/daemon/Constants.cpp | 79 ---- mediachanger/acs/daemon/Constants.hpp | 83 ---- mediachanger/acs/daemon/Tpconfig.hpp | 46 -- mediachanger/acs/daemon/TpconfigLine.hpp | 104 ---- mediachanger/acs/daemon/cta-acsd.conf | 38 -- mediachanger/acs/daemon/cta-acsd.logrotate | 10 - mediachanger/acs/daemon/cta-acsd.service | 12 - tests/CMakeLists.txt | 5 - 83 files changed, 10026 deletions(-) delete mode 100644 cmake/Findstk.cmake delete mode 100644 mediachanger/acs/Acs.cpp delete mode 100644 mediachanger/acs/Acs.hpp delete mode 100644 mediachanger/acs/AcsCmd.cpp delete mode 100644 mediachanger/acs/AcsCmd.hpp delete mode 100644 mediachanger/acs/AcsCmdLine.cpp delete mode 100644 mediachanger/acs/AcsCmdLine.hpp delete mode 100644 mediachanger/acs/AcsCmdLineTest.cpp delete mode 100644 mediachanger/acs/AcsDaemonConfig.cpp delete mode 100644 mediachanger/acs/AcsDaemonConfig.hpp delete mode 100644 mediachanger/acs/AcsDebugBuf.cpp delete mode 100644 mediachanger/acs/AcsDebugBuf.hpp delete mode 100644 mediachanger/acs/AcsDismountCmd.cpp delete mode 100644 mediachanger/acs/AcsDismountCmd.hpp delete mode 100644 mediachanger/acs/AcsDismountCmdLine.cpp delete mode 100644 mediachanger/acs/AcsDismountCmdLine.hpp delete mode 100644 mediachanger/acs/AcsDismountCmdMain.cpp delete mode 100644 mediachanger/acs/AcsImpl.cpp delete mode 100644 mediachanger/acs/AcsImpl.hpp delete mode 100644 mediachanger/acs/AcsLibraryInteraction.cpp delete mode 100644 mediachanger/acs/AcsLibraryInteraction.hpp delete mode 100644 mediachanger/acs/AcsMountCmd.cpp delete mode 100644 mediachanger/acs/AcsMountCmd.hpp delete mode 100644 mediachanger/acs/AcsMountCmdLine.cpp delete mode 100644 mediachanger/acs/AcsMountCmdLine.hpp delete mode 100644 mediachanger/acs/AcsMountCmdMain.cpp delete mode 100644 mediachanger/acs/AcsQueryDriveCmd.cpp delete mode 100644 mediachanger/acs/AcsQueryDriveCmd.hpp delete mode 100644 mediachanger/acs/AcsQueryDriveCmdLine.cpp delete mode 100644 mediachanger/acs/AcsQueryDriveCmdLine.hpp delete mode 100644 mediachanger/acs/AcsQueryDriveCmdMain.cpp delete mode 100644 mediachanger/acs/AcsQueryVolumeCmd.cpp delete mode 100644 mediachanger/acs/AcsQueryVolumeCmd.hpp delete mode 100644 mediachanger/acs/AcsQueryVolumeCmdLine.cpp delete mode 100644 mediachanger/acs/AcsQueryVolumeCmdLine.hpp delete mode 100644 mediachanger/acs/AcsQueryVolumeCmdMain.cpp delete mode 100644 mediachanger/acs/CMakeLists.txt delete mode 100644 mediachanger/acs/CmdLineTool.cpp delete mode 100644 mediachanger/acs/CmdLineTool.hpp delete mode 100644 mediachanger/acs/Constants.hpp delete mode 100755 mediachanger/acs/acsd.init delete mode 100644 mediachanger/acs/acsd.man delete mode 100644 mediachanger/acs/cta-acs-dismount.1cta delete mode 100644 mediachanger/acs/cta-acs-mount.1cta delete mode 100644 mediachanger/acs/cta-acs-querydrive.1cta delete mode 100644 mediachanger/acs/cta-acs-queryvolume.1cta delete mode 100644 mediachanger/acs/cta-acsd.1cta delete mode 100644 mediachanger/acs/daemon/AcsDaemon.cpp delete mode 100644 mediachanger/acs/daemon/AcsDaemon.hpp delete mode 100644 mediachanger/acs/daemon/AcsDaemonMain.cpp delete mode 100644 mediachanger/acs/daemon/AcsDismountTape.cpp delete mode 100644 mediachanger/acs/daemon/AcsDismountTape.hpp delete mode 100644 mediachanger/acs/daemon/AcsForceDismountTape.cpp delete mode 100644 mediachanger/acs/daemon/AcsForceDismountTape.hpp delete mode 100644 mediachanger/acs/daemon/AcsMessageHandler.cpp delete mode 100644 mediachanger/acs/daemon/AcsMessageHandler.hpp delete mode 100644 mediachanger/acs/daemon/AcsMountTapeReadOnly.cpp delete mode 100644 mediachanger/acs/daemon/AcsMountTapeReadOnly.hpp delete mode 100644 mediachanger/acs/daemon/AcsMountTapeReadWrite.cpp delete mode 100644 mediachanger/acs/daemon/AcsMountTapeReadWrite.hpp delete mode 100644 mediachanger/acs/daemon/AcsPendingRequests.cpp delete mode 100644 mediachanger/acs/daemon/AcsPendingRequests.hpp delete mode 100644 mediachanger/acs/daemon/AcsRequest.cpp delete mode 100644 mediachanger/acs/daemon/AcsRequest.hpp delete mode 100644 mediachanger/acs/daemon/AcsRequestDismountTape.cpp delete mode 100644 mediachanger/acs/daemon/AcsRequestDismountTape.hpp delete mode 100644 mediachanger/acs/daemon/AcsdCmdLine.cpp delete mode 100644 mediachanger/acs/daemon/AcsdCmdLine.hpp delete mode 100644 mediachanger/acs/daemon/AcsdCmdLineTest.cpp delete mode 100644 mediachanger/acs/daemon/AcsdConfiguration.cpp delete mode 100644 mediachanger/acs/daemon/AcsdConfiguration.hpp delete mode 100644 mediachanger/acs/daemon/CMakeLists.txt delete mode 100644 mediachanger/acs/daemon/Constants.cpp delete mode 100644 mediachanger/acs/daemon/Constants.hpp delete mode 100644 mediachanger/acs/daemon/Tpconfig.hpp delete mode 100644 mediachanger/acs/daemon/TpconfigLine.hpp delete mode 100644 mediachanger/acs/daemon/cta-acsd.conf delete mode 100644 mediachanger/acs/daemon/cta-acsd.logrotate delete mode 100644 mediachanger/acs/daemon/cta-acsd.service diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c63df723e..1b17823566 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,14 +72,6 @@ endif (NOT DEFINED SKIP_UNIT_TESTS) #Load version information in all cases. include(cmake/CTAVersions.cmake) -if (DEFINED NoACS) - message (STATUS "Running CMake without support for ACS") - set (use_manually_specified_variable ${NoACS}) -else (DEFINED NoACS) - message (STATUS "Running CMake with support for ACS") - message (STATUS "Override with -DNoACS:Bool=true") -endif (DEFINED NoACS) - IF(DEFINED PackageOnly) message (STATUS "Running CMake in package-only mode") set(COMPILE_PACKAGING "1") diff --git a/cmake/Findstk.cmake b/cmake/Findstk.cmake deleted file mode 100644 index f954e63bb2..0000000000 --- a/cmake/Findstk.cmake +++ /dev/null @@ -1,38 +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: -# STK_FOUND -# STK_LIBRARIES -# STK_INCLUDE_DIR - -find_library (STK_LIBRARIES - stk-ssi - PATHS /usr/lib64/CDK /usr/lib/CDK - NO_DEFAULT_PATH) - -find_path (STK_INCLUDE_DIRS - acssys.h - PATHS /usr/include/CDK - NO_DEFAULT_PATH) - -message (STATUS "STK_LIBRARIES=${STK_LIBRARIES}") -message (STATUS "STK_INCLUDE_DIRS=${STK_INCLUDE_DIRS}") - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(stk DEFAULT_MSG - STK_LIBRARIES - STK_INCLUDE_DIRS) diff --git a/cta.spec.in b/cta.spec.in index 592cb4365d..4a7933ec1e 100644 --- a/cta.spec.in +++ b/cta.spec.in @@ -289,7 +289,6 @@ Unit tests and system tests with virtual tape drives %{_libdir}/libctatapeserverscsiunittests.so* %{_libdir}/libctadaemonunittests.so* %{_libdir}/libctamediachangerunittests.so* -%{_libdir}/libctamediachangeracsdaemonunittests.so* %{_bindir}/cta-systemTests %{_libdir}/libctadaemonunittests-multiprocess.so* %attr(0644,root,root) %{_datadir}/%{name}-%{ctaVersion}/unittest/*.suppr @@ -344,34 +343,6 @@ Utilities to faciliate working with the mediachangers %attr(0644,root,root) %doc /usr/share/man/man1/cta-mediachanger-dismount.1cta.gz %attr(0644,root,root) %doc /usr/share/man/man1/cta-mediachanger-mount.1cta.gz -%package -n cta-acsd -Summary: Tools to faciliate working with acsd in cta -Group: Application/CTA -Requires: logrotate -Requires: cta-common = %{version}-%{release} -Requires: cta-lib = %{version}-%{release} -%description -n cta-acsd -CERN Tape Archive: -Tools to faciliate working with acsd in cta -%files -n cta-acsd -%defattr(-,root,root) -%attr(0644,root,root) %config(noreplace) /etc/logrotate.d/cta-acsd -#%attr(0644,root,root) %doc /usr/share/man/man1/cta-acsd.1cta.gz -%attr(0755,root,root) %{_bindir}/cta-acsd -%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/cta/cta-acsd.conf -%attr(0644,root,root) /etc/systemd/system/cta-acsd.service - -%post -n cta-acsd -%systemd_post cta-acsd.service -%systemdDaemonReload - -%preun -n cta-acsd -%systemd_preun cta-acsd.service - -%postun -n cta-acsd -%systemd_postun cta-acsd.service -%systemdDaemonReload - %package -n cta-rmcd Summary: Tools to faciliate working with rmcd and smc in cta Group: Application/CTA @@ -403,25 +374,6 @@ Tools to faciliate working with rmcd and smc in cta %systemd_postun cta-rmcd.service %systemdDaemonReload -%package -n cta-tape-developer-acs-tools -Summary: Cern Advanced mass STORage -Group: Application/Castor -Requires: stk-ssi-lib -BuildRequires: stk-ssi-devel -%description -n cta-tape-developer-acs-tools -castor (Cern Advanced STORage system) - ASC tools for CASTOR tape developers -%files -n cta-tape-developer-acs-tools -%defattr(-,root,root) -%attr(0755,root,root) /usr/bin/cta-acs-queryvolume -%attr(0755,root,root) /usr/bin/cta-acs-dismount -%attr(0755,root,root) /usr/bin/cta-acs-mount -%attr(0755,root,root) /usr/bin/cta-acs-querydrive -%attr(0644,root,root) %doc /usr/share/man/man1/cta-acs-queryvolume.1cta.gz -%attr(0644,root,root) %doc /usr/share/man/man1/cta-acs-mount.1cta.gz -%attr(0644,root,root) %doc /usr/share/man/man1/cta-acs-dismount.1cta.gz -%attr(0644,root,root) %doc /usr/share/man/man1/cta-acs-querydrive.1cta.gz - %package -n cta-common Summary: CERN Tape Archive common items Group: Application/CTA diff --git a/mediachanger/CMakeLists.txt b/mediachanger/CMakeLists.txt index 4f464de54e..2f8e3afe0e 100644 --- a/mediachanger/CMakeLists.txt +++ b/mediachanger/CMakeLists.txt @@ -15,10 +15,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. cmake_minimum_required (VERSION 2.6) -if (NOT DEFINED NoACS) - add_subdirectory(acs) -endif (NOT DEFINED NoACS) - add_subdirectory(reactor) add_subdirectory(castorrmc) find_package(openssl REQUIRED) diff --git a/mediachanger/acs/Acs.cpp b/mediachanger/acs/Acs.cpp deleted file mode 100644 index 9e039e9245..0000000000 --- a/mediachanger/acs/Acs.cpp +++ /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/>. - */ - -#include "Acs.hpp" - -#include <iomanip> -#include <sstream> -#include <stdint.h> -#include <string.h> -#include <vector> - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::Acs::~Acs() { -} - -//------------------------------------------------------------------------------ -// alpd2DriveId -//------------------------------------------------------------------------------ -DRIVEID cta::mediachanger::acs::Acs::alpd2DriveId(const uint32_t acs, - const uint32_t lsm, const uint32_t panel, const uint32_t drive) { - - DRIVEID driveId; - driveId.panel_id.lsm_id.acs = (ACS)acs; - driveId.panel_id.lsm_id.lsm = (LSM)lsm; - driveId.panel_id.panel = (PANEL)panel; - driveId.drive = (DRIVE)drive; - - return driveId; -} - -//------------------------------------------------------------------------------ -// str2Volid -//------------------------------------------------------------------------------ -VOLID cta::mediachanger::acs::Acs::str2Volid(const std::string &str) { - if(EXTERNAL_LABEL_SIZE < str.length()) { - InvalidVolid ex; - ex.getMessage() << "Failed to convert string to volume identifier" - ": String is longer than the " << EXTERNAL_LABEL_SIZE << - " character maximum"; - throw ex; - } - - VOLID v; - strncpy(v.external_label, str.c_str(), sizeof(v.external_label)); - v.external_label[sizeof(v.external_label) - 1] = '\0'; - return v; -} - -//------------------------------------------------------------------------------ -// driveId2Str -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::Acs::driveId2Str(const DRIVEID &driveId) { - std::ostringstream oss; - oss << std::setfill('0') << - std::setw(3) << (int32_t)driveId.panel_id.lsm_id.acs << ":" << - std::setw(3) << (int32_t)driveId.panel_id.lsm_id.lsm << ":" << - std::setw(3) << (int32_t)driveId.panel_id.panel << ":" << - std::setw(3) << (int32_t)driveId.drive; - return oss.str(); -} diff --git a/mediachanger/acs/Acs.hpp b/mediachanger/acs/Acs.hpp deleted file mode 100644 index a334210813..0000000000 --- a/mediachanger/acs/Acs.hpp +++ /dev/null @@ -1,168 +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" - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> -#include <stdint.h> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Abstract class that defines the interface to an object that wraps the ACLS - * C-API. - */ -class Acs { -public: - /** - * Pure-virtual destructor to ensure this class is abstract. - */ - virtual ~Acs() = 0; - - /** - * Converts acs, lsm, panel, drive numbers to the corresponding - * drive ID object. - * - * @param acs The integer for acs. - * @param lsm The integer for lsm. - * @param panel The integer for panel. - * @param drive The integer for drive. - * @return The drive ID object. - */ - static DRIVEID alpd2DriveId(const uint32_t acs, const uint32_t lsm, - const uint32_t panel, const uint32_t drive); - - /** - * Invalid volume identifier. - */ - struct InvalidVolid: public exception::Exception { - InvalidVolid(const std::string &context = "", const bool embedBacktrace = true): - cta::exception::Exception(context, embedBacktrace) {} - }; - - /** - * Returns the VOLID equibvalent of the specified string. - * - * @param str The string representation of the volume identifier. - * @return The VOLID representation of the volume identifier. - * @throw InvalidVolid if the string is longer than EXTERNAL_LABEL_SIZE. - */ - static VOLID str2Volid(const std::string &str); - - /** - * Returns the string reprsentation of the specified drive identifier. - * - * The string format is ACS:LSM:panel:drive - * - * @param driveId The drive identifier. - * @return The string representation. - */ - static std::string driveId2Str(const DRIVEID &driveId); - - /** - * C++ wrapper around the acs_mount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The indentifier of volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param readOnly Set to true to request the volume be mounted for read-only - * access. - * @param bypass Set to true to override the ACSLS verification of - * compatibility between the drive and the media type of the volume. - * @return status value returned by acs_mount(). - */ - virtual STATUS mount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN readOnly, - const BOOLEAN bypass) - = 0; - - /** - * C++ wrapper around the acs_dismount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The identifier of the volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param force Set to true if the dismount should be forced. Forcing a - * dismount means dismounting the volume from the specified drive without - * checking the identifier of the volume. - * @return status value returned by acs_dismount(). - */ - virtual STATUS dismount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN force) - = 0; - - /** - * C++ wrapper around the acs_response() function of the ACSLS C-API. - * - * @param timeout Time in seconds to wait for a response. A value of -1 - * means block indefinitely and an a value of 0 means poll for the existence - * of a response. - * @param seqNumber Output parameter. If a response exists then seqNumber - * is set. - * @param reqId Output parameter. For an acknowledge response reqId is set - * to the request identifier of the original request. For an intermediate or - * final response reqId will be set to 0. - * @param rType Output parameter. Set to the type of the response. - * @param rBuf Output parameter. Set to the response information. - * @return status value returned by acs_response(). - */ - virtual STATUS response( - const int timeout, - SEQ_NO &seqNumber, - REQ_ID &reqId, - ACS_RESPONSE_TYPE &rType, - ALIGNED_BYTES rBuf) = 0; - - /** - * C++ wrapper around the acs_query_volume() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param volIds Array of the volume identifiers to be queried. - * @param count The number of volume identifiers contained iwthin the volId - * parameter. - * @return status value returned by acs_response(). - */ - virtual STATUS queryVolume( - const SEQ_NO seqNumber, - VOLID (&volIds)[MAX_ID], - const unsigned short count) = 0; - -}; // class Acs - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsCmd.cpp b/mediachanger/acs/AcsCmd.cpp deleted file mode 100644 index 13c726692a..0000000000 --- a/mediachanger/acs/AcsCmd.cpp +++ /dev/null @@ -1,115 +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 "AcsCmd.hpp" -#include "common/exception/Exception.hpp" -#include <stdlib.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsCmd::AcsCmd(std::istream &inStream, - std::ostream &outStream, std::ostream &errStream, Acs &acs): - CmdLineTool(inStream, outStream, errStream), m_acs(acs) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsCmd::~AcsCmd() { -} - -//------------------------------------------------------------------------------ -// bool2Str -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::AcsCmd::bool2Str(const BOOLEAN value) const - { - return value ? "TRUE" : "FALSE"; -} - -//------------------------------------------------------------------------------ -// requestResponsesUntilFinal -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsCmd::requestResponsesUntilFinal( - const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)], - const int queryInterval, const int timeout) { - ACS_RESPONSE_TYPE responseType = RT_NONE; - int elapsedTime = 0; - do { - const int remainingTime = timeout - elapsedTime; - const int responseTimeout = remainingTime > queryInterval ? - queryInterval : remainingTime; - - const time_t startTime = time(NULL); - responseType = requestResponse(responseTimeout, requestSeqNumber, buf); - elapsedTime += time(NULL) - startTime; - - if(RT_ACKNOWLEDGE == responseType) { - m_dbg << "Received RT_ACKNOWLEDGE" << std::endl; - } - - if(elapsedTime >= timeout) { - cta::exception::RequestFailed ex; - ex.getMessage() << "Timed out after " << timeout << " seconds"; - throw ex; - } - } while(RT_FINAL != responseType); - - m_dbg << "Received RT_FINAL" << std::endl; -} - -//------------------------------------------------------------------------------ -// requestResponse -//------------------------------------------------------------------------------ -ACS_RESPONSE_TYPE cta::mediachanger::acs::AcsCmd::requestResponse( - const int timeout, const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) { - SEQ_NO responseSeqNumber = 0; - REQ_ID reqId = (REQ_ID)0; - ACS_RESPONSE_TYPE responseType = RT_NONE; - - m_dbg << "Calling Acs::response()" << std::endl; - const STATUS s = m_acs.response(timeout, responseSeqNumber, reqId, - responseType, buf); - m_dbg << "Acs::response() returned " << acs_status(s) << std::endl; - - switch(s) { - case STATUS_SUCCESS: - checkResponseSeqNumber(requestSeqNumber, responseSeqNumber); - return responseType; - case STATUS_PENDING: - return RT_NONE; - default: - cta::exception::RequestFailed ex; - ex.getMessage() << "Failed to request response: " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// checkSeqNumber -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsCmd::checkResponseSeqNumber( const SEQ_NO requestSeqNumber, const SEQ_NO responseSeqNumber) { - if(requestSeqNumber != responseSeqNumber) { - cta::exception::Mismatch ex; - ex.getMessage() << ": Sequence number mismatch: requestSeqNumber=" - << requestSeqNumber << " responseSeqNumber=" << responseSeqNumber; - throw ex; - } -} diff --git a/mediachanger/acs/AcsCmd.hpp b/mediachanger/acs/AcsCmd.hpp deleted file mode 100644 index 54650e61ac..0000000000 --- a/mediachanger/acs/AcsCmd.hpp +++ /dev/null @@ -1,122 +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/Mismatch.hpp" -//#include "common/exception/RequestFailed.hpp" -#include "common/exception/RequestFailed.hpp" -#include "Acs.hpp" -#include "AcsCmd.hpp" -#include "CmdLineTool.hpp" - -#include <istream> -#include <ostream> -#include <string> - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Abstract class implementing common code and data structures for command-line - * tools that interact with ACLS compatible tape libraries. - */ -class AcsCmd: public CmdLineTool { -public: - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs); - - /** - * Pure-virtual destructor to guarantee this class is abstract. - */ - virtual ~AcsCmd() = 0; - -protected: - - /** - * Wrapper around the ACSLS C-API. - */ - Acs &m_acs; - - /** - * Returns the string representation of the specfied boolean value. - * - * @param value The boolean value. - */ - std::string bool2Str(const BOOLEAN value) const; - - /** - * Requests responses from ACSLS in a loop until the RT_FINAL response is - * received. - * - * @param requestSeqNumber The sequemce number that was sent in the initial - * request to the ACSLS. - * @param buf Output parameter. Message buffer into which the RT_FINAL - * response shall be written. - * @param queryInterval Time in seconds to wait between queries to ACS for - * responses. - * @param timeout The time in seconds to spend trying to get the RT_FINAL - * response. - */ - void requestResponsesUntilFinal(const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)], - const int queryInterval, const int timeout); - - /** - * Sends a request for a response to the ACSLS. - * - * @param timeout The timeout. - * @param requestSeqNumber The sequemce number that was sent in the initial - * request to the ACSLS. - * @param buf Output parameter. The response message if there is one. - * @return The type of the response message if there is one or RT_NONE if - * there isn't one. - */ - ACS_RESPONSE_TYPE requestResponse(const int timeout, - const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]); - - /** - * Throws cta::exception::Mismatch if the specified request and - * response sequence-numbers do not match. - * - * @param requestSeqNumber Request sequence-number. - * @param responseSeqNumber Response sequence-number. - */ - void checkResponseSeqNumber(const SEQ_NO requestSeqNumber, - const SEQ_NO responseSeqNumber); - -}; // class AcsCmd - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsCmdLine.cpp b/mediachanger/acs/AcsCmdLine.cpp deleted file mode 100644 index 9ffa7d9e2d..0000000000 --- a/mediachanger/acs/AcsCmdLine.cpp +++ /dev/null @@ -1,178 +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 "AcsCmdLine.hpp" - -#include <stdlib.h> -#include <unistd.h> -#include <vector> - -//------------------------------------------------------------------------------ -// str2DriveId -//------------------------------------------------------------------------------ -DRIVEID cta::mediachanger::acs::AcsCmdLine::str2DriveId(const std::string &str) { - std::vector<std::string> components; - - if(!str.empty()) { - const char separator = ':'; - std::string::size_type beginIndex = 0; - std::string::size_type endIndex = str.find(separator); - - while(endIndex != std::string::npos) { - components.push_back(str.substr(beginIndex, endIndex - beginIndex)); - beginIndex = ++endIndex; - endIndex = str.find(separator, endIndex); - } - - components.push_back(str.substr(beginIndex)); - } - - // The drive ID should consist of 4 components: ACS, LSM, Panel and Transport - if(4 != components.size()) { - InvalidDriveId ex; - ex.getMessage() << "Invalid number of components in drive ID" - ": expected=4, actual=" << components.size(); - throw ex; - } - - const std::string &acsStr = components[0]; - 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()) { - InvalidDriveId ex; - ex.getMessage() << "Invalid ACS string length" - ": expected=1..3, actual=" << acsStr.length(); - throw ex; - } - if(1 > lsmStr.length() || 3 < lsmStr.length()) { - InvalidDriveId ex; - ex.getMessage() << "Invalid LSM string length" - ": expected=1..3, actual=" << lsmStr.length(); - throw ex; - } - if(1 > panStr.length() || 3 < panStr.length()) { - InvalidDriveId ex; - ex.getMessage() << "Invalid panel string length" - ": expected=1..3, actual=" << panStr.length(); - throw ex; - } - if(1 > drvStr.length() || 3 < drvStr.length()) { - InvalidDriveId ex; - ex.getMessage() << "Invalid drive string length" - ": expected=1..3, actual=" << drvStr.length(); - throw ex; - } - - // Each of the 4 components must only contain numerals - if(!onlyContainsNumerals(acsStr)) { - InvalidDriveId ex; - ex.getMessage() << "ACS must only contain numerals: value=" << acsStr; - throw ex; - } - if(!onlyContainsNumerals(lsmStr)) { - InvalidDriveId ex; - ex.getMessage() << "LSM must only contain numerals: value=" << acsStr; - throw ex; - } - if(!onlyContainsNumerals(panStr)) { - InvalidDriveId ex; - ex.getMessage() << "Panel must only contain numerals: value=" << acsStr; - throw ex; - } - if(!onlyContainsNumerals(drvStr)) { - InvalidDriveId ex; - ex.getMessage() << "Drive/Transport must only contain numerals: value=" << - acsStr; - throw ex; - } - - DRIVEID driveId; - driveId.panel_id.lsm_id.acs = (ACS)atoi(acsStr.c_str()); - driveId.panel_id.lsm_id.lsm = (LSM)atoi(lsmStr.c_str()); - driveId.panel_id.panel = (PANEL)atoi(panStr.c_str()); - driveId.drive = (DRIVE)atoi(drvStr.c_str()); - - return driveId; -} - -//------------------------------------------------------------------------------ -// onlyContainsNumerals -//------------------------------------------------------------------------------ -bool cta::mediachanger::acs::AcsCmdLine::onlyContainsNumerals(const std::string &str) { - for(std::string::const_iterator itor = str.begin(); itor != str.end(); - itor++) { - if(*itor < '0' || *itor > '9') { - return false; - } - } - return true; -} - -//------------------------------------------------------------------------------ -// parseQueryInterval -//------------------------------------------------------------------------------ -int cta::mediachanger::acs::AcsCmdLine::parseQueryInterval(const std::string &s) { - const int queryInterval = atoi(s.c_str()); - if(0 >= queryInterval) { - InvalidQueryInterval ex; - ex.getMessage() << "Query value must be an integer greater than 0" - ": value=" << queryInterval; - throw ex; - } - - return queryInterval; -} - -//------------------------------------------------------------------------------ -// parseTimeout -//------------------------------------------------------------------------------ -int cta::mediachanger::acs::AcsCmdLine::parseTimeout(const std::string &s) { - const int timeout = atoi(s.c_str()); - if(0 >= timeout) { - InvalidTimeout ex; - ex.getMessage() << "Timeout value must be an integer greater than 0" - ": value=" << timeout; - throw ex; - } - return timeout; -} - -//------------------------------------------------------------------------------ -// handleMissingParameter -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsCmdLine::handleMissingParameter(const int opt) { - MissingParam ex; - ex.getMessage() << "The -" << (char)opt << " option requires a parameter"; - throw ex; -} - -//------------------------------------------------------------------------------ -// handleUnknownOption -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsCmdLine::handleUnknownOption(const int opt) { - UnknownOption ex; - if(0 == optopt) { - ex.getMessage() << "Unknown command-line option"; - } else { - ex.getMessage() << "Unknown command-line option: -" << (char)opt; - } - throw ex; -} diff --git a/mediachanger/acs/AcsCmdLine.hpp b/mediachanger/acs/AcsCmdLine.hpp deleted file mode 100644 index 38495afee8..0000000000 --- a/mediachanger/acs/AcsCmdLine.hpp +++ /dev/null @@ -1,137 +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" - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Class containing the code common to the parsed command-line of the ACS - * command-line tools provided by CASTOR. - */ -class AcsCmdLine { -public: - - /** - * Invalid drive identifier. - */ - struct InvalidDriveId: public exception::Exception { - InvalidDriveId(const std::string &context = "", const bool embedBacktrace = true): - cta::exception::Exception(context, embedBacktrace) {} - }; - - /** - * Parses the specified string and returns the corresponding drive ID object. - * - * @param str The string to be parsed. - * @return The drive ID object. - * @throw InvalidDriveId if the syntax of the string is invalid. - */ - static DRIVEID str2DriveId(const std::string &str); - -protected: - - /** - * Invalid query interval. - */ - struct InvalidQueryInterval: public exception::Exception { - InvalidQueryInterval(const std::string &context = "", const bool embedBacktrace = true): - cta::exception::Exception(context, embedBacktrace) {} - }; - - /** - * Parses the specified query interval. - * - * @return The parse query interval. - * @throw InvalidQueryInterval if the query interval is invalid. - */ - int parseQueryInterval(const std::string &s); - - /** - * Invalid timeout. - */ - struct InvalidTimeout: public exception::Exception { - InvalidTimeout(const std::string &context = "", const bool embedBacktrace = true): - cta::exception::Exception(context, embedBacktrace) {} - }; - - /** - * Parses the specified timeout. - * - * @return The parse query interval. - * @throw InvalidTimout if the timeout is invalid. - */ - int parseTimeout(const std::string &s); - - /** - * Missing parameter. - */ - struct MissingParam: public exception::Exception { - MissingParam(const std::string &context = "", const bool embedBacktrace = true): - cta::exception::Exception(context, embedBacktrace) {} - }; - - /** - * Handles the specified parameter that is missing a parameter. - * - * @param opt The option. - * @throw MissingParam in all cases. - */ - void handleMissingParameter(const int opt); - - /** - * Unkown option. - */ - struct UnknownOption: public exception::Exception { - UnknownOption(const std::string &context = "", const bool embedBacktrace = true): - cta::exception::Exception(context, embedBacktrace) {} - }; - - /** - * Handles the specified unknown option. - * - * @param opt The option. - * @throw UnknownOption indepedent of the value of opt. - */ - void handleUnknownOption(const int opt); - -private: - - /** - * Returns true if the specified string only contains numerals else false. - * - * @return True if the specified string only contains numerals else false. - */ - static bool onlyContainsNumerals(const std::string &str); - -}; // class AcsCmdLine - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsCmdLineTest.cpp b/mediachanger/acs/AcsCmdLineTest.cpp deleted file mode 100644 index 8a1e50061d..0000000000 --- a/mediachanger/acs/AcsCmdLineTest.cpp +++ /dev/null @@ -1,139 +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/acs/AcsCmdLine.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class cta_mediachanger_acs_AcsCmdLineTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -/** - * Tests good day senario with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, goodDayStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1:2:3:4"); - const auto driveId = AcsCmdLine::str2DriveId(str); - - ASSERT_EQ(1, driveId.panel_id.lsm_id.acs); - ASSERT_EQ(2, driveId.panel_id.lsm_id.lsm); - ASSERT_EQ(3, driveId.panel_id.panel); - ASSERT_EQ(4, driveId.drive); -} - -/** - * Tests too many components with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooManyComponentsStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1:2:3:4:5"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests too few components with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooFewComponentsStr2DriveIdgoodDayStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1:2:3"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests tool long component with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongAcsComponentStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1111:2:3:4"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests tool long component with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongLsmComponentStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1:2222:3:4"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests tool long component with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongPanComponentStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1:2:3333:4"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests tool long component with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, tooLongDrvComponentStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1:2:3:4444"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests empty component with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyAcsComponentStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str(":2:3:4"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests empty component with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyLsmComponentStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1::3:4"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests empty component with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyPanComponentStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1:2::4"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -/** - * Tests empty component with Acs::strToDrveId. - */ -TEST_F(cta_mediachanger_acs_AcsCmdLineTest, emptyDrvComponentStr2DriveId) { - using namespace cta::mediachanger::acs; - const std::string str("1:2:3:"); - ASSERT_THROW(AcsCmdLine::str2DriveId(str), AcsCmdLine::InvalidDriveId); -} - -} // namespace unitTests diff --git a/mediachanger/acs/AcsDaemonConfig.cpp b/mediachanger/acs/AcsDaemonConfig.cpp deleted file mode 100644 index 90520257af..0000000000 --- a/mediachanger/acs/AcsDaemonConfig.cpp +++ /dev/null @@ -1,57 +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 "AcsDaemonConfig.hpp" -//#include "castor/acs/Constants.hpp" -#include "common/log/Constants.hpp" -#include "castor/server/LoggedCastorConfiguration.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -castor::acs::AcsDaemonConfig::AcsDaemonConfig(): - port(0), - queryInterval(0), - cmdTimeout(0) { -} - -//------------------------------------------------------------------------------ -// createFromCastorConfig -//------------------------------------------------------------------------------ -castor::acs::AcsDaemonConfig castor::acs::AcsDaemonConfig:: - createFromCastorConf(log::Logger *const log) { - server::LoggedCastorConfiguration castorConf( - common::CastorConfiguration::getConfig()); - AcsDaemonConfig config; - - config.port = castorConf.getConfEntInt("AcsDaemon", "Port", - (unsigned short)ACS_PORT); - - config.queryInterval = castorConf.getConfEntInt("AcsDaemon", "QueryInterval", - (time_t)ACS_QUERY_INTERVAL); - - config.cmdTimeout = castorConf.getConfEntInt("AcsDaemon", "CmdTimeout", - (time_t)ACS_CMD_TIMEOUT); - - return config; -} diff --git a/mediachanger/acs/AcsDaemonConfig.hpp b/mediachanger/acs/AcsDaemonConfig.hpp deleted file mode 100644 index 1f5ea3fcfe..0000000000 --- a/mediachanger/acs/AcsDaemonConfig.hpp +++ /dev/null @@ -1,75 +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/log/Logger.hpp" -#include "common/log/Logger.hpp" - -#include <time.h> - -namespace castor { -namespace acs { - -/** - * Structure used to store the CASTOR configuration parameters used by the - * CASTOR ACS daemon. - */ -struct AcsDaemonConfig { - - /** - * The TCP/IP port on which the CASTOR ACS daemon listens for incoming Zmq - * connections from the tape server. - */ - unsigned short port; - - /** - * Time to wait in seconds between queries to the tape Library. - */ - time_t queryInterval; - - /** - * The maximum time to wait in seconds for a tape-library command to - * conclude. - */ - time_t cmdTimeout; - - /** - * Constructor that sets all integer member-variables to 0 and all string - * member-variables to the empty string. - */ - AcsDaemonConfig(); - - /** - * Returns a configuration structure based on the contents of - * /etc/castor/castor.conf and compile-time constants. - * - * @param log pointer to NULL or an optional logger object. - * @return The configuration structure. - */ - static AcsDaemonConfig createFromCastorConf( - log::Logger *const log = NULL); - -}; // struct AcsDaemonConfig - -} // namespace acs -} // namespace castor - diff --git a/mediachanger/acs/AcsDebugBuf.cpp b/mediachanger/acs/AcsDebugBuf.cpp deleted file mode 100644 index eb900d5a7b..0000000000 --- a/mediachanger/acs/AcsDebugBuf.cpp +++ /dev/null @@ -1,69 +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/acs/AcsDebugBuf.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::DebugBuf::DebugBuf(std::ostream &os): - m_debug(false), m_os(os), m_writePreamble(true) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::DebugBuf::~DebugBuf() { -} - -//------------------------------------------------------------------------------ -// setDebug -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::DebugBuf::setDebug(const bool value) { - m_debug = value; -} - -//------------------------------------------------------------------------------ -// overflow -//------------------------------------------------------------------------------ -std::streambuf::int_type cta::mediachanger::acs::DebugBuf::overflow( - const int_type c) { - // Only write something if debug mode is on - if(m_debug) { - if(m_writePreamble) { - writePreamble(); - m_writePreamble = false; - } - m_os << (char)c; - } - - // If an end of line was encountered then the next write should be preceeded - // with a preamble - if('\n' == (char)c) { - m_writePreamble = true; - } - - return c; -} - -//------------------------------------------------------------------------------ -// writePreamble -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::DebugBuf::writePreamble() { - m_os << "DEBUG: "; -} diff --git a/mediachanger/acs/AcsDebugBuf.hpp b/mediachanger/acs/AcsDebugBuf.hpp deleted file mode 100644 index afc4168d95..0000000000 --- a/mediachanger/acs/AcsDebugBuf.hpp +++ /dev/null @@ -1,95 +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 <ostream> -#include <streambuf> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Stream buffer class used to prepend a standard preamble to debug - * message-lines. - * - * This stream buffer does not write any output if debug mode has not been - * turned on by calling setDebugMode(true). Any debug message written to this - * stream buffer will be discarded if debug mode is off. - */ -class DebugBuf : public std::streambuf { -public: - - /** - * Constructor. - * - * Initialises the the debug mode to be off. - * - * @param os The output stream to which each debug message-line togther with - * its standard preamble shall be written. - */ - DebugBuf(std::ostream &os); - - /** - * Destructor. - */ - ~DebugBuf(); - - /** - * Set the debug mode to be on (true) or off (false). - * - * The default set in the constructor is off (false). - */ - void setDebug(const bool value); - -protected: - - /** - * Sends the specified character to the output channnel. - */ - int_type overflow (const int_type c); - - /** - * Writes the standard preamble to the output stream. - */ - void writePreamble(); - -private: - - /** - * True if debug mode is on. - */ - bool m_debug; - - /** - * The output stream to which each debug message-line togther with its - * standard preamble shall be written. - */ - std::ostream &m_os; - - /** - * True is a preamble should be written. - */ - bool m_writePreamble; - -}; // class DebugBuf - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsDismountCmd.cpp b/mediachanger/acs/AcsDismountCmd.cpp deleted file mode 100644 index 8c8c8d1f2b..0000000000 --- a/mediachanger/acs/AcsDismountCmd.cpp +++ /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/>. - */ - -#include "AcsDismountCmd.hpp" - -#include <getopt.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsDismountCmd::AcsDismountCmd( - std::istream &inStream, std::ostream &outStream, std::ostream &errStream, - Acs &acs): - AcsCmd(inStream, outStream, errStream, acs) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsDismountCmd::~AcsDismountCmd() { - // Do nothing -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -int cta::mediachanger::acs::AcsDismountCmd::exceptionThrowingMain(const int argc, - char *const *const argv) { - try { - m_cmdLine = AcsDismountCmdLine(argc, argv); - } catch(cta::exception::Exception &ex) { - m_err << ex.getMessage().str() << std::endl; - m_err << std::endl; - m_err << m_cmdLine.getUsage() << std::endl; - return 1; - } - - // Display the usage message to standard out and exit with success if the - // user requested help - if(m_cmdLine.help) { - m_out << AcsDismountCmdLine::getUsage(); - return 0; - } - - // Setup debug mode to be on or off depending on the command-line arguments - m_debugBuf.setDebug(m_cmdLine.debug); - - m_dbg << "force = " << (m_cmdLine.force ? "TRUE" : "FALSE") << std::endl; - m_dbg << "query = " << m_cmdLine.queryInterval << std::endl; - m_dbg << "timeout = " << m_cmdLine.timeout << std::endl; - m_dbg << "VID = " << m_cmdLine.volId.external_label << std::endl; - m_dbg << "DRIVE_SLOT = " << m_acs.driveId2Str(m_cmdLine.libraryDriveSlot) - << std::endl; - - syncDismount(); - return 0; -} - -//------------------------------------------------------------------------------ -// syncDismount -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsDismountCmd::syncDismount() { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendDismountRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, m_cmdLine.queryInterval, - m_cmdLine.timeout); - processDismountResponse(buf); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to dismount volume " << - m_cmdLine.volId.external_label << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// sendDismountRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsDismountCmd::sendDismountRequest( - const SEQ_NO seqNumber) { - const LOCKID lockId = 0; // No lock - - m_dbg << "Calling Acs::dismount()" << std::endl; - const STATUS s = m_acs.dismount(seqNumber, lockId, m_cmdLine.volId, - m_cmdLine.libraryDriveSlot, m_cmdLine.force); - m_dbg << "Acs::dismount() returned " << acs_status(s) << std::endl; - if(STATUS_SUCCESS != s) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to send request to dismount volume " << - m_cmdLine.volId.external_label << " from drive " << - m_acs.driveId2Str(m_cmdLine.libraryDriveSlot) << ": force=" << - (m_cmdLine.force ? "TRUE" : "FALSE") << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processDismountResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsDismountCmd::processDismountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) { - const ACS_DISMOUNT_RESPONSE *const msg = (ACS_DISMOUNT_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->dismount_status) { - cta::exception::Exception ex; - ex.getMessage() << "Status of dismount response is not success: " << - acs_status(msg->dismount_status); - throw ex; - } -} diff --git a/mediachanger/acs/AcsDismountCmd.hpp b/mediachanger/acs/AcsDismountCmd.hpp deleted file mode 100644 index 43a4c5e606..0000000000 --- a/mediachanger/acs/AcsDismountCmd.hpp +++ /dev/null @@ -1,105 +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 "AcsCmd.hpp" -#include "AcsDismountCmdLine.hpp" - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * The class implementing the mount command. - */ -class AcsDismountCmd: public AcsCmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsDismountCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs); - - /** - * Destructor. - */ - virtual ~AcsDismountCmd(); - - /** - * The entry function of the command. - * - * This method sets the m_cmdLine member-variable. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ - int exceptionThrowingMain(const int argc, char *const *const argv); - -protected: - - /** - * Dismounts the tape with the specified VID into the drive with the specified - * drive ID. - * - * This method does not return until the mount has either suceeded, failed or - * the specified timeout has been reached. - * - * @param dismountTimeout The maximum amount of time in seconds to wait for - * the dismount operation to conclude. - * @param queryInterval The amount of time in seconds to wait between - * querying ACS for responses. - */ - void syncDismount(); - - /** - * Sends the dismount request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendDismountRequest(const SEQ_NO seqNumber); - - /** - * Process dismount response. - * - * @param buf The mount-response message. - */ - void processDismountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]); - -private: - - /** - * The parsed command-line. - * - * This member-variable is set by the main() method of this class. - */ - AcsDismountCmdLine m_cmdLine; - -}; // class AcsDismountCmd - -} // namespace acs -} // namepace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsDismountCmdLine.cpp b/mediachanger/acs/AcsDismountCmdLine.cpp deleted file mode 100644 index 42c0058a37..0000000000 --- a/mediachanger/acs/AcsDismountCmdLine.cpp +++ /dev/null @@ -1,180 +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 "Acs.hpp" -#include "AcsCmdLine.hpp" -#include "AcsDismountCmdLine.hpp" -#include "Constants.hpp" - -#include <getopt.h> -#include <stdlib.h> -#include <string.h> - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::AcsDismountCmdLine::AcsDismountCmdLine(): - debug(false), - force(FALSE), - help(false), - queryInterval(0), - timeout(0) { - libraryDriveSlot.panel_id.lsm_id.acs = (ACS)0; - libraryDriveSlot.panel_id.lsm_id.lsm = (LSM)0; - libraryDriveSlot.panel_id.panel = (PANEL)0; - libraryDriveSlot.drive = (DRIVE)0; - memset(volId.external_label, '\0', sizeof(volId.external_label)); -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsDismountCmdLine::AcsDismountCmdLine(const int argc, - char *const *const argv): - debug(false), - force(FALSE), - help(false), - queryInterval(ACS_QUERY_INTERVAL), - timeout(ACS_CMD_TIMEOUT) { - libraryDriveSlot.panel_id.lsm_id.acs = (ACS)0; - libraryDriveSlot.panel_id.lsm_id.lsm = (LSM)0; - libraryDriveSlot.panel_id.panel = (PANEL)0; - libraryDriveSlot.drive = (DRIVE)0; - memset(volId.external_label, '\0', sizeof(volId.external_label)); - - static struct option longopts[] = { - {"debug", 0, NULL, 'd'}, - {"force", 0, NULL, 'f'}, - {"help" , 0, NULL, 'h'}, - {"query" , required_argument, NULL, 'q'}, - {"timeout" , required_argument, NULL, 't'}, - {NULL , 0, NULL, 0 } - }; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - - int opt = 0; - while((opt = getopt_long(argc, argv, ":dfhq:t:", longopts, NULL)) != -1) { - processOption(opt); - } - - // There is no need to continue parsing when the help option is set - if(help) { - return; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc-optind; - - // Check that both VID and DRIVE_SLOT have been specified - if(nbArgs < 2) { - cta::exception::Exception ex; - - ex.getMessage() << - "Both VID and DRIVE_SLOT must be specified"; - - throw ex; - } - - // Parse VID - volId = Acs::str2Volid(argv[optind]); - - // Move on to the next command-line argument - optind++; - - // Parse DRIVE_SLOT - libraryDriveSlot = str2DriveId(argv[optind]); -} - -//------------------------------------------------------------------------------ -// processOption -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsDismountCmdLine::processOption(const int opt) { - switch (opt) { - case 'd': - debug = true; - break; - case 'f': - force = TRUE; - break; - case 'h': - help = true; - break; - case 'q': - queryInterval = parseQueryInterval(optarg); - break; - case 't': - timeout = parseTimeout(optarg); - break; - case ':': - return handleMissingParameter(optopt); - case '?': - return handleUnknownOption(optopt); - default: - { - cta::exception::Exception ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)opt; - throw ex; - } - } // switch(opt) -} - -//------------------------------------------------------------------------------ -// getUsage -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::AcsDismountCmdLine::getUsage() { - std::ostringstream usage; - usage << - "Usage:\n" - "\n" - " cta-acs-dismount [options] VID DRIVE_SLOT\n" - "\n" - "Where:\n" - "\n" - " VID The VID of the volume to be dismounted.\n" - "\n" - " DRIVE_SLOT The slot in the tape library where the drive is located.\n" - " The format of DRIVE_SLOT is as follows:\n" - "\n" - " ACS:LSM:panel:transport\n" - "\n" - "Options:\n" - "\n" - " -d|--debug Turn on the printing of debug information.\n" - "\n" - " -f|--force Force the dismount.\n" - "\n" - " -h|--help Print this help message and exit.\n" - "\n" - " -q|--query SECONDS Time to wait between queries to ACS for responses.\n" - " SECONDS must be an integer value greater than 0.\n" - " The default value of SECONDS is " - << ACS_QUERY_INTERVAL << ".\n" - "\n" - " -t|--timeout SECONDS Time to wait for the dismount to conclude. SECONDS\n" - " must be an integer value greater than 0. The\n" - " default value of SECONDS is " - << ACS_CMD_TIMEOUT << ".\n" - "\n" - "Comments to: CTA team\n"; - return usage.str(); -} diff --git a/mediachanger/acs/AcsDismountCmdLine.hpp b/mediachanger/acs/AcsDismountCmdLine.hpp deleted file mode 100644 index c2e9f72e97..0000000000 --- a/mediachanger/acs/AcsDismountCmdLine.hpp +++ /dev/null @@ -1,114 +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 "AcsCmdLine.hpp" - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Data type used to store the results of parsing the command-line. - */ -struct AcsDismountCmdLine: public AcsCmdLine { - /** - * True if the debug option has been set. - */ - bool debug; - - /** - * True if the dismount should be forced. - * - * Forcing a dismount means dismounting the tape in the specified drive - * without checking the volume identifier of the tape. - */ - BOOLEAN force; - - /** - * True if the help option has been set. - */ - bool help; - - /** - * Time in seconds to wait between queries to ACS for responses. - */ - int queryInterval; - - /** - * Time in seconds to wait for the dismount to conclude. - */ - int timeout; - - /** - * The volume identifier of the tape to be mounted. - */ - VOLID volId; - - /** - * The slot in the tape library where the drive is located. - */ - DRIVEID libraryDriveSlot; - - /** - * Constructor. - * - * Initialises all boolean member-variables to false, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - AcsDismountCmdLine(); - - /** - * Constructor. - * - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - */ - AcsDismountCmdLine(const int argc, char *const *const argv); - - /** - * Gets the usage message that describes the comamnd line. - * - * @return The usage message. - */ - static std::string getUsage(); - -private: - - /** - * Processes the specified option that was returned by getopt_long(). - * - * @param opt The option that was returned by getopt_long(). - */ - void processOption(const int opt); - -}; // class AcsDismountCmdLine - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsDismountCmdMain.cpp b/mediachanger/acs/AcsDismountCmdMain.cpp deleted file mode 100644 index b01f3cf388..0000000000 --- a/mediachanger/acs/AcsDismountCmdMain.cpp +++ /dev/null @@ -1,69 +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 "AcsDismountCmd.hpp" -#include "AcsDismountCmdLine.hpp" -#include "AcsImpl.hpp" - -#include <iostream> - -/** - * An exception throwing version of main(). - * - * @param argc The number of command-line arguments including the program name. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ -static int exceptionThrowingMain(const int argc, char *const *const argv); - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - using namespace cta; - - std::string errorMessage; - - try { - return exceptionThrowingMain(argc, argv); - } catch(cta::exception::Exception &ex) { - errorMessage = ex.getMessage().str(); - } catch(std::exception &se) { - errorMessage = se.what(); - } catch(...) { - errorMessage = "An unknown exception was thrown"; - } - - // Reaching this point means the command has failed, ane exception was throw - // and errorMessage has been set accordingly - - std::cerr << "Aborting: " << errorMessage << std::endl; - return 1; -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -static int exceptionThrowingMain(const int argc, char *const *const argv) { - using namespace cta; - - mediachanger::acs::AcsImpl acs; - mediachanger::acs::AcsDismountCmd cmd(std::cin, std::cout, std::cerr, acs); - - return cmd.exceptionThrowingMain(argc, argv); -} diff --git a/mediachanger/acs/AcsImpl.cpp b/mediachanger/acs/AcsImpl.cpp deleted file mode 100644 index fa22870331..0000000000 --- a/mediachanger/acs/AcsImpl.cpp +++ /dev/null @@ -1,78 +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 "AcsImpl.hpp" - -#include <errno.h> -#include <sstream> -#include <string.h> - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsImpl::~AcsImpl() { -} - -//------------------------------------------------------------------------------ -// mount -//------------------------------------------------------------------------------ -STATUS cta::mediachanger::acs::AcsImpl::mount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN readOnly, - const BOOLEAN bypass) - { - return acs_mount(seqNumber, lockId, volId, driveId, readOnly, bypass); -} - -//------------------------------------------------------------------------------ -// dismount -//------------------------------------------------------------------------------ -STATUS cta::mediachanger::acs::AcsImpl::dismount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN force) - { - return acs_dismount(seqNumber, lockId, volId, driveId, force); -} - -//------------------------------------------------------------------------------ -// response -//------------------------------------------------------------------------------ -STATUS cta::mediachanger::acs::AcsImpl::response( - const int timeout, - SEQ_NO &seqNumber, - REQ_ID &reqId, - ACS_RESPONSE_TYPE &rType, - ALIGNED_BYTES rBuf) { - return acs_response(timeout, &seqNumber, &reqId, &rType, rBuf); -} - -//------------------------------------------------------------------------------ -// queryVolume -//------------------------------------------------------------------------------ -STATUS cta::mediachanger::acs::AcsImpl::queryVolume( - const SEQ_NO seqNumber, - VOLID (&volIds)[MAX_ID], - const unsigned short count) { - return acs_query_volume(seqNumber, volIds, count); -} diff --git a/mediachanger/acs/AcsImpl.hpp b/mediachanger/acs/AcsImpl.hpp deleted file mode 100644 index 5353b7b464..0000000000 --- a/mediachanger/acs/AcsImpl.hpp +++ /dev/null @@ -1,119 +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 "Acs.hpp" - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Concrete class that wraps the ACLS C-API. - */ -class AcsImpl: public Acs { -public: - /** - * Destructor. - */ - ~AcsImpl(); - - /** - * C++ wrapper around the acs_mount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The identifier of the volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param readOnly Set to true to request the volume be mounted for read-only - * access. - * @param bypass Set to true to override the ACSLS verification of - * compatibility between the drive and the media type of the volume. - * @return status value returned by acs_mount(). - */ - STATUS mount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN readOnly, - const BOOLEAN bypass) - ; - - /** - * C++ wrapper around the acs_dismount() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param lockId Lock identifier or 0 meaning no lock. - * @param volId The identifier of the volume to be mounted. - * @param driveId The ID of the drive into which the volume is to be mounted. - * @param force Set to true if the dismount should be forced. Forcing a - * dismount means dismounting the volume from the specified drive without - * checking the identifier of the volume. - * @return status value returned by acs_dismount(). - */ - STATUS dismount( - const SEQ_NO seqNumber, - const LOCKID lockId, - const VOLID &volId, - const DRIVEID &driveId, - const BOOLEAN force) - ; - - /** - * C++ wrapper around the acs_response() function of the ACSLS C-API. - * - * @param timeout Time in seconds to wait for a response. A value of -1 - * means block indefinitely and an a value of 0 means poll for the existence - * of a response. - * @param seqNumber Output parameter. If a response exists then seqNumber - * is set. - * @param reqId Output parameter. For an acknowledge response reqId is set - * to the request identifier of the original request. For an intermediate or - * final response reqId will be set to 0. - * @param rType Output parameter. Set to the type of the response. - * @param rBuf Output parameter. Set to the response information. - * @return status value returned by acs_response(). - */ - STATUS response( - const int timeout, - SEQ_NO &seqNumber, - REQ_ID &reqId, - ACS_RESPONSE_TYPE &rType, - ALIGNED_BYTES rBuf); - - /** - * C++ wrapper around the acs_query_volume() function of the ACSLS C-API. - * - * @param seqNumber Client supplied sequence number. - * @param volIds Array of the volume identifiers to be queried. - * @param count The number of volume identifiers contained iwthin the volId - * parameter. - * @return status value returned by acs_response(). - */ - STATUS queryVolume( - const SEQ_NO seqNumber, - VOLID (&volIds)[MAX_ID], - const unsigned short count); - -}; // class AcsImpl - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsLibraryInteraction.cpp b/mediachanger/acs/AcsLibraryInteraction.cpp deleted file mode 100644 index 645711a357..0000000000 --- a/mediachanger/acs/AcsLibraryInteraction.cpp +++ /dev/null @@ -1,160 +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 "AcsLibraryInteraction.hpp" -#include "common/log/log.hpp" - -#include <stdlib.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsLibraryInteraction::AcsLibraryInteraction( - Acs &acs, cta::log::Logger& log): m_acs(acs), m_log(log) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsLibraryInteraction::~AcsLibraryInteraction() { -} - - -//------------------------------------------------------------------------------ -// requestResponsesUntilFinal -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsLibraryInteraction::requestResponsesUntilFinal( - const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)], - const int queryInterval, const int timeout) const - { - ACS_RESPONSE_TYPE responseType = RT_NONE; - int elapsedTime = 0; - do { - const int remainingTime = timeout - elapsedTime; - const int responseTimeout = remainingTime > queryInterval ? - queryInterval : remainingTime; - - const time_t startTime = time(NULL); - responseType = requestResponse(responseTimeout, requestSeqNumber, buf); - elapsedTime += time(NULL) - startTime; - - if(RT_ACKNOWLEDGE == responseType) { - m_log(LOG_DEBUG,"Received RT_ACKNOWLEDGE"); - } - - if(elapsedTime >= timeout) { - cta::exception::RequestFailed ex; - ex.getMessage() << "Timed out after " << timeout << " seconds"; - throw ex; - } - } while(RT_FINAL != responseType); - - m_log(LOG_DEBUG,"Received RT_FINAL"); -} - -//------------------------------------------------------------------------------ -// requestResponse -//------------------------------------------------------------------------------ -ACS_RESPONSE_TYPE cta::mediachanger::acs::AcsLibraryInteraction::requestResponse( - const int timeout, const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const - { - SEQ_NO responseSeqNumber = 0; - REQ_ID reqId = (REQ_ID)0; - ACS_RESPONSE_TYPE responseType = RT_NONE; - - std::stringstream dbgMsg; - dbgMsg << "Calling Acs::response() for requestSeqNumber=" << requestSeqNumber; - m_log(LOG_DEBUG, dbgMsg.str()); - - const STATUS s = m_acs.response(timeout, responseSeqNumber, reqId, - responseType, buf); - - dbgMsg.str(""); - dbgMsg << "Acs::response() for requestSeqNumber=" << requestSeqNumber << - " returned responseSeqNumber=" << responseSeqNumber << " and status " << - acs_status(s); - m_log(LOG_DEBUG,dbgMsg.str()); - - switch(s) { - case STATUS_SUCCESS: - checkResponseSeqNumber(requestSeqNumber, responseSeqNumber); - return responseType; - case STATUS_PENDING: - return RT_NONE; - default: - cta::exception::RequestFailed ex; - ex.getMessage() << "Failed to request response: " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// checkSeqNumber -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsLibraryInteraction::checkResponseSeqNumber( - const SEQ_NO requestSeqNumber, const SEQ_NO responseSeqNumber) const - { - if(requestSeqNumber != responseSeqNumber) { - cta::exception::Mismatch ex; - ex.getMessage() << ": Sequence number mismatch: requestSeqNumber=" - << requestSeqNumber << " responseSeqNumber=" << responseSeqNumber; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// volumeStatusAsString -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::AcsLibraryInteraction::volumeStatusAsString( - const QU_VOL_STATUS &s) const { - - std::ostringstream os; - os << "vid=" << s.vol_id.external_label << " "; - os << "media_types.dat=" << (int)s.media_type << " "; - - switch(s.location_type) { - case LOCATION_CELL: { - os << "location=cell" << " "; - const CELLID &cellId = s.location.cell_id; - os << "acs=" << (int)cellId.panel_id.lsm_id.acs << " "; - os << "lsm=" << (int)cellId.panel_id.lsm_id.lsm << " "; - os << "panel=" << (int)cellId.panel_id.panel << " "; - os << "raw=" << (int)cellId.row << " "; - os << "column=" << (int)cellId.col << " "; - break; - } - case LOCATION_DRIVE: { - os << "location=drive" << " "; - const DRIVEID &driveId = s.location.drive_id; - os << "acs=" << (int)driveId.panel_id.lsm_id.acs << " "; - os << "lsm=" << (int)driveId.panel_id.lsm_id.lsm << " "; - os << "panel=" << (int)driveId.panel_id.panel << " "; - os << "column=" << (int)driveId.drive << " "; - break; - } - default: - os << "location=UNKNOWN" << " "; - break; - } - - os << "status=" << acs_status(s.status); - return os.str(); -} diff --git a/mediachanger/acs/AcsLibraryInteraction.hpp b/mediachanger/acs/AcsLibraryInteraction.hpp deleted file mode 100644 index 9e0c32d064..0000000000 --- a/mediachanger/acs/AcsLibraryInteraction.hpp +++ /dev/null @@ -1,120 +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/Mismatch.hpp" -#include "common/exception/RequestFailed.hpp" -#include "common/log/log.hpp" -#include "Acs.hpp" - -#include <string> - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Abstract class implementing common code and data structures for mount - * for read-only access, mount for read/write access and dismount requests - * that interact with ACS compatible tape libraries. - */ -class AcsLibraryInteraction { -public: - /** - * Constructor. - * - * @param acs Wrapper around the ACSLS C-API. - */ - AcsLibraryInteraction(Acs &acs, cta::log::Logger &log); - - /** - * Pure-virtual destructor to guarantee this class is abstract. - */ - virtual ~AcsLibraryInteraction() = 0; - -protected: - - /** - * Requests responses from ACSLS in a loop until the RT_FINAL response is - * received. - * - * @param requestSeqNumber The sequemce number that was sent in the initial - * request to the ACSLS. - * @param buf Output parameter. Message buffer into which the RT_FINAL - * response shall be written. - * @param queryInterval Time in seconds to wait between queries to ACS for - * responses. - * @param timeout The time in seconds to spend trying to get the RT_FINAL - * response. - */ - void requestResponsesUntilFinal(const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)], - const int queryInterval, const int timeout) const - ; - - /** - * Sends a request for a response to the ACSLS. - * - * @param timeout The timeout. - * @param requestSeqNumber The sequemce number that was sent in the initial - * request to the ACSLS. - * @param buf Output parameter. The response message if there is one. - * @return The type of the response message if there is one or RT_NONE if - * there isn't one. - */ - ACS_RESPONSE_TYPE requestResponse(const int timeout, - const SEQ_NO requestSeqNumber, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const - ; - - /** - * Throws cta::exception::Mismatch if the specified request and - * response sequence-numbers do not match. - * - * @param requestSeqNumber Request sequence-number. - * @param responseSeqNumber Response sequence-number. - */ - void checkResponseSeqNumber(const SEQ_NO requestSeqNumber, - const SEQ_NO responseSeqNumber) const ; - - /** - * Converts the specified volume status to a human readable representation. - * - * @param s The volume status. - * @return The string presentation of the volume status. - */ - std::string volumeStatusAsString(const QU_VOL_STATUS &s) const; - - /** - * Wrapper around the ACSLS C-API. - */ - Acs &m_acs; - log::Logger &m_log; -}; // class AcsLibraryInteraction - -} // namespace acs -} // namespace mediachanger -} // namespace cta - - diff --git a/mediachanger/acs/AcsMountCmd.cpp b/mediachanger/acs/AcsMountCmd.cpp deleted file mode 100644 index 4707be4325..0000000000 --- a/mediachanger/acs/AcsMountCmd.cpp +++ /dev/null @@ -1,131 +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 "AcsMountCmd.hpp" -#include "AcsMountCmdLine.hpp" -#include <getopt.h> -#include <iostream> -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsMountCmd::AcsMountCmd( - std::istream &inStream, std::ostream &outStream, std::ostream &errStream, - Acs &acs): - AcsCmd(inStream, outStream, errStream, acs) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsMountCmd::~AcsMountCmd() { - // Do nothing -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -int cta::mediachanger::acs::AcsMountCmd::exceptionThrowingMain(const int argc, - char *const *const argv) { - try { - m_cmdLine = AcsMountCmdLine(argc, argv); - } catch(cta::exception::Exception &ex) { - m_err << ex.getMessage().str() << std::endl; - m_err << std::endl; - m_err << m_cmdLine.getUsage() << std::endl; - return 1; - } - - // Display the usage message to standard out and exit with success if the - // user requested help - if(m_cmdLine.help) { - m_out << AcsMountCmdLine::getUsage(); - return 0; - } - - // Setup debug mode to be on or off depending on the command-line arguments - m_debugBuf.setDebug(m_cmdLine.debug); - - m_dbg << "query = " << m_cmdLine.queryInterval << std::endl; - m_dbg << "readonly = " << bool2Str(m_cmdLine.readOnly) << std::endl; - m_dbg << "timeout = " << m_cmdLine.timeout << std::endl; - m_dbg << "VID = " << m_cmdLine.volId.external_label << std::endl; - m_dbg << "DRIVE_SLOT = " << m_acs.driveId2Str(m_cmdLine.libraryDriveSlot) - << std::endl; - - syncMount(); - - return 0; -} - -//------------------------------------------------------------------------------ -// syncMount -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsMountCmd::syncMount() { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendMountRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, m_cmdLine.queryInterval, - m_cmdLine.timeout); - processMountResponse(buf); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to mount volume " << - m_cmdLine.volId.external_label << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// sendMountRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsMountCmd::sendMountRequest(const SEQ_NO seqNumber) { - const LOCKID lockId = 0; // No lock - const BOOLEAN bypass = FALSE; - - m_dbg << "Calling Acs::mount()" << std::endl; - const STATUS s = m_acs.mount(seqNumber, lockId, m_cmdLine.volId, - m_cmdLine.libraryDriveSlot, m_cmdLine.readOnly, bypass); - m_dbg << "Acs::mount() returned " << acs_status(s) << std::endl; - - if(STATUS_SUCCESS != s) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to send request to mount volume " << - m_cmdLine.volId.external_label << " into drive " << - m_acs.driveId2Str(m_cmdLine.libraryDriveSlot) << ": readOnly=" << - (m_cmdLine.readOnly ? "TRUE" : "FALSE") << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processMountResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsMountCmd::processMountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) - { - const ACS_MOUNT_RESPONSE *const msg = (ACS_MOUNT_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->mount_status) { - cta::exception::Exception ex; - ex.getMessage() << "Status of mount response is not success: " << - acs_status(msg->mount_status); - throw ex; - } -} diff --git a/mediachanger/acs/AcsMountCmd.hpp b/mediachanger/acs/AcsMountCmd.hpp deleted file mode 100644 index 2c142888e2..0000000000 --- a/mediachanger/acs/AcsMountCmd.hpp +++ /dev/null @@ -1,101 +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 "AcsCmd.hpp" -#include "AcsMountCmdLine.hpp" - -#include <stdint.h> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * The class implementing the mount command. - */ -class AcsMountCmd: public AcsCmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsMountCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs); - - /** - * Destructor. - */ - virtual ~AcsMountCmd(); - - /** - * The entry function of the command. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ - int exceptionThrowingMain(const int argc, char *const *const argv); - -protected: - - /** - * Mounts the tape with the specified VID into the drive with the specified - * drive ID. - * - * This method does not return until the mount has either suceeded, failed or - * the specified timeout has been reached. - */ - void syncMount(); - - /** - * Sends the mount request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendMountRequest(const SEQ_NO seqNumber); - - /** - * Process mount rsponse. - * - * @param buf The mount-response message. - */ - void processMountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]); - -private: - - /** - * The parsed command-line. - * - * The value of this member variable is set within the main() method of this - * class. - */ - AcsMountCmdLine m_cmdLine; - -}; // class AcsMountCmd - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsMountCmdLine.cpp b/mediachanger/acs/AcsMountCmdLine.cpp deleted file mode 100644 index b73f34ddb1..0000000000 --- a/mediachanger/acs/AcsMountCmdLine.cpp +++ /dev/null @@ -1,175 +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 "Acs.hpp" -#include "AcsMountCmdLine.hpp" -#include "Constants.hpp" - -#include <getopt.h> -#include <stdlib.h> -#include <string.h> - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::AcsMountCmdLine::AcsMountCmdLine(): - debug(false), - help(false), - queryInterval(0), - readOnly(FALSE), - timeout(0) { - libraryDriveSlot.panel_id.lsm_id.acs = (ACS)0; - libraryDriveSlot.panel_id.lsm_id.lsm = (LSM)0; - libraryDriveSlot.panel_id.panel = (PANEL)0; - libraryDriveSlot.drive = (DRIVE)0; - memset(volId.external_label, '\0', sizeof(volId.external_label)); -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsMountCmdLine::AcsMountCmdLine(const int argc, - char *const *const argv): - debug(false), - help(false), - queryInterval(ACS_QUERY_INTERVAL), - readOnly(FALSE), - timeout(ACS_CMD_TIMEOUT) { - libraryDriveSlot.panel_id.lsm_id.acs = (ACS)0; - libraryDriveSlot.panel_id.lsm_id.lsm = (LSM)0; - libraryDriveSlot.panel_id.panel = (PANEL)0; - libraryDriveSlot.drive = (DRIVE)0; - memset(volId.external_label, '\0', sizeof(volId.external_label)); - - static struct option longopts[] = { - {"debug", 0, NULL, 'd'}, - {"help" , 0, NULL, 'h'}, - {"query" , required_argument, NULL, 'q'}, - {"readonly" , 0, NULL, 'r'}, - {"timeout" , required_argument, NULL, 't'}, - {NULL, 0, NULL, 0} - }; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - - int opt = 0; - while((opt = getopt_long(argc, argv, ":dhq:rt:", longopts, NULL)) != -1) { - processOption(opt); - } - - // There is no need to continue parsing when the help option is set - if(help) { - return; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check that both VID and DRIVE_SLOT have been specified - if(nbArgs < 2) { - cta::exception::Exception ex; - ex.getMessage() << "Both VID and DRIVE_SLOT must be specified"; - throw ex; - } - - // Parse VID - volId = Acs::str2Volid(argv[optind]); - - // Move on to the next command-line argument - optind++; - - // Parse DRIVE_SLOT - libraryDriveSlot = str2DriveId(argv[optind]); -} - -//------------------------------------------------------------------------------ -// processOption -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsMountCmdLine::processOption(const int opt) { - switch(opt) { - case 'd': - debug = true; - break; - case 'h': - help = true; - break; - case 'q': - queryInterval = parseQueryInterval(optarg); - break; - case 'r': - readOnly = TRUE; - break; - case 't': - timeout = parseTimeout(optarg); - break; - case ':': - return handleMissingParameter(optopt); - case '?': - return handleUnknownOption(optopt); - default: - { - cta::exception::Exception ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)opt; - throw ex; - } - } // switch(opt) -} - -//------------------------------------------------------------------------------ -// getUsage -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::AcsMountCmdLine::getUsage() { - std::ostringstream usage; - usage << - "Usage:\n" - "\n" - " cta-acs-mount [options] VID DRIVE_SLOT\n" - "\n" - "Where:\n" - "\n" - " VID The VID of the volume to be mounted.\n" - " DRIVE_SLOT The slot in the tape library where the drive is located.\n" - " The format of DRIVE_SLOT is as follows:\n" - "\n" - " ACS:LSM:panel:transport\n" - "\n" - "Options:\n" - "\n" - " -d|--debug Turn on the printing of debug information.\n" - "\n" - " -h|--help Print this help message and exit.\n" - "\n" - " -q|--query SECONDS Time to wait between queries to ACS for responses.\n" - " SECONDS must be an integer value greater than 0.\n" - " The default value of SECONDS is " - << ACS_QUERY_INTERVAL << ".\n" - "\n" - " -r|--readOnly Request the volume is mounted for read-only access\n" - "\n" - " -t|--timeout SECONDS Time to wait for the mount to conclude. SECONDS\n" - " must be an integer value greater than 0. The\n" - " default value of SECONDS is " - << ACS_CMD_TIMEOUT << ".\n" - "\n" - "Comments to: CTA team\n"; - return usage.str(); -} diff --git a/mediachanger/acs/AcsMountCmdLine.hpp b/mediachanger/acs/AcsMountCmdLine.hpp deleted file mode 100644 index c15637b5e1..0000000000 --- a/mediachanger/acs/AcsMountCmdLine.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 "AcsCmdLine.hpp" - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Data type used to store the results of parsing the command-line. - */ -struct AcsMountCmdLine: public AcsCmdLine { - /** - * True if the debug option has been set. - */ - bool debug; - - /** - * True if the help option has been set. - */ - bool help; - - /** - * Time in seconds to wait between queries to ACS for responses. - */ - int queryInterval; - - /** - * True if the tape is to be mount for read-only access. - */ - BOOLEAN readOnly; - - /** - * Time in seconds to wait for the mount to conclude. - */ - int timeout; - - /** - * The volume identifier of the tape to be mounted. - */ - VOLID volId; - - /** - * The slot in the tape library where the drive is located. - */ - DRIVEID libraryDriveSlot; - - /** - * Constructor. - * - * Initialises all BOOLEAN member-variables to FALSE, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - AcsMountCmdLine(); - - /** - * Constructor. - * - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - */ - AcsMountCmdLine(const int argc, char *const *const argv); - - /** - * Gets the usage message that describes the comamnd line. - * - * @return The usage message. - */ - static std::string getUsage(); - -private: - - /** - * Processes the specified option that was returned by getopt_long(). - * - * @param opt The option that was returned by getopt_long(). - */ - void processOption(const int opt); - -}; // class AcsMountCmdLine - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsMountCmdMain.cpp b/mediachanger/acs/AcsMountCmdMain.cpp deleted file mode 100644 index b1c4e965c7..0000000000 --- a/mediachanger/acs/AcsMountCmdMain.cpp +++ /dev/null @@ -1,69 +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 "AcsImpl.hpp" -#include "AcsMountCmd.hpp" -#include "AcsMountCmdLine.hpp" - -#include <iostream> - -/** - * An exception throwing version of main(). - * - * @param argc The number of command-line arguments including the program name. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ -static int exceptionThrowingMain(const int argc, char *const *const argv); - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - using namespace cta; - - std::string errorMessage; - - try { - return exceptionThrowingMain(argc, argv); - } catch(cta::exception::Exception &ex) { - errorMessage = ex.getMessage().str(); - } catch(std::exception &se) { - errorMessage = se.what(); - } catch(...) { - errorMessage = "An unknown exception was thrown"; - } - - // Reaching this point means the command has failed, ane exception was throw - // and errorMessage has been set accordingly - - std::cerr << "Aborting: " << errorMessage << std::endl; - return 1; -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -static int exceptionThrowingMain(const int argc, char *const *const argv) { - using namespace cta; - - mediachanger::acs::AcsImpl acs; - mediachanger::acs::AcsMountCmd cmd(std::cin, std::cout, std::cerr, acs); - - return cmd.exceptionThrowingMain(argc, argv); -} diff --git a/mediachanger/acs/AcsQueryDriveCmd.cpp b/mediachanger/acs/AcsQueryDriveCmd.cpp deleted file mode 100644 index a3150c9fe5..0000000000 --- a/mediachanger/acs/AcsQueryDriveCmd.cpp +++ /dev/null @@ -1,161 +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 "AcsQueryDriveCmd.hpp" -#include "AcsQueryDriveCmdLine.hpp" -#include <getopt.h> -#include <iostream> -#include <string.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsQueryDriveCmd::AcsQueryDriveCmd( - std::istream &inStream, std::ostream &outStream, std::ostream &errStream, - Acs &acs): - AcsCmd(inStream, outStream, errStream, acs) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsQueryDriveCmd::~AcsQueryDriveCmd() { - // Do nothing -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -int cta::mediachanger::acs::AcsQueryDriveCmd::exceptionThrowingMain(const int argc, - char *const *const argv) { - try { - m_cmdLine = AcsQueryDriveCmdLine(argc, argv); - } catch(cta::exception::Exception &ex) { - m_err << ex.getMessage().str() << std::endl; - m_err << std::endl; - m_err << m_cmdLine.getUsage() << std::endl; - return 1; - } - - // Display the usage message to standard out and exit with success if the - // user requested help - if(m_cmdLine.help) { - m_out << AcsQueryDriveCmdLine::getUsage(); - return 0; - } - - // Setup debug mode to be on or off depending on the command-line arguments - m_debugBuf.setDebug(m_cmdLine.debug); - - m_dbg << "query = " << m_cmdLine.queryInterval << std::endl; - m_dbg << "timeout = " << m_cmdLine.timeout << std::endl; - m_dbg << "DRIVE_SLOT = " << m_acs.driveId2Str(m_cmdLine.libraryDriveSlot) << std::endl; - - syncQueryDrive(); - return 0; -} - -//------------------------------------------------------------------------------ -// syncQueryDrive -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryDriveCmd::syncQueryDrive() { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendQueryDriveRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, m_cmdLine.queryInterval, - m_cmdLine.timeout); - processQueryResponse(m_out, buf); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to query drive " << - m_acs.driveId2Str(m_cmdLine.libraryDriveSlot) << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// sendQueryDriveRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryDriveCmd::sendQueryDriveRequest( - const SEQ_NO sequence) { - - m_dbg << "Calling Acs::queryDrive()" << std::endl; - const STATUS s = acs_query_drive(sequence, &(m_cmdLine.libraryDriveSlot), 1); - m_dbg << "Acs::queryDrive() returned " << acs_status(s) << std::endl; - - if(STATUS_SUCCESS != s) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to send query request for drive " << - m_acs.driveId2Str(m_cmdLine.libraryDriveSlot)<< ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processQueryResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryDriveCmd::processQueryResponse( - std::ostream &os, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) { - - const ACS_QUERY_DRV_RESPONSE *const msg = (ACS_QUERY_DRV_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->query_drv_status) { - cta::exception::Exception ex; - ex.getMessage() << "Status of query response is not success: " << - acs_status(msg->query_drv_status); - throw ex; - } - - if((unsigned short)1 != msg->count) { - cta::exception::Exception ex; - ex.getMessage() << "Query response does not contain a single drive: count=" - << msg->count; - throw ex; - } - - // count is 1 so it is safe to make a reference to the single drive status - const QU_DRV_STATUS &drvStatus = msg->drv_status[0]; - - if(m_acs.driveId2Str(m_cmdLine.libraryDriveSlot)!= m_acs.driveId2Str(drvStatus.drive_id)) { - cta::exception::Exception ex; - ex.getMessage() << - "Drive identifier of query response does not match that of request" - " requestDriveID=" <<m_acs.driveId2Str(m_cmdLine.libraryDriveSlot) << - " responseDriveID=" << m_acs.driveId2Str(drvStatus.drive_id); - throw ex; - } - - writeDriveStatus(os, drvStatus); -} - -//------------------------------------------------------------------------------ -// writeDriveStatus -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryDriveCmd::writeDriveStatus( - std::ostream &os, const QU_DRV_STATUS &s) { - - os << "Drive identifier: " << m_acs.driveId2Str(s.drive_id) << std::endl; - os << "Drive type: " << acs_type((TYPE)s.drive_type) << std::endl; - os << "Drive state: " << acs_state(s.state) << std::endl; - os << "Drive status: " << acs_status(s.status) << std::endl; - os << "Volume identifier: " << s.vol_id.external_label << std::endl; -} diff --git a/mediachanger/acs/AcsQueryDriveCmd.hpp b/mediachanger/acs/AcsQueryDriveCmd.hpp deleted file mode 100644 index 2463a16323..0000000000 --- a/mediachanger/acs/AcsQueryDriveCmd.hpp +++ /dev/null @@ -1,115 +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 "AcsCmd.hpp" -#include "AcsQueryDriveCmdLine.hpp" -#include "mediachanger/CmdLineTool.hpp" -#include <stdint.h> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * The class implementing the mount command. - */ -class AcsQueryDriveCmd: public AcsCmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsQueryDriveCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs); - - /** - * Destructor. - */ - virtual ~AcsQueryDriveCmd(); - - /** - * The entry function of the command. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ - int exceptionThrowingMain(const int argc, char *const *const argv); -protected: - - /** - * Queries ACS for information about the drive identifier specified on the - * command-line. - * - * This method does not return until the information has been successfully - * retrieved, an error has occurred or the specified timeout has been - * reached. - * - * @return The drive status of the drive identifier specified on the - * command-line. - */ - void syncQueryDrive(); - - /** - * Sends the query drive request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendQueryDriveRequest(const SEQ_NO seqNumber); - - /** - * Extracts the drive status from the specified query-response message and - * writes it in human-readable form to the specified output stream. - * - * @param os The output stream. - * @param buf The query-response message. - */ - void processQueryResponse(std::ostream &os, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]); - - /** - * Writes a human readable representation of the specified drive status to - * the specified output stream. - * - * @param os The output stream. - * @param s The drive status. - */ - void writeDriveStatus(std::ostream &os, const QU_DRV_STATUS &s); - -private: - - /** - * The parsed command-line. - * - * The value of this member variable is set within the main() method of this - * class. - */ - AcsQueryDriveCmdLine m_cmdLine; - -}; // class AcsQueryDriveCmd - -} // namespace acs -} // namepsace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsQueryDriveCmdLine.cpp b/mediachanger/acs/AcsQueryDriveCmdLine.cpp deleted file mode 100644 index e48c347b9f..0000000000 --- a/mediachanger/acs/AcsQueryDriveCmdLine.cpp +++ /dev/null @@ -1,174 +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 "Acs.hpp" -#include "AcsQueryDriveCmdLine.hpp" -#include "Constants.hpp" -#include <getopt.h> -#include <stdlib.h> -#include <string.h> - - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::AcsQueryDriveCmdLine::AcsQueryDriveCmdLine(): - debug(false), - help(false), - queryInterval(0), - timeout(0) { - libraryDriveSlot.panel_id.lsm_id.acs = (ACS)0; - libraryDriveSlot.panel_id.lsm_id.lsm = (LSM)0; - libraryDriveSlot.panel_id.panel = (PANEL)0; - libraryDriveSlot.drive = (DRIVE)0; - memset(volId.external_label, '\0', sizeof(volId.external_label)); -} - - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsQueryDriveCmdLine::AcsQueryDriveCmdLine(const int argc, - char *const *const argv): - debug(false), - help(false), - queryInterval(ACS_QUERY_INTERVAL), - timeout(ACS_CMD_TIMEOUT) { - libraryDriveSlot.panel_id.lsm_id.acs = (ACS)0; - libraryDriveSlot.panel_id.lsm_id.lsm = (LSM)0; - libraryDriveSlot.panel_id.panel = (PANEL)0; - libraryDriveSlot.drive = (DRIVE)0; - memset(volId.external_label, '\0', sizeof(volId.external_label)); - - static struct option longopts[] = { - {"debug", 0, NULL, 'd'}, - {"help" , 0, NULL, 'h'}, - {"query" , required_argument, NULL, 'q'}, - {"timeout" , required_argument, NULL, 't'}, - {NULL, 0, NULL, 0} - }; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - - int opt = 0; - while((opt = getopt_long(argc, argv, ":dhq:t:", longopts, NULL)) != -1) { - processOption(opt); - } - // There is no need to continue parsing when the help option is set - if(help) { - return; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check that DRIVE_SLOT has been specified - if(1 > nbArgs) { - cta::exception::Exception ex; - ex.getMessage() << "DRIVE_SLOT must be specified"; - throw ex; - } - - // Check that aren't too many non-optional arguments - if(1 < nbArgs) { - cta::exception::Exception ex; - ex.getMessage() << "To many non-optional arguments: expected=1,actual=" << nbArgs; - throw ex; - } - - // Parse DRIVE_SLOT - libraryDriveSlot = str2DriveId(argv[optind]); -} - -//------------------------------------------------------------------------------ -// processOption -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryDriveCmdLine::processOption(const int opt) { - switch(opt) { - case 'd': - debug = true; - break; - case 'h': - help = true; - break; - case 'q': - queryInterval = parseQueryInterval(optarg); - break; - case 't': - timeout = parseTimeout(optarg); - break; - case ':': - return handleMissingParameter(optopt); - case '?': - return handleUnknownOption(optopt); - default: - { - cta::exception::Exception ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)opt; - throw ex; - } - } // switch(opt) -} - - -//------------------------------------------------------------------------------ -// getUsage -//------------------------------------------------------------------------------ - std::string cta::mediachanger::acs::AcsQueryDriveCmdLine::getUsage() { - std::ostringstream usage; - usage << - "Usage:\n" - "\n" - << getProgramName() << " [options] DRIVE_SLOT\n" - "\n" - "Where:\n" - "\n" - " DRIVE_SLOT The slot in the tape library where the drive is located.\n" - " The format of DRIVE_SLOT is as follows:\n" - "\n" - " ACS:LSM:panel:transport\n" - "\n" - "Options:\n" - "\n" - " -d|--debug Turn on the printing of debug information.\n" - "\n" - " -h|--help Print this help message and exit.\n" - " -q|--query SECONDS Time to wait between queries to ACS for responses.\n" - " SECONDS must be an integer value greater than 0.\n" - " The default value of SECONDS is " - << ACS_QUERY_INTERVAL << ".\n" - " -t|--timeout SECONDS Time to wait for the query to conclude. SECONDS\n" - " must be an integer value greater than 0. The\n" - " default value of SECONDS is " - << ACS_CMD_TIMEOUT << ".\n" - "\n"; - return usage.str(); -} - -//------------------------------------------------------------------------------ -// getProgramName -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::AcsQueryDriveCmdLine::getProgramName() { - return "cta-acs-querydrive"; -} - diff --git a/mediachanger/acs/AcsQueryDriveCmdLine.hpp b/mediachanger/acs/AcsQueryDriveCmdLine.hpp deleted file mode 100644 index b62df0e7d6..0000000000 --- a/mediachanger/acs/AcsQueryDriveCmdLine.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 "AcsCmdLine.hpp" -#include "mediachanger/AcsLibrarySlot.hpp" -#include "mediachanger/LibrarySlotParser.hpp" - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Data type used to store the results of parsing the command-line. - */ -struct AcsQueryDriveCmdLine: public AcsCmdLine { - /** - * True if the debug option has been set. - */ - BOOLEAN debug; - - /** - * True if the help option has been set. - */ - BOOLEAN help; - - /** - * Time in seconds to wait between queries to ACS for responses. - */ - int queryInterval; - - /** - * Time in seconds to wait for the dismount to conclude. - */ - int timeout; - - /** - * The volume identifier of the tape to be mounted. - */ - VOLID volId; - - /** - * Constructor. - * - * Initialises all BOOLEAN member-variables to FALSE, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - AcsQueryDriveCmdLine(); - - /** - * Constructor. - * - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - */ - AcsQueryDriveCmdLine(const int argc, char *const *const argv); - - - /** - * Gets the usage message that describes the command line. - * - * @return The usage message. - */ - static std::string getUsage(); - - /** - * Return sthe program name. - * - * @return sthe program name. - */ - static std::string getProgramName(); - - /** - * The slot in the tape library where the drive is located. - */ - - DRIVEID libraryDriveSlot; - - -private: - - /** - * Processes the specified option that was returned by getopt_long(). - * - * @param opt The option that was returned by getopt_long(). - */ - void processOption(const int opt); - -}; // class AcsQueryDriveCmdLine - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsQueryDriveCmdMain.cpp b/mediachanger/acs/AcsQueryDriveCmdMain.cpp deleted file mode 100644 index cfc8d406ae..0000000000 --- a/mediachanger/acs/AcsQueryDriveCmdMain.cpp +++ /dev/null @@ -1,60 +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 "AcsImpl.hpp" -#include "AcsQueryDriveCmd.hpp" -#include "AcsQueryDriveCmdLine.hpp" - -#include <iostream> - -/** - * An exception throwing version of main(). - * - * @param argc The number of command-line arguments including the program name. - * @param argv The command-line arguments. - * @param The exit value of the program. - */ -static int exceptionThrowingMain(const int argc, char *const *const argv); - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - using namespace cta; - std::string errorMessage; - try { - return exceptionThrowingMain(argc, argv); - } catch(cta::exception::Exception &ex) { - errorMessage = ex.getMessage().str(); - } catch(std::exception &se) { - errorMessage = se.what(); - } catch(...) { - errorMessage = "An unknown exception was thrown"; - } - return 1; -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -static int exceptionThrowingMain(const int argc, char *const *const argv) { - using namespace cta; - mediachanger::acs::AcsImpl acs; - mediachanger::acs::AcsQueryDriveCmd cmd(std::cin, std::cout, std::cerr, acs); - return cmd.exceptionThrowingMain(argc, argv); -} diff --git a/mediachanger/acs/AcsQueryVolumeCmd.cpp b/mediachanger/acs/AcsQueryVolumeCmd.cpp deleted file mode 100644 index 9384ed5194..0000000000 --- a/mediachanger/acs/AcsQueryVolumeCmd.cpp +++ /dev/null @@ -1,190 +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 "AcsQueryVolumeCmd.hpp" -#include "AcsQueryVolumeCmdLine.hpp" -#include <getopt.h> -#include <iostream> -#include <string.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsQueryVolumeCmd::AcsQueryVolumeCmd( - std::istream &inStream, std::ostream &outStream, std::ostream &errStream, - Acs &acs): - AcsCmd(inStream, outStream, errStream, acs) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsQueryVolumeCmd::~AcsQueryVolumeCmd() { - // Do nothing -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -int cta::mediachanger::acs::AcsQueryVolumeCmd::exceptionThrowingMain(const int argc, - char *const *const argv) { - try { - m_cmdLine = AcsQueryVolumeCmdLine(argc, argv); - } catch(cta::exception::Exception &ex) { - m_err << ex.getMessage().str() << std::endl; - m_err << std::endl; - m_err << m_cmdLine.getUsage() << std::endl; - return 1; - } - - // Display the usage message to standard out and exit with success if the - // user requested help - if(m_cmdLine.help) { - m_out << AcsQueryVolumeCmdLine::getUsage(); - return 0; - } - - // Setup debug mode to be on or off depending on the command-line arguments - m_debugBuf.setDebug(m_cmdLine.debug); - - m_dbg << "query = " << m_cmdLine.queryInterval << std::endl; - m_dbg << "timeout = " << m_cmdLine.timeout << std::endl; - m_dbg << "VID = " << m_cmdLine.volId.external_label << std::endl; - - syncQueryVolume(); - return 0; -} - -//------------------------------------------------------------------------------ -// syncQueryVolume -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryVolumeCmd::syncQueryVolume() { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendQueryVolumeRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, m_cmdLine.queryInterval, - m_cmdLine.timeout); - processQueryResponse(m_out, buf); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to query volume " << - m_cmdLine.volId.external_label << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// sendQueryVolumeRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryVolumeCmd::sendQueryVolumeRequest( - const SEQ_NO seqNumber) { - VOLID volIds[MAX_ID]; - - memset(volIds, '\0', sizeof(volIds)); - strncpy(volIds[0].external_label, m_cmdLine.volId.external_label, - sizeof(volIds[0].external_label)); - volIds[0].external_label[sizeof(volIds[0].external_label) - 1] = '\0'; - - m_dbg << "Calling Acs::queryVolume()" << std::endl; - const STATUS s = m_acs.queryVolume(seqNumber, volIds, 1); - m_dbg << "Acs::queryVolume() returned " << acs_status(s) << std::endl; - - if(STATUS_SUCCESS != s) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to send query request for volume " << - m_cmdLine.volId.external_label << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processQueryResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryVolumeCmd::processQueryResponse( - std::ostream &os, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) { - - const ACS_QUERY_VOL_RESPONSE *const msg = (ACS_QUERY_VOL_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->query_vol_status) { - cta::exception::Exception ex; - ex.getMessage() << "Status of query response is not success: " << - acs_status(msg->query_vol_status); - throw ex; - } - - if((unsigned short)1 != msg->count) { - cta::exception::Exception ex; - ex.getMessage() << "Query response does not contain a single volume: count=" - << msg->count; - throw ex; - } - - // count is 1 so it is safe to make a reference to the single volume status - const QU_VOL_STATUS &volStatus = msg->vol_status[0]; - - if(strcmp(m_cmdLine.volId.external_label, volStatus.vol_id.external_label)) { - cta::exception::Exception ex; - ex.getMessage() << - "Volume identifier of query response does not match that of request" - ": requestVID=" << m_cmdLine.volId.external_label << - " responseVID=" << volStatus.vol_id.external_label; - throw ex; - } - - writeVolumeStatus(os, volStatus); -} - -//------------------------------------------------------------------------------ -// writeVolumeStatus -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryVolumeCmd::writeVolumeStatus( - std::ostream &os, const QU_VOL_STATUS &s) { - os << "Volume identifier: " << s.vol_id.external_label << std::endl; - os << "Media type (media_types.dat): " << (int)s.media_type << std::endl; - - switch(s.location_type) { - case LOCATION_CELL: { - os << "Location type: cell" << std::endl; - const CELLID &cellId = s.location.cell_id; - os << "ACS: " << (int)cellId.panel_id.lsm_id.acs << std::endl; - os << "LSM: " << (int)cellId.panel_id.lsm_id.lsm << std::endl; - os << "Panel: " << (int)cellId.panel_id.panel << std::endl; - os << "Row: " << (int)cellId.row << std::endl; - os << "Column: " << (int)cellId.col << std::endl; - break; - } - case LOCATION_DRIVE: { - os << "Location type: drive" << std::endl; - const DRIVEID &driveId = s.location.drive_id; - os << "ACS: " << (int)driveId.panel_id.lsm_id.acs << std::endl; - os << "LSM: " << (int)driveId.panel_id.lsm_id.lsm << std::endl; - os << "Panel: " << (int)driveId.panel_id.panel << std::endl; - os << "Drive: " << (int)driveId.drive << std::endl; - break; - } - default: - os << "Location type: UNKNOWN" << std::endl; - break; - } - - os << "Status: " << acs_status(s.status) << std::endl; -} diff --git a/mediachanger/acs/AcsQueryVolumeCmd.hpp b/mediachanger/acs/AcsQueryVolumeCmd.hpp deleted file mode 100644 index 9221d96cbb..0000000000 --- a/mediachanger/acs/AcsQueryVolumeCmd.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 "AcsCmd.hpp" -#include "AcsQueryVolumeCmdLine.hpp" - -#include <stdint.h> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * The class implementing the mount command. - */ -class AcsQueryVolumeCmd: public AcsCmd { -public: - - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - * @param acs Wrapper around the ACSLS C-API. - */ - AcsQueryVolumeCmd(std::istream &inStream, std::ostream &outStream, - std::ostream &errStream, Acs &acs); - - /** - * Destructor. - */ - virtual ~AcsQueryVolumeCmd(); - - /** - * The entry function of the command. - * - * @param argc The number of command-line arguments. - * @param argv The command-line arguments. - * @return The exit value of the program. - */ - int exceptionThrowingMain(const int argc, char *const *const argv); - -protected: - - /** - * Queries ACS for information about the volume identifier specified on the - * command-line. - * - * This method does not return until the information has been successfully - * retrieved, an error has occurred or the specified timeout has been - * reached. - * - * @return The volume status of the volume identifier specified on the - * command-line. - */ - void syncQueryVolume(); - - /** - * Sends the query volume request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendQueryVolumeRequest(const SEQ_NO seqNumber); - - /** - * Extracts the volume status from the specified query-response message and - * writes it in human-readable form to the specified output stream. - * - * @param os The output stream. - * @param buf The query-response message. - */ - void processQueryResponse(std::ostream &os, - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]); - - /** - * Writes a human readable representation of the specified volume status to - * the specified output stream. - * - * @param os The output stream. - * @param s The volume status. - */ - void writeVolumeStatus(std::ostream &os, const QU_VOL_STATUS &s); - -private: - - /** - * The parsed command-line. - * - * The value of this member variable is set within the main() method of this - * class. - */ - AcsQueryVolumeCmdLine m_cmdLine; - -}; // class AcsQueryVolumeCmd - -} // namespace acs -} // namepsace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsQueryVolumeCmdLine.cpp b/mediachanger/acs/AcsQueryVolumeCmdLine.cpp deleted file mode 100644 index 375112ad50..0000000000 --- a/mediachanger/acs/AcsQueryVolumeCmdLine.cpp +++ /dev/null @@ -1,147 +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 "Acs.hpp" -#include "AcsQueryVolumeCmdLine.hpp" -#include "Constants.hpp" - -#include <getopt.h> -#include <stdlib.h> -#include <string.h> - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::AcsQueryVolumeCmdLine::AcsQueryVolumeCmdLine() - : - debug(FALSE), - help(FALSE), - queryInterval(0), - timeout(0) { - memset(volId.external_label, '\0', sizeof(volId.external_label)); -} - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::AcsQueryVolumeCmdLine::AcsQueryVolumeCmdLine(const int argc, - char *const *const argv): - debug(FALSE), - help(FALSE), - queryInterval(ACS_QUERY_INTERVAL), - timeout(ACS_CMD_TIMEOUT) { - memset(volId.external_label, '\0', sizeof(volId.external_label)); - - static struct option longopts[] = { - {"debug", 0, NULL, 'd'}, - {"help" , 0, NULL, 'h'}, - {"query" , required_argument, NULL, 'q'}, - {"timeout" , required_argument, NULL, 't'}, - {NULL, 0, NULL, 0} - }; - - // Prevent getopt() from printing an error message if it does not recognize - // an option character - opterr = 0; - - int opt = 0; - while((opt = getopt_long(argc, argv, ":dhq:t:", longopts, NULL)) != -1) { - processOption(opt); - } - - // There is no need to continue parsing when the help option is set - if(help) { - return; - } - - // Calculate the number of non-option ARGV-elements - const int nbArgs = argc - optind; - - // Check that VID has been specified - if(nbArgs < 1) { - cta::exception::Exception ex; - ex.getMessage() << "VID must be specified"; - throw ex; - } - - // Parse the VID command-line argument - volId = Acs::str2Volid(argv[optind]); -} - -//------------------------------------------------------------------------------ -// processOption -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::AcsQueryVolumeCmdLine::processOption(const int opt) { - switch(opt) { - case 'd': - debug = true; - break; - case 'h': - help = true; - break; - case 'q': - queryInterval = parseQueryInterval(optarg); - break; - case 't': - timeout = parseTimeout(optarg); - break; - case ':': - return handleMissingParameter(optopt); - case '?': - return handleUnknownOption(optopt); - default: - { - cta::exception::Exception ex; - ex.getMessage() << - "getopt_long returned the following unknown value: 0x" << - std::hex << (int)opt; - throw ex; - } - } // switch(opt) -} - -//------------------------------------------------------------------------------ -// getUsage -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::AcsQueryVolumeCmdLine::getUsage() { - std::ostringstream usage; - usage << - "Usage:\n" - " cta-acs-queryvolume [options] VID\n" - "\n" - "Where:\n" - "\n" - " VID The VID of the volume to be queried.\n" - "\n" - "Options:\n" - "\n" - " -d|--debug Turn on the printing of debug information.\n" - " -h|--help Print this help message and exit.\n" - " -q|--query SECONDS Time to wait between queries to ACS for responses.\n" - " SECONDS must be an integer value greater than 0.\n" - " The default value of SECONDS is " - << ACS_QUERY_INTERVAL << ".\n" - " -t|--timeout SECONDS Time to wait for the query to conclude. SECONDS\n" - " must be an integer value greater than 0. The\n" - " default value of SECONDS in " - << ACS_CMD_TIMEOUT << ".\n" - "\n" - "Comments to: CTA team\n"; - return usage.str(); -} diff --git a/mediachanger/acs/AcsQueryVolumeCmdLine.hpp b/mediachanger/acs/AcsQueryVolumeCmdLine.hpp deleted file mode 100644 index d99feb237f..0000000000 --- a/mediachanger/acs/AcsQueryVolumeCmdLine.hpp +++ /dev/null @@ -1,101 +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 "AcsCmdLine.hpp" - -extern "C" { -#include "acssys.h" -#include "acsapi.h" -} - -#include <string> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Data type used to store the results of parsing the command-line. - */ -struct AcsQueryVolumeCmdLine: public AcsCmdLine { - /** - * True if the debug option has been set. - */ - BOOLEAN debug; - - /** - * True if the help option has been set. - */ - BOOLEAN help; - - /** - * Time in seconds to wait between queries to ACS for responses. - */ - int queryInterval; - - /** - * Time in seconds to wait for the dismount to conclude. - */ - int timeout; - - /** - * The volume identifier of the tape to be mounted. - */ - VOLID volId; - - /** - * Constructor. - * - * Initialises all BOOLEAN member-variables to FALSE, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - AcsQueryVolumeCmdLine(); - - /** - * Constructor. - * - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - */ - AcsQueryVolumeCmdLine(const int argc, char *const *const argv); - - /** - * Gets the usage message that describes the comamnd line. - * - * @return The usage message. - */ - static std::string getUsage(); - -private: - - /** - * Processes the specified option that was returned by getopt_long(). - * - * @param opt The option that was returned by getopt_long(). - */ - void processOption(const int opt); - -}; // class AcsQueryVolumeCmdLine - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/AcsQueryVolumeCmdMain.cpp b/mediachanger/acs/AcsQueryVolumeCmdMain.cpp deleted file mode 100644 index a9472eaf94..0000000000 --- a/mediachanger/acs/AcsQueryVolumeCmdMain.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 "AcsImpl.hpp" -#include "AcsQueryVolumeCmd.hpp" -#include "AcsQueryVolumeCmdLine.hpp" - -#include <iostream> - -/** - * An exception throwing version of main(). - * - * @param argc The number of command-line arguments including the program name. - * @param argv The command-line arguments. - * @param The exit value of the program. - */ -static int exceptionThrowingMain(const int argc, char *const *const argv); - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char *const *const argv) { - using namespace cta; - std::string errorMessage; - - try { - return exceptionThrowingMain(argc, argv); - } catch(cta::exception::Exception &ex) { - errorMessage = ex.getMessage().str(); - } catch(std::exception &se) { - errorMessage = se.what(); - } catch(...) { - errorMessage = "An unknown exception was thrown"; - } - - // Reaching this point means the command has failed, ane exception was throw - // and errorMessage has been set accordingly - - std::cerr << "Aborting: " << errorMessage << std::endl; - return 1; -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -static int exceptionThrowingMain(const int argc, char *const *const argv) { - using namespace cta; - - mediachanger::acs::AcsImpl acs; - mediachanger::acs::AcsQueryVolumeCmd cmd(std::cin, std::cout, std::cerr, acs); - - return cmd.exceptionThrowingMain(argc, argv); -} diff --git a/mediachanger/acs/CMakeLists.txt b/mediachanger/acs/CMakeLists.txt deleted file mode 100644 index cd3b19b64e..0000000000 --- a/mediachanger/acs/CMakeLists.txt +++ /dev/null @@ -1,155 +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 -# - -################################################################################ -# Rules to build and install acsd -################################################################################ - -find_package(stk REQUIRED) - -add_subdirectory(daemon) - -add_library(cta-acs - Acs.cpp - AcsImpl.cpp - AcsDebugBuf.cpp - AcsLibraryInteraction.cpp) - -target_link_libraries(cta-acs - ctamediachanger - ctacommon - ctareactor - zmq - ${STK_LIBRARIES}) - -set_target_properties (cta-acs PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) - -################################################################################ -# Rules to build and install castor-tape-acs-dismount -################################################################################ -message(STATUS "Adding cta-acs-dismount target") -set (ACS_DISMOUNT_SRC_FILES - ../../common/exception/Backtrace.cpp - ../../common/exception/Exception.cpp - ../../common/exception/Mismatch.cpp - ../../common/exception/RequestFailed.cpp - Acs.cpp - AcsCmd.cpp - AcsCmdLine.cpp - AcsImpl.cpp - AcsDismountCmd.cpp - AcsDismountCmdLine.cpp - AcsDismountCmdMain.cpp - CmdLineTool.cpp - AcsDebugBuf.cpp) -add_executable (cta-acs-dismount ${ACS_DISMOUNT_SRC_FILES}) -set_target_properties (cta-acs-dismount PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) -target_link_libraries (cta-acs-dismount - ${STK_LIBRARIES}) -install (TARGETS cta-acs-dismount DESTINATION /usr/bin) -install (FILES cta-acs-dismount.1cta DESTINATION /usr/share/man/man1) - -################################################################################ -# Rules to build and install cta-acs-mount -################################################################################ -set (ACS_MOUNT_SRC_FILES - ../../common/exception/Backtrace.cpp - ../../common/exception/Exception.cpp - ../../common/exception/Mismatch.cpp - ../../common/exception/RequestFailed.cpp - Acs.cpp - AcsCmd.cpp - AcsCmdLine.cpp - AcsImpl.cpp - AcsMountCmd.cpp - AcsMountCmdLine.cpp - AcsMountCmdMain.cpp - CmdLineTool.cpp - AcsDebugBuf.cpp) -add_executable (cta-acs-mount ${ACS_MOUNT_SRC_FILES}) -set_target_properties (cta-acs-mount PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) -target_link_libraries (cta-acs-mount - ${STK_LIBRARIES}) -install (TARGETS cta-acs-mount DESTINATION /usr/bin) -install (FILES cta-acs-mount.1cta DESTINATION /usr/share/man/man1) - -################################################################################ -# Rules to build and install cta-acs-queryvolume -################################################################################ -message(STATUS "Adding cta-acs-queryvolume target") -set (ACS_QUERYVOLUME_SRC_FILES - ../../common/exception/Backtrace.cpp - ../../common/exception/Exception.cpp - ../../common/exception/Mismatch.cpp - ../../common/exception/RequestFailed.cpp - Acs.cpp - AcsCmd.cpp - AcsCmdLine.cpp - AcsImpl.cpp - AcsQueryVolumeCmd.cpp - AcsQueryVolumeCmdLine.cpp - AcsQueryVolumeCmdMain.cpp - CmdLineTool.cpp - AcsDebugBuf.cpp) - -add_executable (cta-acs-queryvolume ${ACS_QUERYVOLUME_SRC_FILES}) -target_link_libraries (cta-acs-queryvolume - ${STK_LIBRARIES}) -set_target_properties (cta-acs-queryvolume PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) -install (TARGETS cta-acs-queryvolume - DESTINATION /usr/bin) -install (FILES cta-acs-queryvolume.1cta DESTINATION /usr/share/man/man1) - -################################################################################ -# Rules to build and install cta-acs-querydrive -################################################################################ -message(STATUS "Adding cta-acs-querydrive target") -set (ACS_QUERYDRIVE_SRC_FILES - ../../common/exception/Backtrace.cpp - ../../common/exception/Exception.cpp - ../../common/exception/Mismatch.cpp - ../../common/exception/RequestFailed.cpp - Acs.cpp - AcsCmd.cpp - AcsCmdLine.cpp - AcsImpl.cpp - AcsQueryDriveCmd.cpp - AcsQueryDriveCmdLine.cpp - AcsQueryDriveCmdMain.cpp - CmdLineTool.cpp - AcsDebugBuf.cpp) - -add_executable (cta-acs-querydrive ${ACS_QUERYDRIVE_SRC_FILES}) -target_link_libraries (cta-acs-querydrive - ${STK_LIBRARIES}) -set_target_properties (cta-acs-querydrive PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) -install (TARGETS cta-acs-querydrive - DESTINATION /usr/bin) -install (FILES cta-acs-querydrive.1cta DESTINATION /usr/share/man/man1) diff --git a/mediachanger/acs/CmdLineTool.cpp b/mediachanger/acs/CmdLineTool.cpp deleted file mode 100644 index a3e7153c64..0000000000 --- a/mediachanger/acs/CmdLineTool.cpp +++ /dev/null @@ -1,41 +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 "CmdLineTool.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::CmdLineTool::CmdLineTool(std::istream &inStream, - std::ostream &outStream, std::ostream &errStream): - m_in(inStream), m_out(outStream), m_err(errStream), m_debugBuf(outStream), - m_dbg(&m_debugBuf) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::CmdLineTool::~CmdLineTool() { -} - -//------------------------------------------------------------------------------ -// bool2Str -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::CmdLineTool::bool2Str(const bool value) const { - return value ? "TRUE" : "FALSE"; -} diff --git a/mediachanger/acs/CmdLineTool.hpp b/mediachanger/acs/CmdLineTool.hpp deleted file mode 100644 index cd622725a9..0000000000 --- a/mediachanger/acs/CmdLineTool.hpp +++ /dev/null @@ -1,94 +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/acs/AcsDebugBuf.hpp" - -#include <istream> -#include <ostream> -#include <string> - -namespace cta { -namespace mediachanger { -namespace acs { - -/** - * Abstract class implementing common code and data structures for a - * command-line tool. - */ -class CmdLineTool { -public: - /** - * Constructor. - * - * @param inStream Standard input stream. - * @param outStream Standard output stream. - * @param errStream Standard error stream. - */ - CmdLineTool(std::istream &inStream, std::ostream &outStream, std::ostream &errStream) - ; - - /** - * Pure-virtual destructor to guarantee this class is abstract. - */ - virtual ~CmdLineTool() = 0; - -protected: - - /** - * Standard input stream. - */ - std::istream &m_in; - - /** - * Standard output stream. - */ - std::ostream &m_out; - - /** - * Standard error stream. - */ - std::ostream &m_err; - - /** - * Debug stream buffer that inserts a standard debug preamble before each - * message-line written to it. - */ - cta::mediachanger::acs::DebugBuf m_debugBuf; - - /** - * Stream used to write debug messages. - * - * This stream will insert a standard debug preamble before each message-line - * written to it. - */ - std::ostream m_dbg; - - /** - * Returns the string representation of the specfied boolean value. - * - * @param value The boolean value. - */ - std::string bool2Str(const bool value) const; - -}; // class CmdLineTool - -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/Constants.hpp b/mediachanger/acs/Constants.hpp deleted file mode 100644 index b6c9cfb970..0000000000 --- a/mediachanger/acs/Constants.hpp +++ /dev/null @@ -1,62 +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 - -namespace cta { -//namespace acs { - -/** - * The default TCP/IP port on which the CASTOR ACS daemon listens for incoming Zmq - * connections from the tape server. - */ -const unsigned short ACS_PORT = 54521; - -/** - * Default time to wait in seconds between queries to ACS Library for responses. - */ -const int ACS_QUERY_INTERVAL = 10; - -/** - * Default time to wait in seconds for the tape-library command to conclude. - */ -const int ACS_CMD_TIMEOUT = 610; - -/** - * The maximum ACS sequence number value to be used. - */ -const unsigned short ACS_MAX_SEQ = 65535; - -/** - * Default timeout for the response command to the ACS library. - */ -const int ACS_RESPONSE_TIMEOUT = 5; - -/** - * Enumeration of the states of an ACS request. - */ -enum RequestState { - ACS_REQUEST_TO_EXECUTE, - ACS_REQUEST_IS_RUNNING, - ACS_REQUEST_COMPLETED, - ACS_REQUEST_FAILED, - ACS_REQUEST_TO_DELETE}; - -//} // namespace acs -} // namespace cta - diff --git a/mediachanger/acs/acsd.init b/mediachanger/acs/acsd.init deleted file mode 100755 index c4f78f7857..0000000000 --- a/mediachanger/acs/acsd.init +++ /dev/null @@ -1,111 +0,0 @@ -#! /bin/sh -# -#/****************************************************************************** -# acsd.init -# -# 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. -# -# -# chkconfig: 345 74 31 -# description: Tape server daemon initialisation script -# -# @author castor dev team -#*****************************************************************************/ - -# Source function library. -. /etc/rc.d/init.d/functions - -# Variables -prog="acsd" -export DAEMON_COREFILE_LIMIT="unlimited" -RETVAL=0 - -# Source sysconfig files -if [ -f /etc/sysconfig/castor ]; then - . /etc/sysconfig/castor -fi -if [ -f /etc/sysconfig/$prog ]; then - . /etc/sysconfig/$prog -fi - -start() { - # Run daemon - echo -n $"Starting $prog: " - - cd /var/log/castor - daemon /usr/bin/$prog $ACSD_OPTIONS - - # Write the pid to a file. - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - pid=`ps -eo pid,ppid,comm | egrep " 1 $prog\$" | awk '{print $1}'` - rm -f /var/run/$prog.pid - if [ -n "$pid" ]; then - echo $pid > /var/run/$prog.pid - RETVAL=0 - else - RETVAL=1 - fi - fi - - [ $RETVAL -eq 0 ] && success $"$base startup" || failure $"$base startup" - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog - return $RETVAL -} - -stop() { - echo -n $"Stopping $prog: " - killproc $prog - - RETVAL=$? - echo - [ -f /var/lock/subsys/$prog ] && rm -f /var/lock/subsys/$prog - return $RETVAL -} - - -restart() { - stop - start -} - -# See how we were called -case "$1" in - - start) - start - ;; - stop) - stop - ;; - status) - status $prog - RETVAL=$? - ;; - restart) - restart - ;; - condrestart) - [ -f /var/lock/subsys/$prog ] && restart || : - ;; - *) - echo $"Usage: $0 {start|stop|status|restart|condrestart}" - exit 1 -esac - -exit $RETVAL diff --git a/mediachanger/acs/acsd.man b/mediachanger/acs/acsd.man deleted file mode 100644 index 675fa7e746..0000000000 --- a/mediachanger/acs/acsd.man +++ /dev/null @@ -1,66 +0,0 @@ -.\" 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. -.TH ACSD "8castor" "$Date: 2014/03/24 14:44:00 $" CASTOR "CASTOR" -.SH NAME -acsd \- Automated Cartdridge System daemon -.SH SYNOPSIS -.BI "acsd [OPTIONS]" - -.SH DESCRIPTION -\fBacsd\fP is the daemon responsible for controlling ACS mount and ACS dismount -requests. -.P -When \fBacsd\fP is executed it immediately forks with the parent -terminating and the child running in the background. If required the -\fB\-f, \-\-foreground\fP option can be used to stop \fBacsd\fP from -forking and keep the parent process in the foreground. - -.SH OPTIONS -.TP -\fB\-f, \-\-foreground -Remain in the foreground. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-c, \-\-config <config-file> -Set the location of the CASTOR configuration file (castor.conf). The default location is /etc/castor/castor.conf. - -.SH CASTOR CONFIGURATION PARAMETERS -The acsd daemon reads and uses the following CASTOR configuration -parameters which are specified within the CASTOR configuration file (the -default location is /etc/castor/castor.conf). - -.TP -\fBAcsDaemon CmdTimeout -The maximum time to wait in seconds for a tape-library command to conclude. - -.TP -\fBAcsDaemon Port -The TCP/IP port on which the CASTOR ACS daemon listens for incoming Zmq -connections from the tape server. - -.TP -\fBAcsDaemon QueryInterval -Time to wait in seconds between queries to the tape Library. - -.SH FILES -.TP -.B /etc/castor/castor.conf -Default location of the CASTOR configuration file. -.TP -.B /var/log/castor/acsd.log -Default location of the acsd log file. - -.SH AUTHOR -\fBCASTOR\fP Team <castor.support@cern.ch> diff --git a/mediachanger/acs/cta-acs-dismount.1cta b/mediachanger/acs/cta-acs-dismount.1cta deleted file mode 100644 index 39cc0c6fd2..0000000000 --- a/mediachanger/acs/cta-acs-dismount.1cta +++ /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/>. - -.TH CASTOR-TAPE-ACS-DISMOUNT "1cta" "$Date: 2013/10/09 14:00:00 $" CASTOR "CASTOR" -.SH NAME -cta-acs-dismount \- dismount a volume -.SH SYNOPSIS -.BI "cta-acs-dismount [options] VID DRIVE_SLOT" - -.SH DESCRIPTION -\fBWarning\fP, \fBcta-acs-dismount\fP is a developer tool and is -therefore subject to change in and even removal from a future release of CASTOR. -End users should not rely on this tool to operate their CASTOR installation. - -\fBcta-acs-dismount\fP dismounts the volume with the specfied \fBVID\fP -from the drive located in the specified \fBDRIVE_SLOT\fP of the tape library. -The format of \fBDRIVE_SLOT\fP is as follows: - -.B ACS:LSM:panel:transport - -Please note that this command-line tool communicates directly with the CSI of -the ACS system. This command-line tool does not communicate with any CASTOR -daemons. - -.SH OPTIONS -.TP -\fB\-d, \-\-debug -Turns on the printing of debug information. -.TP -\fB\-f, \-\-force -Force the dismount. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-q, \-\-query SECONDS -Time wait between queries to ACLS for responses. -\fBSECONDS\fP must be an integer value greater than 0. -The default value of \fBSECONDS\fP is 10. -.TP -\fB\-t, \-\-timeout SECONDS -Time to wait for the dismount operation to conclude. -\fBSECONDS\fP must be an integer value greater than 0. -The default value of \fBSECONDS\fP is 610. - -.SH "RETURN CODES" -.TP -\fB 0 -Ok. -.TP -\fB 1 -Command failed. - -.SH AUTHOR -\fBCTA\fP Team diff --git a/mediachanger/acs/cta-acs-mount.1cta b/mediachanger/acs/cta-acs-mount.1cta deleted file mode 100644 index 1adc058396..0000000000 --- a/mediachanger/acs/cta-acs-mount.1cta +++ /dev/null @@ -1,69 +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/>. - -.TH CTA-TAPE-ACS-MOUNT "1cta" "$Date: 2013/10/09 14:00:00 $" CTA "CTA" -.SH NAME -cta-acs-mount \- mount a volume -.SH SYNOPSIS -.BI "cta-acs-mount [options] VID DRIVE_SLOT" - -.SH DESCRIPTION -\fBWarning\fP, \fBcta-acs-mount\fP is a developer tool and is therefore -subject to change in and even removal from a future release of CTA. -End users should not rely on this tool to operate their CTA installation. - -\fBcta-acs-mount\fP mounts the volume with the specfied \fBVID\fP into -the drive located in the specified \fBDRIVE_SLOT\fP of the tape library. -The format of \fBDRIVE_SLOT\fP is as follows: - -.B ACS:LSM:panel:transport - -Please note that this command-line tool communicates directly with the CSI of -the ACS system. This command-line tool does not communicate with any CTA -daemons. - -.SH OPTIONS -.TP -\fB\-d, \-\-debug -Turns on the printing of debug information. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-q, \-\-query SECONDS -Time wait between queries to ACLS for responses. -\fBSECONDS\fP must be an integer value greater than 0. -The default value of \fBSECONDS\fP is 10. -.TP -\fB\-r, \-\-readonly -Request the volume is mounted for read-only access. -.TP -\fB\-t, \-\-timeout SECONDS -Time to wait for the mount operation to conclude. -\fBSECONDS\fP must be an integer value greater than 0. -The default value of \fBSECONDS\fP is 610. - -.SH "RETURN CODES" -.TP -\fB 0 -Ok. -.TP -\fB 1 -Command failed. - -.SH AUTHOR -\fBCTA\fP Team diff --git a/mediachanger/acs/cta-acs-querydrive.1cta b/mediachanger/acs/cta-acs-querydrive.1cta deleted file mode 100644 index f6359650d2..0000000000 --- a/mediachanger/acs/cta-acs-querydrive.1cta +++ /dev/null @@ -1,65 +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/>. - -.TH CTA-TAPE-ACS-QUERYDRIVE "1cta" "$Date: 2013/10/09 14:00:00 $" CTA "CTA" -.SH NAME -cta-acs-querydrive \- queries a drive -.SH SYNOPSIS -.BI "cta-acs-querydrive [options] DRIVE_SLOT" - -.SH DESCRIPTION -\fBWarning\fP, \fBcta-acs-querydrive\fP is a developer tool and is -therefore subject to change and even removal from a future release of CTA. -End users should not rely on this tool to operate their CTA installation. - -\fBcta-acs-querydrive\fP quieries ACS for information about the drive -located in the specified \fBDRIVE_SLOT\fP. The format of \fBDRIVE_SLOT\fP -is as follows: - -.B ACS:LSM:panel:transport - -Please note that this command-line tool communicates directly with the CSI of -the ACS system. This command-line tool does not communicate with any CTA -daemons. - -.SH OPTIONS -.TP -\fB\-d, \-\-debug -Turns on the printing of debug information. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-q, \-\-query SECONDS -Time wait between queries to ACLS for responses. -\fBSECONDS\fP must be an integer value greater than 0. -The default values of \fBSECONDS\fP is 610. -.TP -\fB\-t, \-\-timeout SECONDS -Time to wait for the mount operation to conclude. -\fBSECONDS\fP must be an integer value greater than 0. -The default value of \fBSECONDS\fP is 10. - -.SH "RETURN CODES" -.TP -\fB 0 -Ok. -.TP -\fB 1 -Command failed. - -.SH AUTHOR -\fBCTA\fP Team diff --git a/mediachanger/acs/cta-acs-queryvolume.1cta b/mediachanger/acs/cta-acs-queryvolume.1cta deleted file mode 100644 index e4c2a0c35f..0000000000 --- a/mediachanger/acs/cta-acs-queryvolume.1cta +++ /dev/null @@ -1,62 +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/>. - -.TH CTA-TAPE-ACS-QUERYVOLUME "1cta" "$Date: 2013/10/09 14:00:00 $" CTA "CTA" -.SH NAME -cta-acs-queryvolume \- queries a volume -.SH SYNOPSIS -.BI "cta-acs-queryvolume [options] VID" - -.SH DESCRIPTION -\fBWarning\fP, \fBcastor-tape-acs-queryvolume\fP is a developer tool and is -therefore subject to change in and even removal from a future release of CTA. -End users should not rely on this tool to operate their CTA installation. - -\fBcastor-tape-acs-queryvolume\fP quieries ACS for information about the volume -with the specfied \fBVID\fP. - -Please note that this command-line tool communicates directly with the CSI of -the ACS system. This command-line tool does not communicate with any CTA -daemons. - -.SH OPTIONS -.TP -\fB\-d, \-\-debug -Turns on the printing of debug information. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-q, \-\-query SECONDS -Time wait between queries to ACLS for responses. -\fBSECONDS\fP must be an integer value greater than 0. -The default values of \fBSECONDS\fP is 610. -.TP -\fB\-t, \-\-timeout SECONDS -Time to wait for the mount operation to conclude. -\fBSECONDS\fP must be an integer value greater than 0. -The default value of \fBSECONDS\fP is 10. - -.SH "RETURN CODES" -.TP -\fB 0 -Ok. -.TP -\fB 1 -Command failed. - -.SH AUTHOR -\fBCTA\fP Team diff --git a/mediachanger/acs/cta-acsd.1cta b/mediachanger/acs/cta-acsd.1cta deleted file mode 100644 index b7ab08406d..0000000000 --- a/mediachanger/acs/cta-acsd.1cta +++ /dev/null @@ -1,117 +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/>. -.TH CTA-ACSD "cta" "$Date: 2018/01/10 14:44:00 $" CTA "CTA" -.SH NAME -cta-taped \- Tape server daemon -.SH SYNOPSIS -.BI "cta-taped [OPTIONS]" - -.SH DESCRIPTION -\fBcta-taped\fP is the daemon responsible for controlling one or more tape -drives. -.P -When \fBcta-taped\fP is executed it immediately forks with the parent -terminating and the child running in the background. If required the -\fB\-f, \-\-foreground\fP option can be used to stop \fBcta-taped\fP from -forking and keep the parent process in the foreground. - -.SH TAPE LIBRARY SUPPORT - -CTA supports two types of tape libraries, SCSI compatible ones and Oracle -Automatic Cartridge System (ACS) ones. The cta-taped daemon requires a tape -library daemon to be installed and run on the same tape server as itself. -There are two types of CTA tape library daemons, one for SCSI compatible tape -libraries and one for ACS tape libraries. - -A SCSI compatible tape library requires the following daemon: - -\fBrmcd\fP - -The installation RPM for the \fBrmcd\fP daemon and its manual page is: - -\fBcta-rmc-server-0.0-XX.slc6.x86_64\fP - -The \fBcta-rmcd\fP daemon can be started, stopped and its status queried using -the usual service commands: - -\fBservice cta-rmcd start\fP -.br -\fBservice cta-acsd status\fP -.br -\fBservice cta-acsd stop\fP - -Even though there is a separate daemon for each of the supported tape library -types, there is a single generic set of command-line tools for mounting and -un-mounting tapes: - -\fBcta-tape-mediachanger-mount\fP -.br -\fBcta-tape-mediachanger-dismount\fP - -The installation RPM for these command-line tools and their manual pages is: - -\fBcta-tape-developer-tools-2.1.15-XX.slc6.x86_64\fP - -.SH OPTIONS -.TP -\fB\-f, \-\-foreground -Remain in the foreground. -.TP -\fB\-h, \-\-help -Prints the usage message. -.TP -\fB\-c, \-\-config <config-file> -Set the location of the CTA configuration file (cta.conf). The default location is /etc/cta/cta.conf. - -.SH CTA CONFIGURATION PARAMETERS -The cta-taped daemon reads and uses the following CTA configuration -parameters which are specified within the CTA configuration file (the -default location is /etc/cta/cta.conf). - -.TP -\fBRMC HOST -The host on which the rmcd daemon is running. - -.TP -\fBRMC MAXRQSTATTEMPTS -Maximum number of attempts a retriable RMC request should be issued. - -.TP -\fBTapeServer BlkMoveTimeout -The maximum time in seconds the data-transfer session of tapeserverd can -cease to move data blocks - -.TP -\fBTapeServer BufSize -Size of a memory buffer in the data-transfer cache in bytes (default is 5 -Mebibytes). -## acsd ######################################################################## -# The TCP/IP port on which the CASTOR ACS daemon listens for incoming Zmq -#AcsDaemon Port 54521 -#AcsDaemon QueryInterval 10 -#AcsDaemon CmdTimeout 610 -# The TCP/IP port on which the CTA ACS daemon listens for incoming Zmq -# connections from the tape server. -#AcsDaemon Port 54521 - -# Time to wait in seconds between queries to the tape Library. -#AcsDaemon QueryInterval 10 - -# The maximum time to wait in seconds for a tape-library command to -# conclude. -#AcsDaemon CmdTimeout 610 - -# End-of-File diff --git a/mediachanger/acs/daemon/AcsDaemon.cpp b/mediachanger/acs/daemon/AcsDaemon.cpp deleted file mode 100644 index 5acb5540d7..0000000000 --- a/mediachanger/acs/daemon/AcsDaemon.cpp +++ /dev/null @@ -1,384 +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/Constants.hpp" -#include "AcsDaemon.hpp" -#include "AcsdConfiguration.hpp" -#include "mediachanger/acs/daemon/AcsMessageHandler.hpp" -#include "AcsPendingRequests.hpp" -#include "common/exception/Errnum.hpp" -#include "common/exception/BadAlloc.hpp" -#include "common/exception/Exception.hpp" -#include "common/log/log.hpp" -#include "common/log/SyslogLogger.hpp" -#include "common/threading/Daemon.hpp" -#include <memory> -#include <signal.h> -#include <unistd.h> - -#include <getopt.h> -#include <iostream> - -namespace cta { namespace mediachanger { namespace acs { namespace daemon { - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -AcsDaemon::AcsDaemon( - const int argc, - char **const argv, - cta::log::Logger& log, - std::ostream &outStream, - std::ostream &errStream, - cta::mediachanger::reactor::ZMQReactor &reactor, - const AcsdConfiguration &config): - cta::server::Daemon(log), - m_argc(argc), - m_argv(argv), - m_log(log), - m_out(outStream), - m_err(errStream), - m_reactor(reactor), - m_programName("acsd"), - m_hostName(getHostName()), - m_zmqContext(NULL), - m_config(config), - m_acsPendingRequests(config,log) { -} - -//------------------------------------------------------------------------------ -// getHostName -//------------------------------------------------------------------------------ - -std::string cta::mediachanger::acs::daemon::AcsDaemon::getHostName() const { - char nameBuf[81]; - if(gethostname(nameBuf, sizeof(nameBuf))) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to get host name: "<<ex.getMessage().str(); - m_log(LOG_ERR, ex.getMessage().str()); - throw ex; - } - - return nameBuf; -} - - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ - AcsDaemon::~AcsDaemon() { - m_reactor.clear(); - destroyZmqContext(); - google::protobuf::ShutdownProtobufLibrary(); -} - -//------------------------------------------------------------------------------ -// destroyZmqContext -//------------------------------------------------------------------------------ - - void AcsDaemon::destroyZmqContext() { - if(NULL != m_zmqContext) { - if(zmq_term(m_zmqContext)) { - cta::exception::Exception ex; - std::list<log::Param> params = {log::Param("message", ex.getMessage().str())}; - m_log(LOG_ERR, "Failed to destroy ZMQ context", params); - } else { - m_zmqContext = NULL; - m_log(LOG_INFO, "Successfully destroyed ZMQ context"); - } - } -} - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int AcsDaemon::main() { - - try { - exceptionThrowingMain(m_argc, m_argv); - } catch (cta::exception::Exception &ex) { - // Write the error to standard error - std::cerr << std::endl << "Aborting: " << ex.getMessage().str() << std::endl - << std::endl; - // Log the error - std::list<log::Param> params = { - log::Param("Message", ex.getMessage().str())}; - m_log(LOG_ERR, "Aborting", params); - - return 1; - } - - return 0; -} -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ - -void AcsDaemon::exceptionThrowingMain(const int argc, char **const argv) { - logStartOfDaemon(argc, argv); - m_cmdline = AcsdCmdLine::parse(argc,argv); - - //Display the usage message to standard out and exit with success if the - //user requested help - if(m_cmdline.help) { - m_out << AcsdCmdLine::getUsage(); - return; - } - setCommandLineHasBeenParsed(m_cmdline.foreground); - const std::string runAsStagerSuperuser = m_config.daemonUserName.value(); - const std::string runAsStagerSupergroup = m_config.daemonGroupName.value(); - daemonizeIfNotRunInForegroundAndSetUserAndGroup(runAsStagerSuperuser, runAsStagerSupergroup); - setDumpable(); - - blockSignals(); - initZmqContext(); - setUpReactor(); - mainEventLoop(); - -} - -//------------------------------------------------------------------------------ -// logStartOfDaemon -//------------------------------------------------------------------------------ - - void AcsDaemon::logStartOfDaemon( - const int argc, const char *const *const argv) { - const std::string concatenatedArgs = argvToString(argc, argv); - std::ostringstream msg; - msg << m_programName << " started"; - - std::list<log::Param> params = { - log::Param("argc", argc), - log::Param("argv", concatenatedArgs)}; - m_log(LOG_INFO, msg.str(), params); -} - -//------------------------------------------------------------------------------ -// argvToString -//------------------------------------------------------------------------------ - - std::string AcsDaemon::argvToString( - const int argc, const char *const *const argv) { - std::string str; - - for(int i=0; i < argc; i++) { - if(i != 0) { - str += " "; - } - - str += argv[i]; - } - return str; -} - -//------------------------------------------------------------------------------ -// setDumpable -//------------------------------------------------------------------------------ -void AcsDaemon::setDumpable() { - cta::utils::setDumpableProcessAttribute(true); - const bool dumpable = cta::utils::getDumpableProcessAttribute(); - std::list<log::Param> params = { - log::Param("dumpable", dumpable ? "true" : "false")}; - m_log(LOG_INFO, "Got dumpable attribute of process", params); - if(!dumpable) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to set dumpable attribute of process to true"; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// blockSignals -//------------------------------------------------------------------------------ -void AcsDaemon::blockSignals() const { - sigset_t sigs; - sigemptyset(&sigs); - // The signals that should not asynchronously disturb the daemon - sigaddset(&sigs, SIGHUP); - sigaddset(&sigs, SIGINT); - sigaddset(&sigs, SIGQUIT); - sigaddset(&sigs, SIGPIPE); - sigaddset(&sigs, SIGTERM); - sigaddset(&sigs, SIGUSR1); - sigaddset(&sigs, SIGUSR2); - sigaddset(&sigs, SIGCHLD); - sigaddset(&sigs, SIGTSTP); - sigaddset(&sigs, SIGTTIN); - sigaddset(&sigs, SIGTTOU); - sigaddset(&sigs, SIGPOLL); - sigaddset(&sigs, SIGURG); - sigaddset(&sigs, SIGVTALRM); - cta::exception::Errnum::throwOnNonZero( - sigprocmask(SIG_BLOCK, &sigs, NULL), - "Failed to block signals: sigprocmask() failed"); -} - -//------------------------------------------------------------------------------ -// initZmqContext -//------------------------------------------------------------------------------ - - void AcsDaemon::initZmqContext() { - const int sizeOfIOThreadPoolForZMQ = 1; - m_zmqContext = zmq_init(sizeOfIOThreadPoolForZMQ); - if(NULL == m_zmqContext) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to instantiate ZMQ context: " << ex.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// setUpReactor -//------------------------------------------------------------------------------ -void AcsDaemon::setUpReactor() { - createAndRegisterAcsMessageHandler(); -} - -//------------------------------------------------------------------------------ -// createAndRegisterAcsMessageHandler -//------------------------------------------------------------------------------ -void AcsDaemon::createAndRegisterAcsMessageHandler() { - try { - std::unique_ptr<AcsMessageHandler> handler; - try { - handler.reset(new AcsMessageHandler(m_log, m_reactor, m_zmqContext, m_hostName, - m_config, m_acsPendingRequests)); //create event handler for communicating with the acs daemon - } catch(std::bad_alloc &ba) { - cta::exception::BadAlloc ex; - ex.getMessage() << - "Failed to create event handler for communicating with " - "the CTA ACS daemon: " << ba.what(); - throw ex; - } - m_reactor.registerHandler(handler.get()); - handler.release(); - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << - "Failed to create and register AcsMessageHandler: " << - ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// mainEventLoop -//------------------------------------------------------------------------------ -void AcsDaemon::mainEventLoop() { - while(handleEvents()) { - } -} - -//------------------------------------------------------------------------------ -// handleEvents -//------------------------------------------------------------------------------ -bool AcsDaemon::handleEvents() { - try { - const int timeout = 100; // 100 milliseconds - m_reactor.handleEvents(timeout); - } catch(cta::exception::Exception &ex) { - // Log exception and continue - std::list<log::Param> params = { - log::Param("message", ex.getMessage().str()), - log::Param("backtrace", ex.backtrace()) - }; - m_log(LOG_ERR, - "Unexpected cta exception thrown when handling an I/O event", params); - } catch(std::exception &se) { - // Log exception and continue - std::list<log::Param> params = {log::Param("message", se.what())}; - m_log(LOG_ERR, "Unexpected exception thrown when handling an I/O event", - params); - } catch(...) { - // Log exception and continue - m_log(LOG_ERR, - "Unexpected and unknown exception thrown when handling an I/O event"); - } - - try { - handlePendingRequests(); - } catch(cta::exception::Exception &ex) { - // Log exception and continue - std::list<log::Param> params = { - log::Param("message", ex.getMessage().str()), - log::Param("backtrace", ex.backtrace()) - }; - m_log(LOG_ERR, - "Unexpected cta exception thrown when handling pending requests", - params); - } catch(std::exception &se) { - // Log exception and continue - std::list<log::Param> params = {log::Param("message", se.what())}; - m_log(LOG_ERR, - "Unexpected exception thrown when handling pending requests", params); - } catch(...) { - // Log exception and continue - m_log(LOG_ERR, - "Unexpected and unknown exception thrown when handling pending requests"); - } - - return handlePendingSignals(); -} - -//------------------------------------------------------------------------------ -// handlePendingRequests -//------------------------------------------------------------------------------ -void AcsDaemon::handlePendingRequests() { - m_acsPendingRequests.tick(); - m_acsPendingRequests.handleCompletedRequests(); - m_acsPendingRequests.handleFailedRequests(); - m_acsPendingRequests.handleToDeleteRequests(); -} - -//------------------------------------------------------------------------------ -// handlePendingSignals -//------------------------------------------------------------------------------ - -bool AcsDaemon::handlePendingSignals() { - bool continueMainEventLoop = true; - int sig = 0; - sigset_t allSignals; - siginfo_t sigInfo; - sigfillset(&allSignals); - struct timespec immediateTimeout = {0, 0}; - - // While there is a pending signal to be handled - while (0 < (sig = sigtimedwait(&allSignals, &sigInfo, &immediateTimeout))) { - switch(sig) { - case SIGINT: // Signal number 2 - m_log(LOG_INFO, "Stopping gracefully because SIGINT was received"); - continueMainEventLoop = false; - break; - case SIGTERM: // Signal number 15 - m_log(LOG_INFO, "Stopping gracefully because SIGTERM was received"); - continueMainEventLoop = false; - break; - default: - { - std::list<log::Param> params = {log::Param("signal", sig)}; - m_log(LOG_INFO, "Ignoring signal", params); - } - break; - } - } - - return continueMainEventLoop; -} - - -}}}} diff --git a/mediachanger/acs/daemon/AcsDaemon.hpp b/mediachanger/acs/daemon/AcsDaemon.hpp deleted file mode 100644 index 44d5112ce2..0000000000 --- a/mediachanger/acs/daemon/AcsDaemon.hpp +++ /dev/null @@ -1,228 +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/processCap/ProcessCap.hpp" -#include "common/threading/Daemon.hpp" -#include "mediachanger/reactor/ZMQReactor.hpp" -#include "mediachanger/acs/daemon/AcsdCmdLine.hpp" -#include "AcsdConfiguration.hpp" -#include "AcsPendingRequests.hpp" -#include "common/Constants.hpp" -#include "common/log/SyslogLogger.hpp" -#include "AcsdCmdLine.hpp" -#include <signal.h> - -#include <getopt.h> - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -/** - * CTA ACS daemon responsible for mounting and dismounting tapes for ACS. - */ -class AcsDaemon : public server::Daemon { - -public: - /** - * Constructor. - * - * @param argc The argc of main(). - * @param argv The argv of main(). - * @param stdOut Stream representing standard out. - * @param stdErr Stream representing standard error. - * @param reactor The reactor responsible for dispatching the I/O requests to - * the CTA ACS daemon. - * @param config The CTA configuration parameters used by the CTA ACS - * daemon. - */ - AcsDaemon( - const int argc, - char **const argv, - log::Logger& log, - std::ostream &outStream, - std::ostream &errStream, - cta::mediachanger::reactor::ZMQReactor &reactor, - const AcsdConfiguration &config); - - /** - * Destructor. - */ - ~AcsDaemon(); - - /** - * The main entry function of the daemon. - * - * @return The return code of the process. - */ - int main(); - -protected: - - /** - * Returns the name of the host on which the daemon is running. - */ - std::string getHostName() const; - - /** - * Exception throwing main() function. - * - * @param argc The number of command-line arguments. - * @param argv The array of command-line arguments. - */ - void exceptionThrowingMain(const int argc, char **const argv); - - /** - * Logs the start of the daemon. - */ - void logStartOfDaemon(const int argc, const char *const *const argv); - - /** - * Creates a string that contains the specified command-line arguments - * separated by single spaces. - * - * @param argc The number of command-line arguments. - * @param argv The array of command-line arguments. - */ - std::string argvToString(const int argc, const char *const *const argv) - ; - - /** - * Idempotent method that destroys the ZMQ context. - */ - void destroyZmqContext(); - - /** - * Sets the dumpable attribute of the current process to true. - */ - void setDumpable(); - - /** - * Blocks the signals that should not asynchronously disturb the daemon. - */ - void blockSignals() const; - - /** - * Initialises the ZMQ context. - */ - void initZmqContext(); - /** - * Sets up the reactor. - */ - void setUpReactor(); - - /** - * Creates the handler to handle messages for the acs Zmq requests. - */ - void createAndRegisterAcsMessageHandler(); - - /** - * The main event loop of the daemon. - */ - void mainEventLoop(); - - /** - * Handles any pending events. - * - * @return True if the main event loop should continue, else false. - */ - bool handleEvents(); - - /** - * Handles any pending signals. - * - * @return True if the main event loop should continue, else false. - */ - bool handlePendingSignals(); - - /** - * Handles any pending Acs requests. - * - */ - void handlePendingRequests(); - - /** - * The argc of main(). - */ - const int m_argc; - - /** - * The argv of main(). - */ - char **const m_argv; - - log::Logger &m_log; - - /** - * Standard output stream. - */ - std::ostream &m_out; - - /** - * Standard error stream. - */ - std::ostream &m_err; - - /** - * The reactor responsible for dispatching the file-descriptor event-handlers - * of the CTA ACS daemon. - */ - cta::mediachanger::reactor::ZMQReactor &m_reactor; - /** - * The program name of the daemon. - */ - const std::string m_programName; - - /** - * The name of the host on which the daemon is running. - */ - const std::string m_hostName; - - /** - * The ZMQ context. - */ - void *m_zmqContext; - - /** - * The CTA configuration parameters used by the CTA ACS daemon. - */ - const AcsdConfiguration m_config; - - /** - * The object to handle requests to the CTA ACS daemon. - */ - AcsPendingRequests m_acsPendingRequests; - -private: - - /** - * The parsed command-line. - * - * The value of this member variable is set within the main() method of this - * class. - */ - AcsdCmdLine m_cmdline; - -}; // class AcsDaemon - -} // namespace daemon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsDaemonMain.cpp b/mediachanger/acs/daemon/AcsDaemonMain.cpp deleted file mode 100644 index 5163f7cf7f..0000000000 --- a/mediachanger/acs/daemon/AcsDaemonMain.cpp +++ /dev/null @@ -1,100 +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/log/log.hpp" -#include "common/log/SyslogLogger.hpp" -#include "mediachanger/acs/Constants.hpp" -#include "AcsDaemon.hpp" -#include "AcsdCmdLine.hpp" -#include "mediachanger/reactor/ZMQReactor.hpp" -#include "AcsdConfiguration.hpp" -#include "common/utils/utils.hpp" -#include "common/exception/Exception.hpp" -#include <iostream> - - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -// -// The main() function delegates the bulk of its implementation to this -// exception throwing version. -// -// @param argc The number of command-line arguments. -// @param argv The command-line arguments. -//------------------------------------------------------------------------------ -static int exceptionThrowingMain(cta::log::Logger &log,const int argc,char **const argv); - -//------------------------------------------------------------------------------ -// main -//------------------------------------------------------------------------------ -int main(const int argc, char **const argv) { - using namespace cta; - - const std::string shortHostName = utils::getShortHostname(); - cta::log::SyslogLogger logger(shortHostName, "cta-acsd", log::DEBUG); - try { - logger(LOG_INFO, "started ACSD in CTA"); - } catch(cta::exception::Exception &ex) { - std::cerr << - "Failed to instantiate object representing CTA logging system: " << - ex.getMessage().str() << std::endl; - return 1; - } - int programRc = 1; - try { - programRc = exceptionThrowingMain(logger, argc, argv) ; - } catch(cta::exception::Exception &ex) { - std::list<log::Param> params = { - log::Param("message", ex.getMessage().str())}; - logger(LOG_ERR, "Caught an unexpected CTA exception", params); - } catch(std::exception &se) { - std::list<log::Param> params = {log::Param("what", se.what())}; - logger(LOG_ERR, "Caught an unexpected standard exception", params); - } catch(...) { - logger(LOG_ERR, "Caught an unexpected and unknown exception"); - } - - return programRc; -} - -//------------------------------------------------------------------------------ -// exceptionThrowingMain -//------------------------------------------------------------------------------ -static int exceptionThrowingMain(cta::log::Logger &log, const int argc, char **const argv) { - - - cta::mediachanger::reactor::ZMQReactor reactor(log); - - const cta::mediachanger::acs::daemon::AcsdConfiguration config = cta::mediachanger::acs::daemon::AcsdConfiguration::createFromCtaConf("/etc/cta/cta-acsd.conf",log); - - - // Create the main acsd object - cta::mediachanger::acs::daemon::AcsDaemon daemon( - argc, - argv, - log, - std::cout, - std::cerr, - reactor, - config); - - // Run the acsd daemon - return daemon.main(); - -return 0; -} diff --git a/mediachanger/acs/daemon/AcsDismountTape.cpp b/mediachanger/acs/daemon/AcsDismountTape.cpp deleted file mode 100644 index bbf7da9813..0000000000 --- a/mediachanger/acs/daemon/AcsDismountTape.cpp +++ /dev/null @@ -1,142 +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 "AcsDismountTape.hpp" -#include "common/exception/DismountFailed.hpp" -#include "common/log/log.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsDismountTape::AcsDismountTape( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - Acs &acsWrapper, - log::Logger& log, - const AcsdConfiguration &ctaConf): - cta::mediachanger::acs::AcsLibraryInteraction(acsWrapper, log), - m_volId(acsWrapper.str2Volid(vid)), - m_driveId(acsWrapper.alpd2DriveId(acs,lsm,panel,drive)), - m_acsWrapper(acsWrapper), - m_log(log), - m_ctaConf(ctaConf) { -} - -//------------------------------------------------------------------------------ -// execute -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsDismountTape::execute() const { - syncDismount(); -} - -//------------------------------------------------------------------------------ -// asyncExecute -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsDismountTape::asyncExecute(const SEQ_NO seqNo) const { - asyncDismount(seqNo); -} - - -//------------------------------------------------------------------------------ -// syncDismount -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsDismountTape::syncDismount() const { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendDismountRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, - m_ctaConf.QueryInterval.value(), - m_ctaConf.CmdTimeout.value()); - processDismountResponse(buf); - } catch(cta::exception::Exception &ex) { - cta::exception::DismountFailed df; - df.getMessage() << "Failed to dismount volume " << - m_volId.external_label << ": " << ex.getMessage().str(); - throw df; - } -} - -//------------------------------------------------------------------------------ -// asyncDismount -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsDismountTape::asyncDismount(const SEQ_NO seqNo) const - { - try { - sendDismountRequest(seqNo); - } catch(cta::exception::Exception &ex) { - cta::exception::DismountFailed df; - df.getMessage() << "Failed to send dismount request to ACS " << - m_volId.external_label << ": " << ex.getMessage().str(); - throw df; - } -} - -//------------------------------------------------------------------------------ -// sendDismountRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsDismountTape::sendDismountRequest( - const SEQ_NO seqNumber) const { - const LOCKID lockId = 0; // No lock - const BOOLEAN force = FALSE; - - std::stringstream dbgMsg; - dbgMsg << "Calling Acs::dismount() with seqNumber=" << seqNumber; - m_log(LOG_DEBUG, dbgMsg.str()); - const STATUS s = m_acsWrapper.dismount(seqNumber, lockId, m_volId, - m_driveId, force); - - dbgMsg.str(""); - dbgMsg << "Acs::dismount() for seqNumber=" << seqNumber << " returned " << - acs_status(s); - m_log(LOG_DEBUG,dbgMsg.str()); - if(STATUS_SUCCESS != s) { - cta::exception::DismountFailed ex; - ex.getMessage() << "Failed to send request to dismount volume " << - m_volId.external_label << " from drive " << - m_acsWrapper.driveId2Str(m_driveId) << ": force=" << - (force ? "TRUE" : "FALSE") << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processDismountResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsDismountTape::processDismountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const - { - const ACS_DISMOUNT_RESPONSE *const msg = (ACS_DISMOUNT_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->dismount_status) { - cta::exception::DismountFailed ex; - ex.getMessage() << "Status of dismount response is not success: " << - acs_status(msg->dismount_status); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsDismountTape::~AcsDismountTape() { -} diff --git a/mediachanger/acs/daemon/AcsDismountTape.hpp b/mediachanger/acs/daemon/AcsDismountTape.hpp deleted file mode 100644 index 9393c57586..0000000000 --- a/mediachanger/acs/daemon/AcsDismountTape.hpp +++ /dev/null @@ -1,130 +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/acs/Acs.hpp" -#include "AcsdConfiguration.hpp" -#include "mediachanger/acs/AcsLibraryInteraction.hpp" - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -/** - * Class responsible for dismounting tapes through ACS API. - */ -class AcsDismountTape: public cta::mediachanger::acs::AcsLibraryInteraction { - -public: - - /** - * Constructor. - */ - AcsDismountTape( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - cta::mediachanger::acs::Acs &acsWrapper, - cta::log::Logger& log, - const mediachanger::acs::daemon::AcsdConfiguration &ctaConf); - - /** - * Destructor. - */ - ~AcsDismountTape(); - - /** - * Execute dismount request through ACS API. - */ - void execute() const; - - /** - * Execute asynchronous dismount request through ACS API. - * - * @param The value of sequence number for ACS API. - */ - void asyncExecute(const SEQ_NO seqNo) const; - -protected: - - /** - * Dismounts the tape with the specified m_volId from the drive with the - * specified m_driveId. - * - * This method does not return until the dismount has either succeeded, failed - * or the specified timeout has been reached. - */ - void syncDismount() const; - - - /** - * Dismounts the tape with the specified m_volId from the drive with the - * specified m_driveId. - * This method sends a dismount request to ACSLS and returns. - * - * @param The value of sequence number for ACS API. - */ - void asyncDismount(const SEQ_NO seqNo) const; - - /** - * Sends the dismount request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendDismountRequest(const SEQ_NO seqNumber) const; - - /** - * Throws cta::exception::DismountFailed if the mount was not - * successful. - * - * @param buf The mount-response message. - */ - void processDismountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const; - - /** - * VOLID - */ - VOLID m_volId; - - /** - * DRIVEID - */ - DRIVEID m_driveId; - - /** - * Object providing c wrapper for ACS commands. - */ - Acs &m_acsWrapper; - - log::Logger &m_log; - /** - * The configuration parameters for the CTA ACS daemon. - */ - const mediachanger::acs::daemon::AcsdConfiguration m_ctaConf; - -}; // class AcsDismountTape - -} // namespace daemon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsForceDismountTape.cpp b/mediachanger/acs/daemon/AcsForceDismountTape.cpp deleted file mode 100644 index 00a25ad83b..0000000000 --- a/mediachanger/acs/daemon/AcsForceDismountTape.cpp +++ /dev/null @@ -1,142 +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 "AcsForceDismountTape.hpp" -#include "common/exception/ForceDismountFailed.hpp" -#include "common/log/log.hpp" -#include "common/log/SyslogLogger.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsForceDismountTape::AcsForceDismountTape( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - cta::mediachanger::acs::Acs &acsWrapper, - cta::log::Logger& log, - const AcsdConfiguration &ctaConf): - AcsLibraryInteraction(acsWrapper, log), - m_volId(acsWrapper.str2Volid(vid)), - m_driveId(acsWrapper.alpd2DriveId(acs,lsm,panel,drive)), - m_acsWrapper(acsWrapper), - m_log(log), - m_ctaConf(ctaConf) { -} - -//------------------------------------------------------------------------------ -// execute -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsForceDismountTape::execute() const { - syncForceDismount(); -} - -//------------------------------------------------------------------------------ -// asyncExecute -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsForceDismountTape::asyncExecute(const SEQ_NO seqNo) const { - asyncForceDismount(seqNo); -} - - -//------------------------------------------------------------------------------ -// syncForceDismount -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsForceDismountTape::syncForceDismount() const { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendForceDismountRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, - m_ctaConf.QueryInterval.value(), - m_ctaConf.CmdTimeout.value()); - processForceDismountResponse(buf); - } catch(cta::exception::Exception &ex) { - cta::exception::ForceDismountFailed df; - df.getMessage() << "Failed to force dismount volume " << - m_volId.external_label << ": " << ex.getMessage().str(); - throw df; - } -} - -//------------------------------------------------------------------------------ -// asyncDismount -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsForceDismountTape::asyncForceDismount(const SEQ_NO seqNo) - const { - try { - sendForceDismountRequest(seqNo); - } catch(cta::exception::Exception &ex) { - cta::exception::ForceDismountFailed df; - df.getMessage() << "Failed to send dismount request to ACS " << - m_volId.external_label << ": " << ex.getMessage().str(); - throw df; - } -} - -//------------------------------------------------------------------------------ -// sendDismountRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsForceDismountTape::sendForceDismountRequest( - const SEQ_NO seqNumber) const { - const LOCKID lockId = 0; // No lock - const BOOLEAN force = TRUE; - - std::stringstream dbgMsg; - dbgMsg << "Calling Acs::dismount() with seqNumber=" << seqNumber; - m_log(LOG_DEBUG, dbgMsg.str()); - const STATUS s = m_acsWrapper.dismount(seqNumber, lockId, m_volId, - m_driveId, force); - - dbgMsg.str(""); - dbgMsg << "Acs::dismount() for seqNumber=" << seqNumber << " returned " << - acs_status(s); - m_log(LOG_DEBUG,dbgMsg.str()); - if(STATUS_SUCCESS != s) { - cta::exception::ForceDismountFailed ex; - ex.getMessage() << "Failed to send request to force dismount volume " << - m_volId.external_label << " from drive " << - m_acsWrapper.driveId2Str(m_driveId) << ": force=" << - (force ? "TRUE" : "FALSE") << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processForceDismountResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsForceDismountTape::processForceDismountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const { - const ACS_DISMOUNT_RESPONSE *const msg = (ACS_DISMOUNT_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->dismount_status) { - cta::exception::ForceDismountFailed ex; - ex.getMessage() << "Status of force dismount response is not success: " << - acs_status(msg->dismount_status); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsForceDismountTape::~AcsForceDismountTape() { -} diff --git a/mediachanger/acs/daemon/AcsForceDismountTape.hpp b/mediachanger/acs/daemon/AcsForceDismountTape.hpp deleted file mode 100644 index 5f4cbf69fe..0000000000 --- a/mediachanger/acs/daemon/AcsForceDismountTape.hpp +++ /dev/null @@ -1,133 +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/acs/Acs.hpp" -#include "mediachanger/acs/daemon/AcsdConfiguration.hpp" -#include "mediachanger/acs/AcsLibraryInteraction.hpp" -#include "common/log/log.hpp" -#include "common/log/SyslogLogger.hpp" - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -/** - * Class responsible for dismounting tapes through ACS API. - */ -class AcsForceDismountTape: public cta::mediachanger::acs::AcsLibraryInteraction { - -public: - - /** - * Constructor. - */ - AcsForceDismountTape( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - cta::mediachanger::acs::Acs &acsWrapper, - log::Logger& log, - const AcsdConfiguration &ctaConf); - - /** - * Destructor. - */ - ~AcsForceDismountTape(); - - /** - * Execute force dismount request through ACS API. - */ - void execute() const; - - /** - * Execute asynchronous force dismount request through ACS API. - * - * @param The value of sequence number for ACS API. - */ - void asyncExecute(const SEQ_NO seqNo) const; - -protected: - - /** - * Force dismounts the tape with the specified m_volId from the drive with the - * specified m_driveId. - * - * This method does not return until the dismount has either succeeded, failed - * or the specified timeout has been reached. - */ - void syncForceDismount() const; - - - /** - * Force dismounts the tape with the specified m_volId from the drive with the - * specified m_driveId. - * This method sends a dismount request to ACSLS and returns. - * - * @param The value of sequence number for ACS API. - */ - void asyncForceDismount(const SEQ_NO seqNo) const; - - /** - * Sends the force dismount request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendForceDismountRequest(const SEQ_NO seqNumber) const; - - /** - * Throws cta::exception::DismountFailed if the mount was not - * successful. - * - * @param buf The mount-response message. - */ - void processForceDismountResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const; - - /** - * VOLID - */ - VOLID m_volId; - - /** - * DRIVEID - */ - DRIVEID m_driveId; - - /** - * Object providing c wrapper for ACS commands. - */ - Acs &m_acsWrapper; - - log::Logger &m_log; - - /** - * The configuration parameters for the CTA ACS daemon. - */ - const AcsdConfiguration m_ctaConf; - -}; // class AcsForceDismountTape - -} // namespace daemon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsMessageHandler.cpp b/mediachanger/acs/daemon/AcsMessageHandler.cpp deleted file mode 100644 index 2d9af754b9..0000000000 --- a/mediachanger/acs/daemon/AcsMessageHandler.cpp +++ /dev/null @@ -1,444 +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/Constants.hpp" -#include "mediachanger/acs/daemon/Constants.hpp" -#include "AcsMessageHandler.hpp" -#include "AcsDismountTape.hpp" -#include "AcsForceDismountTape.hpp" -#include "AcsMountTapeReadOnly.hpp" -#include "AcsMountTapeReadWrite.hpp" -#include "mediachanger/acs/Acs.hpp" -#include "mediachanger/acs/AcsImpl.hpp" -#include "common/log/log.hpp" -#include "common/log/SyslogLogger.hpp" -#include "mediachanger/messages.hpp" -#include "mediachanger/ReturnValue.pb.h" -#include "mediachanger/AcsMountTapeReadOnly.pb.h" -#include "mediachanger/AcsMountTapeReadWrite.pb.h" -#include "mediachanger/AcsDismountTape.pb.h" -#include "mediachanger/AcsForceDismountTape.pb.h" -#include "mediachanger/Exception.pb.h" -#include "mediachanger/reactor/ZMQPollEventHandler.hpp" -#include "mediachanger/reactor/ZMQReactor.hpp" -#include "mediachanger/ZmqSocket.hpp" -#include "errno.h" - -#include <iostream> -#include <unistd.h> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsMessageHandler::AcsMessageHandler( - cta::log::Logger &log, - cta::mediachanger::reactor::ZMQReactor &reactor, - void *const zmqContext, - const std::string &hostName, - const AcsdConfiguration &ctaConf, - AcsPendingRequests &acsPendingRequests): - m_log(log), - m_reactor(reactor), - m_socket(zmqContext, ZMQ_ROUTER), - m_hostName(hostName), - m_ctaConf(ctaConf), - m_acsPendingRequests(acsPendingRequests) { - - std::ostringstream endpoint; - endpoint << "tcp://127.0.0.1:" << m_ctaConf.port.value(); - - try { - m_socket.bind(endpoint.str().c_str()); - std::list<log::Param> params = {log::Param("endpoint", endpoint.str())}; - m_log(LOG_INFO, "Bound the ZMQ socket of the AcsMessageHandler", - params); - } catch(cta::exception::Exception &ne){ - cta::exception::Exception ex; - ex.getMessage() << - "Failed to bind the ZMQ socket of the AcsMessageHandler" - ": endpoint=" << endpoint.str() << ": " << ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsMessageHandler::~AcsMessageHandler() - { -} - -//------------------------------------------------------------------------------ -// getName -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::daemon::AcsMessageHandler::getName() - const { - return "AcsMessageHandler"; -} - -//------------------------------------------------------------------------------ -// fillPollFd -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMessageHandler::fillPollFd( - zmq_pollitem_t &fd) { - fd.events = ZMQ_POLLIN; - fd.revents = 0; - fd.socket = m_socket.getZmqSocket(); - fd.fd = -1; -} - -//------------------------------------------------------------------------------ -// handleEvent -//------------------------------------------------------------------------------ -bool cta::mediachanger::acs::daemon::AcsMessageHandler::handleEvent( - const zmq_pollitem_t &fd) { - // Try to receive a request, simply giving up if an exception is raised - cta::mediachanger::Frame rqst; - - //for handling zeroMQ's router socket type specific elements - //ie first frame = identity of the sender - // second one = empty - // third and following = actual data frames - - //The ZmqMsg address data can be dump as string and used as key for storing - //the identity (for clients who need a late answer) - cta::mediachanger::ZmqMsg address; - cta::mediachanger::ZmqMsg empty; - try { - checkSocket(fd); - m_socket.recv(address); - m_socket.recv(empty); - rqst = recvFrame(m_socket); - } catch(cta::exception::Exception &ex) { - std::list<log::Param> params = {log::Param("message", ex.getMessage().str())}; - m_log(LOG_ERR, "AcsMessageHandler failed to handle event", params); - return false; // Give up and stay registered with the reactor - } - std::list<log::Param> params = { - log::Param("sender identity", - utils::hexDump(address.getData(),address.size())) - }; - m_log(LOG_DEBUG, "handling event in AcsMessageHandler", params); - - // From this point on any exception thrown should be converted into an - // Exception message and sent back to the client - cta::mediachanger::Frame reply; - - try { - // if there are any problems we need to send the replay to the client. - reply = dispatchMsgHandler(rqst); - } catch(cta::exception::Exception &ex) { - reply = createExceptionFrame(ECANCELED, ex.getMessage().str()); - m_log(LOG_ERR, ex.getMessage().str()); - } catch(std::exception &se) { - reply = createExceptionFrame(ECANCELED, se.what()); - m_log(LOG_ERR, se.what()); - } catch(...) { - reply = createExceptionFrame(ECANCELED, "Caught an unknown exception"); - m_log(LOG_ERR, "Caught an unknown exception"); - } - - // Send the reply to the client - try { - //we need to prepend our frames the same way we received them - // ie identity + empty frames - m_socket.send(address,ZMQ_SNDMORE); - m_socket.send(empty,ZMQ_SNDMORE); - - cta::mediachanger::sendFrame(m_socket, reply); - } catch(cta::exception::Exception &ex) { - std::list<log::Param> params = {log::Param("message", ex.getMessage().str())}; - m_log(LOG_ERR, "AcsMessageHandler failed to send reply to client", params); - } - - return false; // Stay registered with the reactor -} - -//------------------------------------------------------------------------------ -// checkSocket -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMessageHandler::checkSocket( - const zmq_pollitem_t &fd) const{ - void* underlyingSocket = m_socket.getZmqSocket(); - if(fd.socket != underlyingSocket){ - cta::exception::Exception ex; - ex.getMessage() << "AcsMessageHandler passed wrong poll item"; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// dispatchMsgHandler -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsMessageHandler:: - dispatchMsgHandler(const cta::mediachanger::Frame &rqst) { - m_log(LOG_DEBUG, "AcsMessageHandler dispatching message handler"); - - const cta::mediachanger::acs::daemon::MsgType msgType = (cta::mediachanger::acs::daemon::MsgType)rqst.header.msgtype(); - switch(msgType) { - case cta::mediachanger::MSG_TYPE_ACSMOUNTTAPEREADONLY: - return handleAcsMountTapeReadOnly(rqst); - - case cta::mediachanger::MSG_TYPE_ACSMOUNTTAPEREADWRITE: - return handleAcsMountTapeReadWrite(rqst); - - case cta::mediachanger::MSG_TYPE_ACSDISMOUNTTAPE: - return handleAcsDismountTape(rqst); - - case cta::mediachanger::MSG_TYPE_ACSFORCEDISMOUNTTAPE: - return handleAcsForceDismountTape(rqst); - - default: - { - const std::string msgTypeStr = cta::mediachanger::acs::daemon::msgTypeToString(msgType); - cta::exception::Exception ex; - ex.getMessage() << "Failed to dispatch message handler" - ": Unexpected request type: msgType=" << msgType << " msgTypeStr=" << - msgTypeStr; - throw ex; - } - } -} - -//------------------------------------------------------------------------------ -// handleAcsMountTapeReadOnly -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsMessageHandler:: - handleAcsMountTapeReadOnly(const cta::mediachanger::Frame &rqst) { - m_log(LOG_DEBUG, "Handling AcsMountTapeReadOnly message"); - - try { - cta::mediachanger::AcsMountTapeReadOnly rqstBody; - rqst.parseBodyIntoProtocolBuffer(rqstBody); - - const std::string vid = rqstBody.vid(); - const uint32_t acs = rqstBody.acs(); - const uint32_t lsm = rqstBody.lsm(); - const uint32_t panel = rqstBody.panel(); - const uint32_t drive = rqstBody.drive(); - - std::list<log::Param> params = {log::Param("tapeVid", vid), - log::Param("acs", acs), - log::Param("lsm", lsm), - log::Param("panel", panel), - log::Param("drive", drive)}; - m_log(LOG_INFO, "Mount tape for read-only access", params); - - cta::mediachanger::acs::AcsImpl acsWrapper; - cta::mediachanger::acs::daemon::AcsMountTapeReadOnly acsMountTapeReadOnly(vid, acs, lsm, - panel, drive, acsWrapper, m_log, m_ctaConf); - try { - acsMountTapeReadOnly.execute(); - m_log(LOG_INFO,"Tape successfully mounted for read-only access", params); - } catch (cta::exception::Exception &ne) { - m_log(LOG_ERR,"Tape mount for read-only access failed: " - + ne.getMessage().str(), params); - throw; - } - const cta::mediachanger::Frame reply = createReturnValueFrame(0); - return reply; - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to handle AcsMountTapeReadOnly message: " << - ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// handleAcsMountTapeReadWrite -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsMessageHandler:: - handleAcsMountTapeReadWrite(const cta::mediachanger::Frame &rqst) { - m_log(LOG_DEBUG, "Handling AcsMountTapeReadWrite message"); - - try { - cta::mediachanger::AcsMountTapeReadWrite rqstBody; - rqst.parseBodyIntoProtocolBuffer(rqstBody); - - const std::string vid = rqstBody.vid(); - const uint32_t acs = rqstBody.acs(); - const uint32_t lsm = rqstBody.lsm(); - const uint32_t panel = rqstBody.panel(); - const uint32_t drive = rqstBody.drive(); - - std::list<log::Param> params = {log::Param("tapeVid", vid), - log::Param("acs", acs), - log::Param("lsm", lsm), - log::Param("panel", panel), - log::Param("drive", drive)}; - m_log(LOG_INFO, "Mount tape for read/write access",params); - - cta::mediachanger::acs::AcsImpl acsWrapper; - cta::mediachanger::acs::daemon::AcsMountTapeReadWrite acsMountTapeReadWrite(vid, acs, - lsm, panel, drive, acsWrapper, m_log, m_ctaConf); - try { - acsMountTapeReadWrite.execute(); - m_log(LOG_INFO,"Tape successfully mounted for read/write access", params); - } catch (cta::exception::Exception &ne) { - m_log(LOG_ERR,"Tape mount for read/write access failed: " - + ne.getMessage().str(), params); - throw; - } - const cta::mediachanger::Frame reply = createReturnValueFrame(0); - return reply; - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to handle AcsMountTapeReadWrite message: " << - ne.getMessage().str(); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// handleAcsDismountTape -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsMessageHandler:: - handleAcsDismountTape(const cta::mediachanger::Frame& rqst) { - m_log(LOG_DEBUG, "Handling AcsDismountTape message"); - - try { - cta::mediachanger::AcsDismountTape rqstBody; - rqst.parseBodyIntoProtocolBuffer(rqstBody); - - const std::string vid = rqstBody.vid(); - const uint32_t acs = rqstBody.acs(); - const uint32_t lsm = rqstBody.lsm(); - const uint32_t panel = rqstBody.panel(); - const uint32_t drive = rqstBody.drive(); - - std::list<log::Param> params = {log::Param("tapeVid", vid), - log::Param("acs", acs), - log::Param("lsm", lsm), - log::Param("panel", panel), - log::Param("drive", drive)}; - m_log(LOG_INFO, "Dismount tape",params); - - cta::mediachanger::acs::AcsImpl acsWrapper; - cta::mediachanger::acs::daemon::AcsDismountTape acsDismountTape(vid, acs, lsm, panel, drive, - acsWrapper, m_log, m_ctaConf); - try { - acsDismountTape.execute(); - m_log(LOG_INFO,"Tape successfully dismounted", params); - } catch (cta::exception::Exception &ne) { - m_log(LOG_ERR,"Tape dismount failed: "+ne.getMessage().str(), params); - throw; - } - const cta::mediachanger::Frame reply = createReturnValueFrame(0); - return reply; - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to handle AcsDismountTape message: " << - ne.getMessage().str(); - throw ex; - } catch(...) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to handle AcsDismountTape message: " - << "Caught an unknown exception"; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// handleAcsForceDismountTape -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsMessageHandler:: - handleAcsForceDismountTape(const cta::mediachanger::Frame& rqst) { - m_log(LOG_DEBUG, "Handling AcsDismountTape message"); - - try { - cta::mediachanger::AcsForceDismountTape rqstBody; - rqst.parseBodyIntoProtocolBuffer(rqstBody); - - const std::string vid = rqstBody.vid(); - const uint32_t acs = rqstBody.acs(); - const uint32_t lsm = rqstBody.lsm(); - const uint32_t panel = rqstBody.panel(); - const uint32_t drive = rqstBody.drive(); - - std::list<log::Param> params = {log::Param("tapeVid", vid), - log::Param("acs", acs), - log::Param("lsm", lsm), - log::Param("panel", panel), - log::Param("drive", drive)}; - m_log(LOG_INFO, "Force dismount tape", params); - - cta::mediachanger::acs::AcsImpl acsWrapper; - cta::mediachanger::acs::daemon::AcsForceDismountTape acsForceDismountTape(vid, acs, lsm, - panel, drive, acsWrapper, m_log, m_ctaConf); - try { - acsForceDismountTape.execute(); - m_log(LOG_INFO,"Tape successfully force dismounted", params); - } catch (cta::exception::Exception &ne) { - m_log(LOG_ERR,"Tape force dismount failed: "+ne.getMessage().str(), - params); - throw; - } - const cta::mediachanger::Frame reply = createReturnValueFrame(0); - return reply; - } catch(cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to handle AcsForceDismountTape message: " << - ne.getMessage().str(); - throw ex; - } catch(...) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to handle AcsForceDismountTape message: " - << "Caught an unknown exception"; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// createReturnValueFrame -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsMessageHandler:: - createReturnValueFrame(const int value) { - cta::mediachanger::Frame frame; - - frame.header = cta::mediachanger::protoTapePreFillHeader(); - frame.header.set_msgtype(cta::mediachanger::MSG_TYPE_RETURNVALUE); - frame.header.set_bodyhashvalue(cta::mediachanger::computeSHA1Base64(frame.body)); - frame.header.set_bodysignature("PIPO"); - - cta::mediachanger::ReturnValue body; - body.set_value(value); - frame.serializeProtocolBufferIntoBody(body); - - return frame; -} - -//------------------------------------------------------------------------------ -// createExceptionFrame -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsMessageHandler:: - createExceptionFrame(const int code, const std::string& msg) { - cta::mediachanger::Frame frame; - - frame.header = cta::mediachanger::protoTapePreFillHeader(); - frame.header.set_msgtype(cta::mediachanger::MSG_TYPE_EXCEPTION); - frame.header.set_bodyhashvalue(cta::mediachanger::computeSHA1Base64(frame.body)); - frame.header.set_bodysignature("PIPO"); - - cta::mediachanger::Exception body; - body.set_code(code); - body.set_message(msg); - frame.serializeProtocolBufferIntoBody(body); - - return frame; -} diff --git a/mediachanger/acs/daemon/AcsMessageHandler.hpp b/mediachanger/acs/daemon/AcsMessageHandler.hpp deleted file mode 100644 index 418bf4a84d..0000000000 --- a/mediachanger/acs/daemon/AcsMessageHandler.hpp +++ /dev/null @@ -1,187 +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/acs/Constants.hpp" -#include "mediachanger/Frame.hpp" -#include "mediachanger/ZmqSocket.hpp" -#include "mediachanger/reactor/ZMQReactor.hpp" -#include "AcsDaemon.hpp" -#include "AcsdConfiguration.hpp" -#include "AcsPendingRequests.hpp" -#include "common/log/SyslogLogger.hpp" -#include "mediachanger/reactor/ZMQPollEventHandler.hpp" - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -/** - * Handles the events of the socket listening for connection from the tape - * server daemon. - */ -class AcsMessageHandler: public cta::mediachanger::reactor::ZMQPollEventHandler { -public: - - /** - * Constructor. - * - * @param reactor The reactor to which new CTA ACS daemon connection - * handlers are to be registered. - * @param hostName The name of the host. - * @param zmqContext The ZMQ context. - * @param ctaConf The configuration for the CTA ACS daemon. - * @param acsPendingRequests The object to handle requests to the CTA ACS - * daemon. - */ - AcsMessageHandler( - log::Logger &log, - cta::mediachanger::reactor::ZMQReactor &reactor, - void *const zmqContext, - const std::string &hostName, - const AcsdConfiguration &ctaConf, - AcsPendingRequests &acsPendingRequests); - - /** - * Destructor. - */ - ~AcsMessageHandler(); - - /** - * Returns the human-readable name this event handler. - */ - std::string getName() const; - - /** - * Fills the specified poll file-descriptor ready to be used in a call to - * poll(). - */ - void fillPollFd(zmq_pollitem_t &fd); - - /** - * Handles the specified event. - * - * @param fd The poll file-descriptor describing the event. - * @return true if the event handler should be removed from and deleted by - * the reactor. - */ - bool handleEvent(const zmq_pollitem_t &fd); - -private: - - /** - * Creates a message frame containing a ReturnValue message. - * - * @param value The return value of the ReturnValue message. - * @return The message frame. - */ - cta::mediachanger::Frame createReturnValueFrame(const int value); - - /** - * Creates a message frame containing an Exception message. - * - * @param code The error code of the exception. - * @param msg The message string of the exception. - */ - cta::mediachanger::Frame createExceptionFrame(const int code, - const std::string& msg); - - /** - * Make sure the zmq_pollitem_t's socket is the same as m_socket - * Throw an exception if it is not the case - * @param fd the poll item - */ - void checkSocket(const zmq_pollitem_t &fd) const; - - /** - * Dispatches the appropriate handler method for the specified request - * message. - * - * @param rqst The request. - * @return The reply. - */ - cta::mediachanger::Frame dispatchMsgHandler(const cta::mediachanger::Frame &rqst) ; - - /** - * Handles the mount tape for read-only. - * - * @param rqst The request. - * @return The reply. - */ - cta::mediachanger::Frame handleAcsMountTapeReadOnly(const cta::mediachanger::Frame &rqst); - - /** - * Handles the mount tape for read/write. - * - * @param rqst The request. - * @return The reply. - */ - cta::mediachanger::Frame handleAcsMountTapeReadWrite(const cta::mediachanger::Frame &rqst); - - /** - * Handles the dismount tape request. - * - * @param rqst The request. - * @return The reply. - */ - cta::mediachanger::Frame handleAcsDismountTape(const cta::mediachanger::Frame &rqst); - - /** - * Handles the force dismount tape request. - * - * @param rqst The request. - * @return The reply. - */ - cta::mediachanger::Frame handleAcsForceDismountTape(const cta::mediachanger::Frame &rqst); - - log::Logger &m_log; - /** - * The reactor to which new CTA ACS daemon connection handlers are to - * be registered. - */ - cta::mediachanger::reactor::ZMQReactor &m_reactor; - - /** - * The ZMQ socket listening for messages. - */ - cta::mediachanger::ZmqSocketST m_socket; - - /** - * The name of the host on which CTA ACS daemon is running. - */ - const std::string m_hostName; - - - /** - * The configuration parameters for the CTA ACS daemon. - */ - const acs::daemon::AcsdConfiguration m_ctaConf; - - /** - * The object to handle requests to the CTA ACS daemon. - */ - AcsPendingRequests &m_acsPendingRequests; - -}; // class AcsMessageHandler - -} // namespace deamon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsMountTapeReadOnly.cpp b/mediachanger/acs/daemon/AcsMountTapeReadOnly.cpp deleted file mode 100644 index a8a0c39881..0000000000 --- a/mediachanger/acs/daemon/AcsMountTapeReadOnly.cpp +++ /dev/null @@ -1,213 +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 "AcsMountTapeReadOnly.hpp" -#include "common/exception/MountFailed.hpp" -#include "common/exception/QueryVolumeFailed.hpp" -#include "common/log/log.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::AcsMountTapeReadOnly( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - cta::mediachanger::acs::Acs &acsWrapper, - log::Logger& log, - const AcsdConfiguration &ctaConf): - AcsLibraryInteraction(acsWrapper, log), - m_volId(acsWrapper.str2Volid(vid)), - m_driveId(acsWrapper.alpd2DriveId(acs,lsm,panel,drive)), - m_acsWrapper(acsWrapper), - m_log(log), - m_ctaConf(ctaConf) { -} - -//------------------------------------------------------------------------------ -// execute -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::execute() const { - try { - syncMountTapeReadOnly(); - } catch (cta::exception::MountFailed &mountFailed) { - try { - const std::string queryVolumeResponse = syncQueryVolume(); - mountFailed.getMessage() << " : The query volume response: " << - queryVolumeResponse; - } catch (cta::exception::QueryVolumeFailed &queryFailed) { - mountFailed.getMessage() << " : " << queryFailed.getMessage().str(); - } - throw mountFailed; - } -} - -//------------------------------------------------------------------------------ -// syncMountTapeReadOnly -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::syncMountTapeReadOnly() const - { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendMountTapeReadOnlyRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, - m_ctaConf.QueryInterval.value(), m_ctaConf.CmdTimeout.value()); - processMountTapeReadOnlyResponse(buf); - } catch(cta::exception::Exception &ex) { - cta::exception::MountFailed mf; - mf.getMessage() << "Failed to mount for read-only access volume " << - m_volId.external_label << ": " << ex.getMessage().str(); - throw mf; - } -} - -//------------------------------------------------------------------------------ -// sendMountTapeReadOnlyRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::sendMountTapeReadOnlyRequest( - const SEQ_NO seqNumber) const { - const LOCKID lockId = 0; // No lock - const BOOLEAN bypass = FALSE; - const BOOLEAN readOnly = TRUE; - - m_log(LOG_DEBUG,"Calling Acs::mount()"); - const STATUS s = m_acsWrapper.mount(seqNumber, lockId, m_volId, - m_driveId, readOnly, bypass); - std::stringstream dbgMsg; - dbgMsg << "Acs::mount() returned " << acs_status(s); - m_log(LOG_DEBUG,dbgMsg.str()); - - if(STATUS_SUCCESS != s) { - cta::exception::MountFailed ex; - ex.getMessage() << "Failed to send request to mount for read-only access" - " volume " << m_volId.external_label << " into drive " << - m_acsWrapper.driveId2Str(m_driveId) << ": readOnly=" << - (readOnly ? "TRUE" : "FALSE") << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processMountTapeReadOnlyResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::processMountTapeReadOnlyResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const - { - const ACS_MOUNT_RESPONSE *const msg = (ACS_MOUNT_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->mount_status) { - cta::exception::MountFailed ex; - ex.getMessage() << "Status of mount response is not success: " << - acs_status(msg->mount_status); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// syncQueryVolume -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::syncQueryVolume() const { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - try { - sendQueryVolumeRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, - m_ctaConf.QueryInterval.value(), m_ctaConf.CmdTimeout.value()); - return processQueryResponse(buf); - } catch(cta::exception::Exception &ex) { - cta::exception::QueryVolumeFailed qf; - qf.getMessage() << "Failed to query volume " << - m_volId.external_label << ": " << ex.getMessage().str(); - throw qf; - } -} - -//------------------------------------------------------------------------------ -// sendQueryVolumeRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::sendQueryVolumeRequest ( - const SEQ_NO seqNumber) const { - VOLID volIds[MAX_ID]; - - memset(volIds, '\0', sizeof(volIds)); - strncpy(volIds[0].external_label, m_volId.external_label, - sizeof(volIds[0].external_label)); - volIds[0].external_label[sizeof(volIds[0].external_label) - 1] = '\0'; - - m_log(LOG_DEBUG,"Calling Acs::queryVolume()"); - - const STATUS s = m_acs.queryVolume(seqNumber, volIds, 1); - - std::stringstream dbgMsg; - dbgMsg << "Acs::queryVolume() returned " << acs_status(s); - m_log(LOG_DEBUG,"Calling Acs::queryVolume()"); - - if(STATUS_SUCCESS != s) { - cta::exception::QueryVolumeFailed ex; - ex.getMessage() << "Failed to send query request for volume " << - m_volId.external_label << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processQueryResponse -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::processQueryResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const { - - const ACS_QUERY_VOL_RESPONSE *const msg = (ACS_QUERY_VOL_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->query_vol_status) { - cta::exception::QueryVolumeFailed ex; - ex.getMessage() << "Status of query response is not success: " << - acs_status(msg->query_vol_status); - throw ex; - } - - if((unsigned short)1 != msg->count) { - cta::exception::QueryVolumeFailed ex; - ex.getMessage() << "Query response does not contain a single volume: count=" - << msg->count; - throw ex; - } - - // count is 1 so it is safe to make a reference to the single volume status - const QU_VOL_STATUS &volStatus = msg->vol_status[0]; - - if(strcmp(m_volId.external_label, volStatus.vol_id.external_label)) { - cta::exception::QueryVolumeFailed ex; - ex.getMessage() << - "Volume identifier of query response does not match that of request" - ": requestVID=" << m_volId.external_label << - " responseVID=" << volStatus.vol_id.external_label; - throw ex; - } - - return volumeStatusAsString(volStatus); -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsMountTapeReadOnly::~AcsMountTapeReadOnly() { -} diff --git a/mediachanger/acs/daemon/AcsMountTapeReadOnly.hpp b/mediachanger/acs/daemon/AcsMountTapeReadOnly.hpp deleted file mode 100644 index 86d070eaad..0000000000 --- a/mediachanger/acs/daemon/AcsMountTapeReadOnly.hpp +++ /dev/null @@ -1,142 +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/acs/Acs.hpp" -#include "AcsdConfiguration.hpp" -#include "mediachanger/acs/AcsLibraryInteraction.hpp" - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -/** - * Class responsible for mounting tapes for read-only access through ACS API. - */ -class AcsMountTapeReadOnly: public cta::mediachanger::acs::AcsLibraryInteraction { - -public: - - /** - * Constructor. - */ - AcsMountTapeReadOnly( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - cta::mediachanger::acs::Acs &acsWrapper, - cta::log::Logger& log, - const AcsdConfiguration &ctaConf); - - /** - * Destructor. - */ - ~AcsMountTapeReadOnly(); - - /** - * Execute mount request through ACS API. - * Throws cta::exception::Exception if the mount is not successful. Adds to - * the exception the result of the query volume request for the given volume. - */ - void execute() const ; - -protected: - - /** - * mounts the tape with the specified VID into the drive with the specified - * drive ID. - * - * This method does not return until the mount has either succeeded, failed or - * the specified timeout has been reached. - */ - void syncMountTapeReadOnly() const; - - /** - * Sends the mount request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendMountTapeReadOnlyRequest(const SEQ_NO seqNumber) const; - - /** - * Throws cta::exception::MountFailed if the mount was not - * successful. - * - * @param buf The mount-response message. - */ - void processMountTapeReadOnlyResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const; - - /** - * Queries ACS for information about the volume identifier. - * - * This method does not return until the information has been successfully - * retrieved, an error has occurred or the specified timeout has been - * reached. - * - * @return The string presentation of the query volume response. - */ - std::string syncQueryVolume() const; - - /** - * Sends the query volume request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendQueryVolumeRequest(const SEQ_NO seqNumber) const; - - /** - * Extracts the volume status from the specified query-response message and - * returns it in human-readable form. - * - * @param buf The query-response message. - * @return The string presentation of the query volume response. - */ - std::string processQueryResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const; - - /** - * ACS VOLID - */ - VOLID m_volId; - - /** - * ACS DRIVEID - */ - DRIVEID m_driveId; - - /** - * Object providing c wrapper for ACS commands. - */ - Acs &m_acsWrapper; - log::Logger& m_log; - /** - * The configuration parameters for the CTA ACS daemon. - */ - const AcsdConfiguration m_ctaConf; - -}; // class AcsMountTapeReadOnly - -} // namespace daemon -} // namepsace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsMountTapeReadWrite.cpp b/mediachanger/acs/daemon/AcsMountTapeReadWrite.cpp deleted file mode 100644 index 6759414081..0000000000 --- a/mediachanger/acs/daemon/AcsMountTapeReadWrite.cpp +++ /dev/null @@ -1,216 +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 "AcsMountTapeReadWrite.hpp" -#include "common/exception/MountFailed.hpp" -#include "mediachanger/acs/AcsLibraryInteraction.hpp" -#include "common/exception/QueryVolumeFailed.hpp" -#include "common/log/log.hpp" - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::AcsMountTapeReadWrite( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - cta::mediachanger::acs::Acs &acsWrapper, - cta::log::Logger &log, - const AcsdConfiguration &ctaConf): - AcsLibraryInteraction(acsWrapper, log), - m_volId(acsWrapper.str2Volid(vid)), - m_driveId(acsWrapper.alpd2DriveId(acs,lsm,panel,drive)), - m_acsWrapper(acsWrapper), - m_log(log), - m_ctaConf(ctaConf) { -} - -//------------------------------------------------------------------------------ -// execute -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::execute() const { - try { - syncMountTapeReadWrite(); - } catch (cta::exception::MountFailed &mountFailed) { - try { - const std::string queryVolumeResponse = syncQueryVolume(); - mountFailed.getMessage() << " : The query volume response: " << - queryVolumeResponse; - } catch (cta::exception::QueryVolumeFailed &queryFailed) { - mountFailed.getMessage() << " : " << queryFailed.getMessage().str(); - } - throw mountFailed; - } -} - -//------------------------------------------------------------------------------ -// syncMountTapeReadWrite -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::syncMountTapeReadWrite() const - { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - try { - sendMountTapeReadWriteRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, - m_ctaConf.QueryInterval.value(), m_ctaConf.CmdTimeout.value()); - processMountTapeReadWriteResponse(buf); - } catch(cta::exception::Exception &ex) { - cta::exception::MountFailed mf; - mf.getMessage() << "Failed to mount for read/write access volume " << - m_volId.external_label << ": " << ex.getMessage().str(); - throw mf; - } -} - -//------------------------------------------------------------------------------ -// sendMountTapeReadWriteRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::sendMountTapeReadWriteRequest( - const SEQ_NO seqNumber) const { - const LOCKID lockId = 0; // No lock - const BOOLEAN bypass = FALSE; - const BOOLEAN readOnly = FALSE; - - m_log(LOG_DEBUG,"Calling Acs::mount()"); - const STATUS s = m_acsWrapper.mount(seqNumber, lockId, m_volId, - m_driveId, readOnly, bypass); - std::stringstream dbgMsg; - dbgMsg << "Acs::mount() returned " << acs_status(s); - m_log(LOG_DEBUG,dbgMsg.str()); - - if(STATUS_SUCCESS != s) { - cta::exception::MountFailed ex; - ex.getMessage() << "Failed to send request to mount for read/write access" - " volume " << m_volId.external_label << " into drive " - << m_acsWrapper.driveId2Str(m_driveId) - << ": readOnly=" - << (readOnly ? "TRUE" : "FALSE") << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processMountTapeReadWriteResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::processMountTapeReadWriteResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const - { - const ACS_MOUNT_RESPONSE *const msg = (ACS_MOUNT_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->mount_status) { - cta::exception::MountFailed ex; - ex.getMessage() << "Status of mount response is not success: " << - acs_status(msg->mount_status); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// syncQueryVolume -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::syncQueryVolume() const { - const SEQ_NO requestSeqNumber = 1; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - try { - sendQueryVolumeRequest(requestSeqNumber); - requestResponsesUntilFinal(requestSeqNumber, buf, - m_ctaConf.QueryInterval.value(), m_ctaConf.CmdTimeout.value()); - return processQueryResponse(buf); - } catch(cta::exception::Exception &ex) { - cta::exception::QueryVolumeFailed qf; - qf.getMessage() << "Failed to query volume " << - m_volId.external_label << ": " << ex.getMessage().str(); - throw qf; - } -} - -//------------------------------------------------------------------------------ -// sendQueryVolumeRequest -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::sendQueryVolumeRequest ( - const SEQ_NO seqNumber) const { - VOLID volIds[MAX_ID]; - - memset(volIds, '\0', sizeof(volIds)); - strncpy(volIds[0].external_label, m_volId.external_label, - sizeof(volIds[0].external_label)); - volIds[0].external_label[sizeof(volIds[0].external_label) - 1] = '\0'; - - m_log(LOG_DEBUG,"Calling Acs::queryVolume()"); - - - const STATUS s = m_acs.queryVolume(seqNumber, volIds, 1); - - std::stringstream dbgMsg; - dbgMsg << "Acs::queryVolume() returned " << acs_status(s); - m_log(LOG_DEBUG,"Calling Acs::queryVolume()"); - - if(STATUS_SUCCESS != s) { - cta::exception::QueryVolumeFailed ex; - ex.getMessage() << "Failed to send query request for volume " << - m_volId.external_label << ": " << acs_status(s); - throw ex; - } -} - -//------------------------------------------------------------------------------ -// processQueryResponse -//------------------------------------------------------------------------------ -std::string cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::processQueryResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const { - - const ACS_QUERY_VOL_RESPONSE *const msg = (ACS_QUERY_VOL_RESPONSE *)buf; - - if(STATUS_SUCCESS != msg->query_vol_status) { - cta::exception::QueryVolumeFailed ex; - ex.getMessage() << "Status of query response is not success: " << - acs_status(msg->query_vol_status); - throw ex; - } - - if((unsigned short)1 != msg->count) { - cta::exception::QueryVolumeFailed ex; - ex.getMessage() << "Query response does not contain a single volume: count=" - << msg->count; - throw ex; - } - - // count is 1 so it is safe to make a reference to the single volume status - const QU_VOL_STATUS &volStatus = msg->vol_status[0]; - - if(strcmp(m_volId.external_label, volStatus.vol_id.external_label)) { - cta::exception::QueryVolumeFailed ex; - ex.getMessage() << - "Volume identifier of query response does not match that of request" - ": requestVID=" << m_volId.external_label << - " responseVID=" << volStatus.vol_id.external_label; - throw ex; - } - - return volumeStatusAsString(volStatus); -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsMountTapeReadWrite::~AcsMountTapeReadWrite() { -} diff --git a/mediachanger/acs/daemon/AcsMountTapeReadWrite.hpp b/mediachanger/acs/daemon/AcsMountTapeReadWrite.hpp deleted file mode 100644 index 17cecfb9ef..0000000000 --- a/mediachanger/acs/daemon/AcsMountTapeReadWrite.hpp +++ /dev/null @@ -1,142 +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/acs/Acs.hpp" -#include "AcsdConfiguration.hpp" -#include "mediachanger/acs/AcsLibraryInteraction.hpp" - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -/** - * Class responsible for mounting tapes for read/write access through ACS API. - */ -class AcsMountTapeReadWrite: public cta::mediachanger::acs::AcsLibraryInteraction { - -public: - - /** - * Constructor. - */ - AcsMountTapeReadWrite( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - cta::mediachanger::acs::Acs &acsWrapper, - log::Logger& log, - const AcsdConfiguration &ctaConf); - - /** - * Destructor. - */ - ~AcsMountTapeReadWrite(); - - /** - * Execute mount request through ACS API. - */ - void execute() const; - -protected: - - /** - * mounts the tape with the specified VID into the drive with the specified - * drive ID. - * - * This method does not return until the mount has either succeeded, failed or - * the specified timeout has been reached. - */ - void syncMountTapeReadWrite() const; - - /** - * Sends the mount request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendMountTapeReadWriteRequest(const SEQ_NO seqNumber) const; - - /** - * Throws cta::exception::MountFailed if the mount was not - * successful. - * - * @param buf The mount-response message. - */ - void processMountTapeReadWriteResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const; - - /** - * Queries ACS for information about the volume identifier. - * - * This method does not return until the information has been successfully - * retrieved, an error has occurred or the specified timeout has been - * reached. - * - * @return The string presentation of the query volume response. - */ - std::string syncQueryVolume() const; - - /** - * Sends the query volume request to ACSLS. - * - * @param seqNumber The sequence number to be used in the request. - */ - void sendQueryVolumeRequest(const SEQ_NO seqNumber) const; - - /** - * Extracts the volume status from the specified query-response message and - * returns it in human-readable form. - * - * @param buf The query-response message. - * @return The string presentation of the query volume response. - */ - std::string processQueryResponse( - ALIGNED_BYTES (&buf)[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]) const; - - /** - * ACS VOLID - */ - VOLID m_volId; - - /** - * ACS DRIVEID - */ - DRIVEID m_driveId; - - /** - * Object providing C wrapper for ACS commands. - */ - Acs &m_acsWrapper; - - log::Logger& m_log; - - /** - * The configuration parameters for the CTA ACS daemon. - */ - const AcsdConfiguration m_ctaConf; - -}; // class AcsMountTapeReadWrite - -} // namespace daemon -} // namepsace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsPendingRequests.cpp b/mediachanger/acs/daemon/AcsPendingRequests.cpp deleted file mode 100644 index 16025a0078..0000000000 --- a/mediachanger/acs/daemon/AcsPendingRequests.cpp +++ /dev/null @@ -1,331 +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 "AcsPendingRequests.hpp" -#include "mediachanger/acs/AcsImpl.hpp" -#include "mediachanger/acs/daemon/AcsRequest.hpp" -#include "mediachanger/acs/daemon/AcsDismountTape.hpp" -#include "AcsRequestDismountTape.hpp" -#include "common/Constants.hpp" -#include "mediachanger/Constants.hpp" -#include "mediachanger/acs/daemon/Constants.hpp" -#include "common/log/log.hpp" -#include "mediachanger/messages.hpp" -#include "mediachanger/Frame.hpp" -#include "mediachanger/AcsDismountTape.pb.h" -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::daemon::AcsPendingRequests::AcsPendingRequests( - const AcsdConfiguration &ctaConf, cta::log::Logger &l): - m_ctaConf(ctaConf), - m_log(l), - m_lastTimeResponseUsed(0) { -} - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::daemon::AcsPendingRequests::~AcsPendingRequests() { - for(RequestList::const_iterator itor = m_acsRequestList.begin(); - itor != m_acsRequestList.end(); itor++) { - cta::mediachanger::acs::daemon::AcsRequest *const acsRequest = *itor; - delete acsRequest; - } -} - -//----------------------------------------------------------------------------- -// tick -//----------------------------------------------------------------------------- - - void cta::mediachanger::acs::daemon::AcsPendingRequests::tick() { - bool haveRunningRequests = false; - for(RequestList::const_iterator itor = m_acsRequestList.begin(); - itor != m_acsRequestList.end();itor++) { - cta::mediachanger::acs::daemon::AcsRequest *const acsRequest = *itor; - acsRequest->tick(); - if(acsRequest->isRunning()) { - haveRunningRequests = true; - } - } - - if (haveRunningRequests) { - const time_t now = time(0); - - const time_t secsSinceLastResponse = now - m_lastTimeResponseUsed; - const bool responseTimeExceeded = secsSinceLastResponse > - ACS_RESPONSE_TIMEOUT; - - if (responseTimeExceeded) { - const int responseTimeout = 0 ; // 0 - means pool for - // the existence of a response. - - SEQ_NO responseSeqNumber = 0; - REQ_ID reqId = (REQ_ID)0; - ACS_RESPONSE_TYPE responseType = RT_NONE; - ALIGNED_BYTES buf[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - - m_log(LOG_DEBUG, - "AcsPendingRequests::tick() Calling Acs::response()"); - - const STATUS responseStatus = m_acs.response(responseTimeout, - responseSeqNumber, reqId, responseType, buf); - - if (STATUS_SUCCESS == responseStatus) { - setRequestResponse(responseSeqNumber,responseType, buf); - } - m_lastTimeResponseUsed = time(0); - } - } -} - -//----------------------------------------------------------------------------- -// setRequestResponse -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsPendingRequests::setRequestResponse( - const SEQ_NO responseSeqNumber, const ACS_RESPONSE_TYPE responseType, - const ALIGNED_BYTES *const responseMsg) { - for(RequestList::const_iterator itor = m_acsRequestList.begin(); - itor != m_acsRequestList.end();itor++) { - cta::mediachanger::acs::daemon::AcsRequest *const acsRequest = *itor; - if ( responseSeqNumber == acsRequest->getSeqNo()) { - std::stringstream dbgMsg; - dbgMsg << "AcsPendingRequests::setRequestResponse responseType=" << - responseType << " " << acsRequest->str(); - m_log(LOG_DEBUG, dbgMsg.str()); - acsRequest->setResponse(responseType, responseMsg); - } - } -} - -//----------------------------------------------------------------------------- -// handleCompletedRequests -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsPendingRequests::handleCompletedRequests() { - for(RequestList::const_iterator itor = m_acsRequestList.begin(); - itor != m_acsRequestList.end();itor++) { - cta::mediachanger::acs::daemon::AcsRequest *const acsRequest = *itor; - if (acsRequest->isCompleted()) { - std::list<log::Param> params = {log::Param("tapeVid", acsRequest->getVid()), - log::Param("acs", acsRequest->getAcs()), - log::Param("lsm", acsRequest->getLsm()), - log::Param("panel", acsRequest->getPanel()), - log::Param("drive", acsRequest->getDrive()), - log::Param("sender identity", acsRequest->getIdentity()) - }; - m_log(LOG_INFO,"Tape successfully dismounted",params); - acsRequest->sendReplayToClientOnce(); - acsRequest->setStateToDelete(); - } - } -} - -//----------------------------------------------------------------------------- -// handleFailedRequests -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsPendingRequests::handleFailedRequests() { - for(RequestList::const_iterator itor = m_acsRequestList.begin(); - itor != m_acsRequestList.end();itor++) { - cta::mediachanger::acs::daemon::AcsRequest *const acsRequest = *itor; - if (acsRequest->isFailed()) { - std::list<log::Param> params = {log::Param("tapeVid", acsRequest->getVid()), - log::Param("acs", acsRequest->getAcs()), - log::Param("lsm", acsRequest->getLsm()), - log::Param("panel", acsRequest->getPanel()), - log::Param("drive", acsRequest->getDrive()), - log::Param("sender identity", acsRequest->getIdentity()) - }; - m_log(LOG_INFO,"Dismount tape failed", params); - acsRequest->sendReplayToClientOnce(); - acsRequest->setStateToDelete(); - } - } -} - -//----------------------------------------------------------------------------- -// handleToDeleteRequests -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsPendingRequests::handleToDeleteRequests() { - for(RequestList::iterator itor = m_acsRequestList.begin(); - itor != m_acsRequestList.end();itor++) { - cta::mediachanger::acs::daemon::AcsRequest *const acsRequest = *itor; - if (acsRequest->isToDelete()) { - m_log(LOG_DEBUG,"AcsPendingRequests::handleToDeleteRequests " + - acsRequest->str()); - delete acsRequest; - itor=m_acsRequestList.erase(itor); - } - } -} - -//----------------------------------------------------------------------------- -// checkAndAddRequest -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsPendingRequests::checkAndAddRequest( - mediachanger::ZmqMsg &address, mediachanger::ZmqMsg &empty, - const cta::mediachanger::Frame &rqst, cta::mediachanger::ZmqSocketST &socket) { - std::list<log::Param> params = { - log::Param("sender identity", - utils::hexDump(address.getData(), address.size())) - }; - m_log(LOG_DEBUG, "AcsPendingRequests::checkAndAddRequest", params); - - const cta::mediachanger::acs::daemon::MsgType msgType = (cta::mediachanger::acs::daemon::MsgType)rqst.header.msgtype(); - switch(msgType) { - case mediachanger::MSG_TYPE_ACSMOUNTTAPEREADONLY: - case mediachanger::MSG_TYPE_ACSMOUNTTAPEREADWRITE: - { - cta::exception::Exception ex; - ex.getMessage() << "Failed to check request" - ": Handling of this message type is not implemented: msgtype=" << - rqst.header.msgtype(); - throw ex; - } - case mediachanger::MSG_TYPE_ACSDISMOUNTTAPE: - checkAndAddRequestDismountTape(address, empty, rqst, socket); - break; - default: - { - const std::string msgTypeStr = cta::mediachanger::acs::daemon::msgTypeToString(msgType); - cta::exception::Exception ex; - ex.getMessage() << "Failed to check request" - ": Unexpected request type: msgType=" << msgType << " msgTypeStr=" << - msgTypeStr; - throw ex; - } - } -} - -//----------------------------------------------------------------------------- -// checkAndAddRequestDismountTape -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsPendingRequests::checkAndAddRequestDismountTape( - mediachanger::ZmqMsg &address, mediachanger::ZmqMsg &empty, - const mediachanger::Frame &rqst, mediachanger::ZmqSocketST &socket) { - m_log(LOG_DEBUG, - "AcsPendingRequests::checkAndAddRequestDismountTape"); - - mediachanger::AcsDismountTape rqstBody; - rqst.parseBodyIntoProtocolBuffer(rqstBody); - - const std::string vid = rqstBody.vid(); - const uint32_t acs = rqstBody.acs(); - const uint32_t lsm = rqstBody.lsm(); - const uint32_t panel = rqstBody.panel(); - const uint32_t drive = rqstBody.drive(); - - checkRequest(vid, acs, lsm, panel, drive); - - std::list<log::Param> params = {log::Param("tapeVid", vid), - log::Param("acs", acs), - log::Param("lsm", lsm), - log::Param("panel", panel), - log::Param("drive", drive), - log::Param("sender identity", - utils::hexDump(address.getData(), address.size())) - }; - m_log(LOG_INFO, "Dismount tape", params); - - const SEQ_NO seqNo = getSequenceNumber(); - std::list<log::Param> seqParam = {log::Param("seqNumber", seqNo)}; - m_log(LOG_DEBUG, "ACS sequence number", seqParam); - - try { - cta::mediachanger::acs::daemon::AcsRequest * acsRequestDismountTape = - new AcsRequestDismountTape(vid, acs, lsm, panel, drive, - //new AcsRequestDismountTape AcsRequestDismountTape(vid, acs, lsm, panel, drive, - m_ctaConf, socket, address, empty, m_log, seqNo); - - acsRequestDismountTape->setStateToExecute(); - m_acsRequestList.push_back(acsRequestDismountTape); - } catch (cta::exception::Exception &ne) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to add dismount request: " - << ne.getMessage().str(); - m_log(LOG_ERR, ex.getMessage().str()); - throw ex; - } -} - -//----------------------------------------------------------------------------- -// checkRequest -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsPendingRequests::checkRequest(const std::string &vid, - const uint32_t acs, const uint32_t lsm, const uint32_t panel, - const uint32_t drive) const { - for(RequestList::const_iterator itor = m_acsRequestList.begin(); - itor != m_acsRequestList.end();itor++) { - cta::mediachanger::acs::daemon::AcsRequest *const acsRequest = *itor; - if (acs == acsRequest->getAcs() && lsm == acsRequest->getLsm() && - panel == acsRequest->getPanel() && drive == acsRequest->getDrive()) { - cta::exception::Exception ex; - ex.getMessage() << "Check request failed: " - "acs, lsm, panel, drive already are used by another request: "<< - acsRequest->str(); - throw ex; - } - if (std::string::npos != vid.find(acsRequest->getVid())) { - cta::exception::Exception ex; - ex.getMessage() << "Check request failed: " - "vid already is used by another request: "<< - acsRequest->str(); - throw ex; - } - } -} - -//----------------------------------------------------------------------------- -// getSequenceNumber -//----------------------------------------------------------------------------- -SEQ_NO cta::mediachanger::acs::daemon::AcsPendingRequests::getSequenceNumber() const { - unsigned short maxSeqNo = 0; - unsigned short minSeqNo = ACS_MAX_SEQ; - - for(RequestList::const_iterator itor = m_acsRequestList.begin(); - itor != m_acsRequestList.end();itor++) { - cta::mediachanger::acs::daemon::AcsRequest *const acsRequest = *itor; - if (maxSeqNo < acsRequest->getSeqNo()) { - maxSeqNo = acsRequest->getSeqNo(); - } - if (minSeqNo > acsRequest->getSeqNo()) { - minSeqNo = acsRequest->getSeqNo(); - } - } - - // first request - if(ACS_MAX_SEQ == minSeqNo && 0 == maxSeqNo) { - return 1; - } - - // try to get number from 1 to minSeqNo - if(1 != minSeqNo ) { - return minSeqNo-1; - } - - // try to get number from maxSeqNo to maximum allowed - if (ACS_MAX_SEQ != maxSeqNo) { - return maxSeqNo+1; - } - - cta::exception::Exception ex; - ex.getMessage() << "Failed to get sequence number for ACS" - ": allocated minimum seqNo=\""<<minSeqNo<<"\""<< - " allocated maximum seqNo=\""<<maxSeqNo<<"\""; - m_log(LOG_ERR, ex.getMessage().str()); - throw ex; -} diff --git a/mediachanger/acs/daemon/AcsPendingRequests.hpp b/mediachanger/acs/daemon/AcsPendingRequests.hpp deleted file mode 100644 index b7fff05a26..0000000000 --- a/mediachanger/acs/daemon/AcsPendingRequests.hpp +++ /dev/null @@ -1,196 +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/acs/daemon/AcsdConfiguration.hpp" -#include "common/log/log.hpp" -#include "common/log/SyslogLogger.hpp" -#include "mediachanger/acs/daemon/AcsRequest.hpp" -#include "mediachanger/acs/AcsImpl.hpp" -#include "mediachanger/messages.hpp" -#include "mediachanger/Frame.hpp" -#include "mediachanger/ZmqMsg.hpp" -#include "mediachanger/ZmqSocket.hpp" -#include "mediachanger/ZmqSocketST.hpp" -#include <list> -#include <time.h> - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -/** - * Class responsible for keeping track of the Acs requests controlled by - * the CTA ACS daemon. - */ -class AcsPendingRequests { -public: - - /** - * Constructor. - * - * @param ctaConf The configuration for the CTA ACS daemon. - */ - AcsPendingRequests(const AcsdConfiguration &ctaConf, cta::log::Logger &); - - /** - * Destructor. - */ - ~AcsPendingRequests(); - - /** - * Notifies the AcsPendingRequests that it should perform any time related - * actions. - * - * This method does not have to be called at any time precise interval. - */ - void tick(); - - /** - * Requests to the CTA ACS daemon might have several states. - * - * ACS_REQUEST_TO_EXECUTE - is initial state. When request arrives from a - * client it is set to be asynchronous executed to ACS Library. - * ACS_REQUEST_IS_RUNNING - the state in which we periodically query ACS - * Library to check the status of the ongoing request. - * ACS_REQUEST_COMPLETED - indicates that the request is completed - * successfully. - * ACS_REQUEST_FAILED - indicates that the request is completed - * unsuccessfully. - * ACS_REQUEST_TO_DELETE - indicates that the request is handled and might - * be deleted. - * - * /- COMPLETED -\ - * TO_EXECUTE -> IS_RUNNING ->| |-> TO_DELETE - * \- FAILED -/ - */ - - /** - * Handles successfully completed requests. - */ - void handleCompletedRequests(); - - /** - * Handles failed requests. - */ - void handleFailedRequests(); - - /** - * Performs cleanup for deleted requests. - */ - void handleToDeleteRequests(); - - /** - * Performs general checks for the incoming requests and calls next checker - * for the message. Throws exceptions if checks are not passed. - * - * @param address ZMQ message with client address. - * @param empty ZMQ empty message. - * @param rqst ZMQ message with CTA frame. - * @param socket ZMQ socket to use. - */ - - void checkAndAddRequest(mediachanger::ZmqMsg &address, - mediachanger::ZmqMsg &empty, - const mediachanger:: Frame &rqst, - mediachanger::ZmqSocketST &socket); - -/** - * Performs dismount specific checks for the incoming request and add it to - * the list of the request to be handled. - * - * @param address ZMQ message with client address. - * @param empty ZMQ empty message. - * @param rqst ZMQ message with CTA frame. - * @param socket ZMQ socket to use. - */ - void checkAndAddRequestDismountTape(mediachanger::ZmqMsg &address, - mediachanger::ZmqMsg &empty, - const mediachanger::Frame &rqst, - mediachanger::ZmqSocketST &socket); - - /** - * Find and return free sequence number for the ACS request. - * - * @return The value of free sequence number for the ACS request. Throws - * exception if the is no free sequence number. - */ - SEQ_NO getSequenceNumber() const; - - /** - * Sets the type of the response and the response message in the ACS request - * with the sequence number equal response sequence number. - * - * @param responseSeqNumber The sequence number to find ongoing ACS request. - * @param responseType The type of the response message. - * @param responseMsg The response message - */ - void setRequestResponse(const SEQ_NO responseSeqNumber, - const ACS_RESPONSE_TYPE responseType, - const ALIGNED_BYTES *const responseMsg); - - /** - * Performs checks for the request before adding it to the ACS requests list. - * Throws exceptions if there are any problems. - * - * @param vid The vid of the ACS request. - * @param acs The acs value of the ACS request. - * @param lsm The lsm value of the ACS request. - * @param panel The panel value of the ACS request. - * @param drive The drive value of the ACS request. - */ - void checkRequest(const std::string &vid, const uint32_t acs, - const uint32_t lsm, const uint32_t panel, const uint32_t drive) const ; - -private: - - /** - * The object representing cta configuration parameters for - * the CTA ACS daemon. - */ - const AcsdConfiguration m_ctaConf; - - log::Logger &m_log; - /** - * Type for the list of the ACS requests. - */ - typedef std::list<AcsRequest *> RequestList; - - /** - * The list for the ACS requests. - */ - RequestList m_acsRequestList; - - /** - * The ACLS C-API wrapper. - */ - AcsImpl m_acs; - - /** - * The time when the last ACS response command was used. - */ - time_t m_lastTimeResponseUsed; - -}; // class AcsPendingRequests - -} // namespace deamon -} // namepsace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsRequest.cpp b/mediachanger/acs/daemon/AcsRequest.cpp deleted file mode 100644 index cde1dae83e..0000000000 --- a/mediachanger/acs/daemon/AcsRequest.cpp +++ /dev/null @@ -1,283 +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 "AcsRequest.hpp" -#include "mediachanger/messages.hpp" -#include "mediachanger/ReturnValue.pb.h" -#include "mediachanger/Exception.pb.h" -#include "common/utils/utils.hpp" - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::daemon::AcsRequest::AcsRequest(cta::mediachanger::ZmqSocketST &socket, - cta::mediachanger::ZmqMsg &address, cta::mediachanger::ZmqMsg &empty, - const SEQ_NO seqNo, const std::string vid, const uint32_t acs, - const uint32_t lsm, const uint32_t panel, const uint32_t drive): - m_seqNo(seqNo), - m_vid(vid), - m_acs(acs), - m_lsm(lsm), - m_panel(panel), - m_drive(drive), - m_socket(socket), - m_identity(utils::hexDump(address.getData(),address.size())), - m_isReplaySent(false) { - zmq_msg_init_size (&m_addressMsg, address.size()); - memcpy (zmq_msg_data (&m_addressMsg), (const void*)&address.getZmqMsg(), - address.size()); - - zmq_msg_init_size (&m_emptyMsg, empty.size()); - memcpy (zmq_msg_data (&m_emptyMsg), (const void*)&empty.getZmqMsg(), - empty.size()); -} - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::daemon::AcsRequest::~AcsRequest() { - zmq_msg_close(&m_addressMsg); - zmq_msg_close(&m_emptyMsg); -} - -//----------------------------------------------------------------------------- -// isToExecute -//----------------------------------------------------------------------------- -bool cta::mediachanger::acs::daemon::AcsRequest::isToExecute() const { - if (ACS_REQUEST_TO_EXECUTE == m_state) { - return true; - } else { - return false; - }; -} - -//----------------------------------------------------------------------------- -// isRunning -//----------------------------------------------------------------------------- -bool cta::mediachanger::acs::daemon::AcsRequest::isRunning() const { - if (ACS_REQUEST_IS_RUNNING == m_state) { - return true; - } else { - return false; - }; -} - -//----------------------------------------------------------------------------- -// isCompleted -//----------------------------------------------------------------------------- -bool cta::mediachanger::acs::daemon::AcsRequest::isCompleted() const { - if (ACS_REQUEST_COMPLETED == m_state) { - return true; - } else { - return false; - }; -} - -//----------------------------------------------------------------------------- -// isFailed -//----------------------------------------------------------------------------- -bool cta::mediachanger::acs::daemon::AcsRequest::isFailed() const { - if (ACS_REQUEST_FAILED == m_state) { - return true; - } else { - return false; - }; -} - -//----------------------------------------------------------------------------- -// isToDelete -//----------------------------------------------------------------------------- -bool cta::mediachanger::acs::daemon::AcsRequest::isToDelete() const { - if (ACS_REQUEST_TO_DELETE == m_state) { - return true; - } else { - return false; - }; -} - -//------------------------------------------------------------------------------ -// createReturnValueFrame -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsRequest::createReturnValueFrame( - const int value) { - cta::mediachanger::Frame frame; - - frame.header = cta::mediachanger::protoTapePreFillHeader(); - frame.header.set_msgtype(cta::mediachanger::MSG_TYPE_RETURNVALUE); - frame.header.set_bodyhashvalue( - cta::mediachanger::computeSHA1Base64(frame.body)); - frame.header.set_bodysignature("PIPO"); - - cta::mediachanger::ReturnValue body; - body.set_value(value); - frame.serializeProtocolBufferIntoBody(body); - - return frame; -} - -//------------------------------------------------------------------------------ -// createExceptionFrame -//------------------------------------------------------------------------------ -cta::mediachanger::Frame cta::mediachanger::acs::daemon::AcsRequest:: - createExceptionFrame(const int code, const std::string& msg) { - cta::mediachanger::Frame frame; - - frame.header = cta::mediachanger::protoTapePreFillHeader(); - frame.header.set_msgtype(mediachanger::MSG_TYPE_EXCEPTION); - frame.header.set_bodyhashvalue(mediachanger::computeSHA1Base64(frame.body)); - frame.header.set_bodysignature("PIPO"); - - cta::mediachanger::Exception body; - body.set_code(code); - body.set_message(msg); - frame.serializeProtocolBufferIntoBody(body); - - return frame; -} - - -//----------------------------------------------------------------------------- -// sendReplayToClientOnce -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsRequest::sendReplayToClientOnce() { - if(m_isReplaySent) { - cta::exception::Exception ex; - ex.getMessage() << "Failed to send second replay to the client"; - throw ex; - } - m_socket.send(&m_addressMsg,ZMQ_SNDMORE); - m_socket.send(&m_emptyMsg,ZMQ_SNDMORE); - - //messages::sendFrame(m_socket, m_reply); - sendFrame(m_socket, m_reply); -} - -//----------------------------------------------------------------------------- -// getIdentity -//----------------------------------------------------------------------------- -std::string cta::mediachanger::acs::daemon::AcsRequest::getIdentity() const { - return m_identity; -} - -//----------------------------------------------------------------------------- -// str -//----------------------------------------------------------------------------- -std::string cta::mediachanger::acs::daemon::AcsRequest::str() const { - std::ostringstream oss; - oss << "vid=" << m_vid << " acs=" << m_acs << " lsm=" << m_lsm << " panel=" << - m_panel << " drive=" << m_drive << " identity=" << getIdentity(); - return oss.str(); -} - -//------------------------------------------------------------------------------ -// getVid -//------------------------------------------------------------------------------ -const std::string &cta::mediachanger::acs::daemon::AcsRequest::getVid() const { - return m_vid; -} - -//------------------------------------------------------------------------------ -// getAcs -//------------------------------------------------------------------------------ -uint32_t cta::mediachanger::acs::daemon::AcsRequest::getAcs() const { - return m_acs; -} - -//------------------------------------------------------------------------------ -// getLsm -//------------------------------------------------------------------------------ -uint32_t cta::mediachanger::acs::daemon::AcsRequest::getLsm() const { - return m_lsm; -} - -//------------------------------------------------------------------------------ -// getPanel -//------------------------------------------------------------------------------ -uint32_t cta::mediachanger::acs::daemon::AcsRequest::getPanel() const { - return m_panel; -} - -//------------------------------------------------------------------------------ -// getDrive -//------------------------------------------------------------------------------ -uint32_t cta::mediachanger::acs::daemon::AcsRequest::getDrive() const { - return m_drive; -} - - -//------------------------------------------------------------------------------ -// getSeqNo -//------------------------------------------------------------------------------ -SEQ_NO cta::mediachanger::acs::daemon::AcsRequest::getSeqNo() const { - return m_seqNo; -} - -//------------------------------------------------------------------------------ -// setResponse -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsRequest::setResponse( - const ACS_RESPONSE_TYPE responseType, - const ALIGNED_BYTES *const responseMsg) { - m_responseType = responseType; - memcpy(m_responseMsg,responseMsg,MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)); -} - -//------------------------------------------------------------------------------ -// setStateFailed -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsRequest::setStateFailed(const int code, - const std::string& msg) { - m_reply = createExceptionFrame(code, msg); - m_state = ACS_REQUEST_FAILED; -} - -//------------------------------------------------------------------------------ -// setStateCompleted -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsRequest::setStateCompleted() { - m_reply = createReturnValueFrame(0); - m_state = ACS_REQUEST_COMPLETED; -} - -//------------------------------------------------------------------------------ -// setStateIsRunning -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsRequest::setStateIsRunning() { - if (isToExecute()) { - m_state = ACS_REQUEST_IS_RUNNING; - } else { - cta::exception::Exception ex; - ex.getMessage() << "Failed to set request state to running from state="<< - m_state; - throw ex; - } -} - -//------------------------------------------------------------------------------ -// setStateToExecute -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsRequest::setStateToExecute() { - m_state = ACS_REQUEST_TO_EXECUTE; -} - -//------------------------------------------------------------------------------ -// setStateToDelete -//------------------------------------------------------------------------------ -void cta::mediachanger::acs::daemon::AcsRequest::setStateToDelete() { - m_state = ACS_REQUEST_TO_DELETE; -} diff --git a/mediachanger/acs/daemon/AcsRequest.hpp b/mediachanger/acs/daemon/AcsRequest.hpp deleted file mode 100644 index 03bfc88d2f..0000000000 --- a/mediachanger/acs/daemon/AcsRequest.hpp +++ /dev/null @@ -1,317 +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/Constants.hpp" -#include "mediachanger/acs/Constants.hpp" -#include "mediachanger/messages.hpp" -#include "mediachanger/ZmqSocket.hpp" -#include "mediachanger/ZmqSocketST.hpp" -#include "mediachanger/acs/AcsImpl.hpp" -#include "common/exception/Exception.hpp" -#include <time.h> - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - - -/** - * Abstract class defining the ACS request presentation to be used in the list - * of pending ACS requests. - */ -class AcsRequest { -public: - - /** - * Constructor. - * - * @param socket ZMQ socket to use. - * @param address ZMQ message with client address. - * @param empty ZMQ empty message. - * @param seqNo Sequence number for the ACS request. - * @param vid The vid of the ACS request. - * @param acs The acs value of the ACS request. - * @param lsm The lsm value of the ACS request. - * @param panel The panel value of the ACS request. - * @param drive The drive value of the ACS request. - */ - AcsRequest(ZmqSocketST &socket, ZmqMsg &address, - ZmqMsg &empty, const SEQ_NO seqNo, - const std::string vid, const uint32_t acs, - const uint32_t lsm, const uint32_t panel, const uint32_t drive); - - /** - * Destructor. - */ - virtual ~AcsRequest() = 0; - - /** - * Perform any time related actions with the request to CTA ACS daemon. - * - * This method does not have to be called at any time precise interval. - */ - virtual void tick() = 0; - - /** - * Checks if the ACS request is in to be executed state. - * - * @return true if the ACS request in state to Execute. - */ - bool isToExecute() const; - - /** - * Sets state of the ACS request to be executed. - */ - void setStateToExecute(); - - /** - * Checks if the ACS request is in running state. - * - * @return true if the ACS request is in running state. - */ - bool isRunning() const; - - /** - * Sets state of the ACS request to running. - */ - void setStateIsRunning(); - - /** - * Checks if the ACS request is in completed state. - * - * @return true if the ACS request is in completed state. - */ - bool isCompleted() const; - - /** - * Sets state of the ACS request to completed and fills ZMQ replay frame with - * good status 0. - */ - void setStateCompleted(); - - /** - * Checks if the ACS request is in failed state. - * - * @return true if the ACS request is in failed state. - */ - bool isFailed() const; - - /** - * Sets state of the ACS request to failed and fills ZMQ replay frame with - * exception data. - */ - void setStateFailed(const int code,const std::string& msg); - - /** - * Checks if the ACS request is in to delete state. - * - * @return true if the ACS request is in to delete state. - */ - bool isToDelete() const; - - /** - * Sets state of the ACS request to be deleted. - */ - void setStateToDelete(); - - /** - * Gets the vid component of the ACS request. - * - * @return the vid component of the ACS request. - */ - const std::string &getVid() const; - - /** - * Gets the acs component of the ACS request. - * - * @return the acs component of the ACS request. - */ - uint32_t getAcs() const; - - /** - * Gets the lsm component of the ACS request. - * - * @return the lsm component of the ACS request. - */ - uint32_t getLsm() const; - - /** - * Gets the panel component of the ACS request. - * - * @return the panel component of the ACS request. - */ - uint32_t getPanel() const; - - /** - * Gets the drive component of the ACS request. - * - * @return the drive component of the ACS request. - */ - uint32_t getDrive() const; - - /** - * Gets the SeqNumber component of the ACS request. - * - * @return the SeqNo component of the ACS request. - */ - SEQ_NO getSeqNo() const; - - /** - * Sets the fields of the response message of the ACS response request. - * - * @param responseType The type of the response message. - * @param responseMsg The response message. - */ - void setResponse(const ACS_RESPONSE_TYPE responseType, - const ALIGNED_BYTES *const responseMsg); - - /** - * Send a replay to the client who issued the ACS request. - */ - void sendReplayToClientOnce(); - - /** - * Returns string presentation for the connection identity with the client. - * - * @return The connection Identity. - */ - std::string getIdentity() const; - - /** - * Returns a string representing ACS request. - * - * @return The value of string presentation for the request - */ - std::string str() const; - - /** - * Abstract method to be implemented in concrete implementation. Checks - * the status of the response from the response message buffer and the type of - * the response. Throws exception if the type of the response is RT_FINAL but - * the status is not success. - * - * @return true if the type of response RT_FINAL and the response status - * is STATUS_SUCCESS. - */ - virtual bool isResponseFinalAndSuccess() const = 0; - -private: - - /** - * Creates a message frame containing a ReturnValue message. - * - * @param value The return value of the ReturnValue message. - * @return The message frame. - */ - //cta::messages::Frame createReturnValueFrame(const int value); - Frame createReturnValueFrame(const int value); - - /** - * Creates a message frame containing an Exception message. - * - * @param code The error code of the exception. - * @param msg The message string of the exception. - */ - Frame createExceptionFrame(const int code, - const std::string& msg); - - /** - * Request sequence number of the ACS request. - */ - const SEQ_NO m_seqNo; - - /** - * The vid component of the ACS request. - */ - const std::string m_vid; - - /** - * The acs component of the ACS request. - */ - const uint32_t m_acs; - - /** - * The lsm component of the ACS request. - */ - const uint32_t m_lsm; - - /** - * The panel component of the ACS request. - */ - const uint32_t m_panel; - - /** - * The drive component of the ACS request. - */ - const uint32_t m_drive; - - /** - * Internal state of the ACS request. - */ - RequestState m_state ; - - /** - * Replay ZMQ frame for the client. - */ - Frame m_reply; - - /** - * The ZMQ socket listening for messages. - */ - ZmqSocketST &m_socket; - - /** - * Client identity for logging. - */ - const std::string m_identity; - - /** - * ZMQ address message for the client. - */ - zmq_msg_t m_addressMsg; - - /** - * ZMQ empty message for the client. - */ - zmq_msg_t m_emptyMsg; - - /** - * Store is the replay to the client has been sent or not. - */ - bool m_isReplaySent; - -protected: - /** - * The type of the response message associated with the ACS request. - */ - ACS_RESPONSE_TYPE m_responseType; - - /** - * The response message associated with the ACS request. - */ - ALIGNED_BYTES m_responseMsg[MAX_MESSAGE_SIZE / sizeof(ALIGNED_BYTES)]; - -}; // class AcsRequest - -} // namepsace daemon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsRequestDismountTape.cpp b/mediachanger/acs/daemon/AcsRequestDismountTape.cpp deleted file mode 100644 index 74ed0fa0a9..0000000000 --- a/mediachanger/acs/daemon/AcsRequestDismountTape.cpp +++ /dev/null @@ -1,112 +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 "AcsRequestDismountTape.hpp" -#include "common/exception/DismountFailed.hpp" -#include "common/log/log.hpp" - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -cta::mediachanger::acs::daemon::AcsRequestDismountTape::AcsRequestDismountTape( - const std::string &vid, const uint32_t acs, - const uint32_t lsm, const uint32_t panel, const uint32_t drive, - const AcsdConfiguration &ctaConf, - mediachanger::ZmqSocketST &socket, - mediachanger::ZmqMsg &address, - mediachanger::ZmqMsg &empty, - log::Logger &log, - const SEQ_NO seqNo): - AcsRequest(socket, address, empty, seqNo, vid, acs, lsm, panel, drive), - m_ctaConf(ctaConf), - m_acsDismountTape(vid, acs, lsm, panel, drive, m_acs, log, ctaConf), - m_lastTimeLibraryQueried(0), - m_log(log), - m_timeAcsCommandStarted(0) { -} - -//----------------------------------------------------------------------------- -// tick -//----------------------------------------------------------------------------- -void cta::mediachanger::acs::daemon::AcsRequestDismountTape::tick() { - try { - if (isToExecute()) { - m_log(LOG_DEBUG,"AcsRequestDismountTape::tick isToExecute"); - m_acsDismountTape.asyncExecute(getSeqNo()); - setStateIsRunning(); - m_timeAcsCommandStarted = time(0); - } - - const time_t now = time(0); - - const time_t secsSinceLastQuery = now - m_lastTimeLibraryQueried; - const bool firstQueryOrTimeExceeded = (unsigned int)secsSinceLastQuery > - m_ctaConf.QueryInterval.value(); - - if(isRunning() && firstQueryOrTimeExceeded) { - if(isResponseFinalAndSuccess()) { - setStateCompleted(); - m_log(LOG_DEBUG, - "AcsRequestDismountTape::tick ACS_REQUEST_COMPLETED"); - } else { - m_log(LOG_DEBUG,"AcsRequestDismountTape::tick " - "firstQueryOrTimeExceeded()"); - m_lastTimeLibraryQueried = time(0); - } - } - - const time_t secsSinceCommandStarted = now - m_timeAcsCommandStarted; - const bool acsCommandTimeExceeded = (unsigned int)secsSinceCommandStarted > - m_ctaConf.CmdTimeout.value(); - - if(isRunning() && acsCommandTimeExceeded) { - cta::exception::RequestFailed ex; - ex.getMessage() << "ACS command timed out after " << - secsSinceCommandStarted << " seconds"; - throw ex; - } - } catch (cta::exception::Exception &ex) { - setStateFailed(ECANCELED, ex.getMessage().str()); - m_log(LOG_ERR,"Failed to handle the ACS dismount tape request: " - + ex.getMessage().str()); - } catch(std::exception &se) { - setStateFailed(ECANCELED, se.what()); - m_log(LOG_ERR, se.what()); - } catch(...) { - setStateFailed(ECANCELED, "Caught an unknown exception"); - m_log(LOG_ERR, "Caught an unknown exception"); - } -} - -//------------------------------------------------------------------------------ -// isResponseFinalAndSuccess -//------------------------------------------------------------------------------ -bool cta::mediachanger::acs::daemon::AcsRequestDismountTape::isResponseFinalAndSuccess() const { - if (RT_FINAL == m_responseType ) { - const ACS_DISMOUNT_RESPONSE *const msg = - (ACS_DISMOUNT_RESPONSE *)m_responseMsg; - if(STATUS_SUCCESS != msg->dismount_status) { - cta::exception::DismountFailed ex; - ex.getMessage() << "Status of dismount response is not success: " << - acs_status(msg->dismount_status); - throw ex; - } - return true; - } - return false; -} diff --git a/mediachanger/acs/daemon/AcsRequestDismountTape.hpp b/mediachanger/acs/daemon/AcsRequestDismountTape.hpp deleted file mode 100644 index 7ec284f6e4..0000000000 --- a/mediachanger/acs/daemon/AcsRequestDismountTape.hpp +++ /dev/null @@ -1,113 +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/acs/daemon/AcsdConfiguration.hpp" -#include "mediachanger/acs/daemon/AcsDismountTape.hpp" -#include "mediachanger/acs/AcsImpl.hpp" -#include "mediachanger/acs/daemon/AcsRequest.hpp" - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { -/** - * Concrete class providing a dismount tape implementation of an AcsRequest - * abstract class. - */ -class AcsRequestDismountTape: public AcsRequest { -public: - - /** - * Constructor. - * - * @param vid The vid of the ACS request. - * @param acs The acs value of the ACS request. - * @param lsm The lsm value of the ACS request. - * @param panel The panel value of the ACS request. - * @param drive The drive value of the ACS request. - * @param ctaConf The configuration for the CTA ACS daemon. - * @param socket ZMQ socket to use. - * @param address ZMQ message with client address. - * @param empty ZMQ empty message. - * @param seqNo Sequence number for the ACS request. - */ - AcsRequestDismountTape( - const std::string &vid, - const uint32_t acs, - const uint32_t lsm, - const uint32_t panel, - const uint32_t drive, - const AcsdConfiguration &ctaConf, - mediachanger::ZmqSocketST &socket, - mediachanger::ZmqMsg &address, - mediachanger::ZmqMsg &empty, - cta::log::Logger& log, - const SEQ_NO seqNo); - - /** - * Perform any time related actions with the request to CTA ACS daemon. - * - * This method does not have to be called at any time precise interval. - */ - void tick(); - - /** - * Checks the status of the response from the dismount response message buffer - * and the type of the response. Throws exception if the type of the response - * is RT_FINAL but the status is not success. - * - * @return true if the type of response RT_FINAL and the response status - * is STATUS_SUCCESS. - */ - bool isResponseFinalAndSuccess() const; - -private: - - /** - * The CTA configuration parameters for the CTA ACS daemon. - */ - const AcsdConfiguration m_ctaConf; - - /** - * The object representing the class for tape dismount through ACS API. - */ - AcsDismountTape m_acsDismountTape; - - /** - * The ACLS C-API wrapper. - */ - AcsImpl m_acs; - - /** - * The time when the ACS library queried last time. - */ - time_t m_lastTimeLibraryQueried; - - cta::log::Logger &m_log; - /** - * The time at which ACS command was started. - */ - time_t m_timeAcsCommandStarted; - -}; // class AcsRequestDismountTape -} // namespace daemon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsdCmdLine.cpp b/mediachanger/acs/daemon/AcsdCmdLine.cpp deleted file mode 100644 index c55e5484f9..0000000000 --- a/mediachanger/acs/daemon/AcsdCmdLine.cpp +++ /dev/null @@ -1,135 +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 "AcsdCmdLine.hpp" -#include "common/exception/Exception.hpp" -#include "common/log/log.hpp" -#include <iostream> -#include <getopt.h> - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -AcsdCmdLine::AcsdCmdLine(): - foreground(false), - help(false), - readOnly(false) { -} - -//so instead -//use the factory pattern that makes an instance of that class together with the arguments wanted passed but not a constryuctor by itself - -AcsdCmdLine AcsdCmdLine::parse(const int argc, char *const *const argv) { - AcsdCmdLine cmdline; - - struct option longopts[] = { - // { .name, .has_args, .flag, .val } (see getopt.h)) - { "foreground", no_argument, NULL, 'f' }, - { "help", no_argument, NULL, 'h' }, - { "config", required_argument, NULL, 'c' }, - { "readOnly" , no_argument, NULL, 'r'}, - { NULL, 0, NULL, '\0' } - }; - - char c; - // Reset getopt's global variables to make sure we start fresh - optind=0; - // Prevent getopt from printing out errors on stdout - opterr=0; - // We ask getopt to not reshuffle argv ('+') - while ((c = getopt_long(argc, argv, ":fhc:r", longopts, NULL)) != -1) { - //log:write(LOG_INFO, "Usage: [options]\n"); - switch (c) { - case 'r': - cmdline.readOnly = true; - break; - case 'f': - cmdline.foreground = true; - break; - case 'c': - cmdline.configLocation = optarg; - break; - case 'h': - cmdline.help = true; - break; - case ':': - throw exception::Exception(std::string("Incorrect command-line arguments: The -") + (char)optopt + - " option is missing an argument\n\n" + getUsage()); - case '?': - throw exception::Exception(std::string("Incorrect command-line arguments: Unknown option\n\n") + getUsage()); - default: - throw exception::Exception(std::string("Incorrect command-line arguments\n\n") + getUsage()); - } - } - - - const int expectedNbNonOptionalArgs = 0; - const int nbNonOptionalArgs = argc - optind; - - // Check for empty string arguments - // These might have been passed in by systemd - for(int i = optind; i < argc; i++) { - if(std::string(argv[i]).empty()) { - exception::Exception ex; - ex.getMessage() << "Incorrect command-line arguments: Encountered an empty string argument at argv[" << i - << "]\n\n" << getUsage(); - throw ex; - } - } - - if (expectedNbNonOptionalArgs != nbNonOptionalArgs) { - exception::Exception ex; - ex.getMessage() << "Incorrect command-line arguments: Incorrect number of non-optional arguments: expected=" << - expectedNbNonOptionalArgs << ",actual=" << nbNonOptionalArgs << "\n\n" << getUsage(); - throw ex; - } - - return cmdline; -} - -//------------------------------------------------------------------------------ -// getUsage -//------------------------------------------------------------------------------ -std::string AcsdCmdLine::getUsage() { - std::ostringstream usage; - usage << - "Usage:\n" - " cta-acsd [options]\n" - "\n" - "Where:\n" - "\n" - "Options:\n" - "\n" - "--foreground or -f Remain in the Foreground\n" - "--readOnly or -r Request the volume is mounted for read-only access\n" - "--config <config-file> or -c Configuration file\n" - "--help or -h Print this help and exit\n" - "\n" - "Comments to CTA team\n"; - return usage.str(); -} - -} // namespace daemon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/AcsdCmdLine.hpp b/mediachanger/acs/daemon/AcsdCmdLine.hpp deleted file mode 100644 index e43801a21c..0000000000 --- a/mediachanger/acs/daemon/AcsdCmdLine.hpp +++ /dev/null @@ -1,73 +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/CmdLine.hpp" -#include <string.h> - -namespace cta{ -namespace mediachanger{ -namespace acs{ -namespace daemon{ - -struct AcsdCmdLine { - - bool foreground; - - bool help; - - std::string configLocation; - - /** - * True if the tape is to be mount for read-only access. - */ - bool readOnly; - - /** - * Constructor. - * - * Initialises all BOOLEAN member-variables to FALSE, all integer - * member-variables to 0 and the volume identifier to an empty string. - */ - AcsdCmdLine(); - - /** - * Constructor. - * - * Parses the specified command-line arguments. - * - * @param argc Argument count from the executable's entry function: main(). - * @param argv Argument vector from the executable's entry function: main(). - */ - static AcsdCmdLine parse(const int argc, char *const *const argv); - - /** - * Gets the usage message that describes the comamnd line. - * - * @return The usage message. - */ - static std::string getUsage(); - -}; - -} -} -} -} - diff --git a/mediachanger/acs/daemon/AcsdCmdLineTest.cpp b/mediachanger/acs/daemon/AcsdCmdLineTest.cpp deleted file mode 100644 index 2f116f138e..0000000000 --- a/mediachanger/acs/daemon/AcsdCmdLineTest.cpp +++ /dev/null @@ -1,156 +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 "mediachanger/acs/daemon/AcsdCmdLine.hpp" -#include <gtest/gtest.h> -#include <list> -#include <memory> - -namespace unitTests { - -class cta_mediachanger_acs_daemon_AcsdCmdLineTest : public ::testing::Test { -protected: - - struct Argcv { - int argc; - char **argv; - Argcv(): argc(0), argv(NULL) { - } - }; - typedef std::list<Argcv*> ArgcvList; - ArgcvList m_argsList; - - /** - * Creates a duplicate string using the new operator. - */ - char *dupString(const char *str) { - const size_t len = strlen(str); - char *duplicate = new char[len+1]; - strncpy(duplicate, str, len); - duplicate[len] = '\0'; - return duplicate; - } - - virtual void SetUp() { - } - - virtual void TearDown() { - // Allow getopt_long to be called again - optind = 0; - - for(ArgcvList::const_iterator itor = m_argsList.begin(); - itor != m_argsList.end(); itor++) { - for(int i=0; i < (*itor)->argc; i++) { - delete[] (*itor)->argv[i]; - } - delete[] (*itor)->argv; - delete *itor; - } - } -}; - - -TEST_F(cta_mediachanger_acs_daemon_AcsdCmdLineTest, constructor_no_command_line_args) { - using namespace cta::mediachanger::acs::daemon; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 1; - args->argv = new char *[2]; - args->argv[0] = dupString("cta-acsd"); - args->argv[1] = NULL; - const auto acsdcmdLine = AcsdCmdLine::parse(args->argc, args->argv); - - ASSERT_FALSE(acsdcmdLine.foreground); - ASSERT_TRUE(acsdcmdLine.configLocation.empty()); - ASSERT_FALSE(acsdcmdLine.help); -} - -TEST_F(cta_mediachanger_acs_daemon_AcsdCmdLineTest, default_constructor) { - using namespace cta::mediachanger::acs::daemon; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 0; - const auto acsdcmdLine = AcsdCmdLine::parse(args->argc, args->argv); - - ASSERT_FALSE(acsdcmdLine.foreground); - ASSERT_TRUE(acsdcmdLine.configLocation.empty()); - ASSERT_FALSE(acsdcmdLine.help); -} - -TEST_F(cta_mediachanger_acs_daemon_AcsdCmdLineTest, constructor_foreground) { - using namespace cta::mediachanger::acs::daemon; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-acsd"); - args->argv[1] = dupString("-f"); - args->argv[2] = NULL; - const auto acsdcmdLine = AcsdCmdLine::parse(args->argc, args->argv); - - ASSERT_TRUE(acsdcmdLine.foreground); -} - -TEST_F(cta_mediachanger_acs_daemon_AcsdCmdLineTest, constructor_help) { - using namespace cta::mediachanger::acs::daemon; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-acsd"); - args->argv[1] = dupString("-h"); - args->argv[2] = NULL; - const auto acsdcmdLine = AcsdCmdLine::parse(args->argc, args->argv); - ASSERT_TRUE(acsdcmdLine.help); -} - -TEST_F(cta_mediachanger_acs_daemon_AcsdCmdLineTest, constructor_configLocation) { - using namespace cta::mediachanger::acs::daemon; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 3; - args->argv = new char *[4]; - args->argv[0] = dupString("cta-acsd"); - args->argv[1] = dupString("-c"); - args->argv[2] = dupString(""); - args->argv[3] = NULL; - const auto acsdcmdLine = AcsdCmdLine::parse(args->argc, args->argv); - ASSERT_EQ(acsdcmdLine.configLocation,""); -} - -TEST_F(cta_mediachanger_acs_daemon_AcsdCmdLineTest, constructor_readOnly) { - using namespace cta::mediachanger::acs::daemon; - - Argcv *args = new Argcv(); - m_argsList.push_back(args); - args->argc = 2; - args->argv = new char *[3]; - args->argv[0] = dupString("cta-acsd"); - args->argv[1] = dupString("-r"); - args->argv[2] = NULL; - const auto acsdcmdLine = AcsdCmdLine::parse(args->argc, args->argv); - ASSERT_TRUE(acsdcmdLine.readOnly); -} - -} // namespace unitTests diff --git a/mediachanger/acs/daemon/AcsdConfiguration.cpp b/mediachanger/acs/daemon/AcsdConfiguration.cpp deleted file mode 100644 index b5d5b42117..0000000000 --- a/mediachanger/acs/daemon/AcsdConfiguration.cpp +++ /dev/null @@ -1,54 +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 "AcsdConfiguration.hpp" -#include "common/ConfigurationFile.hpp" -#include "Tpconfig.hpp" -#include <time.h> - - -//------------------------------------------------------------------------------ -// GlobalConfiguration::createFromCtaConf w path -//------------------------------------------------------------------------------ -cta::mediachanger::acs::daemon::AcsdConfiguration cta::mediachanger::acs::daemon::AcsdConfiguration::createFromCtaConf( - const std::string& generalConfigPath, cta::log::Logger& log) { - AcsdConfiguration ret; - // Parse config file - ConfigurationFile cf(generalConfigPath); - // Extract configuration from parsed config file TpConfig - ret.port.setFromConfigurationFile(cf, generalConfigPath); - ret.QueryInterval.setFromConfigurationFile(cf, generalConfigPath); - ret.CmdTimeout.setFromConfigurationFile(cf, generalConfigPath); - ret.daemonUserName.setFromConfigurationFile(cf, generalConfigPath); - ret.daemonGroupName.setFromConfigurationFile(cf, generalConfigPath); - - // If we get here, the configuration file is good enough to be logged. - ret.port.log(log); - ret.QueryInterval.log(log); - ret.CmdTimeout.log(log); - ret.daemonUserName.log(log); - ret.daemonGroupName.log(log); - - return ret; -} - -//------------------------------------------------------------------------------ -// GlobalConfiguration::gDummyLogger (static member) -//------------------------------------------------------------------------------ -cta::log::DummyLogger cta::mediachanger::acs::daemon::AcsdConfiguration::gDummyLogger("",""); - diff --git a/mediachanger/acs/daemon/AcsdConfiguration.hpp b/mediachanger/acs/daemon/AcsdConfiguration.hpp deleted file mode 100644 index 61f70f714e..0000000000 --- a/mediachanger/acs/daemon/AcsdConfiguration.hpp +++ /dev/null @@ -1,64 +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 <string> -#include <map> -#include <type_traits> -#include <limits> -#include "common/log/DummyLogger.hpp" -#include "common/exception/Exception.hpp" -#include "common/SourcedParameter.hpp" -#include "Tpconfig.hpp" -#include "mediachanger/acs/Constants.hpp" -#include "common/ConfigurationFile.hpp" - -#include <time.h> - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { -/** - * Class containing all the parameters needed by the watchdog process - * to spawn a transfer session per drive. - */ -struct AcsdConfiguration { - static AcsdConfiguration createFromCtaConf( - const std::string & generalConfigPath, - cta::log::Logger & log = gDummyLogger); - - SourcedParameter<uint64_t> port{ - "acsd", "Port", (uint64_t)ACS_PORT, "Compile time default"}; - SourcedParameter<uint64_t> QueryInterval{ - "acsd", "QueryInterval", (long unsigned int)ACS_QUERY_INTERVAL, "Compile time default"}; - SourcedParameter<uint64_t> CmdTimeout{ - "acsd", "CmdTimeout",(long unsigned int) ACS_CMD_TIMEOUT, "Compile time default"}; - SourcedParameter<std::string> daemonUserName{ - "acsd", "DaemonUserName", "cta", "Compile time default"}; - SourcedParameter<std::string> daemonGroupName{ - "acsd", "DaemonGroupName", "tape", "Compile time default"}; -private: - /** A private dummy logger which will simplify the implementation of the - * functions (just unconditionally log things). */ - static cta::log::DummyLogger gDummyLogger; -} ; -} // namespace daemon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/CMakeLists.txt b/mediachanger/acs/daemon/CMakeLists.txt deleted file mode 100644 index 814accaca1..0000000000 --- a/mediachanger/acs/daemon/CMakeLists.txt +++ /dev/null @@ -1,62 +0,0 @@ -cmake_minimum_required (VERSION 2.6) - -find_package(Protobuf3 REQUIRED) -find_package(openssl REQUIRED) -find_package(zeromq REQUIRED) - -include_directories (${PROTOBUF3_INCLUDE_DIRS}) - - -PROTOBUF3_GENERATE_CPP(WDMsgSources WDMsgHeaders WatchdogMessage.proto) - -SET_SOURCE_FILES_PROPERTIES(${WDMsgHeaders} PROPERTIES HEADER_FILE_ONLY TRUE) - - -set (ACS_DAEMON_SRC_FILES - AcsDaemon.cpp - AcsDaemonMain.cpp - AcsdConfiguration.cpp - AcsRequest.cpp - AcsPendingRequests.cpp - AcsdCmdLine.cpp - AcsDismountTape.cpp - AcsMessageHandler.cpp - AcsMountTapeReadWrite.cpp - AcsMountTapeReadOnly.cpp - AcsForceDismountTape.cpp - Constants.cpp - AcsRequestDismountTape.cpp -) -add_executable (cta-acsd ${ACS_DAEMON_SRC_FILES}) - -set_target_properties (cta-acsd PROPERTIES - COMPILE_FLAGS -I/usr/include/CDK - COMPILE_DEFINITIONS LINUX) - -target_link_libraries( - cta-acsd - ctacommon - ctareactor - cta-acs - ctamediachanger - zmq - ${STK_LIBRARIES}) - -set_property (TARGET cta-acsd APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH}) - -install (FILES cta-acsd.conf DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/cta) -install (TARGETS cta-acsd DESTINATION /usr/bin) -install (FILES cta-acsd.logrotate DESTINATION /etc/logrotate.d RENAME cta-acsd) -install (FILES cta-acsd.service DESTINATION /etc/systemd/system) - -add_library (ctamediachangeracsdaemonunittests SHARED AcsdCmdLineTest.cpp AcsdCmdLine.cpp) -set_property(TARGET ctamediachangeracsdaemonunittests PROPERTY SOVERSION "${CTA_SOVERSION}") -set_property(TARGET ctamediachangeracsdaemonunittests PROPERTY VERSION "${CTA_LIBVERSION}") - -target_link_libraries (ctamediachangeracsdaemonunittests - ctamediachangerunittests) - -install (TARGETS ctamediachangeracsdaemonunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR}) - - - diff --git a/mediachanger/acs/daemon/Constants.cpp b/mediachanger/acs/daemon/Constants.cpp deleted file mode 100644 index cc522d158a..0000000000 --- a/mediachanger/acs/daemon/Constants.cpp +++ /dev/null @@ -1,79 +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 "Constants.hpp" - -//------------------------------------------------------------------------------ -// msgTypeToString -//------------------------------------------------------------------------------ -const char *cta::mediachanger::acs::daemon::msgTypeToString(const cta::mediachanger::acs::daemon::MsgType msgType) { - switch(msgType) { - case MSG_TYPE_NONE: - return "None"; - case MSG_TYPE_EXCEPTION: - return "Exception"; - case MSG_TYPE_FORKCLEANER: - return "ForkCleaner"; - case MSG_TYPE_FORKDATATRANSFER: - return "ForkDataTransfer"; - case MSG_TYPE_FORKLABEL: - return "ForkLabel"; - case MSG_TYPE_FORKSUCCEEDED: - return "ForkSucceeded"; - case MSG_TYPE_HEARTBEAT: - return "Heartbeat"; - case MSG_TYPE_MIGRATIONJOBFROMTAPEGATEWAY: - return "MigrationJobFromTapeGateway"; - case MSG_TYPE_MIGRATIONJOBFROMWRITETP: - return "MigrationJobFromWriteTp"; - case MSG_TYPE_NBFILESONTAPE: - return "NbFilesOnTape"; - case MSG_TYPE_PROCESSCRASHED: - return "ProcessCrashed"; - case MSG_TYPE_PROCESSEXITED: - return "ProcessExited"; - case MSG_TYPE_RECALLJOBFROMREADTP: - return "RecallJobFromReadTp"; - case MSG_TYPE_RECALLJOBFROMTAPEGATEWAY: - return "RecallJobFromTapeGAteway"; - case MSG_TYPE_RETURNVALUE: - return "ReturnValue"; - case MSG_TYPE_STOPPROCESSFORKER: - return "StopProcessForker"; - case MSG_TYPE_TAPEMOUNTEDFORMIGRATION: - return "TapeMountedForMigration"; - case MSG_TYPE_TAPEMOUNTEDFORRECALL: - return "TapeMountedForRecall"; - case MSG_TYPE_LABELERROR: - return "LabelError"; - case MSG_TYPE_ACSMOUNTTAPEREADONLY: - return "AcsMountTapeReadOnly"; - case MSG_TYPE_ACSMOUNTTAPEREADWRITE: - return "AcsMountTapeReadWrite"; - case MSG_TYPE_ACSDISMOUNTTAPE: - return "AcsDismountTape"; - case MSG_TYPE_ACSFORCEDISMOUNTTAPE: - return "AcsForceDismountTape"; - case MSG_TYPE_ADDLOGPARAMS: - return "AddLogParams"; - case MSG_TYPE_DELETELOGPARAMS: - return "DeleteLogParams"; - default: - return "Unknown"; - } -} // msgTypeToString() diff --git a/mediachanger/acs/daemon/Constants.hpp b/mediachanger/acs/daemon/Constants.hpp deleted file mode 100644 index ddf7020562..0000000000 --- a/mediachanger/acs/daemon/Constants.hpp +++ /dev/null @@ -1,83 +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 - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -enum ProtocolType { - PROTOCOL_TYPE_NONE, - PROTOCOL_TYPE_TAPE -}; - -enum MsgType { - /* 0 */ MSG_TYPE_NONE = 0, - /* 1 */ MSG_TYPE_EXCEPTION = 1, - /* 2 */ MSG_TYPE_FORKCLEANER = 2, - /* 3 */ MSG_TYPE_FORKDATATRANSFER = 3, - /* 4 */ MSG_TYPE_FORKLABEL = 4, - /* 5 */ MSG_TYPE_FORKSUCCEEDED = 5, - /* 6 */ MSG_TYPE_HEARTBEAT = 6, - /* 7 */ MSG_TYPE_MIGRATIONJOBFROMTAPEGATEWAY = 7, - /* 8 */ MSG_TYPE_MIGRATIONJOBFROMWRITETP = 8, - /* 9 */ MSG_TYPE_NBFILESONTAPE = 9, - /* 10 */ MSG_TYPE_PROCESSCRASHED = 10, - /* 11 */ MSG_TYPE_PROCESSEXITED = 11, - /* 12 */ MSG_TYPE_RECALLJOBFROMREADTP = 12, - /* 13 */ MSG_TYPE_RECALLJOBFROMTAPEGATEWAY = 13, - /* 14 */ MSG_TYPE_RETURNVALUE = 14, - /* 15 */ MSG_TYPE_STOPPROCESSFORKER = 15, - /* 16 */ MSG_TYPE_TAPEMOUNTEDFORMIGRATION = 16, - /* 17 */ MSG_TYPE_TAPEMOUNTEDFORRECALL = 17, - /* 18 */ MSG_TYPE_TAPEUNMOUNTSTARTED = 18, - /* 19 */ MSG_TYPE_TAPEUNMOUNTED = 19, - /* 20 */ MSG_TYPE_LABELERROR = 20, - /* 21 */ MSG_TYPE_ACSMOUNTTAPEREADONLY = 21, - /* 22 */ MSG_TYPE_ACSMOUNTTAPEREADWRITE = 22, - /* 23 */ MSG_TYPE_ACSDISMOUNTTAPE = 23, - /* 24 */ MSG_TYPE_ACSFORCEDISMOUNTTAPE = 24, - /* 25 */ MSG_TYPE_ADDLOGPARAMS = 25, - /* 26 */ MSG_TYPE_DELETELOGPARAMS = 26, - /* 27 */ MSG_TYPE_ARCHIVEJOBFROMCTA = 27, - /* 28 */ MSG_TYPE_RETRIEVEJOBFROMCTA = 28 -}; - -enum ProtocolVersion { - PROTOCOL_VERSION_NONE, - PROTOCOL_VERSION_1 -}; - -/** - * Returns the string representation of the specified message type. - * - * This method is thread safe because it only returns pointers to string - * literals. - * - * In the case where the specified message type is unknown this method does not - * throw an exception, instead is returns a string literal that explains the - * message type is unknown. - */ -const char *msgTypeToString(const MsgType msgType); - -} // namespace daemon -} // namespace acs -} // namespace mediachanger -} // namespace cta diff --git a/mediachanger/acs/daemon/Tpconfig.hpp b/mediachanger/acs/daemon/Tpconfig.hpp deleted file mode 100644 index 47fafa56aa..0000000000 --- a/mediachanger/acs/daemon/Tpconfig.hpp +++ /dev/null @@ -1,46 +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 "TpconfigLine.hpp" -#include "common/SourcedParameter.hpp" -#include "common/exception/Exception.hpp" - -#include <map> - -namespace cta { namespace mediachanger { namespace acs { namespace daemon { - -/** - * A map of lines parsed from a TPCONFIG file (key is the drive name) - */ -class Tpconfig: public std::map<std::string, SourcedParameter<cta::mediachanger::acs::daemon::TpconfigLine>> { -public: - - CTA_GENERATE_EXCEPTION_CLASS(InvalidArgument); - CTA_GENERATE_EXCEPTION_CLASS(DuplicateEntry); - /** - * Parses the specified TPCONFIG file. - * - * @param filename The filename of the TPCONFIG file. - * @return The result of parsing the TPCONFIG file. - */ - static Tpconfig parseFile(const std::string &filename); -}; // class TpconfigLines - -}}}} // namespace cta::tape::daemon diff --git a/mediachanger/acs/daemon/TpconfigLine.hpp b/mediachanger/acs/daemon/TpconfigLine.hpp deleted file mode 100644 index 4b7a74b4cb..0000000000 --- a/mediachanger/acs/daemon/TpconfigLine.hpp +++ /dev/null @@ -1,104 +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 <string> -#include "mediachanger/LibrarySlot.hpp" -#include <memory> - -namespace cta { -namespace mediachanger { -namespace acs { -namespace daemon { - -/** - * The data stored in a data-line (as opposed to a comment-line) from a - * TPCONFIG file (/etc/cta/TPCONFIG). - */ -class TpconfigLine { -public: - /** - * The unit name of the tape drive. - */ - std::string unitName; - - /** - * The logical library of the tape drive. - */ - std::string logicalLibrary; - - /** - * The filename of the device file of the tape drive. - */ - std::string devFilename; - - /** - * The slot in the tape library that contains the tape drive (string encoded). - */ - std::string rawLibrarySlot; - - /** - * Accessor method to the library slot strcuture. - * @return reference to the library slot. - */ - const cta::mediachanger::LibrarySlot & librarySlot() const; - -private: - /** - * The library slot structure. - */ - std::unique_ptr <cta::mediachanger::LibrarySlot> m_librarySlot; - -public: - /** - * Trivial constructor (used in unit tests). - */ - TpconfigLine(); - - /** - * Constructor. - * - * @param unitName The unit name of the tape drive. - * @param dgn The Device Group Name (DGN) of the tape drive. - * @param devFilename The filename of the device file of the tape drive. - * @param librarySlot The slot in the tape library that contains the tape - * drive. - */ - TpconfigLine( - const std::string &unitName, - const std::string &logicalLibrary, - const std::string &devFilename, - const std::string &librarySlot); - - /** - * Copy constructor - * @param o the other TpConfigLine to be copied. - */ - TpconfigLine(const TpconfigLine& o); - - /** - * Copy operator - * @param o the other TpConfigLine to copy. - * @return a reference to the object - */ - TpconfigLine& operator=(const TpconfigLine& o); - static const size_t maxNameLen = 100; -}; // struct TpconfigLine - -}}}} // namespace cta::mediachanger::acs::daemon diff --git a/mediachanger/acs/daemon/cta-acsd.conf b/mediachanger/acs/daemon/cta-acsd.conf deleted file mode 100644 index e97d8b4096..0000000000 --- a/mediachanger/acs/daemon/cta-acsd.conf +++ /dev/null @@ -1,38 +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/>. - -################################################################################ -# -# CTA Sample Configuration File -# -################################################################################ - -# The log mask. Logs with a level lower than this value will be masked. -# Possible values are: -# EMERG -# ALERT -# CRIT -# ERR -# WARNING -# NOTICE -# INFO -# DEBUG -# USERERR -# -# Please note that the USERERR log level is equivalent to NOTICE because it is -# a convention of CTA to use log level NOTICE to label user errors. -# -# taped LogMask INFO diff --git a/mediachanger/acs/daemon/cta-acsd.logrotate b/mediachanger/acs/daemon/cta-acsd.logrotate deleted file mode 100644 index de8fd8ac53..0000000000 --- a/mediachanger/acs/daemon/cta-acsd.logrotate +++ /dev/null @@ -1,10 +0,0 @@ -/var/log/cta/cta-acsd*.log { - compress - daily - missingok - rotate 500 - delaycompress - postrotate - /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true - endscript -} diff --git a/mediachanger/acs/daemon/cta-acsd.service b/mediachanger/acs/daemon/cta-acsd.service deleted file mode 100644 index c2ce4f78ed..0000000000 --- a/mediachanger/acs/daemon/cta-acsd.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=CERN Tape Archive (CTA) acsd daemon -After=syslog.target network-online.target - -[Service] -ExecStart=/usr/bin/cta-acsd -LimitCORE=infinity -Type=forking -Restart=no - -[Install] -WantedBy=default.target diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4ff01c1e4f..f0fbe9917c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -43,11 +43,6 @@ target_link_libraries(cta-unitTests gtest pthread) -if (NOT DEFINED NoACS) - target_link_libraries(cta-unitTests - ctamediachangeracsdaemonunittests) -endif (NOT DEFINED NoACS) - set_property (TARGET cta-unitTests APPEND PROPERTY INSTALL_RPATH ${PROTOBUF3_RPATH}) if (OCCI_SUPPORT) set_property (TARGET cta-unitTests APPEND PROPERTY INSTALL_RPATH ${ORACLE-INSTANTCLIENT_RPATH}) -- GitLab