Commit 196c861d authored by Steven Murray's avatar Steven Murray
Browse files

Added Catalogue::getAllTapes()

parent 966def63
......@@ -342,6 +342,13 @@ public:
*/
virtual common::dataStructures::VidToTapeMap getTapesByVid(const std::set<std::string> &vids) const = 0;
/**
* Returns all the tapes within the CTA catalogue.
*
* @return Map from tape volume identifier to tape.
*/
virtual common::dataStructures::VidToTapeMap getAllTapes() const = 0;
/**
* Reclaims the specified tape.
*
......
......@@ -233,6 +233,10 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->getTapesByVid(vids);}, m_maxTriesToConnect);
}
common::dataStructures::VidToTapeMap getAllTapes() const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getAllTapes();}, m_maxTriesToConnect);
}
void reclaimTape(const common::dataStructures::SecurityIdentity &admin, const std::string &vid) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->reclaimTape(admin, vid);}, m_maxTriesToConnect);
}
......
......@@ -28,6 +28,7 @@
#include <algorithm>
#include <gtest/gtest.h>
#include <iomanip>
#include <limits>
#include <map>
#include <memory>
......@@ -8194,6 +8195,53 @@ TEST_P(cta_catalogue_CatalogueTest, getTapesByVid_no_vids) {
ASSERT_TRUE(m_catalogue->getTapesByVid(vids).empty());
}
TEST_P(cta_catalogue_CatalogueTest, getAllTapes_no_tapes) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getAllTapes().empty());
}
TEST_P(cta_catalogue_CatalogueTest, getAllTapes_many_tapes) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getTapes().empty());
const std::string logicalLibraryName = "logical_library_name";
const std::string tapePoolName = "tape_pool_name";
const uint64_t nbPartialTapes = 2;
const uint64_t capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000;
const bool disabledValue = true;
const bool fullValue = false;
m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName, "Create logical library");
m_catalogue->createTapePool(m_admin, tapePoolName, nbPartialTapes, true, "Create tape pool");
const uint32_t nbTapes = 1000;
for(uint32_t i = 0; i < nbTapes; i++) {
std::ostringstream vid;
vid << "V" << std::setfill('0') << std::setw(5) << i;
const std::string tapeComment = "Create tape " + vid.str();
m_catalogue->createTape(m_admin, vid.str(), logicalLibraryName, tapePoolName, capacityInBytes, disabledValue,
fullValue, tapeComment);
}
const auto vidToTapeMap = m_catalogue->getAllTapes();
ASSERT_EQ(nbTapes, vidToTapeMap.size());
for(uint32_t i = 0; i < nbTapes; i++) {
std::ostringstream vid;
vid << "V" << std::setfill('0') << std::setw(5) << i;
const std::string tapeComment = "Create tape " + vid.str();
const auto tapeItor = vidToTapeMap.find(vid.str());
ASSERT_NE(vidToTapeMap.end(), tapeItor);
ASSERT_EQ(vid.str(), tapeItor->second.vid);
ASSERT_EQ(tapeComment, tapeItor->second.comment);
}
}
TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_0_no_tape_files) {
using namespace cta;
......
......@@ -71,6 +71,7 @@ public:
std::list<TapePool> getTapePools() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
std::list<common::dataStructures::Tape> getTapes(const TapeSearchCriteria& searchCriteria) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
// getTapesByVid is implemented below (and works).
common::dataStructures::VidToTapeMap getAllTapes() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
std::list<TapeForWriting> getTapesForWriting(const std::string& logicalLibraryName) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
bool isAdmin(const common::dataStructures::SecurityIdentity& admin) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyAdminHostComment(const common::dataStructures::SecurityIdentity& admin, const std::string& hostName, const std::string& comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -2030,6 +2030,87 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getTapesByVid(const std::se
}
}
//------------------------------------------------------------------------------
// getAllTapes
//------------------------------------------------------------------------------
common::dataStructures::VidToTapeMap RdbmsCatalogue::getAllTapes() const {
try {
common::dataStructures::VidToTapeMap vidToTapeMap;
std::string sql =
"SELECT "
"VID AS VID,"
"LOGICAL_LIBRARY_NAME AS LOGICAL_LIBRARY_NAME,"
"TAPE_POOL_NAME AS TAPE_POOL_NAME,"
"ENCRYPTION_KEY AS ENCRYPTION_KEY,"
"CAPACITY_IN_BYTES AS CAPACITY_IN_BYTES,"
"DATA_IN_BYTES AS DATA_IN_BYTES,"
"LAST_FSEQ AS LAST_FSEQ,"
"IS_DISABLED AS IS_DISABLED,"
"IS_FULL AS IS_FULL,"
"LBP_IS_ON AS LBP_IS_ON,"
"LABEL_DRIVE AS LABEL_DRIVE,"
"LABEL_TIME AS LABEL_TIME,"
"LAST_READ_DRIVE AS LAST_READ_DRIVE,"
"LAST_READ_TIME AS LAST_READ_TIME,"
"LAST_WRITE_DRIVE AS LAST_WRITE_DRIVE,"
"LAST_WRITE_TIME AS LAST_WRITE_TIME,"
"USER_COMMENT AS USER_COMMENT,"
"CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
"CREATION_LOG_TIME AS CREATION_LOG_TIME,"
"LAST_UPDATE_USER_NAME AS LAST_UPDATE_USER_NAME,"
"LAST_UPDATE_HOST_NAME AS LAST_UPDATE_HOST_NAME,"
"LAST_UPDATE_TIME AS LAST_UPDATE_TIME "
"FROM "
"TAPE";
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(sql, rdbms::AutocommitMode::OFF);
auto rset = stmt.executeQuery();
while (rset.next()) {
common::dataStructures::Tape tape;
tape.vid = rset.columnString("VID");
tape.logicalLibraryName = rset.columnString("LOGICAL_LIBRARY_NAME");
tape.tapePoolName = rset.columnString("TAPE_POOL_NAME");
tape.encryptionKey = rset.columnOptionalString("ENCRYPTION_KEY");
tape.capacityInBytes = rset.columnUint64("CAPACITY_IN_BYTES");
tape.dataOnTapeInBytes = rset.columnUint64("DATA_IN_BYTES");
tape.lastFSeq = rset.columnUint64("LAST_FSEQ");
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");
tape.lastWriteLog = getTapeLogFromRset(rset, "LAST_WRITE_DRIVE", "LAST_WRITE_TIME");
tape.comment = rset.columnString("USER_COMMENT");
tape.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME");
tape.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME");
tape.creationLog.time = rset.columnUint64("CREATION_LOG_TIME");
tape.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME");
tape.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME");
tape.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME");
vidToTapeMap[tape.vid] = tape;
}
return vidToTapeMap;
} catch (exception::LostDatabaseConnection &le) {
throw exception::LostDatabaseConnection(std::string(__FUNCTION__) + " failed: " + le.getMessage().str());
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// reclaimTape
//------------------------------------------------------------------------------
......
......@@ -341,6 +341,13 @@ public:
*/
common::dataStructures::VidToTapeMap getTapesByVid(const std::set<std::string> &vids) const override;
/**
* Returns all the tapes within the CTA catalogue.
*
* @return Map from tape volume identifier to tape.
*/
common::dataStructures::VidToTapeMap getAllTapes() const override;
/**
* Reclaims the specified tape.
*
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment