Commit 5fff44cf authored by Steven Murray's avatar Steven Murray
Browse files

Implemented RdbmsCatalogue::modifyMountPolicyComment()

parent ec9e5423
......@@ -3656,6 +3656,93 @@ TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyMaxDrivesAllowed_nonExisten
ASSERT_THROW(m_catalogue->modifyMountPolicyMaxDrivesAllowed(m_cliSI, name, maxDrivesAllowed), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyComment) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getMountPolicies().empty());
const std::string name = "mount_policy";
const uint64_t archivePriority = 1;
const uint64_t minArchiveRequestAge = 2;
const uint64_t retrievePriority = 3;
const uint64_t minRetrieveRequestAge = 4;
const uint64_t maxDrivesAllowed = 5;
const std::string &comment = "Create mount policy";
m_catalogue->createMountPolicy(
m_cliSI,
name,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
comment);
{
const std::list<common::dataStructures::MountPolicy> mountPolicies = m_catalogue->getMountPolicies();
ASSERT_EQ(1, mountPolicies.size());
const common::dataStructures::MountPolicy mountPolicy = mountPolicies.front();
ASSERT_EQ(name, mountPolicy.name);
ASSERT_EQ(archivePriority, mountPolicy.archivePriority);
ASSERT_EQ(minArchiveRequestAge, mountPolicy.archiveMinRequestAge);
ASSERT_EQ(retrievePriority, mountPolicy.retrievePriority);
ASSERT_EQ(minRetrieveRequestAge, mountPolicy.retrieveMinRequestAge);
ASSERT_EQ(maxDrivesAllowed, mountPolicy.maxDrivesAllowed);
ASSERT_EQ(comment, mountPolicy.comment);
const common::dataStructures::EntryLog creationLog = mountPolicy.creationLog;
ASSERT_EQ(m_cliSI.username, creationLog.username);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = mountPolicy.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
}
const std::string modifiedComment = "Modified comment";
m_catalogue->modifyMountPolicyComment(m_cliSI, name, modifiedComment);
{
const std::list<common::dataStructures::MountPolicy> mountPolicies = m_catalogue->getMountPolicies();
ASSERT_EQ(1, mountPolicies.size());
const common::dataStructures::MountPolicy mountPolicy = mountPolicies.front();
ASSERT_EQ(name, mountPolicy.name);
ASSERT_EQ(archivePriority, mountPolicy.archivePriority);
ASSERT_EQ(minArchiveRequestAge, mountPolicy.archiveMinRequestAge);
ASSERT_EQ(retrievePriority, mountPolicy.retrievePriority);
ASSERT_EQ(minRetrieveRequestAge, mountPolicy.retrieveMinRequestAge);
ASSERT_EQ(maxDrivesAllowed, mountPolicy.maxDrivesAllowed);
ASSERT_EQ(modifiedComment, mountPolicy.comment);
const common::dataStructures::EntryLog creationLog = mountPolicy.creationLog;
ASSERT_EQ(m_cliSI.username, creationLog.username);
ASSERT_EQ(m_cliSI.host, creationLog.host);
}
}
TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyComment_nonExistentMountPolicy) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getMountPolicies().empty());
const std::string name = "mount_policy";
const std::string comment = "Comment";
ASSERT_THROW(m_catalogue->modifyMountPolicyComment(m_cliSI, name, comment), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, createRequesterMountRule) {
using namespace cta;
......
......@@ -3110,8 +3110,35 @@ void RdbmsCatalogue::modifyMountPolicyMaxDrivesAllowed(const common::dataStructu
//------------------------------------------------------------------------------
// modifyMountPolicyComment
//------------------------------------------------------------------------------
void RdbmsCatalogue::modifyMountPolicyComment(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &name, const std::string &comment) {
throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
void RdbmsCatalogue::modifyMountPolicyComment(const common::dataStructures::SecurityIdentity &cliIdentity,
const std::string &name, const std::string &comment) {
try {
const time_t now = time(nullptr);
const char *const sql =
"UPDATE MOUNT_POLICY SET "
"USER_COMMENT = :USER_COMMENT,"
"LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME,"
"LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME,"
"LAST_UPDATE_TIME = :LAST_UPDATE_TIME "
"WHERE "
"MOUNT_POLICY_NAME = :MOUNT_POLICY_NAME";
auto conn = m_connPool.getConn();
auto stmt = conn->createStmt(sql, rdbms::Stmt::AutocommitMode::ON);
stmt->bindString(":USER_COMMENT", comment);
stmt->bindString(":LAST_UPDATE_USER_NAME", cliIdentity.username);
stmt->bindString(":LAST_UPDATE_HOST_NAME", cliIdentity.host);
stmt->bindUint64(":LAST_UPDATE_TIME", now);
stmt->bindString(":MOUNT_POLICY_NAME", name);
stmt->executeNonQuery();
if(0 == stmt->getNbAffectedRows()) {
throw exception::UserError(std::string("Cannot modify mount policy ") + name + " because they do not exist");
}
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
......
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