Commit caeb2a20 authored by Steven Murray's avatar Steven Murray
Browse files

Implemented RdbmsCatalogue::modifyMountPolicyRetrievePriority()

parent 6aad4d92
......@@ -3396,6 +3396,93 @@ TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyArchiveMinRequestAge_nonExi
ASSERT_THROW(m_catalogue->modifyMountPolicyArchiveMinRequestAge(m_cliSI, name, minArchiveRequestAge), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyRetreivePriority) {
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 modifiedRetrievePriority = retrievePriority + 10;
m_catalogue->modifyMountPolicyRetrievePriority(m_cliSI, name, modifiedRetrievePriority);
{
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(modifiedRetrievePriority, 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);
}
}
TEST_P(cta_catalogue_CatalogueTest, modifyMountPolicyRetrievePriority_nonExistentMountPolicy) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getMountPolicies().empty());
const std::string name = "mount_policy";
const uint64_t retrievePriority = 1;
ASSERT_THROW(m_catalogue->modifyMountPolicyRetrievePriority(m_cliSI, name, retrievePriority), exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, createRequesterMountRule) {
using namespace cta;
......
......@@ -3008,8 +3008,35 @@ void RdbmsCatalogue::modifyMountPolicyArchiveMinRequestAge(const common::dataStr
//------------------------------------------------------------------------------
// modifyMountPolicyRetrievePriority
//------------------------------------------------------------------------------
void RdbmsCatalogue::modifyMountPolicyRetrievePriority(const common::dataStructures::SecurityIdentity &cliIdentity, const std::string &name, const uint64_t retrievePriority) {
throw exception::Exception(std::string(__FUNCTION__) + " not implemented");
void RdbmsCatalogue::modifyMountPolicyRetrievePriority(const common::dataStructures::SecurityIdentity &cliIdentity,
const std::string &name, const uint64_t retrievePriority) {
try {
const time_t now = time(nullptr);
const char *const sql =
"UPDATE MOUNT_POLICY SET "
"RETRIEVE_PRIORITY = :RETRIEVE_PRIORITY,"
"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_PRIORITY", retrievePriority);
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