diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index 6617bf209857a5e90d44412bd2974dcdd70aa9e9..2786a72703386f831b7a008e170af2a42211e2e9 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -2937,6 +2937,91 @@ 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_TRUE(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, false); + + { + 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_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); + } +} + +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; diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index f7519352be3ffe882b3ea446fb33e5fa92b01d48..ed15c3f221ca75769c4da8637ebab4a898bf0835 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -2067,7 +2067,26 @@ void RdbmsCatalogue::setTapeDisabled(const common::dataStructures::SecurityIdent // setTapeLbp //------------------------------------------------------------------------------ void RdbmsCatalogue::setTapeLbp(const std::string &vid, const bool lbpValue) { - throw exception::Exception(std::string(__FUNCTION__) + " not implemented"); + 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->bindUint64(":LBP_IS_ON", lbpValue ? 1 : 0); + 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()); + } } //------------------------------------------------------------------------------