diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index e647e8ebe95b79680de8a03a026e779a82e86b96..c2973e8b7312bc0ed9eff36e13ee300d1d005718 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -201,12 +201,10 @@ public: virtual void modifyTapeTapePoolName(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const std::string &tapePoolName) = 0; virtual void modifyTapeCapacityInBytes(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const uint64_t capacityInBytes) = 0; virtual void modifyTapeEncryptionKey(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const std::string &encryptionKey) = 0; - virtual void modifyTapeLabelLog(const std::string &vid, const std::string &drive) = 0; // internal function (noCLI) virtual void modifyTapeLastWrittenLog(const std::string &vid, const std::string &drive) = 0; // internal function (noCLI) virtual void modifyTapeLastReadLog(const std::string &vid, const std::string &drive) = 0; // internal function (noCLI) virtual void setTapeFull(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool fullValue) = 0; virtual void setTapeDisabled(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool disabledValue) = 0; - virtual void setTapeLbp(const std::string &vid, const bool lbpValue) = 0; // internal function (noCLI) virtual void modifyTapeComment(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const std::string &comment) = 0; virtual void modifyRequesterMountPolicy(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &instanceName, const std::string &requesterName, const std::string &mountPolicy) = 0; @@ -384,6 +382,15 @@ public: */ virtual common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) = 0; + /** + * Notifies the catalogue that the specified tape was labelled. + * + * @param vid The volume identifier of the tape. + * @param drive The name of tape drive that was used to label the tape. + * @param lbpIsOn Set to true if Logical Block Protection (LBP) was enabled. + */ + virtual void tapeLabelled(const std::string &vid, const std::string &drive, const bool lbpIsOn) = 0; + /** * Prepares the catalogue for a new archive file and returns the information * required to queue the associated archive request. diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index db33ed0383e9ef745ccab1d5db20899125684f55..45de1257758b12d5d20117e5b859567b31e93be2 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -2525,7 +2525,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeEncryptionKey_nonExistentTape) { ASSERT_THROW(m_catalogue->modifyTapeEncryptionKey(m_cliSI, vid, encryptionKey), exception::UserError); } -TEST_P(cta_catalogue_CatalogueTest, modifyTapeLabelLog) { +TEST_P(cta_catalogue_CatalogueTest, tapeLabelled) { using namespace cta; ASSERT_TRUE(m_catalogue->getTapes().empty()); @@ -2573,8 +2573,9 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLabelLog) { ASSERT_EQ(creationLog, lastModificationLog); } - const std::string modifiedDrive = "modified_drive"; - m_catalogue->modifyTapeLabelLog(vid, modifiedDrive); + const std::string labelDrive = "labelling_drive"; + const bool lbpIsOn = true; + m_catalogue->tapeLabelled(vid, labelDrive, lbpIsOn); { const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(); @@ -2589,10 +2590,11 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLabelLog) { ASSERT_EQ(capacityInBytes, tape.capacityInBytes); ASSERT_TRUE(disabledValue == tape.disabled); ASSERT_TRUE(fullValue == tape.full); - ASSERT_FALSE(tape.lbp); + ASSERT_TRUE((bool)tape.lbp); + ASSERT_TRUE(tape.lbp.value()); ASSERT_EQ(comment, tape.comment); ASSERT_TRUE((bool)tape.labelLog); - ASSERT_EQ(modifiedDrive, tape.labelLog.value().drive); + ASSERT_EQ(labelDrive, tape.labelLog.value().drive); ASSERT_FALSE(tape.lastReadLog); ASSERT_FALSE(tape.lastWriteLog); @@ -2602,15 +2604,16 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLabelLog) { } } -TEST_P(cta_catalogue_CatalogueTest, modifyTapeLabelLog_nonExistentTape) { +TEST_P(cta_catalogue_CatalogueTest, tapeLabelled_nonExistentTape) { using namespace cta; ASSERT_TRUE(m_catalogue->getTapes().empty()); const std::string vid = "vid"; - const std::string drive = "drive"; + const std::string labelDrive = "drive"; + const bool lbpIsOn = true; - ASSERT_THROW(m_catalogue->modifyTapeLabelLog(vid, drive), exception::UserError); + ASSERT_THROW(m_catalogue->tapeLabelled(vid, labelDrive, lbpIsOn), exception::UserError); } TEST_P(cta_catalogue_CatalogueTest, modifyTapeLastWrittenLog) { @@ -2957,92 +2960,6 @@ TEST_P(cta_catalogue_CatalogueTest, setTapeDisabled_nonExistentTape) { ASSERT_THROW(m_catalogue->setTapeDisabled(m_cliSI, vid, true), exception::UserError); } -TEST_P(cta_catalogue_CatalogueTest, setTapeLbp) { - using namespace cta; - - ASSERT_TRUE(m_catalogue->getTapes().empty()); - - const std::string vid = "vid"; - const std::string logicalLibraryName = "logical_library_name"; - const std::string tapePoolName = "tape_pool_name"; - const std::string encryptionKey = "encryption_key"; - const uint64_t capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000; - const bool disabledValue = false; - const bool fullValue = false; - const std::string comment = "Create tape"; - - m_catalogue->createLogicalLibrary(m_cliSI, logicalLibraryName, "Create logical library"); - - m_catalogue->createTapePool(m_cliSI, tapePoolName, 2, true, "Create tape pool"); - - m_catalogue->createTape(m_cliSI, vid, logicalLibraryName, tapePoolName, encryptionKey, capacityInBytes, disabledValue, - fullValue, comment); - - { - const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(); - - ASSERT_EQ(1, tapes.size()); - - const common::dataStructures::Tape tape = tapes.front(); - ASSERT_EQ(vid, tape.vid); - ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName); - ASSERT_EQ(tapePoolName, tape.tapePoolName); - ASSERT_EQ(encryptionKey, tape.encryptionKey); - ASSERT_EQ(capacityInBytes, tape.capacityInBytes); - ASSERT_TRUE(disabledValue == tape.disabled); - ASSERT_TRUE(fullValue == tape.full); - ASSERT_FALSE(tape.lbp); - ASSERT_EQ(comment, tape.comment); - ASSERT_FALSE(tape.labelLog); - ASSERT_FALSE(tape.lastReadLog); - ASSERT_FALSE(tape.lastWriteLog); - - const common::dataStructures::EntryLog creationLog = tape.creationLog; - ASSERT_EQ(m_cliSI.username, creationLog.username); - ASSERT_EQ(m_cliSI.host, creationLog.host); - - const common::dataStructures::EntryLog lastModificationLog = tape.lastModificationLog; - ASSERT_EQ(creationLog, lastModificationLog); - } - - m_catalogue->setTapeLbp(vid, true); - - { - const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(); - - ASSERT_EQ(1, tapes.size()); - - const common::dataStructures::Tape tape = tapes.front(); - ASSERT_EQ(vid, tape.vid); - ASSERT_EQ(logicalLibraryName, tape.logicalLibraryName); - ASSERT_EQ(tapePoolName, tape.tapePoolName); - ASSERT_EQ(encryptionKey, tape.encryptionKey); - ASSERT_EQ(capacityInBytes, tape.capacityInBytes); - ASSERT_FALSE(tape.disabled); - ASSERT_FALSE(tape.full); - ASSERT_TRUE((bool)tape.lbp); - ASSERT_TRUE(tape.lbp.value()); - ASSERT_EQ(comment, tape.comment); - ASSERT_FALSE(tape.labelLog); - ASSERT_FALSE(tape.lastReadLog); - ASSERT_FALSE(tape.lastWriteLog); - - const common::dataStructures::EntryLog creationLog = tape.creationLog; - ASSERT_EQ(m_cliSI.username, creationLog.username); - ASSERT_EQ(m_cliSI.host, creationLog.host); - } -} - -TEST_P(cta_catalogue_CatalogueTest, setTapeLbp_nonExistentTape) { - using namespace cta; - - ASSERT_TRUE(m_catalogue->getTapes().empty()); - - const std::string vid = "vid"; - - ASSERT_THROW(m_catalogue->setTapeLbp(vid, false), exception::UserError); -} - TEST_P(cta_catalogue_CatalogueTest, getTapesForWriting) { using namespace cta; @@ -3061,8 +2978,8 @@ TEST_P(cta_catalogue_CatalogueTest, getTapesForWriting) { m_catalogue->createTapePool(m_cliSI, tapePoolName, 2, true, "Create tape pool"); m_catalogue->createTape(m_cliSI, vid, logicalLibraryName, tapePoolName, encryptionKey, capacityInBytes, disabledValue, fullValue, comment); - m_catalogue->modifyTapeLabelLog(vid, "tape_drive"); - m_catalogue->setTapeLbp(vid, true); + const bool lbpIsOn = true; + m_catalogue->tapeLabelled(vid, "tape_drive", lbpIsOn); const std::list<catalogue::TapeForWriting> tapes = m_catalogue->getTapesForWriting(logicalLibraryName); diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index 99b228a95b38cc6b772427da150ae87fa9dac6d4..7039dac0bdd691b9b99aad722fbea2feaf989853 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -1905,35 +1905,6 @@ void RdbmsCatalogue::modifyTapeEncryptionKey(const common::dataStructures::Secur } } -//------------------------------------------------------------------------------ -// modifyTapeLabelLog -//------------------------------------------------------------------------------ -void RdbmsCatalogue::modifyTapeLabelLog(const std::string &vid, const std::string &drive) { - try { - const time_t now = time(nullptr); - const char *const sql = - "UPDATE TAPE SET " - "LABEL_DRIVE = :LABEL_DRIVE," - "LABEL_TIME = :LABEL_TIME " - "WHERE " - "VID = :VID"; - auto conn = m_connPool.getConn(); - auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON); - stmt->bindString(":LABEL_DRIVE", drive); - stmt->bindUint64(":LABEL_TIME", now); - stmt->bindString(":VID", vid); - stmt->executeNonQuery(); - - if(0 == stmt->getNbAffectedRows()) { - throw exception::UserError(std::string("Cannot modify tape ") + vid + " because it does not exist"); - } - } catch(exception::UserError &) { - throw; - } catch (exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // modifyTapeLastWrittenLog //------------------------------------------------------------------------------ @@ -2060,32 +2031,6 @@ void RdbmsCatalogue::setTapeDisabled(const common::dataStructures::SecurityIdent } } -//------------------------------------------------------------------------------ -// setTapeLbp -//------------------------------------------------------------------------------ -void RdbmsCatalogue::setTapeLbp(const std::string &vid, const bool lbpValue) { - try { - const char *const sql = - "UPDATE TAPE SET " - "LBP_IS_ON = :LBP_IS_ON " - "WHERE " - "VID = :VID"; - auto conn = m_connPool.getConn(); - auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON); - stmt->bindBool(":LBP_IS_ON", lbpValue); - stmt->bindString(":VID", vid); - stmt->executeNonQuery(); - - if(0 == stmt->getNbAffectedRows()) { - throw exception::UserError(std::string("Cannot modify tape ") + vid + " because it does not exist"); - } - } catch(exception::UserError &) { - throw; - } catch (exception::Exception &ex) { - throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); - } -} - //------------------------------------------------------------------------------ // modifyTapeComment //------------------------------------------------------------------------------ @@ -3304,7 +3249,38 @@ common::dataStructures::ArchiveFile RdbmsCatalogue::getArchiveFileById(const uin throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } } - + +//------------------------------------------------------------------------------ +// tapeLabelled +//------------------------------------------------------------------------------ +void RdbmsCatalogue::tapeLabelled(const std::string &vid, const std::string &drive, const bool lbpIsOn) { + try { + const time_t now = time(nullptr); + const char *const sql = + "UPDATE TAPE SET " + "LABEL_DRIVE = :LABEL_DRIVE," + "LABEL_TIME = :LABEL_TIME," + "LBP_IS_ON = :LBP_IS_ON " + "WHERE " + "VID = :VID"; + auto conn = m_connPool.getConn(); + auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON); + stmt->bindString(":LABEL_DRIVE", drive); + stmt->bindUint64(":LABEL_TIME", now); + stmt->bindBool(":LBP_IS_ON", lbpIsOn); + stmt->bindString(":VID", vid); + stmt->executeNonQuery(); + + if(0 == stmt->getNbAffectedRows()) { + throw exception::UserError(std::string("Cannot modify tape ") + vid + " because it does not exist"); + } + } catch(exception::UserError &) { + throw; + } catch (exception::Exception &ex) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); + } +} + //------------------------------------------------------------------------------ // prepareForNewFile //------------------------------------------------------------------------------ diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index d3aace775f3826ef3d65b7e39c5eafc6703db923..24eab6c89d5ef00e3cf46208acfca86396fc02dc 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -188,12 +188,10 @@ public: virtual void modifyTapeTapePoolName(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const std::string &tapePoolName) override; virtual void modifyTapeCapacityInBytes(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const uint64_t capacityInBytes) override; virtual void modifyTapeEncryptionKey(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const std::string &encryptionKey) override; - virtual void modifyTapeLabelLog(const std::string &vid, const std::string &drive) override; // internal function (noCLI) virtual void modifyTapeLastWrittenLog(const std::string &vid, const std::string &drive) override; // internal function (noCLI) virtual void modifyTapeLastReadLog(const std::string &vid, const std::string &drive) override; // internal function (noCLI) virtual void setTapeFull(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool fullValue) override; virtual void setTapeDisabled(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool disabledValue) override; - virtual void setTapeLbp(const std::string &vid, const bool lbpValue) override; // internal function (noCLI) virtual void modifyTapeComment(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const std::string &comment) override; virtual void modifyRequesterMountPolicy(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &instanceName, const std::string &requesterName, const std::string &mountPolicy) override; @@ -369,7 +367,16 @@ public: * @return The archive file. */ virtual common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) override; - + + /** + * Notifies the catalogue that the specified tape was labelled. + * + * @param vid The volume identifier of the tape. + * @param drive The name of tape drive that was used to label the tape. + * @param lbpIsOn Set to true if Logical Block Protection (LBP) was enabled. + */ + virtual void tapeLabelled(const std::string &vid, const std::string &drive, const bool lbpIsOn) override; + /** * Prepares the catalogue for a new archive file and returns the information * required to queue the associated archive request. diff --git a/scheduler/Scheduler.cpp b/scheduler/Scheduler.cpp index 505bcd03269c2649ec4989925dc45fbe4a0b42db..d2532f114ed9a79de1e2ebcbddd2cdac67cc60d1 100644 --- a/scheduler/Scheduler.cpp +++ b/scheduler/Scheduler.cpp @@ -171,27 +171,6 @@ void cta::Scheduler::queueLabel(const cta::common::dataStructures::SecurityIdent throw cta::exception::Exception(std::string("Not implemented: ") + __PRETTY_FUNCTION__); } -//------------------------------------------------------------------------------ -// setTapeFull -//------------------------------------------------------------------------------ -void cta::Scheduler::setTapeFull(const cta::common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool fullValue) { - m_catalogue.setTapeFull(cliIdentity, vid, fullValue); -} - -//------------------------------------------------------------------------------ -// setTapeDisabled -//------------------------------------------------------------------------------ -void cta::Scheduler::setTapeDisabled(const cta::common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool disabledValue) { - m_catalogue.setTapeDisabled(cliIdentity, vid, disabledValue); -} - -//------------------------------------------------------------------------------ -// setTapeLbp -//------------------------------------------------------------------------------ -void cta::Scheduler::setTapeLbp(const std::string &vid, const bool lbpValue) { - m_catalogue.setTapeLbp(vid, lbpValue); -} - //------------------------------------------------------------------------------ // repack //------------------------------------------------------------------------------ diff --git a/scheduler/Scheduler.hpp b/scheduler/Scheduler.hpp index 783e0b31b99177d32b758785530388a11fcbfe3d..6d3959f3765669f1b18df83653dca95fab5a648a 100644 --- a/scheduler/Scheduler.hpp +++ b/scheduler/Scheduler.hpp @@ -126,9 +126,6 @@ public: * accomplish it will dequeue it. */ virtual void queueLabel(const cta::common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool force, const bool lbp, const optional<std::string> &tag); - virtual void setTapeFull(const cta::common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool fullValue); - virtual void setTapeDisabled(const cta::common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const bool disabledValue); - virtual void setTapeLbp(const std::string &vid, const bool lbpValue); // internal function (noCLI) virtual void repack(const cta::common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const optional<std::string> &tag, const cta::common::dataStructures::RepackType); virtual void cancelRepack(const cta::common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid); diff --git a/scheduler/SchedulerTest.cpp b/scheduler/SchedulerTest.cpp index 469d161de549633e832798aa0a0773a30dad08c8..5ce87e73b967b0893a403b8f6ef076e51a829ab9 100644 --- a/scheduler/SchedulerTest.cpp +++ b/scheduler/SchedulerTest.cpp @@ -394,8 +394,8 @@ TEST_P(SchedulerTest, archive_and_retrieve_new_file) { catalogue.createTape(s_adminOnAdminHost, s_vid, s_libraryName, s_tapePoolName, nullopt, capacityInBytes, notDisabled, notFull, tapeComment); - catalogue.modifyTapeLabelLog(s_vid, "tape_drive"); - catalogue.setTapeLbp(s_vid, true); + const bool lbpIsOn = true; + catalogue.tapeLabelled(s_vid, "tape_drive", lbpIsOn); { // Emulate a tape server by asking for a mount and then a file (and succeed @@ -534,8 +534,8 @@ TEST_P(SchedulerTest, retry_archive_until_max_reached) { catalogue.createTape(s_adminOnAdminHost, s_vid, s_libraryName, s_tapePoolName, nullopt, capacityInBytes, notDisabled, notFull, tapeComment); - catalogue.modifyTapeLabelLog(s_vid, "tape_drive"); - catalogue.setTapeLbp(s_vid, true); + const bool lbpIsOn = true; + catalogue.tapeLabelled(s_vid, "tape_drive", lbpIsOn); { // Emulate a tape server by asking for a mount and then a file diff --git a/xroot_plugins/XrdCtaFile.cpp b/xroot_plugins/XrdCtaFile.cpp index 5e426264fe7e64e426c1b9b410d4c6e20d2bc99e..d5c86217424698e3a322c4400134e57b7072e488 100644 --- a/xroot_plugins/XrdCtaFile.cpp +++ b/xroot_plugins/XrdCtaFile.cpp @@ -988,10 +988,10 @@ void XrdCtaFile::xCom_tape() { m_catalogue->modifyTapeEncryptionKey(m_cliIdentity, vid.value(), encryptionkey.value()); } if(disabled) { - m_scheduler->setTapeDisabled(m_cliIdentity, vid.value(), disabled.value()); + m_catalogue->setTapeDisabled(m_cliIdentity, vid.value(), disabled.value()); } if(full) { - m_scheduler->setTapeDisabled(m_cliIdentity, vid.value(), full.value()); + m_catalogue->setTapeFull(m_cliIdentity, vid.value(), full.value()); } } else if("reclaim" == m_requestTokens.at(2)) { //reclaim