diff --git a/scheduler/ArchiveMount.cpp b/scheduler/ArchiveMount.cpp index a84038409fa209e860ebf3dbe78582c549897f70..57a86cdb0edbe83e9d9306f31805e4c7992b710a 100644 --- a/scheduler/ArchiveMount.cpp +++ b/scheduler/ArchiveMount.cpp @@ -18,25 +18,35 @@ #include "scheduler/ArchiveMount.hpp" - -namespace cta { - -ArchiveMount::ArchiveMount(std::unique_ptr<cta::SchedulerDatabase::TapeMount>& mount) { - // Check that the pointer is of the proper type - if (!dynamic_cast<cta::SchedulerDatabase::ArchiveMount *>(mount.get())) { - throw WrongMountType("In ArchiveMount::ArchiveMount(): could not cast mount to SchedulerDatabase::ArchiveMount"); - } - m_dbMount.reset(dynamic_cast<cta::SchedulerDatabase::ArchiveMount *>(mount.release())); +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::ArchiveMount::ArchiveMount( + std::unique_ptr<SchedulerDatabase::TapeMount> dbMount) { + m_dbMount.reset( + dynamic_cast<SchedulerDatabase::ArchiveMount*>(dbMount.release())); + if(!m_dbMount.get()) { + throw WrongMountType(std::string(__FUNCTION__) + + ": could not cast mount to SchedulerDatabase::ArchiveMount"); } - -void ArchiveMount::finish() { - throw NotImplemented (""); } - -ArchiveMount::~ArchiveMount() { +//------------------------------------------------------------------------------ +// getMountType +//------------------------------------------------------------------------------ +cta::MountType::Enum cta::ArchiveMount::getMountType() const throw() { + return MountType::ARCHIVE; } +//------------------------------------------------------------------------------ +// finish +//------------------------------------------------------------------------------ +void cta::ArchiveMount::finish() { + throw NotImplemented (""); +} - -} \ No newline at end of file +//------------------------------------------------------------------------------ +// destructor +//------------------------------------------------------------------------------ +cta::ArchiveMount::~ArchiveMount() throw() { +} diff --git a/scheduler/ArchiveMount.hpp b/scheduler/ArchiveMount.hpp index b4c3e12a0ea894400b387613e6501e0edea01ec1..b57e99fe043aff54a71aa86f2fffc4740204aec3 100644 --- a/scheduler/ArchiveMount.hpp +++ b/scheduler/ArchiveMount.hpp @@ -18,9 +18,12 @@ #pragma once -#include "TapeMount.hpp" -#include "SchedulerDatabase.hpp" #include "common/exception/Exception.hpp" +#include "scheduler/ArchiveJob.hpp" +#include "scheduler/ArchiveMount.hpp" +#include "scheduler/SchedulerDatabase.hpp" +#include "scheduler/TapeMount.hpp" + #include <memory> namespace cta { @@ -34,10 +37,26 @@ namespace cta { class ArchiveMount: public TapeMount { friend class Scheduler; private: - ArchiveMount(std::unique_ptr<cta::SchedulerDatabase::TapeMount> &mount); + + /** + * Constructor. + * + * @param dbMount The database representation of this mount. + */ + ArchiveMount(std::unique_ptr<cta::SchedulerDatabase::TapeMount> dbMount); + public: + CTA_GENERATE_EXCEPTION_CLASS(WrongMountType); CTA_GENERATE_EXCEPTION_CLASS(NotImplemented); + + /** + * Returns The type of this tape mount. + * + * @return The type of this tape mount. + */ + MountType::Enum getMountType() const throw(); + /** * Notifies the scheduler that the session is finished */ @@ -45,13 +64,24 @@ namespace cta { /** * Job factory + * + * @return A unique_ptr to the next archive job or NULL if there are no more + * archive jobs left for this tape mount. */ - std::unique_ptr<ArchiveMount> getNextJob(); + std::unique_ptr<ArchiveJob> getNextJob(); - virtual ~ArchiveMount(); + /** + * Destructor. + */ + virtual ~ArchiveMount() throw(); + private: + + /** + * The database representation of this mount. + */ std::unique_ptr<cta::SchedulerDatabase::ArchiveMount> m_dbMount; - - - }; -} + + }; // class ArchiveMount + +} // namespace cta diff --git a/scheduler/CMakeLists.txt b/scheduler/CMakeLists.txt index 2ff69d13c76821bad0aca554d622e9d1bfd109a7..3b370a58e08dfa5b788e6b7335b930edf5b243ec 100644 --- a/scheduler/CMakeLists.txt +++ b/scheduler/CMakeLists.txt @@ -12,11 +12,13 @@ set (CTA_SCHEDULER_SRC_FILES ArchiveToFileRequest.cpp ArchiveToTapeCopyRequest.cpp TapeJob.cpp + TapeMount.cpp LogicalLibrary.cpp mockDB/MockSchedulerDatabase.cpp mockDB/MockSchedulerDatabaseFactory.cpp RetrieveJob.cpp RetrieveFromTapeCopyRequest.cpp + RetrieveMount.cpp RetrieveRequest.cpp RetrieveToDirRequest.cpp RetrieveToFileRequest.cpp @@ -25,6 +27,7 @@ set (CTA_SCHEDULER_SRC_FILES SchedulerDatabaseFactory.cpp mockDB/SqliteColumnNameToIndex.cpp mockDB/SQLiteStatementDeleter.cpp + MountType.cpp UserRequest.cpp) add_library (ctascheduler SHARED diff --git a/scheduler/MountType.cpp b/scheduler/MountType.cpp new file mode 100644 index 0000000000000000000000000000000000000000..895e5342b0edf3752c4732f3ee1fed1eb754b129 --- /dev/null +++ b/scheduler/MountType.cpp @@ -0,0 +1,32 @@ +/* + * 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 "scheduler/MountType.hpp" + +//------------------------------------------------------------------------------ +// toString +//------------------------------------------------------------------------------ +const char *cta::MountType::toString(const MountType::Enum enumValue) + throw() { + switch(enumValue) { + case Enum::NONE : return "NONE"; + case Enum::ARCHIVE : return "ARCHIVE"; + case Enum::RETRIEVE: return "RETRIEVE"; + default : return "UNKNOWN"; + } +} diff --git a/scheduler/MountType.hpp b/scheduler/MountType.hpp new file mode 100644 index 0000000000000000000000000000000000000000..89f7cae58a1c99d2d854f67382e8612c4bd8db74 --- /dev/null +++ b/scheduler/MountType.hpp @@ -0,0 +1,47 @@ +/* + * 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 { + /** + * Enumeration class of the possible types of tape mount. + */ + struct MountType { + public: + + /** + * Enumeration of the possible types of tape mount. + */ + enum Enum { + NONE, + ARCHIVE, + RETRIEVE}; + + /** + * Thread safe method that returns the string representation of the + * specified enumeration value. + * + * @param enumValue The enumeration value. + * @return The string representation. + */ + static const char *toString(const MountType::Enum enumValue) throw(); + + }; // struct MountType + +} diff --git a/scheduler/RetrieveMount.cpp b/scheduler/RetrieveMount.cpp new file mode 100644 index 0000000000000000000000000000000000000000..04c22305916c1eb8b6a8c03b34988e8ddace2c8e --- /dev/null +++ b/scheduler/RetrieveMount.cpp @@ -0,0 +1,52 @@ +/* + * 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 "scheduler/RetrieveMount.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::RetrieveMount::RetrieveMount( + std::unique_ptr<SchedulerDatabase::TapeMount> dbMount) { + m_dbMount.reset( + dynamic_cast<SchedulerDatabase::RetrieveMount*>(dbMount.release())); + if(!m_dbMount.get()) { + throw WrongMountType(std::string(__FUNCTION__) + + ": could not cast mount to SchedulerDatabase::RetrieveMount"); + } +} + +//------------------------------------------------------------------------------ +// getMountType +//------------------------------------------------------------------------------ +cta::MountType::Enum cta::RetrieveMount::getMountType() const throw() { + return MountType::ARCHIVE; +} + +//------------------------------------------------------------------------------ +// finish +//------------------------------------------------------------------------------ +void cta::RetrieveMount::finish() { + throw NotImplemented (""); +} + +//------------------------------------------------------------------------------ +// destructor +//------------------------------------------------------------------------------ +cta::RetrieveMount::~RetrieveMount() throw() { +} diff --git a/scheduler/RetrieveMount.hpp b/scheduler/RetrieveMount.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b4d541fdd97e77792bb1029d6c5c9db8db609950 --- /dev/null +++ b/scheduler/RetrieveMount.hpp @@ -0,0 +1,87 @@ +/* + * The CERN Tape Archive (CTA) project + * Copyright (C) 2015 CERN + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include "common/exception/Exception.hpp" +#include "scheduler/RetrieveJob.hpp" +#include "scheduler/RetrieveMount.hpp" +#include "scheduler/SchedulerDatabase.hpp" +#include "scheduler/TapeMount.hpp" + +#include <memory> + +namespace cta { + + class RetrieveMount; + /** + * The class driving a retrieve mount. + * The class only has private constructors as it is instanciated by + * the Scheduler class. + */ + class RetrieveMount: public TapeMount { + friend class Scheduler; + private: + + /** + * Constructor. + * + * @param dbMount The database representation of this mount. + */ + RetrieveMount(std::unique_ptr<cta::SchedulerDatabase::TapeMount> dbMount); + + public: + + CTA_GENERATE_EXCEPTION_CLASS(WrongMountType); + CTA_GENERATE_EXCEPTION_CLASS(NotImplemented); + + /** + * Returns The type of this tape mount. + * + * @return The type of this tape mount. + */ + MountType::Enum getMountType() const throw(); + + /** + * Notifies the scheduler that the session is finished + */ + virtual void finish(); + + /** + * Job factory + * + * @return A unique_ptr to the next archive job or NULL if there are no more + * archive jobs left for this tape mount. + */ + std::unique_ptr<RetrieveJob> getNextJob(); + + /** + * Destructor. + */ + virtual ~RetrieveMount() throw(); + + private: + + /** + * The database representation of this mount. + */ + std::unique_ptr<cta::SchedulerDatabase::RetrieveMount> m_dbMount; + + }; // class RetrieveMount + +} // namespace cta diff --git a/scheduler/Scheduler.cpp b/scheduler/Scheduler.cpp index 5470755713c1119642d1c242c9244e64d71195cf..b92672acef4a344ef1ebc9f84054479912b61e12 100644 --- a/scheduler/Scheduler.cpp +++ b/scheduler/Scheduler.cpp @@ -16,29 +16,30 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "common/admin/AdminHost.hpp" +#include "common/admin/AdminUser.hpp" +#include "common/archiveNS/StorageClass.hpp" +#include "common/archiveNS/Tape.hpp" +#include "common/archiveRoutes/ArchiveRoute.hpp" #include "common/exception/Exception.hpp" #include "common/remoteFS/RemotePathAndStatus.hpp" #include "common/UserIdentity.hpp" #include "common/Utils.hpp" +#include "common/SecurityIdentity.hpp" +#include "common/TapePool.hpp" #include "nameserver/NameServer.hpp" #include "remotens/RemoteNS.hpp" -#include "common/admin/AdminHost.hpp" -#include "common/admin/AdminUser.hpp" #include "scheduler/ArchiveMount.hpp" -#include "common/archiveRoutes/ArchiveRoute.hpp" #include "scheduler/ArchiveToDirRequest.hpp" #include "scheduler/ArchiveToFileRequest.hpp" #include "scheduler/ArchiveToTapeCopyRequest.hpp" #include "scheduler/LogicalLibrary.hpp" #include "scheduler/RetrieveFromTapeCopyRequest.hpp" +#include "scheduler/RetrieveMount.hpp" #include "scheduler/RetrieveToDirRequest.hpp" #include "scheduler/RetrieveToFileRequest.hpp" #include "scheduler/Scheduler.hpp" #include "scheduler/SchedulerDatabase.hpp" -#include "common/SecurityIdentity.hpp" -#include "common/archiveNS/StorageClass.hpp" -#include "common/archiveNS/Tape.hpp" -#include "common/TapePool.hpp" #include "scheduler/TapeMount.hpp" #include <iostream> @@ -749,22 +750,33 @@ void cta::Scheduler::queueRetrieveRequest( std::unique_ptr<cta::TapeMount> cta::Scheduler::getNextMount( const std::string &logicalLibraryName, const std::string & driveName) { // First try to get the next mount from the database. - std::unique_ptr<SchedulerDatabase::TapeMount> - mount(m_db.getNextMount(logicalLibraryName, driveName)); - if (!mount.get()) { - return std::unique_ptr<cta::TapeMount>(NULL); - } else if (dynamic_cast<SchedulerDatabase::ArchiveMount *>(mount.get())) { - // Create out own ArchiveMount structure, which immediately takes - // ownership of the mount. - std::unique_ptr<ArchiveMount> internalRet(new ArchiveMount(mount)); - throw NotImplemented("Archive"); - } else if (dynamic_cast<SchedulerDatabase::RetriveMount *>(mount.get())) { - throw NotImplemented("Retrive"); - } else { - throw NotImplemented("Unknown type"); + std::unique_ptr<SchedulerDatabase::TapeMount> dbMount; + + dbMount = m_db.getNextMount(logicalLibraryName, driveName); + + return dbMountToSchedulerMount(std::move(dbMount)); +} + +//------------------------------------------------------------------------------ +// dbTapeMountToSchedulerTapeMount +//------------------------------------------------------------------------------ +std::unique_ptr<cta::TapeMount> cta::Scheduler::dbMountToSchedulerMount( + std::unique_ptr<SchedulerDatabase::TapeMount> dbMount) const { + if(!dbMount.get()) { + return std::unique_ptr<cta::TapeMount>(); + } + + switch(dbMount->getMountType()) { + case MountType::ARCHIVE: + return std::unique_ptr<TapeMount>(new ArchiveMount(std::move(dbMount))); + case MountType::RETRIEVE: + return std::unique_ptr<TapeMount>(new RetrieveMount(std::move(dbMount))); + default: + throw exception::Exception(std::string("Unexpected database mount type: ") + + MountType::toString(dbMount->getMountType())); } - throw NotImplemented(""); } + // ////------------------------------------------------------------------------------ //// finishedMount diff --git a/scheduler/Scheduler.hpp b/scheduler/Scheduler.hpp index 61075222f7fcb2260d727f8799d1aa6fc91704f7..e4a8cb83194299c1dda9eba2777b2a6afa9a3b6d 100644 --- a/scheduler/Scheduler.hpp +++ b/scheduler/Scheduler.hpp @@ -822,6 +822,17 @@ private: std::map<uint16_t, std::string> createCopyNbToPoolMap( const std::list<ArchiveRoute> &routes) const; + /** + * Returns an instance of a scheduler ArchiveMount ot RetrieveMount object + * wrapped around the specified scheduler database mount object. + * + * @param dbMount The database object. + * @return An instance of a scheduler ArchiveMount ot RetrieveMount object + * wrapped around the specified scheduler database mount object. + */ + std::unique_ptr<cta::TapeMount> dbMountToSchedulerMount( + std::unique_ptr<SchedulerDatabase::TapeMount> dbMount) const; + }; // class Scheduler } // namespace cta diff --git a/scheduler/SchedulerDatabase.hpp b/scheduler/SchedulerDatabase.hpp index 7fe899573e4b5468b200c040b6bc1cc12f7a9c4d..34271cf98cb3086343a74780a41d68a8a040f7e2 100644 --- a/scheduler/SchedulerDatabase.hpp +++ b/scheduler/SchedulerDatabase.hpp @@ -25,6 +25,7 @@ #include <memory> #include "common/archiveNS/ArchiveFileStatus.hpp" #include "common/remoteFS/RemotePathAndStatus.hpp" +#include "scheduler/MountType.hpp" namespace cta { @@ -63,10 +64,18 @@ public: /** * An umbrella class from which ArchiveSession and RetrieveSession will - * inherit. Just allows RTTI. - * Mounts, and jobs from the DB will be subclasses of the SchedulerDB + * inherit. */ - class TapeMount {public: virtual ~TapeMount(){}}; + struct TapeMount { + /** + * Returns The type of this tape mount. + * + * @return The type of this tape mount. + */ + virtual MountType::Enum getMountType() const throw() = 0; + + virtual ~TapeMount() {} + }; /** * Starts a session, and updates the relevant information in the DB. @@ -172,7 +181,18 @@ public: class ArchiveMount: public TapeMount { friend class SchedulerDatabase; + private: + ArchiveMount() {} public: + /** + * Returns The type of this tape mount. + * + * @return The type of this tape mount. + */ + MountType::Enum getMountType() const throw() { + return MountType::ARCHIVE; + } + virtual ~ArchiveMount() {}; }; @@ -233,15 +253,23 @@ public: /*============ Retrieve management: tape server side ======================*/ - class RetriveMount: public TapeMount { + class RetrieveMount: public TapeMount { friend class SchedulerDatabase; private: - RetriveMount(); + RetrieveMount() {} public: + /** + * Returns The type of this tape mount. + * + * @return The type of this tape mount. + */ + MountType::Enum getMountType() const throw() { + return MountType::RETRIEVE; + } }; class RetrieveJob { - friend class RetriveMount; + friend class RetrieveMount; public: cta::RemotePathAndStatus remoteFile; cta::ArchiveFileStatus archiveFile; diff --git a/scheduler/TapeMount.cpp b/scheduler/TapeMount.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea4a36464cb378214dd45d2d86c8151aeb703322 --- /dev/null +++ b/scheduler/TapeMount.cpp @@ -0,0 +1,25 @@ +/* + * 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 "scheduler/TapeMount.hpp" + +//------------------------------------------------------------------------------ +// destructor +//------------------------------------------------------------------------------ +cta::TapeMount::~TapeMount() throw() { +} diff --git a/scheduler/TapeMount.hpp b/scheduler/TapeMount.hpp index 3e995ce6450f3fb2261d2fa5d79a5a33e3e71f90..c905883bcb82a9d6ab23efc1312a6a4500a00f65 100644 --- a/scheduler/TapeMount.hpp +++ b/scheduler/TapeMount.hpp @@ -18,6 +18,8 @@ #pragma once +#include "scheduler/MountType.hpp" + namespace cta { /** * A placeholder class from which will derive ArchiveSession and RetriveSession. @@ -25,13 +27,24 @@ namespace cta { */ class TapeMount { public: + + /** + * Returns The type of this tape mount. + * + * @return The type of this tape mount. + */ + virtual MountType::Enum getMountType() const throw() = 0; + /** * Notifies the scheduler that the session is finished */ virtual void finish() = 0; - virtual ~TapeMount() {} + /** + * Destructor. + */ + virtual ~TapeMount() throw() = 0; - }; + }; // class TapeMount -} \ No newline at end of file +}