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

Added unit-test prepareForNewFile_requester_mount_rule_overide

parent 794f2433
......@@ -325,6 +325,15 @@ public:
virtual common::dataStructures::TapeCopyToPoolMap getTapeCopyToPoolMap(const std::string &storageClass) const = 0;
/**
* Returns true if the specified user running the CTA command-line tool on
* the specified host has administrator privileges.
*
* @param cliIdentity The name of the user and the host on which they are
* running the CTA command-line tool.
* @return True if the specified user running the CTA command-line tool on
* the specified host has administrator privileges.
*/
virtual bool isAdmin(const common::dataStructures::SecurityIdentity &cliIdentity) const = 0;
/**
......
......@@ -1247,17 +1247,17 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, createRequesterMountRule) {
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_cliSI, mountPolicyName, requesterName, comment);
const std::list<common::dataStructures::RequesterMountRule> requesters = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, requesters.size());
const std::list<common::dataStructures::RequesterMountRule> rules = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, rules.size());
const common::dataStructures::RequesterMountRule requester = requesters.front();
const common::dataStructures::RequesterMountRule rule = rules.front();
ASSERT_EQ(requesterName, requester.name);
ASSERT_EQ(mountPolicyName, requester.mountPolicy);
ASSERT_EQ(comment, requester.comment);
ASSERT_EQ(m_cliSI.username, requester.creationLog.username);
ASSERT_EQ(m_cliSI.host, requester.creationLog.host);
ASSERT_EQ(requester.creationLog, requester.lastModificationLog);
ASSERT_EQ(requesterName, rule.name);
ASSERT_EQ(mountPolicyName, rule.mountPolicy);
ASSERT_EQ(comment, rule.comment);
ASSERT_EQ(m_cliSI.username, rule.creationLog.username);
ASSERT_EQ(m_cliSI.host, rule.creationLog.host);
ASSERT_EQ(rule.creationLog, rule.lastModificationLog);
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, createRequesterMountRule_same_twice) {
......@@ -1480,7 +1480,7 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, deleteRequesterGroupMountRule_non_ex
ASSERT_THROW(m_catalogue->deleteRequesterGroupMountRule("non_existant_requester_group"), catalogue::UserError);
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareForNewFile) {
TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareForNewFile_requester_mount_rule) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getRequesterMountRules().empty());
......@@ -1500,23 +1500,23 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareForNewFile) {
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"create mount group");
"create mount policy");
const std::string comment = "create mount rule for requester";
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_cliSI, mountPolicyName, requesterName, comment);
const std::list<common::dataStructures::RequesterMountRule> requesters = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, requesters.size());
const std::list<common::dataStructures::RequesterMountRule> rules = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, rules.size());
const common::dataStructures::RequesterMountRule requester = requesters.front();
const common::dataStructures::RequesterMountRule rule = rules.front();
ASSERT_EQ(requesterName, requester.name);
ASSERT_EQ(mountPolicyName, requester.mountPolicy);
ASSERT_EQ(comment, requester.comment);
ASSERT_EQ(m_cliSI.username, requester.creationLog.username);
ASSERT_EQ(m_cliSI.host, requester.creationLog.host);
ASSERT_EQ(requester.creationLog, requester.lastModificationLog);
ASSERT_EQ(requesterName, rule.name);
ASSERT_EQ(mountPolicyName, rule.mountPolicy);
ASSERT_EQ(comment, rule.comment);
ASSERT_EQ(m_cliSI.username, rule.creationLog.username);
ASSERT_EQ(m_cliSI.host, rule.creationLog.host);
ASSERT_EQ(rule.creationLog, rule.lastModificationLog);
ASSERT_TRUE(m_catalogue->getArchiveRoutes().empty());
......@@ -1528,16 +1528,13 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareForNewFile) {
const std::string tapePoolName = "tape_pool";
const uint64_t nbPartialTapes = 2;
const bool is_encrypted = true;
m_catalogue->createTapePool(m_cliSI, tapePoolName, nbPartialTapes, is_encrypted,
"create tape pool");
m_catalogue->createTapePool(m_cliSI, tapePoolName, nbPartialTapes, is_encrypted, "create tape pool");
const uint64_t copyNb = 1;
const std::string archiveRouteComment = "create archive route";
m_catalogue->createArchiveRoute(m_cliSI, storageClassName, copyNb, tapePoolName,
archiveRouteComment);
m_catalogue->createArchiveRoute(m_cliSI, storageClassName, copyNb, tapePoolName, archiveRouteComment);
const std::list<common::dataStructures::ArchiveRoute> routes =
m_catalogue->getArchiveRoutes();
const std::list<common::dataStructures::ArchiveRoute> routes = m_catalogue->getArchiveRoutes();
ASSERT_EQ(1, routes.size());
......@@ -1551,8 +1548,107 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareForNewFile) {
ASSERT_EQ(m_cliSI.username, creationLog.username);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
route.lastModificationLog;
const common::dataStructures::EntryLog lastModificationLog = route.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
common::dataStructures::TapeCopyToPoolMap copyToPoolMap = m_catalogue->getTapeCopyToPoolMap(storageClassName);
ASSERT_EQ(1, copyToPoolMap.size());
std::pair<uint64_t, std::string> maplet = *(copyToPoolMap.begin());
ASSERT_EQ(copyNb, maplet.first);
ASSERT_EQ(tapePoolName, maplet.second);
common::dataStructures::UserIdentity userIdentity;
userIdentity.name = requesterName;
userIdentity.group = "group";
uint64_t expectedArchiveFileId = 0;
for(uint64_t i = 0; i<10; i++) {
const common::dataStructures::ArchiveFileQueueCriteria queueCriteria =
m_catalogue->prepareForNewFile(storageClassName, userIdentity);
if(0 == i) {
expectedArchiveFileId = queueCriteria.fileId;
} else {
expectedArchiveFileId++;
}
ASSERT_EQ(expectedArchiveFileId, queueCriteria.fileId);
ASSERT_EQ(1, queueCriteria.copyToPoolMap.size());
ASSERT_EQ(copyNb, queueCriteria.copyToPoolMap.begin()->first);
ASSERT_EQ(tapePoolName, queueCriteria.copyToPoolMap.begin()->second);
ASSERT_EQ(archivePriority, queueCriteria.mountPolicy.archivePriority);
ASSERT_EQ(minArchiveRequestAge, queueCriteria.mountPolicy.archiveMinRequestAge);
ASSERT_EQ(maxDrivesAllowed, queueCriteria.mountPolicy.maxDrivesAllowed);
}
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareForNewFile_requester_group_mount_rule) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getRequesterMountRules().empty());
const std::string mountPolicyName = "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;
m_catalogue->createMountPolicy(
m_cliSI,
mountPolicyName,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"create mount policy");
const std::string comment = "create mount rule for requester group";
const std::string requesterGroupName = "requester_group_name";
m_catalogue->createRequesterGroupMountRule(m_cliSI, mountPolicyName, requesterGroupName, comment);
const std::list<common::dataStructures::RequesterGroupMountRule> rules = m_catalogue->getRequesterGroupMountRules();
ASSERT_EQ(1, rules.size());
const common::dataStructures::RequesterGroupMountRule rule = rules.front();
ASSERT_EQ(requesterGroupName, rule.name);
ASSERT_EQ(mountPolicyName, rule.mountPolicy);
ASSERT_EQ(comment, rule.comment);
ASSERT_EQ(m_cliSI.username, rule.creationLog.username);
ASSERT_EQ(m_cliSI.host, rule.creationLog.host);
ASSERT_EQ(rule.creationLog, rule.lastModificationLog);
ASSERT_TRUE(m_catalogue->getArchiveRoutes().empty());
const std::string storageClassName = "storage_class";
const uint64_t nbCopies = 2;
m_catalogue->createStorageClass(m_cliSI, storageClassName, nbCopies, "create storage class");
const std::string tapePoolName = "tape_pool";
const uint64_t nbPartialTapes = 2;
const bool is_encrypted = true;
m_catalogue->createTapePool(m_cliSI, tapePoolName, nbPartialTapes, is_encrypted, "create tape pool");
const uint64_t copyNb = 1;
const std::string archiveRouteComment = "create archive route";
m_catalogue->createArchiveRoute(m_cliSI, storageClassName, copyNb, tapePoolName, archiveRouteComment);
const std::list<common::dataStructures::ArchiveRoute> routes = m_catalogue->getArchiveRoutes();
ASSERT_EQ(1, routes.size());
const common::dataStructures::ArchiveRoute route = routes.front();
ASSERT_EQ(storageClassName, route.storageClassName);
ASSERT_EQ(copyNb, route.copyNb);
ASSERT_EQ(tapePoolName, route.tapePoolName);
ASSERT_EQ(archiveRouteComment, route.comment);
const common::dataStructures::EntryLog creationLog = route.creationLog;
ASSERT_EQ(m_cliSI.username, creationLog.username);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = route.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
common::dataStructures::TapeCopyToPoolMap copyToPoolMap =
......@@ -1562,6 +1658,124 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareForNewFile) {
ASSERT_EQ(copyNb, maplet.first);
ASSERT_EQ(tapePoolName, maplet.second);
common::dataStructures::UserIdentity userIdentity;
userIdentity.name = "username";
userIdentity.group = requesterGroupName;
uint64_t expectedArchiveFileId = 0;
for(uint64_t i = 0; i<10; i++) {
const common::dataStructures::ArchiveFileQueueCriteria queueCriteria =
m_catalogue->prepareForNewFile(storageClassName, userIdentity);
if(0 == i) {
expectedArchiveFileId = queueCriteria.fileId;
} else {
expectedArchiveFileId++;
}
ASSERT_EQ(expectedArchiveFileId, queueCriteria.fileId);
ASSERT_EQ(1, queueCriteria.copyToPoolMap.size());
ASSERT_EQ(copyNb, queueCriteria.copyToPoolMap.begin()->first);
ASSERT_EQ(tapePoolName, queueCriteria.copyToPoolMap.begin()->second);
ASSERT_EQ(archivePriority, queueCriteria.mountPolicy.archivePriority);
ASSERT_EQ(minArchiveRequestAge, queueCriteria.mountPolicy.archiveMinRequestAge);
ASSERT_EQ(maxDrivesAllowed, queueCriteria.mountPolicy.maxDrivesAllowed);
}
}
TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareForNewFile_requester_mount_rule_overide) {
using namespace cta;
ASSERT_TRUE(m_catalogue->getRequesterMountRules().empty());
const std::string mountPolicyName = "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;
m_catalogue->createMountPolicy(
m_cliSI,
mountPolicyName,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"create mount policy");
const std::string requesterRuleComment = "create mount rule for requester";
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_cliSI, mountPolicyName, requesterName, requesterRuleComment);
const std::list<common::dataStructures::RequesterMountRule> requesterRules = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, requesterRules.size());
const common::dataStructures::RequesterMountRule requesterRule = requesterRules.front();
ASSERT_EQ(requesterName, requesterRule.name);
ASSERT_EQ(mountPolicyName, requesterRule.mountPolicy);
ASSERT_EQ(requesterRuleComment, requesterRule.comment);
ASSERT_EQ(m_cliSI.username, requesterRule.creationLog.username);
ASSERT_EQ(m_cliSI.host, requesterRule.creationLog.host);
ASSERT_EQ(requesterRule.creationLog, requesterRule.lastModificationLog);
const std::string requesterGroupRuleComment = "create mount rule for requester group";
const std::string requesterGroupName = "requester_group_name";
m_catalogue->createRequesterGroupMountRule(m_cliSI, mountPolicyName, requesterName, requesterGroupRuleComment);
const std::list<common::dataStructures::RequesterGroupMountRule> requesterGroupRules =
m_catalogue->getRequesterGroupMountRules();
ASSERT_EQ(1, requesterGroupRules.size());
const common::dataStructures::RequesterGroupMountRule requesterGroupRule = requesterGroupRules.front();
ASSERT_EQ(requesterName, requesterGroupRule.name);
ASSERT_EQ(mountPolicyName, requesterGroupRule.mountPolicy);
ASSERT_EQ(requesterGroupRuleComment, requesterGroupRule.comment);
ASSERT_EQ(m_cliSI.username, requesterGroupRule.creationLog.username);
ASSERT_EQ(m_cliSI.host, requesterGroupRule.creationLog.host);
ASSERT_EQ(requesterGroupRule.creationLog, requesterGroupRule.lastModificationLog);
ASSERT_TRUE(m_catalogue->getArchiveRoutes().empty());
const std::string storageClassName = "storage_class";
const uint64_t nbCopies = 2;
m_catalogue->createStorageClass(m_cliSI, storageClassName, nbCopies,
"create storage class");
const std::string tapePoolName = "tape_pool";
const uint64_t nbPartialTapes = 2;
const bool is_encrypted = true;
m_catalogue->createTapePool(m_cliSI, tapePoolName, nbPartialTapes, is_encrypted, "create tape pool");
const uint64_t copyNb = 1;
const std::string archiveRouteComment = "create archive route";
m_catalogue->createArchiveRoute(m_cliSI, storageClassName, copyNb, tapePoolName, archiveRouteComment);
const std::list<common::dataStructures::ArchiveRoute> routes = m_catalogue->getArchiveRoutes();
ASSERT_EQ(1, routes.size());
const common::dataStructures::ArchiveRoute route = routes.front();
ASSERT_EQ(storageClassName, route.storageClassName);
ASSERT_EQ(copyNb, route.copyNb);
ASSERT_EQ(tapePoolName, route.tapePoolName);
ASSERT_EQ(archiveRouteComment, route.comment);
const common::dataStructures::EntryLog creationLog = route.creationLog;
ASSERT_EQ(m_cliSI.username, creationLog.username);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = route.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
common::dataStructures::TapeCopyToPoolMap copyToPoolMap = m_catalogue->getTapeCopyToPoolMap(storageClassName);
ASSERT_EQ(1, copyToPoolMap.size());
std::pair<uint64_t, std::string> maplet = *(copyToPoolMap.begin());
ASSERT_EQ(copyNb, maplet.first);
ASSERT_EQ(tapePoolName, maplet.second);
common::dataStructures::UserIdentity userIdentity;
userIdentity.name = requesterName;
userIdentity.group = "group";
......@@ -1601,8 +1815,7 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareToRetrieveFile) {
const bool fullValue = false;
const std::string createTapeComment = "create tape";
m_catalogue->createLogicalLibrary(m_cliSI, logicalLibraryName,
"create logical library");
m_catalogue->createLogicalLibrary(m_cliSI, logicalLibraryName, "create logical library");
m_catalogue->createTapePool(m_cliSI, tapePoolName, 2, true, "create tape pool");
m_catalogue->createTape(m_cliSI, vid1, logicalLibraryName, tapePoolName, encryptionKey, capacityInBytes,
disabledValue, fullValue, createTapeComment);
......@@ -1770,23 +1983,23 @@ TEST_F(cta_catalogue_InMemoryCatalogueTest, prepareToRetrieveFile) {
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"create mount group");
"create mount policy");
const std::string comment = "create mount rule for requester";
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_cliSI, mountPolicyName, requesterName, comment);
const std::list<common::dataStructures::RequesterMountRule> requesters = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, requesters.size());
const std::list<common::dataStructures::RequesterMountRule> rules = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, rules.size());
const common::dataStructures::RequesterMountRule requester = requesters.front();
const common::dataStructures::RequesterMountRule rule = rules.front();
ASSERT_EQ(requesterName, requester.name);
ASSERT_EQ(mountPolicyName, requester.mountPolicy);
ASSERT_EQ(comment, requester.comment);
ASSERT_EQ(m_cliSI.username, requester.creationLog.username);
ASSERT_EQ(m_cliSI.host, requester.creationLog.host);
ASSERT_EQ(requester.creationLog, requester.lastModificationLog);
ASSERT_EQ(requesterName, rule.name);
ASSERT_EQ(mountPolicyName, rule.mountPolicy);
ASSERT_EQ(comment, rule.comment);
ASSERT_EQ(m_cliSI.username, rule.creationLog.username);
ASSERT_EQ(m_cliSI.host, rule.creationLog.host);
ASSERT_EQ(rule.creationLog, rule.lastModificationLog);
common::dataStructures::UserIdentity userIdentity;
userIdentity.name = requesterName;
......
......@@ -2420,9 +2420,8 @@ void RdbmsCatalogue::setDriveStatus(const common::dataStructures::SecurityIdenti
//------------------------------------------------------------------------------
// prepareForNewFile
//------------------------------------------------------------------------------
common::dataStructures::ArchiveFileQueueCriteria
RdbmsCatalogue::prepareForNewFile(
const std::string &storageClass, const common::dataStructures::UserIdentity &user) {
common::dataStructures::ArchiveFileQueueCriteria RdbmsCatalogue::prepareForNewFile(const std::string &storageClass,
const common::dataStructures::UserIdentity &user) {
const common::dataStructures::TapeCopyToPoolMap copyToPoolMap =
getTapeCopyToPoolMap(storageClass);
const uint64_t expectedNbRoutes = getExpectedNbArchiveRoutes(storageClass);
......@@ -2442,14 +2441,23 @@ common::dataStructures::ArchiveFileQueueCriteria
throw ex;
}
common::dataStructures::MountPolicy mountPolicy = getMountPolicyForAUser(user.name);
const RequesterAndGroupMountPolicies mountPolicies = getMountPolicies(user.name, user.group);
// Requester mount policies overrule requester group mount policies
common::dataStructures::MountPolicy mountPolicy;
if(!mountPolicies.requesterMountPolicies.empty()) {
mountPolicy = mountPolicies.requesterMountPolicies.front();
} else if(!mountPolicies.requesterGroupMountPolicies.empty()) {
mountPolicy = mountPolicies.requesterGroupMountPolicies.front();
} else {
throw UserError(std::string("Cannot prepare for a new archive file because no mount policy exists for " +
user.name + ":" + user.group));
}
// Now that we have both the archive routes and the mount policy it's safe to
// consume an archive file identifier
const uint64_t archiveFileId = getNextArchiveFileId();
return common::dataStructures::ArchiveFileQueueCriteria(archiveFileId,
copyToPoolMap, mountPolicy);
return common::dataStructures::ArchiveFileQueueCriteria(archiveFileId, copyToPoolMap, mountPolicy);
}
//------------------------------------------------------------------------------
......@@ -2507,71 +2515,6 @@ uint64_t RdbmsCatalogue::getExpectedNbArchiveRoutes(const std::string &storageCl
}
}
//------------------------------------------------------------------------------
// getMountPolicyForAUser
//------------------------------------------------------------------------------
common::dataStructures::MountPolicy RdbmsCatalogue::getMountPolicyForAUser(const std::string &username) const {
const char *const sql =
"SELECT "
"MOUNT_POLICY.MOUNT_POLICY_NAME AS MOUNT_POLICY_NAME,"
"ARCHIVE_PRIORITY AS ARCHIVE_PRIORITY,"
"ARCHIVE_MIN_REQUEST_AGE AS ARCHIVE_MIN_REQUEST_AGE,"
"RETRIEVE_PRIORITY AS RETRIEVE_PRIORITY,"
"RETRIEVE_MIN_REQUEST_AGE AS RETRIEVE_MIN_REQUEST_AGE,"
"MAX_DRIVES_ALLOWED AS MAX_DRIVES_ALLOWED,"
"MOUNT_POLICY.USER_COMMENT AS USER_COMMENT,"
"MOUNT_POLICY.CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"MOUNT_POLICY.CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
"MOUNT_POLICY.CREATION_LOG_TIME AS CREATION_LOG_TIME,"
"MOUNT_POLICY.LAST_UPDATE_USER_NAME AS LAST_UPDATE_USER_NAME,"
"MOUNT_POLICY.LAST_UPDATE_HOST_NAME AS LAST_UPDATE_HOST_NAME,"
"MOUNT_POLICY.LAST_UPDATE_TIME AS LAST_UPDATE_TIME "
"FROM "
"MOUNT_POLICY "
"INNER JOIN REQUESTER_MOUNT_RULE ON "
"MOUNT_POLICY.MOUNT_POLICY_NAME = REQUESTER_MOUNT_RULE.MOUNT_POLICY_NAME "
"WHERE "
"REQUESTER_MOUNT_RULE.REQUESTER_NAME = :REQUESTER_NAME";
std::unique_ptr<DbStmt> stmt(m_conn->createStmt(sql));
stmt->bindString(":REQUESTER_NAME", username);
std::unique_ptr<DbRset> rset(stmt->executeQuery());
if(rset->next()) {
common::dataStructures::MountPolicy policy;
policy.name = rset->columnText("MOUNT_POLICY_NAME");
policy.archivePriority = rset->columnUint64("ARCHIVE_PRIORITY");
policy.archiveMinRequestAge = rset->columnUint64("ARCHIVE_MIN_REQUEST_AGE");
policy.retrievePriority = rset->columnUint64("RETRIEVE_PRIORITY");
policy.retrieveMinRequestAge = rset->columnUint64("RETRIEVE_MIN_REQUEST_AGE");
policy.maxDrivesAllowed =
rset->columnUint64("MAX_DRIVES_ALLOWED");
policy.comment = rset->columnText("USER_COMMENT");
policy.creationLog.username = rset->columnText("CREATION_LOG_USER_NAME");
policy.creationLog.host = rset->columnText("CREATION_LOG_HOST_NAME");
policy.creationLog.time = rset->columnUint64("CREATION_LOG_TIME");
policy.lastModificationLog.username = rset->columnText("LAST_UPDATE_USER_NAME");
policy.lastModificationLog.host = rset->columnText("LAST_UPDATE_HOST_NAME");
policy.lastModificationLog.time = rset->columnUint64("LAST_UPDATE_TIME");
return policy;
} else {
exception::Exception ex;
ex.getMessage() << "Failed to find a mount policy for user " << username;
throw ex;
}
}
//------------------------------------------------------------------------------
// fileWrittenToTape
//------------------------------------------------------------------------------
......@@ -2703,13 +2646,30 @@ void RdbmsCatalogue::throwIfCommonEventDataMismatch(const common::dataStructures
//------------------------------------------------------------------------------
// prepareToRetrieveFile
//------------------------------------------------------------------------------
common::dataStructures::RetrieveFileQueueCriteria RdbmsCatalogue::prepareToRetrieveFile(
const uint64_t archiveFileId,
common::dataStructures::RetrieveFileQueueCriteria RdbmsCatalogue::prepareToRetrieveFile(const uint64_t archiveFileId,
const common::dataStructures::UserIdentity &user) {
const std::map<uint64_t, common::dataStructures::TapeFile> tapeFiles = getTapeFiles(archiveFileId);
const common::dataStructures::MountPolicy mountPolicy = getMountPolicyForAUser(user.name);
return common::dataStructures::RetrieveFileQueueCriteria(tapeFiles, mountPolicy);
try {
const std::map<uint64_t, common::dataStructures::TapeFile> tapeFiles = getTapeFiles(archiveFileId);
const RequesterAndGroupMountPolicies mountPolicies = getMountPolicies(user.name, user.group);
// Requester mount policies overrule requester group mount policies
common::dataStructures::MountPolicy mountPolicy;
if(!mountPolicies.requesterMountPolicies.empty()) {
mountPolicy = mountPolicies.requesterMountPolicies.front();
} else if(!mountPolicies.requesterGroupMountPolicies.empty()) {
mountPolicy = mountPolicies.requesterGroupMountPolicies.front();
} else {
UserError ue;
ue.getMessage() << "Cannot prepare to retrieve the file with archive file ID because no mount policy exists "
"for " + user.name + ":" + user.group;
throw ue;
}
return common::dataStructures::RetrieveFileQueueCriteria(tapeFiles, mountPolicy);
} catch(UserError &) {
throw;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
......@@ -2757,8 +2717,94 @@ std::map<uint64_t, common::dataStructures::TapeFile> RdbmsCatalogue::getTapeFile
//------------------------------------------------------------------------------
RequesterAndGroupMountPolicies RdbmsCatalogue::getMountPolicies(const std::string &requesterName,
const std::string &requesterGroupName) {
RequesterAndGroupMountPolicies policies;
return policies;
try {
const char *const sql =
"SELECT "
"'REQUESTER' AS RULE_TYPE,"
"REQUESTER_MOUNT_RULE.REQUESTER_NAME AS ASSIGNEE,"
"MOUNT_POLICY.MOUNT_POLICY_NAME AS MOUNT_POLICY_NAME,"
"MOUNT_POLICY.ARCHIVE_PRIORITY AS ARCHIVE_PRIORITY,"
"MOUNT_POLICY.ARCHIVE_MIN_REQUEST_AGE AS ARCHIVE_MIN_REQUEST_AGE,"
"MOUNT_POLICY.RETRIEVE_PRIORITY AS RETRIEVE_PRIORITY,"
"MOUNT_POLICY.RETRIEVE_MIN_REQUEST_AGE AS RETRIEVE_MIN_REQUEST_AGE,"
"MOUNT_POLICY.MAX_DRIVES_ALLOWED AS MAX_DRIVES_ALLOWED,"
"MOUNT_POLICY.USER_COMMENT AS USER_COMMENT,"
"MOUNT_POLICY.CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"MOUNT_POLICY.CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
"MOUNT_POLICY.CREATION_LOG_TIME AS CREATION_LOG_TIME,"
"MOUNT_POLICY.LAST_UPDATE_USER_NAME AS LAST_UPDATE_USER_NAME,"
"MOUNT_POLICY.LAST_UPDATE_HOST_NAME AS LAST_UPDATE_HOST_NAME,"
"MOUNT_POLICY.LAST_UPDATE_TIME AS LAST_UPDATE_TIME "
"FROM "
"REQUESTER_MOUNT_RULE "
"INNER JOIN "
"MOUNT_POLICY "
"ON "
"REQUESTER_MOUNT_RULE.MOUNT_POLICY_NAME = MOUNT_POLICY.MOUNT_POLICY_NAME "
"WHERE "
"REQUESTER_MOUNT_RULE.REQUESTER_NAME = :REQUESTER_NAME "
"UNION "
"SELECT "
"'REQUESTER_GROUP' AS RULE_TYPE,"
"REQUESTER_GROUP_MOUNT_RULE.REQUESTER_GROUP_NAME AS ASSIGNEE,"
"MOUNT_POLICY.MOUNT_POLICY_NAME AS MOUNT_POLICY_NAME,"
"MOUNT_POLICY.ARCHIVE_PRIORITY AS ARCHIVE_PRIORITY,"
"MOUNT_POLICY.ARCHIVE_MIN_REQUEST_AGE AS ARCHIVE_MIN_REQUEST_AGE,"
"MOUNT_POLICY.RETRIEVE_PRIORITY AS RETRIEVE_PRIORITY,"
"MOUNT_POLICY.RETRIEVE_MIN_REQUEST_AGE AS RETRIEVE_MIN_REQUEST_AGE,"
"MOUNT_POLICY.MAX_DRIVES_ALLOWED AS MAX_DRIVES_ALLOWED,"
"MOUNT_POLICY.USER_COMMENT AS USER_COMMENT,"
"MOUNT_POLICY.CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME,"
"MOUNT_POLICY.CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME,"
"MOUNT_POLICY.CREATION_LOG_TIME AS CREATION_LOG_TIME,"
"MOUNT_POLICY.LAST_UPDATE_USER_NAME AS LAST_UPDATE_USER_NAME,"
"MOUNT_POLICY.LAST_UPDATE_HOST_NAME AS LAST_UPDATE_HOST_NAME,"
"MOUNT_POLICY.LAST_UPDATE_TIME AS LAST_UPDATE_TIME "
"FROM "
"REQUESTER_GROUP_MOUNT_RULE "
"INNER JOIN "
"MOUNT_POLICY "
"ON "
"REQUESTER_GROUP_MOUNT_RULE.MOUNT_POLICY_NAME = MOUNT_POLICY.MOUNT_POLICY_NAME "
"WHERE "
"REQUESTER_GROUP_MOUNT_RULE.REQUESTER_GROUP_NAME = :REQUESTER_GROUP_NAME;";