Commit e11c27e9 authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

cta/CTA#534: The road to migration

Add isFromCastor field to the catalogue DB.

CTA only sets this filed to false and respects it in the getTapesForWriting
parent 875eb148
......@@ -284,7 +284,7 @@ public:
/**
* Creates a tape which is assumed to have logical block protection (LBP)
* enabled.
* enabled and isFromCastor disabled.
*/
virtual void createTape(
const common::dataStructures::SecurityIdentity &admin,
......@@ -381,6 +381,14 @@ public:
* @param vid The volume identifier of the tape.
*/
virtual void setTapeReadOnlyOnError(const std::string &vid) = 0;
/**
* This method notifies the CTA catalogue to set the specified tape is from CASTOR.
* This method only for unitTests and MUST never be called in CTA!!!
*
* @param vid The volume identifier of the tape.
*/
virtual void setTapeIsFromCastorInUnitTests(const std::string &vid) = 0;
virtual void setTapeDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const bool disabledValue) = 0;
virtual void modifyTapeComment(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &comment) = 0;
......
......@@ -269,6 +269,10 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->setTapeReadOnlyOnError(vid);}, m_maxTriesToConnect);
}
void setTapeIsFromCastorInUnitTests(const std::string &vid) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->setTapeIsFromCastorInUnitTests(vid);}, m_maxTriesToConnect);
}
void setTapeDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const bool disabledValue) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->setTapeDisabled(admin, vid, disabledValue);}, m_maxTriesToConnect);
}
......
This diff is collapsed.
......@@ -116,6 +116,7 @@ public:
void setTapeFull(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const bool fullValue) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void setTapeReadOnly(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const bool readOnlyValue) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void setTapeReadOnlyOnError(const std::string &vid) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void setTapeIsFromCastorInUnitTests(const std::string &vid) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void setTapePoolEncryption(const common::dataStructures::SecurityIdentity& admin, const std::string& name, const bool encryptionValue) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
bool tapeExists(const std::string& vid) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void tapeLabelled(const std::string& vid, const std::string& drive) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -155,6 +155,7 @@ common::dataStructures::Tape MysqlCatalogue::selectTapeForUpdate(rdbms::Conn &co
"IS_DISABLED AS IS_DISABLED,"
"IS_FULL AS IS_FULL,"
"IS_READ_ONLY AS IS_READ_ONLY,"
"IS_FROM_CASTOR AS IS_FROM_CASTOR,"
"LABEL_DRIVE AS LABEL_DRIVE,"
"LABEL_TIME AS LABEL_TIME,"
......@@ -198,6 +199,7 @@ common::dataStructures::Tape MysqlCatalogue::selectTapeForUpdate(rdbms::Conn &co
tape.disabled = rset.columnBool("IS_DISABLED");
tape.full = rset.columnBool("IS_FULL");
tape.readOnly = rset.columnBool("IS_READ_ONLY");
tape.isFromCastor = rset.columnBool("IS_FROM_CASTOR");
tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME");
tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME");
......
......@@ -219,6 +219,7 @@ common::dataStructures::Tape OracleCatalogue::selectTapeForUpdate(rdbms::Conn &c
"IS_DISABLED AS IS_DISABLED,"
"IS_FULL AS IS_FULL,"
"IS_READ_ONLY AS IS_READ_ONLY,"
"IS_FROM_CASTOR AS IS_FROM_CASTOR,"
"LABEL_DRIVE AS LABEL_DRIVE,"
"LABEL_TIME AS LABEL_TIME,"
......@@ -262,6 +263,7 @@ common::dataStructures::Tape OracleCatalogue::selectTapeForUpdate(rdbms::Conn &c
tape.disabled = rset.columnBool("IS_DISABLED");
tape.full = rset.columnBool("IS_FULL");
tape.readOnly = rset.columnBool("IS_READ_ONLY");
tape.isFromCastor = rset.columnBool("IS_FROM_CASTOR");
tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME");
tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME");
......
......@@ -210,6 +210,7 @@ common::dataStructures::Tape PostgresCatalogue::selectTapeForUpdate(rdbms::Conn
"IS_DISABLED AS IS_DISABLED,"
"IS_FULL AS IS_FULL,"
"IS_READ_ONLY AS IS_READ_ONLY,"
"IS_FROM_CASTOR AS IS_FROM_CASTOR,"
"LABEL_DRIVE AS LABEL_DRIVE,"
"LABEL_TIME AS LABEL_TIME,"
......@@ -253,6 +254,7 @@ common::dataStructures::Tape PostgresCatalogue::selectTapeForUpdate(rdbms::Conn
tape.disabled = rset.columnBool("IS_DISABLED");
tape.full = rset.columnBool("IS_FULL");
tape.readOnly = rset.columnBool("IS_READ_ONLY");
tape.isFromCastor = rset.columnBool("IS_FROM_CASTOR");
tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME");
tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME");
......
......@@ -1734,6 +1734,8 @@ void RdbmsCatalogue::createTape(
const bool full,
const bool readOnly,
const std::string &comment) {
// CTA hard code this field to FALSE
const bool isFromCastor = false;
try {
if(vid.empty()) {
throw UserSpecifiedAnEmptyStringVid("Cannot create tape because the VID is an empty string");
......@@ -1791,6 +1793,7 @@ void RdbmsCatalogue::createTape(
"IS_DISABLED,"
"IS_FULL,"
"IS_READ_ONLY,"
"IS_FROM_CASTOR,"
"USER_COMMENT,"
......@@ -1813,6 +1816,7 @@ void RdbmsCatalogue::createTape(
":IS_DISABLED,"
":IS_FULL,"
":IS_READ_ONLY,"
":IS_FROM_CASTOR,"
":USER_COMMENT,"
......@@ -1836,6 +1840,7 @@ void RdbmsCatalogue::createTape(
stmt.bindBool(":IS_DISABLED", disabled);
stmt.bindBool(":IS_FULL", full);
stmt.bindBool(":IS_READ_ONLY", readOnly);
stmt.bindBool(":IS_FROM_CASTOR", isFromCastor);
stmt.bindString(":USER_COMMENT", comment);
......@@ -1974,6 +1979,7 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
"TAPE.IS_DISABLED AS IS_DISABLED,"
"TAPE.IS_FULL AS IS_FULL,"
"TAPE.IS_READ_ONLY AS IS_READ_ONLY,"
"TAPE.IS_FROM_CASTOR AS IS_FROM_CASTOR,"
"TAPE.LABEL_DRIVE AS LABEL_DRIVE,"
"TAPE.LABEL_TIME AS LABEL_TIME,"
......@@ -2095,6 +2101,7 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
tape.disabled = rset.columnBool("IS_DISABLED");
tape.full = rset.columnBool("IS_FULL");
tape.readOnly = rset.columnBool("IS_READ_ONLY");
tape.isFromCastor = rset.columnBool("IS_FROM_CASTOR");
tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME");
tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME");
......@@ -2141,6 +2148,7 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getTapesByVid(const std::se
"TAPE.IS_DISABLED AS IS_DISABLED,"
"TAPE.IS_FULL AS IS_FULL,"
"TAPE.IS_READ_ONLY AS IS_READ_ONLY,"
"TAPE.IS_FROM_CASTOR AS IS_FROM_CASTOR,"
"TAPE.LABEL_DRIVE AS LABEL_DRIVE,"
"TAPE.LABEL_TIME AS LABEL_TIME,"
......@@ -2209,6 +2217,7 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getTapesByVid(const std::se
tape.disabled = rset.columnBool("IS_DISABLED");
tape.full = rset.columnBool("IS_FULL");
tape.readOnly = rset.columnBool("IS_READ_ONLY");
tape.isFromCastor = rset.columnBool("IS_FROM_CASTOR");
tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME");
tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME");
......@@ -2258,7 +2267,8 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getAllTapes() const {
"TAPE.LAST_FSEQ AS LAST_FSEQ,"
"TAPE.IS_DISABLED AS IS_DISABLED,"
"TAPE.IS_FULL AS IS_FULL,"
"TAPE.IS_READ_ONLY AS IS_READ_ONLY,"
"TAPE.IS_READ_ONLY AS IS_READ_ONLY,"
"TAPE.IS_FROM_CASTOR AS IS_FROM_CASTOR,"
"TAPE.LABEL_DRIVE AS LABEL_DRIVE,"
"TAPE.LABEL_TIME AS LABEL_TIME,"
......@@ -2303,6 +2313,7 @@ common::dataStructures::VidToTapeMap RdbmsCatalogue::getAllTapes() const {
tape.disabled = rset.columnBool("IS_DISABLED");
tape.full = rset.columnBool("IS_FULL");
tape.readOnly = rset.columnBool("IS_READ_ONLY");
tape.isFromCastor = rset.columnBool("IS_FROM_CASTOR");
tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME");
tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME");
......@@ -2854,6 +2865,32 @@ void RdbmsCatalogue::setTapeReadOnlyOnError(const std::string &vid) {
}
}
//------------------------------------------------------------------------------
// setTapeIsFromCastorInUnitTests
//------------------------------------------------------------------------------
void RdbmsCatalogue::setTapeIsFromCastorInUnitTests(const std::string &vid) {
try {
const char *const sql =
"UPDATE TAPE SET "
"IS_FROM_CASTOR = '1' "
"WHERE "
"VID = :VID";
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(sql);
stmt.bindString(":VID", vid);
stmt.executeNonQuery();
if (0 == stmt.getNbAffectedRows()) {
throw exception::Exception(std::string("Tape ") + vid + " does not exist");
}
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// setTapeDisabled
//------------------------------------------------------------------------------
......@@ -5251,6 +5288,7 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string &
"IS_DISABLED = '0' AND "
"IS_FULL = '0' AND "
"IS_READ_ONLY = '0' AND "
"IS_FROM_CASTOR = '0' AND "
"LOGICAL_LIBRARY_NAME = :LOGICAL_LIBRARY_NAME";
auto conn = m_connPool.getConn();
......
......@@ -396,6 +396,14 @@ public:
*/
void setTapeReadOnlyOnError(const std::string &vid) override;
/**
* This method notifies the CTA catalogue to set the specified tape is from CASTOR.
* This method only for unitTests and MUST never be called in CTA!!!
*
* @param vid The volume identifier of the tape.
*/
void setTapeIsFromCastorInUnitTests(const std::string &vid) override;
void setTapeDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const bool disabledValue) override;
void modifyTapeComment(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &comment) override;
......
......@@ -257,6 +257,8 @@ common::dataStructures::Tape SqliteCatalogue::selectTape(rdbms::Conn &conn, cons
"LAST_FSEQ AS LAST_FSEQ,"
"IS_DISABLED AS IS_DISABLED,"
"IS_FULL AS IS_FULL,"
"IS_READ_ONLY AS IS_READ_ONLY,"
"IS_FROM_CASTOR AS IS_FROM_CASTOR,"
"LABEL_DRIVE AS LABEL_DRIVE,"
"LABEL_TIME AS LABEL_TIME,"
......@@ -299,6 +301,8 @@ common::dataStructures::Tape SqliteCatalogue::selectTape(rdbms::Conn &conn, cons
tape.lastFSeq = rset.columnUint64("LAST_FSEQ");
tape.disabled = rset.columnBool("IS_DISABLED");
tape.full = rset.columnBool("IS_FULL");
tape.readOnly = rset.columnBool("IS_READ_ONLY");
tape.isFromCastor = rset.columnBool("IS_FROM_CASTOR");
tape.labelLog = getTapeLogFromRset(rset, "LABEL_DRIVE", "LABEL_TIME");
tape.lastReadLog = getTapeLogFromRset(rset, "LAST_READ_DRIVE", "LAST_READ_TIME");
......
......@@ -87,6 +87,7 @@ CREATE TABLE TAPE(
IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,
IS_FULL CHAR(1) CONSTRAINT TAPE_IF_NN NOT NULL,
IS_READ_ONLY CHAR(1) CONSTRAINT TAPE_IRO_NN NOT NULL,
IS_FROM_CASTOR CHAR(1) CONSTRAINT TAPE_IFC_NN NOT NULL,
LABEL_DRIVE VARCHAR(100),
LABEL_TIME NUMERIC(20, 0),
LAST_READ_DRIVE VARCHAR(100),
......@@ -109,7 +110,8 @@ CREATE TABLE TAPE(
REFERENCES TAPE_POOL(TAPE_POOL_NAME),
CONSTRAINT TAPE_IS_DISABLED_BOOL_CK CHECK(IS_DISABLED IN ('0', '1')),
CONSTRAINT TAPE_IS_FULL_BOOL_CK CHECK(IS_FULL IN ('0', '1')),
CONSTRAINT TAPE_IS_READ_ONLY_BOOL_CK CHECK(IS_READ_ONLY IN ('0', '1'))
CONSTRAINT TAPE_IS_READ_ONLY_BOOL_CK CHECK(IS_READ_ONLY IN ('0', '1')),
CONSTRAINT TAPE_IS_FROM_CASTOR_BOOL_CK CHECK(IS_FROM_CASTOR IN ('0', '1'))
);
CREATE INDEX TAPE_TAPE_POOL_NAME_IDX ON TAPE(TAPE_POOL_NAME);
CREATE TABLE MOUNT_POLICY(
......
......@@ -49,6 +49,10 @@ CREATE TRIGGER `CHECK_TAPE_BEFORE_INSERT` BEFORE INSERT ON `TAPE`
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_READ_ONLY should be 0 or 1';
END IF;
IF new.IS_FROM_CASTOR not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_FROM_CASTOR should be 0 or 1';
END IF;
END;
CREATE TRIGGER `CHECK_TAPE_BEFORE_UPDATE` BEFORE UPDATE ON `TAPE`
......@@ -66,6 +70,10 @@ CREATE TRIGGER `CHECK_TAPE_BEFORE_UPDATE` BEFORE UPDATE ON `TAPE`
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_READ_ONLY should be 0 or 1';
END IF;
IF new.IS_FROM_CASTOR not in ('0','1') THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'TAPE.IS_FROM_CASTOR should be 0 or 1';
END IF;
END;
CREATE TRIGGER `TAPE_FILE_COPY_NB_GT_ZERO_BEFORE_INSERT` BEFORE INSERT ON `TAPE_FILE`
......
......@@ -63,6 +63,7 @@ struct Tape {
bool full;
bool disabled;
bool readOnly;
bool isFromCastor;
EntryLog creationLog;
EntryLog lastModificationLog;
std::string comment;
......
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