Commit 74a26795 authored by Steven Murray's avatar Steven Murray
Browse files

Removed Catalogue::prepareForNewFile()

parent a41e9d1f
......@@ -137,26 +137,6 @@ public:
const std::string &storageClassName,
const common::dataStructures::UserIdentity &user) = 0;
/**
* Prepares the catalogue for a new archive file and returns the information
* required to queue the associated archive request.
*
* @param diskInstanceName The name of the disk instance to which the
* storage class belongs.
* @param storageClassName The name of the storage class of the file to be
* archived. The storage class name is only guaranteed to be unique within
* its disk instance. The storage class name will be used by the Catalogue
* to determine the destination tape pool for each tape copy.
* @param user The user for whom the file is to be archived. This will be
* used by the Catalogue to determine the mount policy to be used when
* archiving the file.
* @return The information required to queue the associated archive request.
*/
virtual common::dataStructures::ArchiveFileQueueCriteriaAndFileId prepareForNewFile(
const std::string &diskInstanceName,
const std::string &storageClassName,
const common::dataStructures::UserIdentity &user) = 0;
/**
* Returns the list of tapes that can be written to by a tape drive in the
* specified logical library, in other words tapes that are labelled, not
......
......@@ -77,11 +77,6 @@ public:
return retryOnLostConnection(m_log, [&]{return m_catalogue->getArchiveFileQueueCriteria(diskInstanceName, storageClassName, user);}, m_maxTriesToConnect);
}
common::dataStructures::ArchiveFileQueueCriteriaAndFileId prepareForNewFile(const std::string &diskInstanceName,
const std::string &storageClassName, const common::dataStructures::UserIdentity &user) override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->prepareForNewFile(diskInstanceName, storageClassName, user);}, m_maxTriesToConnect);
}
std::list<TapeForWriting> getTapesForWriting(const std::string &logicalLibraryName) const override {
return retryOnLostConnection(m_log, [&]{return m_catalogue->getTapesForWriting(logicalLibraryName);}, m_maxTriesToConnect);
}
......
......@@ -5255,381 +5255,6 @@ TEST_P(cta_catalogue_CatalogueTest, getArchiveFileQueueCriteria_requester_mount_
m_catalogue->getArchiveFileQueueCriteria(storageClass.diskInstance, storageClass.name, userIdentity);
}
TEST_P(cta_catalogue_CatalogueTest, prepareForNewFile_no_archive_routes) {
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_admin,
mountPolicyName,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"Create mount policy");
const std::string comment = "Create mount rule for requester";
const std::string diskInstanceName = "disk_instance_name";
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_admin, mountPolicyName, diskInstanceName, requesterName, comment);
const std::list<common::dataStructures::RequesterMountRule> rules = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, rules.size());
const common::dataStructures::RequesterMountRule rule = rules.front();
ASSERT_EQ(diskInstanceName, rule.diskInstance);
ASSERT_EQ(requesterName, rule.name);
ASSERT_EQ(mountPolicyName, rule.mountPolicy);
ASSERT_EQ(comment, rule.comment);
ASSERT_EQ(m_admin.username, rule.creationLog.username);
ASSERT_EQ(m_admin.host, rule.creationLog.host);
ASSERT_EQ(rule.creationLog, rule.lastModificationLog);
// Do not create any archive routes
ASSERT_TRUE(m_catalogue->getArchiveRoutes().empty());
common::dataStructures::StorageClass storageClass;
storageClass.diskInstance = diskInstanceName;
storageClass.name = "storage_class";
storageClass.nbCopies = 2;
storageClass.comment = "Create storage class";
m_catalogue->createStorageClass(m_admin, storageClass);
common::dataStructures::UserIdentity userIdentity;
userIdentity.name = requesterName;
userIdentity.group = "group";
ASSERT_THROW(m_catalogue->prepareForNewFile(storageClass.diskInstance, storageClass.name, userIdentity),
exception::UserError);
}
TEST_P(cta_catalogue_CatalogueTest, prepareForNewFile_requester_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_admin,
mountPolicyName,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"Create mount policy");
const std::string comment = "Create mount rule for requester";
const std::string diskInstanceName = "disk_instance_name";
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_admin, mountPolicyName, diskInstanceName, requesterName, comment);
const std::list<common::dataStructures::RequesterMountRule> rules = m_catalogue->getRequesterMountRules();
ASSERT_EQ(1, rules.size());
const common::dataStructures::RequesterMountRule rule = rules.front();
ASSERT_EQ(diskInstanceName, rule.diskInstance);
ASSERT_EQ(requesterName, rule.name);
ASSERT_EQ(mountPolicyName, rule.mountPolicy);
ASSERT_EQ(comment, rule.comment);
ASSERT_EQ(m_admin.username, rule.creationLog.username);
ASSERT_EQ(m_admin.host, rule.creationLog.host);
ASSERT_EQ(rule.creationLog, rule.lastModificationLog);
ASSERT_TRUE(m_catalogue->getArchiveRoutes().empty());
common::dataStructures::StorageClass storageClass;
storageClass.diskInstance = diskInstanceName;
storageClass.name = "storage_class";
storageClass.nbCopies = 2;
storageClass.comment = "Create storage class";
m_catalogue->createStorageClass(m_admin, storageClass);
const std::string tapePoolName = "tape_pool";
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
m_catalogue->createTapePool(m_admin, tapePoolName, nbPartialTapes, isEncrypted, "Create tape pool");
const uint64_t copyNb = 1;
const std::string archiveRouteComment = "Create archive route";
m_catalogue->createArchiveRoute(m_admin, storageClass.diskInstance, storageClass.name, 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(storageClass.name, 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_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = route.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
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::ArchiveFileQueueCriteriaAndFileId queueCriteria =
m_catalogue->prepareForNewFile(storageClass.diskInstance, storageClass.name, 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_P(cta_catalogue_CatalogueTest, 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_admin,
mountPolicyName,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"Create mount policy");
const std::string comment = "Create mount rule for requester group";
const std::string diskInstanceName = "disk_instance";
const std::string requesterGroupName = "requester_group";
m_catalogue->createRequesterGroupMountRule(m_admin, mountPolicyName, diskInstanceName, 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_admin.username, rule.creationLog.username);
ASSERT_EQ(m_admin.host, rule.creationLog.host);
ASSERT_EQ(rule.creationLog, rule.lastModificationLog);
ASSERT_TRUE(m_catalogue->getArchiveRoutes().empty());
common::dataStructures::StorageClass storageClass;
storageClass.diskInstance = diskInstanceName;
storageClass.name = "storage_class";
storageClass.nbCopies = 2;
storageClass.comment = "Create storage class";
m_catalogue->createStorageClass(m_admin, storageClass);
const std::string tapePoolName = "tape_pool";
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
m_catalogue->createTapePool(m_admin, tapePoolName, nbPartialTapes, isEncrypted, "Create tape pool");
const uint64_t copyNb = 1;
const std::string archiveRouteComment = "Create archive route";
m_catalogue->createArchiveRoute(m_admin, storageClass.diskInstance, storageClass.name, 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(storageClass.name, 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_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = route.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
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::ArchiveFileQueueCriteriaAndFileId queueCriteria =
m_catalogue->prepareForNewFile(storageClass.diskInstance, storageClass.name, 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_P(cta_catalogue_CatalogueTest, 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_admin,
mountPolicyName,
archivePriority,
minArchiveRequestAge,
retrievePriority,
minRetrieveRequestAge,
maxDrivesAllowed,
"Create mount policy");
const std::string requesterRuleComment = "Create mount rule for requester";
const std::string diskInstanceName = "disk_instance_name";
const std::string requesterName = "requester_name";
m_catalogue->createRequesterMountRule(m_admin, mountPolicyName, diskInstanceName, 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_admin.username, requesterRule.creationLog.username);
ASSERT_EQ(m_admin.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";
m_catalogue->createRequesterGroupMountRule(m_admin, mountPolicyName, diskInstanceName, 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_admin.username, requesterGroupRule.creationLog.username);
ASSERT_EQ(m_admin.host, requesterGroupRule.creationLog.host);
ASSERT_EQ(requesterGroupRule.creationLog, requesterGroupRule.lastModificationLog);
ASSERT_TRUE(m_catalogue->getArchiveRoutes().empty());
common::dataStructures::StorageClass storageClass;
storageClass.diskInstance = diskInstanceName;
storageClass.name = "storage_class";
storageClass.nbCopies = 2;
storageClass.comment = "Create storage class";
m_catalogue->createStorageClass(m_admin, storageClass);
const std::string tapePoolName = "tape_pool";
const uint64_t nbPartialTapes = 2;
const bool isEncrypted = true;
m_catalogue->createTapePool(m_admin, tapePoolName, nbPartialTapes, isEncrypted, "Create tape pool");
const uint64_t copyNb = 1;
const std::string archiveRouteComment = "Create archive route";
m_catalogue->createArchiveRoute(m_admin, storageClass.diskInstance, storageClass.name, 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(storageClass.name, 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_admin.username, creationLog.username);
ASSERT_EQ(m_admin.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog = route.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
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::ArchiveFileQueueCriteriaAndFileId queueCriteria =
m_catalogue->prepareForNewFile(storageClass.diskInstance, storageClass.name, 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_P(cta_catalogue_CatalogueTest, prepareToRetrieveFileUsingArchiveFileId) {
using namespace cta;
......
......@@ -102,8 +102,6 @@ public:
uint64_t checkAndGetNextArchiveFileId(const std::string &diskInstanceName, const std::string &storageClassName, const common::dataStructures::UserIdentity &user) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::ArchiveFileQueueCriteria getArchiveFileQueueCriteria(const std::string &diskInstanceName,
const std::string &storageClassName, const common::dataStructures::UserIdentity &user) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::ArchiveFileQueueCriteriaAndFileId prepareForNewFile(const std::string &diskInstanceName,
const std::string &storageClassName, const common::dataStructures::UserIdentity &user) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::RetrieveFileQueueCriteria prepareToRetrieveFile(const std::string& instanceName, const uint64_t archiveFileId, const common::dataStructures::UserIdentity& user, log::LogContext &lc) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
common::dataStructures::RetrieveFileQueueCriteria prepareToRetrieveFileByDiskFileId(const std::string &diskInstanceName, const std::string &diskFileId, const common::dataStructures::UserIdentity &user, log::LogContext &lc) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
void reclaimTape(const common::dataStructures::SecurityIdentity& admin, const std::string& vid) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -4018,62 +4018,6 @@ common::dataStructures::ArchiveFileQueueCriteria RdbmsCatalogue::getArchiveFileQ
}
}
//------------------------------------------------------------------------------
// prepareForNewFile
//------------------------------------------------------------------------------
common::dataStructures::ArchiveFileQueueCriteriaAndFileId RdbmsCatalogue::prepareForNewFile(
const std::string &diskInstanceName,
const std::string &storageClassName, const common::dataStructures::UserIdentity &user) {
try {
auto conn = m_connPool.getConn();
const common::dataStructures::TapeCopyToPoolMap copyToPoolMap = getTapeCopyToPoolMap(conn, diskInstanceName,
storageClassName);
const uint64_t expectedNbRoutes = getExpectedNbArchiveRoutes(conn, diskInstanceName, storageClassName);
// Check that the number of archive routes is correct
if(copyToPoolMap.empty()) {
exception::UserError ue;
ue.getMessage() << "Storage class " << diskInstanceName << ":" << storageClassName << " has no archive routes";
throw ue;
}
if(copyToPoolMap.size() != expectedNbRoutes) {
exception::UserError ue;
ue.getMessage() << "Storage class " << diskInstanceName << ":" << storageClassName << " does not have the"
" expected number of archive routes routes: expected=" << expectedNbRoutes << ", actual=" <<
copyToPoolMap.size();
throw ue;
}
const RequesterAndGroupMountPolicies mountPolicies = getMountPolicies(conn, diskInstanceName, 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 {
exception::UserError ue;
ue.getMessage() << "Cannot archive file because there are no mount rules for the requester or their group:"
" storageClass=" << storageClassName << " requester=" << diskInstanceName << ":" << user.name << ":" <<
user.group;
throw ue;
}
// 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(conn);
return common::dataStructures::ArchiveFileQueueCriteriaAndFileId(archiveFileId, copyToPoolMap, mountPolicy);
} catch(exception::LostDatabaseConnection &le) {
throw exception::LostDatabaseConnection(std::string(__FUNCTION__) + " failed: " + le.getMessage().str());
} catch(exception::UserError &) {
throw;
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
}
}
//------------------------------------------------------------------------------
// getTapeCopyToPoolMap
//------------------------------------------------------------------------------
......
......@@ -141,26 +141,6 @@ public:
const std::string &storageClassName,
const common::dataStructures::UserIdentity &user) override;
/**
* Prepares the catalogue for a new archive file and returns the information
* required to queue the associated archive request.
*
* @param diskInstanceName The name of the disk instance to which the
* storage class belongs.
* @param storageClassName The name of the storage class of the file to be
* archived. The storage class name is only guaranteed to be unique within
* its disk instance. The storage class name will be used by the Catalogue
* to determine the destination tape pool for each tape copy.
* @param user The user for whom the file is to be archived. This will be
* used by the Catalogue to determine the mount policy to be used when
* archiving the file.
* @return The information required to queue the associated archive request.
*/
common::dataStructures::ArchiveFileQueueCriteriaAndFileId prepareForNewFile(
const std::string &diskInstanceName,
const std::string &storageClassName,
const common::dataStructures::UserIdentity &user) override;
/**
* Returns the list of tapes that can be written to by a tape drive in the
* specified logical library, in other words tapes that are labelled, not
......
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