Commit 47fe5096 authored by Steven Murray's avatar Steven Murray
Browse files

Added Catalogue::setLogicalLibraryDisabled()

parent fc5ea160
......@@ -278,6 +278,7 @@ public:
virtual void deleteLogicalLibrary(const std::string &name) = 0;
virtual std::list<common::dataStructures::LogicalLibrary> getLogicalLibraries() const = 0;
virtual void modifyLogicalLibraryComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) = 0;
virtual void setLogicalLibraryDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool disabledValue) = 0;
/**
* Creates a tape which is assumed to have logical block protection (LBP)
......
......@@ -205,6 +205,10 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyLogicalLibraryComment(admin, name, comment);}, m_maxTriesToConnect);
}
void setLogicalLibraryDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool disabledValue) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->setLogicalLibraryDisabled(admin, name, disabledValue);}, m_maxTriesToConnect);
}
void createTape(const common::dataStructures::SecurityIdentity &admin, const std::string &vid, const std::string &mediaType, const std::string &vendor, const std::string &logicalLibraryName, const std::string &tapePoolName, const uint64_t capacityInBytes, const bool disabled, const bool full, const std::string &comment) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->createTape(admin, vid, mediaType, vendor, logicalLibraryName, tapePoolName, capacityInBytes, disabled, full, comment);}, m_maxTriesToConnect);
}
......
......@@ -2304,6 +2304,106 @@ TEST_P(cta_catalogue_CatalogueTest, createLogicalLibrary_same_twice) {
ASSERT_THROW(m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName, logicalLibraryIsDisabled, comment), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, setLogicalLibraryDisabled_true) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getLogicalLibraries().empty());
const std::string logicalLibraryName = "logical_library";
const std::string comment = "Create logical library";
const bool logicalLibraryIsDisabled= false;
m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName, logicalLibraryIsDisabled, comment);
{
const std::list<common::dataStructures::LogicalLibrary> libs =
m_catalogue->getLogicalLibraries();
ASSERT_EQ(1, libs.size());
const common::dataStructures::LogicalLibrary lib = libs.front();
ASSERT_EQ(logicalLibraryName, lib.name);
ASSERT_FALSE(lib.isDisabled);
ASSERT_EQ(comment, lib.comment);
const common::dataStructures::EntryLog creationLog = lib.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
lib.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
const bool modifiedLogicalLibraryIsDisabled= true;
m_catalogue->setLogicalLibraryDisabled(m_admin, logicalLibraryName, modifiedLogicalLibraryIsDisabled);
{
const std::list<common::dataStructures::LogicalLibrary> libs =
m_catalogue->getLogicalLibraries();
ASSERT_EQ(1, libs.size());
const common::dataStructures::LogicalLibrary lib = libs.front();
ASSERT_EQ(logicalLibraryName, lib.name);
ASSERT_EQ(modifiedLogicalLibraryIsDisabled, lib.isDisabled);
ASSERT_EQ(comment, lib.comment);
const common::dataStructures::EntryLog creationLog = lib.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
}
}
TEST_P(cta_catalogue_CatalogueTest, setLogicalLibraryDisabled_false) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getLogicalLibraries().empty());
const std::string logicalLibraryName = "logical_library";
const std::string comment = "Create logical library";
const bool logicalLibraryIsDisabled= false;
m_catalogue->createLogicalLibrary(m_admin, logicalLibraryName, logicalLibraryIsDisabled, comment);
{
const std::list<common::dataStructures::LogicalLibrary> libs =
m_catalogue->getLogicalLibraries();
ASSERT_EQ(1, libs.size());
const common::dataStructures::LogicalLibrary lib = libs.front();
ASSERT_EQ(logicalLibraryName, lib.name);
ASSERT_FALSE(lib.isDisabled);
ASSERT_EQ(comment, lib.comment);
const common::dataStructures::EntryLog creationLog = lib.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
lib.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
const bool modifiedLogicalLibraryIsDisabled= false;
m_catalogue->setLogicalLibraryDisabled(m_admin, logicalLibraryName, modifiedLogicalLibraryIsDisabled);
{
const std::list<common::dataStructures::LogicalLibrary> libs =
m_catalogue->getLogicalLibraries();
ASSERT_EQ(1, libs.size());
const common::dataStructures::LogicalLibrary lib = libs.front();
ASSERT_EQ(logicalLibraryName, lib.name);
ASSERT_EQ(modifiedLogicalLibraryIsDisabled, lib.isDisabled);
ASSERT_EQ(comment, lib.comment);
const common::dataStructures::EntryLog creationLog = lib.creationLog;
ASSERT_EQ(m_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
}
}
TEST_P(cta_catalogue_CatalogueTest, deleteLogicalLibrary) {
using namespace cta;
......
......@@ -76,6 +76,7 @@ public:
void modifyArchiveRouteComment(const common::dataStructures::SecurityIdentity& admin, const std::string& instanceName, const std::string& storageClassName, const uint32_t copyNb, const std::string& comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyArchiveRouteTapePoolName(const common::dataStructures::SecurityIdentity& admin, const std::string& instanceName, const std::string& storageClassName, const uint32_t copyNb, const std::string& tapePoolName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyLogicalLibraryComment(const common::dataStructures::SecurityIdentity& admin, const std::string& name, const std::string& comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void setLogicalLibraryDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool disabledValue) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyMountPolicyArchiveMinRequestAge(const common::dataStructures::SecurityIdentity& admin, const std::string& name, const uint64_t minArchiveRequestAge) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyMountPolicyArchivePriority(const common::dataStructures::SecurityIdentity& admin, const std::string& name, const uint64_t archivePriority) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void modifyMountPolicyComment(const common::dataStructures::SecurityIdentity& admin, const std::string& name, const std::string& comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -1684,6 +1684,41 @@ void RdbmsCatalogue::modifyLogicalLibraryComment(const common::dataStructures::S
}
}
//------------------------------------------------------------------------------
// setLogicalLibraryDisabled
//------------------------------------------------------------------------------
void RdbmsCatalogue::setLogicalLibraryDisabled(const common::dataStructures::SecurityIdentity &admin,
const std::string &name, const bool disabledValue) {
try {
const time_t now = time(nullptr);
const char *const sql =
"UPDATE LOGICAL_LIBRARY 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 "
"LOGICAL_LIBRARY_NAME = :LOGICAL_LIBRARY_NAME";
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(":LOGICAL_LIBRARY_NAME", name);
stmt.executeNonQuery();
if(0 == stmt.getNbAffectedRows()) {
throw exception::UserError(std::string("Cannot modify logical library ") + name + " because it does not exist");
}
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str());
throw;
}
}
//------------------------------------------------------------------------------
// createTape
//------------------------------------------------------------------------------
......
......@@ -273,6 +273,7 @@ public:
void deleteLogicalLibrary(const std::string &name) override;
std::list<common::dataStructures::LogicalLibrary> getLogicalLibraries() const override;
void modifyLogicalLibraryComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) override;
virtual void setLogicalLibraryDisabled(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool disabledValue) override;
/**
* Creates a 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