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

Implemented RdbmsCatalogue::modifyMountPolicyRetrieveMinRequestAge()

parent caeb2a20
......@@ -3308,7 +3308,6 @@ TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyArchivePriority_nonExistent
ASSERT_THROW(m_catalogue->modifyMountPolicyArchivePriority(m_cliSI, name, archivePriority), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyArchiveMinRequestAge) {
using namespace cta;
......@@ -3483,6 +3482,93 @@ TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyRetrievePriority_nonExisten
ASSERT_THROW(m_catalogue->modifyMountPolicyRetrievePriority(m_cliSI, name, retrievePriority), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyRetrieveMinRequestAge) {
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 uint64_t modifiedMinRetrieveRequestAge = minRetrieveRequestAge + 10;
m_catalogue->modifyMountPolicyRetrieveMinRequestAge(m_cliSI, name, modifiedMinRetrieveRequestAge);
{
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(modifiedMinRetrieveRequestAge, 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);
}
}
TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyRetrieveMinRequestAge_nonExistentMountPolicy) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getMountPolicies().empty());
const std::string name = "mount_policy";
const uint64_t minRetrieveRequestAge = 2;
ASSERT_THROW(m_catalogue->modifyMountPolicyRetrieveMinRequestAge(m_cliSI, name, minRetrieveRequestAge), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, createRequesterMountRule) {
using namespace cta;
......
......@@ -3042,8 +3042,35 @@ void RdbmsCatalogue::modifyMountPolicyRetrievePriority(const common::dataStructu
//------------------------------------------------------------------------------
// modifyMountPolicyRetrieveMinRequestAge
//------------------------------------------------------------------------------
void RdbmsCatalogue::modifyMountPolicyRetrieveMinRequestAge(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &name, const uint64_t minRetrieveRequestAge) {
throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
void RdbmsCatalogue::modifyMountPolicyRetrieveMinRequestAge(const common::dataStructures::SecurityIdentity &cliIdentity,
const std::string &name, const uint64_t minRetrieveRequestAge) {
try {
const time_t now = time(nullptr);
const char *const sql =
"UPDATE MOUNT_POLICY SET "
"RETRIEVE_MIN_REQUEST_AGE = :RETRIEVE_MIN_REQUEST_AGE,"
"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->bindUint64(":RETRIEVE_MIN_REQUEST_AGE", minRetrieveRequestAge);
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