Commit abd9d9c9 authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[tape-lifecycle] The tape.disabled has been replaced by the tape STATE DISABLED

parent cc8bb9d2
......@@ -180,7 +180,7 @@ CREATE TABLE TAPE(
LAST_FSEQ BIGINT UNSIGNED CONSTRAINT TAPE_LF_NN NOT NULL,
NB_MASTER_FILES BIGINT UNSIGNED DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,
MASTER_DATA_IN_BYTES BIGINT UNSIGNED DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,
IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,
IS_DISABLED CHAR(1),
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,
......
......@@ -212,7 +212,7 @@ CREATE TABLE TAPE(
LAST_FSEQ NUMERIC(20, 0) CONSTRAINT TAPE_LF_NN NOT NULL,
NB_MASTER_FILES NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,
MASTER_DATA_IN_BYTES NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,
IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,
IS_DISABLED CHAR(1),
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,
......
......@@ -194,7 +194,7 @@ CREATE TABLE TAPE(
LAST_FSEQ NUMERIC(20, 0) CONSTRAINT TAPE_LF_NN NOT NULL,
NB_MASTER_FILES NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,
MASTER_DATA_IN_BYTES NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,
IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,
IS_DISABLED CHAR(1),
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,
......
......@@ -166,7 +166,7 @@ CREATE TABLE TAPE(
LAST_FSEQ INTEGER CONSTRAINT TAPE_LF_NN NOT NULL,
NB_MASTER_FILES INTEGER DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,
MASTER_DATA_IN_BYTES INTEGER DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,
IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,
IS_DISABLED CHAR(1),
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,
......
......@@ -7170,7 +7170,7 @@ namespace catalogue{
" LAST_FSEQ NUMERIC(20, 0) CONSTRAINT TAPE_LF_NN NOT NULL,"
" NB_MASTER_FILES NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,"
" MASTER_DATA_IN_BYTES NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,"
" IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,"
" IS_DISABLED CHAR(1),"
" 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,"
......@@ -7592,7 +7592,7 @@ namespace catalogue{
" LAST_FSEQ BIGINT UNSIGNED CONSTRAINT TAPE_LF_NN NOT NULL,"
" NB_MASTER_FILES BIGINT UNSIGNED DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,"
" MASTER_DATA_IN_BYTES BIGINT UNSIGNED DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,"
" IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,"
" IS_DISABLED CHAR(1),"
" 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,"
......@@ -7999,7 +7999,7 @@ namespace catalogue{
" LAST_FSEQ INTEGER CONSTRAINT TAPE_LF_NN NOT NULL,"
" NB_MASTER_FILES INTEGER DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,"
" MASTER_DATA_IN_BYTES INTEGER DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,"
" IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,"
" IS_DISABLED CHAR(1),"
" 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,"
......@@ -8432,7 +8432,7 @@ namespace catalogue{
" LAST_FSEQ NUMERIC(20, 0) CONSTRAINT TAPE_LF_NN NOT NULL,"
" NB_MASTER_FILES NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,"
" MASTER_DATA_IN_BYTES NUMERIC(20, 0) DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,"
" IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,"
" IS_DISABLED CHAR(1),"
" 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,"
......
......@@ -612,12 +612,12 @@ public:
virtual void modifyTapeEncryptionKeyName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &encryptionKeyName) = 0;
/**
* Modify the state of the specified tape
* @param admin, the person or the system who modified the state of the tape
* @param vid the VID of the tape to change the state
* @param state the new state
* @param stateReason the reason why the state changes, if the state is ACTIVE and the stateReason is nullopt, the state will be reset to null
* @param stateModifiedBy who modified the state of the tape (operator, tapeserver...)
*/
virtual void modifyTapeState(const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason, const std::string & stateModifiedBy) = 0;
virtual void modifyTapeState(const common::dataStructures::SecurityIdentity &admin,const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason) = 0;
/**
* Sets the full status of the specified tape.
*
......@@ -658,7 +658,7 @@ public:
*/
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 setTapeDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string & reason) = 0;
virtual void setTapeDirty(const std::string & vid) = 0;
......
......@@ -356,8 +356,8 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyTapeEncryptionKeyName(admin, vid, encryptionKeyName);}, m_maxTriesToConnect);
}
void modifyTapeState(const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason, const std::string & stateModifiedBy) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyTapeState(vid, state, stateReason, stateModifiedBy);}, m_maxTriesToConnect);
void modifyTapeState(const common::dataStructures::SecurityIdentity &admin,const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyTapeState(admin,vid, state, stateReason);}, m_maxTriesToConnect);
}
void setTapeFull(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const bool fullValue) override {
......@@ -376,8 +376,8 @@ public:
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);
void setTapeDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string & reason) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->setTapeDisabled(admin, vid, reason);}, m_maxTriesToConnect);
}
void setTapeDirty(const std::string & vid) override {
......
This diff is collapsed.
......@@ -61,10 +61,6 @@ struct CreateTapeAttributes {
*/
bool full;
/**
* True if the tape is disabled.
*/
bool disabled;
/**
* True if the tape is read-only.
......@@ -93,7 +89,6 @@ struct CreateTapeAttributes {
*/
CreateTapeAttributes():
full(false),
disabled(false),
readOnly(false) {
}
}; // struct CreateTapeAttributes
......
......@@ -129,7 +129,7 @@ public:
void modifyStorageClassNbCopies(const common::dataStructures::SecurityIdentity& admin, const std::string& name, const uint64_t nbCopies) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyTapeComment(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const cta::optional<std::string> &comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyTapeEncryptionKeyName(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const std::string& encryptionKeyName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyTapeState(const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason, const std::string & stateModifiedBy) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyTapeState(const common::dataStructures::SecurityIdentity &admin,const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyTapeMediaType(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const std::string& mediaType) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyTapeVendor(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const std::string& vendor) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyTapeLogicalLibraryName(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const std::string& logicalLibraryName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......@@ -150,7 +150,7 @@ public:
void reclaimTape(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, cta::log::LogContext & lc) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void checkTapeForLabel(const std::string& vid) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
uint64_t getNbFilesOnTape(const std::string& vid) const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void setTapeDisabled(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const bool disabledValue) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void setTapeDisabled(const common::dataStructures::SecurityIdentity& admin, const std::string& vid, const std::string & reason) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
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 setTapeDirty(const std::string & vid) 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"); }
......@@ -169,11 +169,11 @@ public:
// Special functions for unit tests.
void addEnabledTape(const std::string & vid) {
threading::MutexLocker lm(m_tapeEnablingMutex);
m_tapeEnabling[vid]=true;
m_tapeEnabling[vid]=common::dataStructures::Tape::ACTIVE;
}
void addDisabledTape(const std::string & vid) {
threading::MutexLocker lm(m_tapeEnablingMutex);
m_tapeEnabling[vid]=false;
m_tapeEnabling[vid]=common::dataStructures::Tape::DISABLED;
}
common::dataStructures::VidToTapeMap getTapesByVid(const std::set<std::string>& vids) const {
// Minimal implementation of VidToMap for retrieve request unit tests. We just support
......@@ -183,9 +183,9 @@ public:
common::dataStructures::VidToTapeMap ret;
for (const auto & v: vids) {
try {
ret[v].disabled = !m_tapeEnabling.at(v);
ret[v].state = m_tapeEnabling.at(v);
} catch (std::out_of_range &) {
ret[v].disabled = false;
ret[v].state = common::dataStructures::Tape::ACTIVE;
}
}
return ret;
......@@ -235,7 +235,7 @@ public:
}
private:
mutable threading::Mutex m_tapeEnablingMutex;
std::map<std::string, bool> m_tapeEnabling;
std::map<std::string, common::dataStructures::Tape::State> m_tapeEnabling;
};
}} // namespace cta::catalogue.
......@@ -3161,7 +3161,6 @@ void RdbmsCatalogue::createTape(
std::string vendor = tape.vendor;
std::string logicalLibraryName = tape.logicalLibraryName;
std::string tapePoolName = tape.tapePoolName;
bool disabled = tape.disabled;
bool full = tape.full;
bool readOnly = tape.readOnly;
// Translate an empty comment string to a NULL database value
......@@ -3234,7 +3233,6 @@ void RdbmsCatalogue::createTape(
"TAPE_POOL_ID," "\n"
"DATA_IN_BYTES," "\n"
"LAST_FSEQ," "\n"
"IS_DISABLED," "\n"
"IS_FULL," "\n"
"IS_READ_ONLY," "\n"
"IS_FROM_CASTOR," "\n"
......@@ -3261,7 +3259,6 @@ void RdbmsCatalogue::createTape(
":TAPE_POOL_ID," "\n"
":DATA_IN_BYTES," "\n"
":LAST_FSEQ," "\n"
":IS_DISABLED," "\n"
":IS_FULL," "\n"
":IS_READ_ONLY," "\n"
":IS_FROM_CASTOR," "\n"
......@@ -3290,16 +3287,15 @@ void RdbmsCatalogue::createTape(
stmt.bindUint64(":TAPE_POOL_ID", tapePoolId.value());
stmt.bindUint64(":DATA_IN_BYTES", 0);
stmt.bindUint64(":LAST_FSEQ", 0);
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", tapeComment);
std::string stateModifiedBy = admin.username + "@" + admin.host;
std::string stateModifiedBy = RdbmsCatalogue::generateTapeStateModifiedBy(admin);
stmt.bindString(":TAPE_STATE",cta::common::dataStructures::Tape::stateToString(tape.state));
stmt.bindString(":STATE_REASON",tape.stateReason);
stmt.bindString(":STATE_REASON",stateReason);
stmt.bindUint64(":STATE_UPDATE_TIME",now);
stmt.bindString(":STATE_MODIFIED_BY", stateModifiedBy);
......@@ -3320,13 +3316,12 @@ void RdbmsCatalogue::createTape(
.add("vendor", vendor)
.add("logicalLibraryName", logicalLibraryName)
.add("tapePoolName", tapePoolName)
.add("isDisabled", disabled ? 1 : 0)
.add("isFull", full ? 1 : 0)
.add("isReadOnly", readOnly ? 1 : 0)
.add("isFromCastor", isFromCastor ? 1 : 0)
.add("userComment", tape.comment ? tape.comment.value() : "")
.add("tapeState",cta::common::dataStructures::Tape::stateToString(tape.state))
.add("stateReason",tape.stateReason ? tape.stateReason.value() : "")
.add("stateReason",stateReason ? stateReason.value() : "")
.add("stateUpdateTime",now)
.add("stateModifiedBy",stateModifiedBy)
.add("creationLogUserName", admin.username)
......@@ -3500,7 +3495,6 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
"TAPE.NB_MASTER_FILES AS NB_MASTER_FILES,"
"TAPE.MASTER_DATA_IN_BYTES AS MASTER_DATA_IN_BYTES,"
"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_FROM_CASTOR AS IS_FROM_CASTOR,"
......@@ -3549,7 +3543,6 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
searchCriteria.tapePool ||
searchCriteria.vo ||
searchCriteria.capacityInBytes ||
searchCriteria.disabled ||
searchCriteria.full ||
searchCriteria.readOnly ||
searchCriteria.diskFileIds ||
......@@ -3593,11 +3586,6 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
sql += " MEDIA_TYPE.CAPACITY_IN_BYTES = :CAPACITY_IN_BYTES";
addedAWhereConstraint = true;
}
if(searchCriteria.disabled) {
if(addedAWhereConstraint) sql += " AND ";
sql += " TAPE.IS_DISABLED = :IS_DISABLED";
addedAWhereConstraint = true;
}
if(searchCriteria.full) {
if(addedAWhereConstraint) sql += " AND ";
sql += " TAPE.IS_FULL = :IS_FULL";
......@@ -3639,7 +3627,6 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
if(searchCriteria.tapePool) stmt.bindString(":TAPE_POOL_NAME", searchCriteria.tapePool.value());
if(searchCriteria.vo) stmt.bindString(":VO", searchCriteria.vo.value());
if(searchCriteria.capacityInBytes) stmt.bindUint64(":CAPACITY_IN_BYTES", searchCriteria.capacityInBytes.value());
if(searchCriteria.disabled) stmt.bindBool(":IS_DISABLED", searchCriteria.disabled.value());
if(searchCriteria.full) stmt.bindBool(":IS_FULL", searchCriteria.full.value());
if(searchCriteria.readOnly) stmt.bindBool(":IS_READ_ONLY", searchCriteria.readOnly.value());
try{
......@@ -3679,7 +3666,6 @@ std::list<common::dataStructures::Tape> RdbmsCatalogue::getTapes(rdbms::Conn &co
tape.nbMasterFiles = rset.columnUint64("NB_MASTER_FILES");
tape.masterDataInBytes = rset.columnUint64("MASTER_DATA_IN_BYTES");
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");
......@@ -3808,7 +3794,6 @@ std::string RdbmsCatalogue::getSelectTapesBy100VidsSql() const {
"MEDIA_TYPE.CAPACITY_IN_BYTES AS CAPACITY_IN_BYTES,"
"TAPE.DATA_IN_BYTES AS DATA_IN_BYTES,"
"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_FROM_CASTOR AS IS_FROM_CASTOR,"
......@@ -3880,7 +3865,6 @@ void RdbmsCatalogue::executeGetTapesBy100VidsStmtAndCollectResults(rdbms::Stmt &
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.readOnly = rset.columnBool("IS_READ_ONLY");
tape.isFromCastor = rset.columnBool("IS_FROM_CASTOR");
......@@ -4492,7 +4476,7 @@ void RdbmsCatalogue::modifyTapeEncryptionKeyName(const common::dataStructures::S
//------------------------------------------------------------------------------
// modifyTapeState
//------------------------------------------------------------------------------
void RdbmsCatalogue::modifyTapeState(const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason, const std::string & stateModifiedBy){
void RdbmsCatalogue::modifyTapeState(const common::dataStructures::SecurityIdentity &admin,const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason){
try {
using namespace common::dataStructures;
const time_t now = time(nullptr);
......@@ -4528,7 +4512,7 @@ void RdbmsCatalogue::modifyTapeState(const std::string &vid, const common::dataS
stmt.bindString(":TAPE_STATE", stateStr);
stmt.bindString(":STATE_REASON", stateReasonCopy);
stmt.bindUint64(":STATE_UPDATE_TIME", now);
stmt.bindString(":STATE_MODIFIED_BY",stateModifiedBy);
stmt.bindString(":STATE_MODIFIED_BY",generateTapeStateModifiedBy(admin));
stmt.bindString(":VID",vid);
stmt.executeNonQuery();
......@@ -4544,6 +4528,10 @@ void RdbmsCatalogue::modifyTapeState(const std::string &vid, const common::dataS
}
}
std::string RdbmsCatalogue::generateTapeStateModifiedBy(const common::dataStructures::SecurityIdentity & admin){
return admin.username + "@" + admin.host;
}
//------------------------------------------------------------------------------
// tapeMountedForArchive
//------------------------------------------------------------------------------
......@@ -4812,38 +4800,10 @@ void RdbmsCatalogue::setTapeIsFromCastorInUnitTests(const std::string &vid) {
// setTapeDisabled
//------------------------------------------------------------------------------
void RdbmsCatalogue::setTapeDisabled(const common::dataStructures::SecurityIdentity &admin,
const std::string &vid, const bool disabledValue) {
const std::string &vid, const std::string & reason) {
try {
const time_t now = time(nullptr);
const char *const sql =
"UPDATE TAPE SET "
"IS_DISABLED = :IS_DISABLED,"
"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);
stmt.bindBool(":IS_DISABLED", disabledValue);
stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username);
stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.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");
}
log::LogContext lc(m_log);
log::ScopedParamContainer spc(lc);
spc.add("vid", vid)
.add("isDisabled", disabledValue ? 1 : 0)
.add("lastUpdateUserName", admin.username)
.add("lastUpdateHostName", admin.host)
.add("lastUpdateTime", now);
lc.log(log::INFO, "Catalogue - user modified tape - isDisabled");
modifyTapeState(admin,vid,common::dataStructures::Tape::DISABLED,reason);
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
......@@ -7770,7 +7730,7 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string &
"WHERE "
// "TAPE.LABEL_DRIVE IS NOT NULL AND " // Set when the tape has been labelled
// "TAPE.LABEL_TIME IS NOT NULL AND " // Set when the tape has been labelled
"TAPE.IS_DISABLED = '0' AND "
"TAPE.TAPE_STATE = :TAPE_STATE AND "
"TAPE.IS_FULL = '0' AND "
"TAPE.IS_READ_ONLY = '0' AND "
"TAPE.IS_FROM_CASTOR = '0' AND "
......@@ -7780,6 +7740,7 @@ std::list<TapeForWriting> RdbmsCatalogue::getTapesForWriting(const std::string &
auto conn = m_connPool.getConn();
auto stmt = conn.createStmt(sql);
stmt.bindString(":LOGICAL_LIBRARY_NAME", logicalLibraryName);
stmt.bindString(":TAPE_STATE",common::dataStructures::Tape::stateToString(common::dataStructures::Tape::ACTIVE));
auto rset = stmt.executeQuery();
while (rset.next()) {
TapeForWriting tape;
......@@ -8014,7 +7975,7 @@ std::unique_ptr<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveF
"TAPE_FILE.VID = TAPE.VID "
"WHERE "
"ARCHIVE_FILE.ARCHIVE_FILE_ID = :ARCHIVE_FILE_ID AND "
"TAPE.IS_DISABLED = '0' "
"TAPE.TAPE_STATE = 'ACTIVE' "
"ORDER BY "
"TAPE_FILE.CREATION_TIME ASC";
auto stmt = conn.createStmt(sql);
......@@ -8241,12 +8202,13 @@ std::unique_ptr<common::dataStructures::ArchiveFile> RdbmsCatalogue::getArchiveF
"WHERE "
"ARCHIVE_FILE.DISK_INSTANCE_NAME = :DISK_INSTANCE_NAME AND "
"ARCHIVE_FILE.DISK_FILE_ID = :DISK_FILE_ID AND "
"TAPE.IS_DISABLED = '0' "
"TAPE.TAPE_STATE = :TAPE_STATE "
"ORDER BY "
"TAPE_FILE.CREATION_TIME ASC";
auto stmt = conn.createStmt(sql);
stmt.bindString(":DISK_INSTANCE_NAME", diskInstanceName);
stmt.bindString(":DISK_FILE_ID", diskFileId);
stmt.bindString(":TAPE_STATE",common::dataStructures::Tape::stateToString(common::dataStructures::Tape::ACTIVE));
auto rset = stmt.executeQuery();
std::unique_ptr<common::dataStructures::ArchiveFile> archiveFile;
while (rset.next()) {
......
......@@ -578,8 +578,8 @@ public:
void modifyTapeLogicalLibraryName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &logicalLibraryName) override;
void modifyTapeTapePoolName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &tapePoolName) override;
void modifyTapeEncryptionKeyName(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &encryptionKeyName) override;
void modifyTapeState(const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason, const std::string & stateModifiedBy) override;
void modifyTapeState(const common::dataStructures::SecurityIdentity &admin,const std::string &vid, const common::dataStructures::Tape::State & state, const cta::optional<std::string> & stateReason) override;
static std::string generateTapeStateModifiedBy(const common::dataStructures::SecurityIdentity & admin);
/**
* Sets the full status of the specified tape.
*
......@@ -620,7 +620,7 @@ public:
*/
void setTapeIsFromCastorInUnitTests(const std::string &vid) override;
void setTapeDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const bool disabledValue) override;
void setTapeDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string & reason) override;
void setTapeDirty(const std::string & vid) override;
void modifyTapeComment(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const cta::optional<std::string> &comment) override;
......
......@@ -72,11 +72,6 @@ struct TapeSearchCriteria {
*/
optional<uint64_t> capacityInBytes;
/**
* Set to true if searching for disabled tapes.
*/
optional<bool> disabled;
/**
* Set to true if searching for full tapes.
*/
......
......@@ -145,7 +145,7 @@ CREATE TABLE TAPE(
LAST_FSEQ UINT64TYPE CONSTRAINT TAPE_LF_NN NOT NULL,
NB_MASTER_FILES UINT64TYPE DEFAULT 0 CONSTRAINT TAPE_NB_MASTER_FILES_NN NOT NULL,
MASTER_DATA_IN_BYTES UINT64TYPE DEFAULT 0 CONSTRAINT TAPE_MASTER_DATA_IN_BYTES_NN NOT NULL,
IS_DISABLED CHAR(1) CONSTRAINT TAPE_ID_NN NOT NULL,
IS_DISABLED CHAR(1),
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,
......
......@@ -235,6 +235,11 @@ ALTER TABLE TAPE DROP COLUMN IS_EXPORTED;
--changeset ccaffy:17 failOnError:true dbms:oracle
--preconditions onFail:HALT onError:HALT
--precondition-sql-check expectedResult:"3.1" SELECT CONCAT(CONCAT(CAST(SCHEMA_VERSION_MAJOR as VARCHAR(10)),'.'), CAST(SCHEMA_VERSION_MINOR AS VARCHAR(10))) AS CATALOGUE_VERSION FROM CTA_CATALOGUE;
ALTER TABLE TAPE DROP CONSTRAINT TAPE_ID_NN;
--changeset ccaffy:18 failOnError:true dbms:oracle
--preconditions onFail:HALT onError:HALT
--precondition-sql-check expectedResult:"3.1" SELECT CONCAT(CONCAT(CAST(SCHEMA_VERSION_MAJOR as VARCHAR(10)),'.'), CAST(SCHEMA_VERSION_MINOR AS VARCHAR(10))) AS CATALOGUE_VERSION FROM CTA_CATALOGUE;
UPDATE CTA_CATALOGUE SET STATUS='PRODUCTION';
UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MAJOR=3;
UPDATE CTA_CATALOGUE SET SCHEMA_VERSION_MINOR=2;
......
......@@ -560,18 +560,18 @@ const std::map<cmd_key_t, cmd_val_t> cmdOptions = {
{{ AdminCmd::CMD_STORAGECLASS, AdminCmd::SUBCMD_LS }, { }},
/*----------------------------------------------------------------------------------------------------*/
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_ADD },
{ opt_vid, opt_mediatype, opt_vendor, opt_logicallibrary, opt_tapepool, opt_disabled, opt_full, opt_readonly,
{ opt_vid, opt_mediatype, opt_vendor, opt_logicallibrary, opt_tapepool, opt_full, opt_readonly,
opt_state.optional(), opt_reason.optional(), opt_comment.optional() }},
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_CH },
{ opt_vid, opt_mediatype.optional(), opt_vendor.optional(), opt_logicallibrary.optional(),
opt_tapepool.optional(), opt_encryptionkeyname.optional(), opt_disabled.optional(),
opt_tapepool.optional(), opt_encryptionkeyname.optional(),
opt_full.optional(), opt_readonly.optional(), opt_state.optional(), opt_reason.optional(), opt_comment.optional() }},
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_RM }, { opt_vid }},
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_RECLAIM }, { opt_vid }},
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_LS },
{ opt_vid.optional(), opt_mediatype.optional(), opt_vendor.optional(),
opt_logicallibrary.optional(), opt_tapepool.optional(), opt_vo.optional(), opt_capacity.optional(),
opt_disabled.optional(), opt_full.optional(), opt_readonly.optional(), opt_fidfile.optional(), opt_all.optional(), opt_state.optional() }},
opt_full.optional(), opt_readonly.optional(), opt_fidfile.optional(), opt_all.optional(), opt_state.optional() }},
{{ AdminCmd::CMD_TAPE, AdminCmd::SUBCMD_LABEL },
{ opt_vid, opt_force.optional() }},
/*----------------------------------------------------------------------------------------------------*/
......
......@@ -35,8 +35,8 @@ Tape::Tape():
nbMasterFiles(0),
masterDataInBytes(0),
full(false),
disabled(false),
readOnly(false)
readOnly(false),
state(Tape::State::ACTIVE)
{}
const std::map<Tape::State,std::string> Tape::STATE_TO_STRING_MAP = {
......@@ -73,7 +73,7 @@ bool Tape::operator==(const Tape &rhs) const {
&& dataOnTapeInBytes==rhs.dataOnTapeInBytes
&& encryptionKeyName==rhs.encryptionKeyName
&& full==rhs.full
&& disabled==rhs.disabled
&& state==rhs.state
&& readOnly==rhs.readOnly
&& creationLog==rhs.creationLog
&& lastModificationLog==rhs.lastModificationLog
......@@ -116,11 +116,20 @@ Tape::State Tape::stringToState(const std::string& state) {
}
}
bool Tape::isDisabled() const {
return state == Tape::State::DISABLED;
}
//------------------------------------------------------------------------------
// operator<<
//------------------------------------------------------------------------------
std::ostream &operator<<(std::ostream &os, const Tape &obj) {
std::string stateStr = "UNKNOWN";
try {
stateStr = Tape::stateToString(obj.state);
} catch(const cta::exception::Exception &ex){
//Do nothing
}
os << "(vid=" << obj.vid
<< " lastFSeq=" << obj.lastFSeq
<< " logicalLibraryName=" << obj.logicalLibraryName
......@@ -129,11 +138,14 @@ std::ostream &operator<<(std::ostream &os, const Tape &obj) {
<< " dataOnTapeInBytes=" << obj.dataOnTapeInBytes
<< " encryptionKeyName=" << (obj.encryptionKeyName ? obj.encryptionKeyName.value() : "null")
<< " full=" << obj.full
<< " disabled=" << obj.disabled
<< " readOnly=" << obj.readOnly
<< " creationLog=" << obj.creationLog
<< " lastModificationLog=" << obj.lastModificationLog
<< " comment=" << obj.comment
<< " state=" << stateStr
<< " stateReason=" << (obj.stateReason ? obj.stateReason.value() : "null")
<< " stateUpdateTime=" << obj.stateUpdateTime
<< " stateModifiedBy=" << obj.stateModifiedBy
<< " labelLog=" << obj.labelLog
<< " lastWriteLog=" << obj.lastWriteLog
<< " lastReadLog=" << obj.lastReadLog << ")";
......
......@@ -113,6 +113,8 @@ struct Tape {
std::string stateModifiedBy;
time_t stateUpdateTime;
bool isDisabled() const;
}; // struct Tape
std::ostream &operator<<(std::ostream &os, const Tape &obj);
......
......@@ -162,7 +162,6 @@ kubectl --namespace ${NAMESPACE} exec ctacli -- cta-admin --json version | jq
--tapepool ctasystest \
--comment "ctasystest" \
--vid ${VID} \
--disabled false \
--full false \
--readonly false \
--comment "ctasystest"
......
......@@ -384,8 +384,8 @@ std::string Helpers::selectBestRetrieveQueue(const std::set<std::string>& candid
grqsmLock.unlock();
updateFuture.wait();
grqsmLock.lock();
if(!g_retrieveQueueStatistics.at(v).tapeStatus.disabled || (g_retrieveQueueStatistics.at(v).tapeStatus.disabled && forceDisabledTape)) {
logUpdateCacheIfNeeded(false,g_retrieveQueueStatistics.at(v),"!g_retrieveQueueStatistics.at(v).tapeStatus.disabled || (g_retrieveQueueStatistics.at(v).tapeStatus.disabled && forceDisabledTape)");
if(g_retrieveQueueStatistics.at(v).tapeStatus.state == common::dataStructures::Tape::ACTIVE || (g_retrieveQueueStatistics.at(v).tapeStatus.isDisabled() && forceDisabledTape)) {
logUpdateCacheIfNeeded(false,g_retrieveQueueStatistics.at(v),"g_retrieveQueueStatistics.at(v).tapeStatus.state == common::dataStructures::Tape::ACTIVE || (g_retrieveQueueStatistics.at(v).tapeStatus.isDisabled() && forceDisabledTape)");
candidateVidsStats.emplace_back(g_retrieveQueueStatistics.at(v).stats);
}
} else {
......@@ -400,7 +400,7 @@ std::string Helpers::selectBestRetrieveQueue(const std::set<std::string>& candid
logUpdateCacheIfNeeded(false,g_retrieveQueueStatistics.at(v),"Cache is not updated, timeSinceLastUpdate ("+std::to_string(timeSinceLastUpdate)+
") <= c_retrieveQueueCacheMaxAge ("+std::to_string(c_retrieveQueueCacheMaxAge)+")");
// We're lucky: cache hit (and not stale)
if (!g_retrieveQueueStatistics.at(v).tapeStatus.disabled || (g_retrieveQueueStatistics.at(v).tapeStatus.disabled && forceDisabledTape))
if (g_retrieveQueueStatistics.at(v).tapeStatus.state == common::dataStructures::Tape::ACTIVE || (g_retrieveQueueStatistics.at(v).tapeStatus.isDisabled() && forceDisabledTape))