diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index 7c31701bbd8e61c4cdd9202aa04bde830d8da1e0..e647e8ebe95b79680de8a03a026e779a82e86b96 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -454,8 +454,8 @@ public: /** * Returns the list of tapes that can be written to by a tape drive in the - * specified logical library, in other words tapes that are not disabled, not - * full and are in the specified logical library. + * specified logical library, in other words tapes that are labelled, not + * disabled, not full and are in the specified logical library. * * @param logicalLibraryName The name of the logical library. */ diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index 2786a72703386f831b7a008e170af2a42211e2e9..a19739edc498ef499046d46c2b232d1557a3c336 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -1786,6 +1786,7 @@ TEST_P(cta_catalogue_CatalogueTest, createTape) { 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); @@ -1833,6 +1834,7 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_no_encryption_key) { 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); @@ -1880,6 +1882,7 @@ TEST_P(cta_catalogue_CatalogueTest, createTape_16_exabytes_capacity) { 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); @@ -2142,6 +2145,7 @@ TEST_P(cta_catalogue_CatalogueTest, deleteTape) { 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); @@ -2201,6 +2205,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLogicalLibraryName) { 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); @@ -2229,6 +2234,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLogicalLibraryName) { 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); @@ -2289,6 +2295,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeTapePoolName) { 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); @@ -2317,6 +2324,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeTapePoolName) { 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); @@ -2377,6 +2385,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeCapacityInBytes) { 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); @@ -2406,6 +2415,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeCapacityInBytes) { ASSERT_EQ(modifiedCapacityInBytes, 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); @@ -2462,6 +2472,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeEncryptionKey) { 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); @@ -2491,6 +2502,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeEncryptionKey) { 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); @@ -2547,6 +2559,7 @@ 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_EQ(comment, tape.comment); ASSERT_FALSE(tape.labelLog); ASSERT_FALSE(tape.lastReadLog); @@ -2576,6 +2589,7 @@ 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_EQ(comment, tape.comment); ASSERT_TRUE((bool)tape.labelLog); ASSERT_EQ(modifiedDrive, tape.labelLog.value().drive); @@ -2633,6 +2647,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLastWrittenLog) { 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); @@ -2662,6 +2677,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLastWrittenLog) { 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); @@ -2719,6 +2735,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLastReadLog) { 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); @@ -2748,6 +2765,7 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapeLastReadLog) { 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_TRUE((bool)tape.lastReadLog); @@ -2805,6 +2823,7 @@ TEST_P(cta_catalogue_CatalogueTest, setTapeFull) { 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); @@ -2888,6 +2907,7 @@ TEST_P(cta_catalogue_CatalogueTest, setTapeDisabled) { 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); @@ -2971,7 +2991,7 @@ TEST_P(cta_catalogue_CatalogueTest, setTapeLbp) { ASSERT_EQ(capacityInBytes, tape.capacityInBytes); ASSERT_TRUE(disabledValue == tape.disabled); ASSERT_TRUE(fullValue == tape.full); - ASSERT_TRUE(tape.lbp); + ASSERT_FALSE(tape.lbp); ASSERT_EQ(comment, tape.comment); ASSERT_FALSE(tape.labelLog); ASSERT_FALSE(tape.lastReadLog); @@ -2985,7 +3005,7 @@ TEST_P(cta_catalogue_CatalogueTest, setTapeLbp) { ASSERT_EQ(creationLog, lastModificationLog); } - m_catalogue->setTapeLbp(vid, false); + m_catalogue->setTapeLbp(vid, true); { const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes(); @@ -3000,7 +3020,8 @@ TEST_P(cta_catalogue_CatalogueTest, setTapeLbp) { ASSERT_EQ(capacityInBytes, tape.capacityInBytes); ASSERT_FALSE(tape.disabled); ASSERT_FALSE(tape.full); - ASSERT_FALSE(tape.lbp); + ASSERT_TRUE((bool)tape.lbp); + ASSERT_TRUE(tape.lbp.value()); ASSERT_EQ(comment, tape.comment); ASSERT_FALSE(tape.labelLog); ASSERT_FALSE(tape.lastReadLog); @@ -3036,12 +3057,10 @@ TEST_P(cta_catalogue_CatalogueTest, getTapesForWriting) { const bool fullValue = false; const std::string comment = "Create tape"; - m_catalogue->createLogicalLibrary(m_cliSI, logicalLibraryName, - "Create logical library"); + 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); + m_catalogue->createTape(m_cliSI, vid, logicalLibraryName, tapePoolName, encryptionKey, capacityInBytes, disabledValue, + fullValue, comment); const std::list<catalogue::TapeForWriting> tapes = m_catalogue->getTapesForWriting(logicalLibraryName); @@ -3053,7 +3072,6 @@ TEST_P(cta_catalogue_CatalogueTest, getTapesForWriting) { ASSERT_EQ(0, tape.lastFSeq); ASSERT_EQ(capacityInBytes, tape.capacityInBytes); ASSERT_EQ(0, tape.dataOnTapeInBytes); - ASSERT_TRUE(tape.lbp); } TEST_P(cta_catalogue_CatalogueTest, createMountPolicy) { @@ -3828,6 +3846,7 @@ TEST_P(cta_catalogue_CatalogueTest, prepareToRetrieveFile) { ASSERT_EQ(capacityInBytes, tape.capacityInBytes); ASSERT_TRUE(disabledValue == tape.disabled); ASSERT_TRUE(fullValue == tape.full); + ASSERT_FALSE(tape.lbp); ASSERT_EQ(createTapeComment, tape.comment); ASSERT_FALSE(tape.labelLog); ASSERT_FALSE(tape.lastReadLog); @@ -3851,6 +3870,7 @@ TEST_P(cta_catalogue_CatalogueTest, prepareToRetrieveFile) { ASSERT_EQ(capacityInBytes, tape.capacityInBytes); ASSERT_TRUE(disabledValue == tape.disabled); ASSERT_TRUE(fullValue == tape.full); + ASSERT_FALSE(tape.lbp); ASSERT_EQ(createTapeComment, tape.comment); ASSERT_FALSE(tape.labelLog); ASSERT_FALSE(tape.lastReadLog); @@ -4079,6 +4099,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_many_archive_files) { 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); @@ -4362,6 +4383,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_2_tape_files_different_tap 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); @@ -4385,6 +4407,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_2_tape_files_different_tap 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); @@ -4582,6 +4605,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_2_tape_files_same_archive_ 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); @@ -4725,6 +4749,7 @@ TEST_P(cta_catalogue_CatalogueTest, fileWrittenToTape_2_tape_files_corrupted_dis 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); @@ -4865,6 +4890,7 @@ TEST_P(cta_catalogue_CatalogueTest, deleteArchiveFile) { 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); @@ -4888,6 +4914,7 @@ TEST_P(cta_catalogue_CatalogueTest, deleteArchiveFile) { 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); diff --git a/catalogue/OracleCatalogue.cpp b/catalogue/OracleCatalogue.cpp index 33c6ba530c657a54c9067067ce09ef5d9d8f2fd2..1a977a2e823f2c393c5afd8aba2af087f03147d1 100644 --- a/catalogue/OracleCatalogue.cpp +++ b/catalogue/OracleCatalogue.cpp @@ -230,9 +230,9 @@ common::dataStructures::Tape OracleCatalogue::selectTapeForUpdate(rdbms::Conn &c tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.disabled = rset->columnUint64("IS_DISABLED"); - tape.full = rset->columnUint64("IS_FULL"); - tape.lbp = rset->columnUint64("LBP_IS_ON"); + tape.disabled = rset->columnBool("IS_DISABLED"); + tape.full = rset->columnBool("IS_FULL"); + tape.lbp = rset->columnOptionalBool("LBP_IS_ON"); tape.labelLog = getTapeLogFromRset(*rset, "LABEL_DRIVE", "LABEL_TIME"); tape.lastReadLog = getTapeLogFromRset(*rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index ed15c3f221ca75769c4da8637ebab4a898bf0835..99b228a95b38cc6b772427da150ae87fa9dac6d4 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -724,7 +724,7 @@ void RdbmsCatalogue::createTapePool( stmt->bindString(":TAPE_POOL_NAME", name); stmt->bindUint64(":NB_PARTIAL_TAPES", nbPartialTapes); - stmt->bindUint64(":IS_ENCRYPTED", encryptionValue ? 1 : 0); + stmt->bindBool(":IS_ENCRYPTED", encryptionValue); stmt->bindString(":USER_COMMENT", comment); @@ -817,7 +817,7 @@ std::list<common::dataStructures::TapePool> RdbmsCatalogue::getTapePools() const pool.name = rset->columnString("TAPE_POOL_NAME"); pool.nbPartialTapes = rset->columnUint64("NB_PARTIAL_TAPES"); - pool.encryption = rset->columnUint64("IS_ENCRYPTED"); + pool.encryption = rset->columnBool("IS_ENCRYPTED"); pool.comment = rset->columnString("USER_COMMENT"); pool.creationLog.username = rset->columnString("CREATION_LOG_USER_NAME"); pool.creationLog.host = rset->columnString("CREATION_LOG_HOST_NAME"); @@ -919,7 +919,7 @@ void RdbmsCatalogue::setTapePoolEncryption(const common::dataStructures::Securit "TAPE_POOL_NAME = :TAPE_POOL_NAME"; auto conn = m_connPool.getConn(); auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON); - stmt->bindUint64(":IS_ENCRYPTED", encryptionValue ? 1 : 0); + stmt->bindBool(":IS_ENCRYPTED", encryptionValue); stmt->bindString(":LAST_UPDATE_USER_NAME", cliIdentity.username); stmt->bindString(":LAST_UPDATE_HOST_NAME", cliIdentity.host); stmt->bindUint64(":LAST_UPDATE_TIME", now); @@ -1390,7 +1390,6 @@ void RdbmsCatalogue::createTape( "LAST_FSEQ," "IS_DISABLED," "IS_FULL," - "LBP_IS_ON," "USER_COMMENT," @@ -1411,7 +1410,6 @@ void RdbmsCatalogue::createTape( ":LAST_FSEQ," ":IS_DISABLED," ":IS_FULL," - ":LBP_IS_ON," ":USER_COMMENT," @@ -1431,9 +1429,8 @@ void RdbmsCatalogue::createTape( stmt->bindUint64(":CAPACITY_IN_BYTES", capacityInBytes); stmt->bindUint64(":DATA_IN_BYTES", 0); stmt->bindUint64(":LAST_FSEQ", 0); - stmt->bindUint64(":IS_DISABLED", disabled ? 1 : 0); - stmt->bindUint64(":IS_FULL", full ? 1 : 0); - stmt->bindUint64(":LBP_IS_ON", 1); + stmt->bindBool(":IS_DISABLED", disabled); + stmt->bindBool(":IS_FULL", full); stmt->bindString(":USER_COMMENT", comment); @@ -1588,9 +1585,9 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(const TapeSearc if(searchCriteria.logicalLibrary) stmt->bindString(":LOGICAL_LIBRARY_NAME", searchCriteria.logicalLibrary.value()); if(searchCriteria.tapePool) stmt->bindString(":TAPE_POOL_NAME", searchCriteria.tapePool.value()); if(searchCriteria.capacityInBytes) stmt->bindUint64(":CAPACITY_IN_BYTES", searchCriteria.capacityInBytes.value()); - if(searchCriteria.disabled) stmt->bindUint64(":IS_DISABLED", searchCriteria.disabled.value() ? 1 : 0); - if(searchCriteria.full) stmt->bindUint64(":IS_FULL", searchCriteria.full.value() ? 1 : 0); - if(searchCriteria.lbp) stmt->bindUint64(":LBP_IS_ON", searchCriteria.lbp.value() ? 1 : 0); + if(searchCriteria.disabled) stmt->bindBool(":IS_DISABLED", searchCriteria.disabled.value()); + if(searchCriteria.full) stmt->bindBool(":IS_FULL", searchCriteria.full.value()); + if(searchCriteria.lbp) stmt->bindBool(":LBP_IS_ON", searchCriteria.lbp.value()); auto rset = stmt->executeQuery(); while (rset->next()) { @@ -1603,9 +1600,9 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(const TapeSearc tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.disabled = rset->columnUint64("IS_DISABLED"); - tape.full = rset->columnUint64("IS_FULL"); - tape.lbp = rset->columnUint64("LBP_IS_ON"); + tape.disabled = rset->columnBool("IS_DISABLED"); + tape.full = rset->columnBool("IS_FULL"); + tape.lbp = rset->columnOptionalBool("LBP_IS_ON"); tape.labelLog = getTapeLogFromRset(*rset, "LABEL_DRIVE", "LABEL_TIME"); tape.lastReadLog = getTapeLogFromRset(*rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); @@ -1703,9 +1700,9 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getTapesByVid(const std::se tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.disabled = rset->columnUint64("IS_DISABLED"); - tape.full = rset->columnUint64("IS_FULL"); - tape.lbp = rset->columnUint64("LBP_IS_ON"); + tape.disabled = rset->columnBool("IS_DISABLED"); + tape.full = rset->columnBool("IS_FULL"); + tape.lbp = rset->columnOptionalBool("LBP_IS_ON"); tape.labelLog = getTapeLogFromRset(*rset, "LABEL_DRIVE", "LABEL_TIME"); tape.lastReadLog = getTapeLogFromRset(*rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); @@ -2012,7 +2009,7 @@ void RdbmsCatalogue::setTapeFull(const common::dataStructures::SecurityIdentity "VID = :VID"; auto conn = m_connPool.getConn(); auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON); - stmt->bindUint64(":IS_FULL", fullValue ? 1 : 0); + stmt->bindBool(":IS_FULL", fullValue); stmt->bindString(":LAST_UPDATE_USER_NAME", cliIdentity.username); stmt->bindString(":LAST_UPDATE_HOST_NAME", cliIdentity.host); stmt->bindUint64(":LAST_UPDATE_TIME", now); @@ -2046,7 +2043,7 @@ void RdbmsCatalogue::setTapeDisabled(const common::dataStructures::SecurityIdent "VID = :VID"; auto conn = m_connPool.getConn(); auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON); - stmt->bindUint64(":IS_DISABLED", disabledValue ? 1 : 0); + stmt->bindBool(":IS_DISABLED", disabledValue); stmt->bindString(":LAST_UPDATE_USER_NAME", cliIdentity.username); stmt->bindString(":LAST_UPDATE_HOST_NAME", cliIdentity.host); stmt->bindUint64(":LAST_UPDATE_TIME", now); @@ -2075,7 +2072,7 @@ void RdbmsCatalogue::setTapeLbp(const std::string &vid, const bool lbpValue) { "VID = :VID"; auto conn = m_connPool.getConn(); auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON); - stmt->bindUint64(":LBP_IS_ON", lbpValue ? 1 : 0); + stmt->bindBool(":LBP_IS_ON", lbpValue); stmt->bindString(":VID", vid); stmt->executeNonQuery(); @@ -2092,8 +2089,35 @@ void RdbmsCatalogue::setTapeLbp(const std::string &vid, const bool lbpValue) { //------------------------------------------------------------------------------ // modifyTapeComment //------------------------------------------------------------------------------ -void RdbmsCatalogue::modifyTapeComment(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &vid, const std::string &comment) { - throw exception::Exception(std::string(__FUNCTION__) + " not implemented"); +void RdbmsCatalogue::modifyTapeComment(const common::dataStructures::SecurityIdentity &cliIdentity, + const std::string &vid, const std::string &comment) { + try { + const time_t now = time(nullptr); + const char *const sql = + "UPDATE TAPE SET " + "USER_COMMENT = :USER_COMMENT," + "LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME," + "LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME," + "LAST_UPDATE_TIME = :LAST_UPDATE_TIME " + "WHERE " + "VID = :VID"; + auto conn = m_connPool.getConn(); + auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON); + stmt->bindString(":USER_COMMENT", comment); + stmt->bindString(":LAST_UPDATE_USER_NAME", cliIdentity.username); + stmt->bindString(":LAST_UPDATE_HOST_NAME", cliIdentity.host); + stmt->bindUint64(":LAST_UPDATE_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()); + } } //------------------------------------------------------------------------------ @@ -3749,11 +3773,13 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string & "TAPE_POOL_NAME AS TAPE_POOL_NAME," "CAPACITY_IN_BYTES AS CAPACITY_IN_BYTES," "DATA_IN_BYTES AS DATA_IN_BYTES," - "LAST_FSEQ AS LAST_FSEQ," - "LBP_IS_ON AS LBP_IS_ON " + "LAST_FSEQ AS LAST_FSEQ " "FROM " "TAPE " "WHERE " + "LBP_IS_ON IS NOT NULL AND " + "LABEL_DRIVE IS NOT NULL AND " + "LABEL_TIME IS NOT NULL AND " "IS_DISABLED = 0 AND " "IS_FULL = 0 AND " "LOGICAL_LIBRARY_NAME = :LOGICAL_LIBRARY_NAME"; @@ -3763,13 +3789,11 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string & auto rset = stmt->executeQuery(); while (rset->next()) { TapeForWriting tape; - tape.vid = rset->columnString("VID"); tape.tapePool = rset->columnString("TAPE_POOL_NAME"); tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.lbp = rset->columnUint64("LBP_IS_ON"); tapes.push_back(tape); } diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index 58aa626b0fb52752fa0a0de5f7282204c30374cd..d3aace775f3826ef3d65b7e39c5eafc6703db923 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -145,8 +145,7 @@ public: virtual void modifyLogicalLibraryComment(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &name, const std::string &comment) override; /** - * Creates a tape which is assumed to have logical block protection (LBP) - * enabled. + * Creates a tape. * * @param encryptionKey The optional identifier of the encrption key. This * optional parameter should either have a non-empty string value or no value @@ -429,8 +428,8 @@ public: /** * Returns the list of tapes that can be written to by a tape drive in the - * specified logical library, in other words tapes that are not disabled, not - * full and are in the specified logical library. + * specified logical library, in other words tapes that are labelled, not + * disabled, not full and are in the specified logical library. * * @param logicalLibraryName The name of the logical library. */ diff --git a/catalogue/SqliteCatalogue.cpp b/catalogue/SqliteCatalogue.cpp index 1b5c87efbebafec4b008eea5daa3fec97a0047b6..3caeb3924c2eeadf1e765d2a06e91329220905f8 100644 --- a/catalogue/SqliteCatalogue.cpp +++ b/catalogue/SqliteCatalogue.cpp @@ -238,9 +238,9 @@ common::dataStructures::Tape SqliteCatalogue::selectTapeForUpdate(rdbms::Conn &c tape.capacityInBytes = rset->columnUint64("CAPACITY_IN_BYTES"); tape.dataOnTapeInBytes = rset->columnUint64("DATA_IN_BYTES"); tape.lastFSeq = rset->columnUint64("LAST_FSEQ"); - tape.disabled = rset->columnUint64("IS_DISABLED"); - tape.full = rset->columnUint64("IS_FULL"); - tape.lbp = rset->columnUint64("LBP_IS_ON"); + tape.disabled = rset->columnBool("IS_DISABLED"); + tape.full = rset->columnBool("IS_FULL"); + tape.lbp = rset->columnOptionalBool("LBP_IS_ON"); tape.labelLog = getTapeLogFromRset(*rset, "LABEL_DRIVE", "LABEL_TIME"); tape.lastReadLog = getTapeLogFromRset(*rset, "LAST_READ_DRIVE", "LAST_READ_TIME"); diff --git a/catalogue/TapeForWriting.cpp b/catalogue/TapeForWriting.cpp index 1aed4661137009d033e2c67c89c5287ba4898669..7874afd2f6b181d9ba5b9c59de36c32b395af3ad 100644 --- a/catalogue/TapeForWriting.cpp +++ b/catalogue/TapeForWriting.cpp @@ -27,8 +27,7 @@ namespace catalogue { TapeForWriting::TapeForWriting(): lastFSeq(0), capacityInBytes(0), - dataOnTapeInBytes(0), - lbp(false) { + dataOnTapeInBytes(0) { } //------------------------------------------------------------------------------ @@ -44,11 +43,10 @@ bool TapeForWriting::operator==(const TapeForWriting &rhs) const { std::ostream &operator<<(std::ostream &os, const TapeForWriting &obj) { os << "{" << - "vid=" << obj.vid << "," << - "lastFseq=" << obj.lastFSeq << "," << - "capacityInBytes=" << obj.capacityInBytes << "," << - "dataOnTapeInBytes=" << obj.dataOnTapeInBytes << "," << - "lbp=" << (obj.lbp ? "true" : "false") << + "vid=" << obj.vid << "," << + "lastFseq=" << obj.lastFSeq << "," << + "capacityInBytes=" << obj.capacityInBytes << "," << + "dataOnTapeInBytes=" << obj.dataOnTapeInBytes << "}"; return os; diff --git a/catalogue/TapeForWriting.hpp b/catalogue/TapeForWriting.hpp index 8d9626919a31b4e4b40abe245d665932ebf046e4..4b1e99136d57809147831151cb3a236dff27f780 100644 --- a/catalogue/TapeForWriting.hpp +++ b/catalogue/TapeForWriting.hpp @@ -18,6 +18,8 @@ #pragma once +#include "common/optional.hpp" + #include <ostream> #include <stdint.h> #include <string> @@ -74,11 +76,6 @@ struct TapeForWriting { */ uint64_t dataOnTapeInBytes; - /** - * True if the tape uses logical block protection. - */ - bool lbp; - }; // struct TapeForWriting /** diff --git a/catalogue/catalogue_common_schema.sql b/catalogue/catalogue_common_schema.sql index 3117962a08097bae9af14b25a7cac998ca98cba5..4e1fefbb0ec4eb443263f35d6ca2381bf6477bb1 100644 --- a/catalogue/catalogue_common_schema.sql +++ b/catalogue/catalogue_common_schema.sql @@ -86,7 +86,7 @@ CREATE TABLE TAPE( LAST_FSEQ INTEGER NOT NULL, IS_DISABLED INTEGER NOT NULL, IS_FULL INTEGER NOT NULL, - LBP_IS_ON INTEGER NOT NULL, + LBP_IS_ON INTEGER, LABEL_DRIVE VARCHAR2(100), LABEL_TIME INTEGER, LAST_READ_DRIVE VARCHAR2(100), diff --git a/catalogue/catalogue_schema.pdf b/catalogue/catalogue_schema.pdf index 19bfcd4556bb0e7b930e007aeaafe46f6882c808..3c3f3032aa19cf04b9c6b168bb899167b956f6f1 100644 Binary files a/catalogue/catalogue_schema.pdf and b/catalogue/catalogue_schema.pdf differ diff --git a/common/dataStructures/Tape.cpp b/common/dataStructures/Tape.cpp index 97b66ebc3af178a1a3426986771ea1f91d3ba437..dcaaed5b9df0ec967c30a947ab3b99e0600dc6c9 100644 --- a/common/dataStructures/Tape.cpp +++ b/common/dataStructures/Tape.cpp @@ -71,8 +71,8 @@ std::ostream &operator<<(std::ostream &os, const Tape &obj) { << " tapePoolName=" << obj.tapePoolName << " capacityInBytes=" << obj.capacityInBytes << " dataOnTapeInBytes=" << obj.dataOnTapeInBytes - << " encryptionKey=" << ((bool)obj.encryptionKey ? obj.encryptionKey.value() : "null") - << " lbp=" << obj.lbp + << " encryptionKey=" << (obj.encryptionKey ? obj.encryptionKey.value() : "null") + << " lbp=" << (obj.lbp ? (obj.lbp.value() ? "true" : "false") : "null") << " full=" << obj.full << " disabled=" << obj.disabled << " creationLog=" << obj.creationLog diff --git a/common/dataStructures/Tape.hpp b/common/dataStructures/Tape.hpp index d84497632017b5c80f02ee0d15f5efa63ce356fa..d3e88b90c4d11a805f5f044c32ea6e9dcfbf3885 100644 --- a/common/dataStructures/Tape.hpp +++ b/common/dataStructures/Tape.hpp @@ -57,7 +57,13 @@ struct Tape { */ optional<std::string> encryptionKey; - bool lbp; + /** + * Specifies whether or not the tape has Logical Block Protection (LBP) + * enabled. This value is not set until the tape is either labelled or + * imported as a tape containing pre-existing files. + */ + optional<bool> lbp; + bool full; bool disabled; EntryLog creationLog; diff --git a/rdbms/OcciRset.hpp b/rdbms/OcciRset.hpp index be4a488d1aba9cb3bfbc2703e8568a1281d0adce..e5b4d59c7a18364029d8cf6f4823b1d52195ead6 100644 --- a/rdbms/OcciRset.hpp +++ b/rdbms/OcciRset.hpp @@ -82,7 +82,7 @@ public: /** * Returns the value of the specified column as a string. * - * This method will return a nullptr column value as an optional with no value. + * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The string value of the specified column. @@ -92,7 +92,7 @@ public: /** * Returns the value of the specified column as an integer. * - * This method will return a nullptr column value as an optional with no value. + * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The value of the specified column. diff --git a/rdbms/Rset.cpp b/rdbms/Rset.cpp index 1f29b5caa8136b73d0c90c7600b22f33bd5f769e..3ff6de5099a7a8911574f23a88c7ee8969cc36e0 100644 --- a/rdbms/Rset.cpp +++ b/rdbms/Rset.cpp @@ -60,5 +60,37 @@ uint64_t Rset::columnUint64(const std::string &colName) const { } } +//------------------------------------------------------------------------------ +// columnBool +//------------------------------------------------------------------------------ +bool Rset::columnBool(const std::string &colName) const { + try { + const optional<bool> col = columnOptionalBool(colName); + if(col) { + return col.value(); + } else { + throw NullDbValue(std::string("Database column ") + colName + " contains a nullptr value"); + } + } catch(exception::Exception &ex) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); + } +} + +//------------------------------------------------------------------------------ +// columnOptionalBool +//------------------------------------------------------------------------------ +optional<bool> Rset::columnOptionalBool(const std::string &colName) const { + try { + const auto column = columnOptionalUint64(colName); + if(column) { + return optional<bool>(column.value() != 0 ? true : false); + } else { + return nullopt; + } + } catch(exception::Exception &ex) { + throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); + } +} + } // namespace rdbms } // namespace cta diff --git a/rdbms/Rset.hpp b/rdbms/Rset.hpp index 40c3d7573cc5de5a0ff04fc5b4090b2ac2d4151b..5aa3adfd2566df463eff9c56b18b322abc6de5b5 100644 --- a/rdbms/Rset.hpp +++ b/rdbms/Rset.hpp @@ -74,7 +74,7 @@ public: /** * Returns the value of the specified column as a string. * - * This method will return a nullptr column value as an optional with no value. + * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The string value of the specified column. @@ -92,16 +92,43 @@ public: */ uint64_t columnUint64(const std::string &colName) const; + /** + * Returns the value of the specified column as a boolean. + * + * Please note that the underlying database column type is expected to be a + * number where a non-zero value means true and a value of zero means false. + * + * This method will throw an exception if the value of the specified column + * is nullptr. + * + * @param colName The name of the column. + * @return The value of the specified column. + */ + bool columnBool(const std::string &colName) const; + /** * Returns the value of the specified column as an integer. * - * This method will return a nullptr column value as an optional with no value. + * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The value of the specified column. */ virtual optional<uint64_t> columnOptionalUint64(const std::string &colName) const = 0; + /** + * Returns the value of the specified column as a boolean. + * + * Please note that the underlying database column type is expected to be a + * number where a non-zero value means true and a value of zero means false. + * + * This method will return a null column value as an optional with no value. + * + * @param colName The name of the column. + * @return The value of the specified column. + */ + virtual optional<bool> columnOptionalBool(const std::string &colName) const; + }; // class Rset } // namespace rdbms diff --git a/rdbms/SqliteRset.hpp b/rdbms/SqliteRset.hpp index 7fb68efaed50a8c747e0e8f1aa3e4adbfa23040a..6065d7285bba2a46f9141ae53134f75095677b75 100644 --- a/rdbms/SqliteRset.hpp +++ b/rdbms/SqliteRset.hpp @@ -77,7 +77,7 @@ public: /** * Returns the value of the specified column as a string. * - * This method will return a nullptr column value as an optional with no value. + * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The string value of the specified column. @@ -87,7 +87,7 @@ public: /** * Returns the value of the specified column as an integer. * - * This method will return a nullptr column value as an optional with no value. + * This method will return a null column value as an optional with no value. * * @param colName The name of the column. * @return The value of the specified column. diff --git a/rdbms/Stmt.cpp b/rdbms/Stmt.cpp index e345eba700af2a801f9cae4cd67e15743ede698b..8d275f167e8497adda5c7c11634a002adf7a5275 100644 --- a/rdbms/Stmt.cpp +++ b/rdbms/Stmt.cpp @@ -33,5 +33,23 @@ Stmt::Stmt(const AutocommitMode autocommitMode): m_autoCommitMode(autocommitMode Stmt::~Stmt() throw() { } +//------------------------------------------------------------------------------ +// bindBool +//------------------------------------------------------------------------------ +void Stmt::bindBool(const std::string ¶mName, const bool paramValue) { + bindOptionalBool(paramName, paramValue); +} + +//------------------------------------------------------------------------------ +// bindOptionalBool +//------------------------------------------------------------------------------ +void Stmt::bindOptionalBool(const std::string ¶mName, const optional<bool> ¶mValue) { + if(paramValue) { + bindOptionalUint64(paramName, paramValue.value() ? 1 : 0); + } else { + bindOptionalUint64(paramName, nullopt); + } +} + } // namespace rdbms } // namespace cta diff --git a/rdbms/Stmt.hpp b/rdbms/Stmt.hpp index ca18f722d30d9d3d329771891c55d42915cf1902..8796d7221c1b5e869f380ce5aa397736d5e0c48d 100644 --- a/rdbms/Stmt.hpp +++ b/rdbms/Stmt.hpp @@ -109,6 +109,22 @@ public: */ virtual void bindOptionalUint64(const std::string ¶mName, const optional<uint64_t> ¶mValue) = 0; + /** + * Binds an SQL parameter. + * + * @param paramName The name of the parameter. + * @param paramValue The value to be bound. + */ + void bindBool(const std::string ¶mName, const bool paramValue); + + /** + * Binds an SQL parameter. + * + * @param paramName The name of the parameter. + * @param paramValue The value to be bound. + */ + void bindOptionalBool(const std::string ¶mName, const optional<bool> ¶mValue); + /** * Binds an SQL parameter of type string. *