diff --git a/scheduler/CMakeLists.txt b/scheduler/CMakeLists.txt index 2ccea2b814411660b3e910cfb68536a36950d459..edbf4ed9e678ebe4a3bb7dad9bad7b2fa4339953 100644 --- a/scheduler/CMakeLists.txt +++ b/scheduler/CMakeLists.txt @@ -18,6 +18,7 @@ set (CTA_SCHEDULER_SRC_FILES mockDB/SqliteColumnNameToIndex.cpp mockDB/SQLiteStatementDeleter.cpp MountType.cpp + PositioningMethod.cpp RetrieveJob.cpp RetrieveFromTapeCopyRequest.cpp RetrieveMount.cpp diff --git a/scheduler/PositioningMethod.cpp b/scheduler/PositioningMethod.cpp new file mode 100644 index 0000000000000000000000000000000000000000..22032b6ee1b4df2beb2a3f6a5bfa070c94f411a0 --- /dev/null +++ b/scheduler/PositioningMethod.cpp @@ -0,0 +1,34 @@ +/* + * The CERN Tape Retrieve (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 "scheduler/PositioningMethod.hpp" + +//------------------------------------------------------------------------------ +// positioningMethodtoString(PositioningMethod) +//------------------------------------------------------------------------------ +const char *cta::positioningMethodToStr(const PositioningMethod enumValue) + throw() { + switch(enumValue) { + case PositioningMethod::ByBlock: + return "ByBlock"; + case PositioningMethod::ByFSeq: + return "ByFSeq"; + default: + return "Unknown Positioning Method"; + } +} diff --git a/scheduler/PositioningMethod.hpp b/scheduler/PositioningMethod.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f25e55afcfd9a2f1d29202e637076b947eb47708 --- /dev/null +++ b/scheduler/PositioningMethod.hpp @@ -0,0 +1,39 @@ +/* + * The CERN Tape Retrieve (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 <stdint.h> + +namespace cta { + + /** + * Positioning methods + */ + enum class PositioningMethod: uint8_t { + ByBlock = 0, + ByFSeq = 1 + }; + + /** + * Thread safe method that returns the string representation of the + * specified enumeration vale. + */ + const char *positioningMethodToStr(const PositioningMethod enumValue) throw(); + +} // namespace cta diff --git a/scheduler/RetrieveJob.cpp b/scheduler/RetrieveJob.cpp index fabef4bb37e4dd8a6c15801da14b0b780c056d2b..d3f67dd96e5d047a992dc393072374278505dd9a 100644 --- a/scheduler/RetrieveJob.cpp +++ b/scheduler/RetrieveJob.cpp @@ -55,18 +55,3 @@ void cta::RetrieveJob::failed(const exception::Exception &ex) { // retry //------------------------------------------------------------------------------ void cta::RetrieveJob::retry() { } - -//------------------------------------------------------------------------------ -// positioningMethodtoString(PositioningMethod) -//------------------------------------------------------------------------------ -std::string cta::RetrieveJob::positioningMethodtoString(PositioningMethod pm) { - switch(pm) { - case PositioningMethod::ByBlock: - return "ByBlock"; - case PositioningMethod::ByFSeq: - return "ByFSeq"; - default: - return "Unknown Positioning Method"; - } -} - diff --git a/scheduler/RetrieveJob.hpp b/scheduler/RetrieveJob.hpp index 620b917ed1a995c375557c9fa020fac544125556..bf38d8d10bebbeffb58b70af703b5775ecec587e 100644 --- a/scheduler/RetrieveJob.hpp +++ b/scheduler/RetrieveJob.hpp @@ -22,6 +22,7 @@ #include "common/archiveNS/TapeFileLocation.hpp" #include "common/exception/Exception.hpp" #include "common/remoteFS/RemotePathAndStatus.hpp" +#include "scheduler/PositioningMethod.hpp" #include <string> @@ -40,16 +41,6 @@ class RetrieveJob { */ friend class RetrieveMount; -public: - - /** - * Positioning methods - */ - enum class PositioningMethod: uint8_t { - ByBlock = 0, - ByFSeq = 1 - }; - protected: /** @@ -103,16 +94,6 @@ public: */ void retry(); - /** - * Converts the positioning method into string - * - * @param pm the positioning method - * @return the method in string format - */ - std::string positioningMethodtoString(PositioningMethod pm); - -public: - /** * The mount to which the job belongs. */ diff --git a/tapeserver/castor/tape/tapeserver/daemon/RecallTaskInjector.cpp b/tapeserver/castor/tape/tapeserver/daemon/RecallTaskInjector.cpp index 94054f328422f2b1fa668d647ccc45a1f44d8f4e..6e7d15af795cede302b9958f373be65a3e01ed2d 100644 --- a/tapeserver/castor/tape/tapeserver/daemon/RecallTaskInjector.cpp +++ b/tapeserver/castor/tape/tapeserver/daemon/RecallTaskInjector.cpp @@ -88,7 +88,7 @@ void RecallTaskInjector::startThreads() { void RecallTaskInjector::injectBulkRecalls(const std::vector<cta::RetrieveJob *>& jobs) { for (auto it = jobs.begin(); it != jobs.end(); ++it) { - (*it)->positioningMethod=cta::RetrieveJob::PositioningMethod::ByBlock; + (*it)->positioningMethod=cta::PositioningMethod::ByBlock; LogContext::ScopedParam sp[]={ LogContext::ScopedParam(m_lc, Param("NSHOSTNAME", (*it)->archiveFile.nsHostName)), diff --git a/tapeserver/castor/tape/tapeserver/file/File.cpp b/tapeserver/castor/tape/tapeserver/file/File.cpp index c20e8afe1b0050d43151d60109c28b7739f3586e..57789eff2e43a00051f7daf0f226bd1a9472ec96 100644 --- a/tapeserver/castor/tape/tapeserver/file/File.cpp +++ b/tapeserver/castor/tape/tapeserver/file/File.cpp @@ -157,7 +157,7 @@ namespace castor { try{ position(fileToRecall); } catch(...){ - if(cta::RetrieveJob::PositioningMethod::ByFSeq==m_positionCommandCode && + if(cta::PositioningMethod::ByFSeq==m_positionCommandCode && m_session->getCurrentFilePart() != Header){ m_session->setCorrupted(); } @@ -167,7 +167,7 @@ namespace castor { } ReadFile::~ReadFile() throw() { - if(cta::RetrieveJob::PositioningMethod::ByFSeq==m_positionCommandCode && + if(cta::PositioningMethod::ByFSeq==m_positionCommandCode && m_session->getCurrentFilePart() != Header){ m_session->setCorrupted(); } @@ -243,7 +243,7 @@ namespace castor { void ReadFile::position( const cta::RetrieveJob &fileToRecall) { - if(m_session->getCurrentFilePart() != Header && fileToRecall.positioningMethod!=cta::RetrieveJob::PositioningMethod::ByBlock) { + if(m_session->getCurrentFilePart() != Header && fileToRecall.positioningMethod!=cta::PositioningMethod::ByBlock) { m_session->setCorrupted(); throw SessionCorrupted(); } @@ -252,10 +252,10 @@ namespace castor { // and allow next call to position to discover we failed half way m_session->setCurrentFilePart(HeaderProcessing); - if(cta::RetrieveJob::PositioningMethod::ByBlock==m_positionCommandCode) { + if(cta::PositioningMethod::ByBlock==m_positionCommandCode) { positionByBlockID(fileToRecall); } - else if(cta::RetrieveJob::PositioningMethod::ByFSeq==m_positionCommandCode) { + else if(cta::PositioningMethod::ByFSeq==m_positionCommandCode) { positionByFseq(fileToRecall); } else { diff --git a/tapeserver/castor/tape/tapeserver/file/File.hpp b/tapeserver/castor/tape/tapeserver/file/File.hpp index 5a907535b228a95a07e06402a8b69f487bb2f90e..cacc71a4550ba7fb32124da9fad7dc96dbaf5693 100644 --- a/tapeserver/castor/tape/tapeserver/file/File.hpp +++ b/tapeserver/castor/tape/tapeserver/file/File.hpp @@ -336,7 +336,7 @@ namespace castor { /** * What kind of command we use to position ourself on the tape (fseq or blockid) */ - cta::RetrieveJob::PositioningMethod m_positionCommandCode; + cta::PositioningMethod m_positionCommandCode; }; /** diff --git a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp index cce79b138d3ee826525ea33efe82b1a93444af86..c166f2644a58cf38f76e955d9aac8384121fe27f 100644 --- a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp +++ b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp @@ -81,7 +81,7 @@ namespace UnitTests { castor::tape::tapeFile::ReadSession *rs; rs = new castor::tape::tapeFile::ReadSession(d, volInfo); ASSERT_NE((long int)rs, 0); - fileToRecall.positioningMethod = cta::RetrieveJob::PositioningMethod::ByBlock; + fileToRecall.positioningMethod = cta::PositioningMethod::ByBlock; ASSERT_THROW({castor::tape::tapeFile::ReadFile rf1(rs, fileToRecall);}, castor::exception::Exception); //cannot read a file on an empty tape delete rs; } @@ -103,7 +103,7 @@ namespace UnitTests { castor::tape::tapeFile::ReadSession *rs; rs = new castor::tape::tapeFile::ReadSession(d, volInfo); { - fileToRecall.positioningMethod = cta::RetrieveJob::PositioningMethod::ByBlock; + fileToRecall.positioningMethod = cta::PositioningMethod::ByBlock; castor::tape::tapeFile::ReadFile rf1(rs, fileToRecall); ASSERT_THROW({castor::tape::tapeFile::ReadFile rf2(rs, fileToRecall);},castor::tape::tapeFile::SessionAlreadyInUse); //cannot have two ReadFile's on the same session } @@ -155,7 +155,7 @@ namespace UnitTests { castor::tape::tapeFile::ReadSession *rs; rs = new castor::tape::tapeFile::ReadSession(d, volInfo); { - fileToRecall.positioningMethod = cta::RetrieveJob::PositioningMethod::ByBlock; + fileToRecall.positioningMethod = cta::PositioningMethod::ByBlock; castor::tape::tapeFile::ReadFile rf(rs, fileToRecall); size_t bs = rf.getBlockSize(); char *data = new char[bs+1]; @@ -200,7 +200,7 @@ namespace UnitTests { ASSERT_EQ(rs->isCorrupted(), false); ASSERT_EQ(rs->m_vid.compare(label), 0); { - fileToRecall.positioningMethod = cta::RetrieveJob::PositioningMethod::ByBlock; + fileToRecall.positioningMethod = cta::PositioningMethod::ByBlock; castor::tape::tapeFile::ReadFile rf(rs, fileToRecall); size_t bs = rf.getBlockSize(); ASSERT_EQ(bs, block_size);