Commit 2717feeb authored by Steven Murray's avatar Steven Murray
Browse files

Added unit-test SqliteCatalogueTest.prepareForNewFile

parent f33c3529
......@@ -201,8 +201,25 @@ public:
const cta::common::dataStructures::TapeFileLocation &tapeFileLocation) = 0;
virtual cta::common::dataStructures::TapeCopyToPoolMap getTapeCopyToPoolMap(const std::string &storageClass) const = 0;
virtual cta::common::dataStructures::MountPolicy getArchiveMountPolicy(const cta::common::dataStructures::UserIdentity &requester) const = 0;
virtual cta::common::dataStructures::MountPolicy getRetrieveMountPolicy(const cta::common::dataStructures::UserIdentity &requester) const = 0;
/**
* Returns the archive mount policy for the specified end user.
*
* @param user The name of the end user.
* @return The archive mount policy.
*/
virtual cta::common::dataStructures::MountPolicy getArchiveMountPolicy(
const std::string &user) const = 0;
/**
* Returns the retrieve mount policy for the specified end user.
*
* @param user The name of the end user.
* @return The retrieve mount policy.
*/
virtual cta::common::dataStructures::MountPolicy getRetrieveMountPolicy(
const std::string &user) const = 0;
virtual bool isAdmin(const cta::common::dataStructures::SecurityIdentity &cliIdentity) const = 0;
}; // class Catalogue
......
......@@ -452,8 +452,7 @@ cta::common::dataStructures::TapeCopyToPoolMap cta::catalogue::DummyCatalogue::
// getArchiveMountPolicy
//------------------------------------------------------------------------------
cta::common::dataStructures::MountPolicy cta::catalogue::DummyCatalogue::
getArchiveMountPolicy(const common::dataStructures::UserIdentity &requester)
const {
getArchiveMountPolicy(const std::string &user) const {
return cta::common::dataStructures::MountPolicy();
}
......@@ -461,8 +460,7 @@ cta::common::dataStructures::MountPolicy cta::catalogue::DummyCatalogue::
// getRetrieveMountPolicy
//------------------------------------------------------------------------------
cta::common::dataStructures::MountPolicy cta::catalogue::DummyCatalogue::
getRetrieveMountPolicy(const common::dataStructures::UserIdentity &requester)
const {
getRetrieveMountPolicy(const std::string &user) const {
return cta::common::dataStructures::MountPolicy();
}
......
......@@ -158,8 +158,24 @@ public:
virtual cta::common::dataStructures::TapeCopyToPoolMap getTapeCopyToPoolMap(const std::string &storageClass) const;
virtual cta::common::dataStructures::MountPolicy getArchiveMountPolicy(const cta::common::dataStructures::UserIdentity &requester) const;
virtual cta::common::dataStructures::MountPolicy getRetrieveMountPolicy(const cta::common::dataStructures::UserIdentity &requester) const;
/**
* Returns the archive mount policy for the specified end user.
*
* @param user The name of the end user.
* @return The archive mount policy.
*/
virtual cta::common::dataStructures::MountPolicy getArchiveMountPolicy(
const std::string &user) const;
/**
* Returns the retrieve mount policy for the specified end user.
*
* @param user The name of the end user.
* @return The retrieve mount policy.
*/
virtual cta::common::dataStructures::MountPolicy getRetrieveMountPolicy(
const std::string &user) const;
virtual bool isAdmin(const cta::common::dataStructures::SecurityIdentity &cliIdentity) const;
}; // class DummyCatalogue
......
......@@ -2044,11 +2044,31 @@ cta::common::dataStructures::ArchiveFileQueueCriteria
const std::string &storageClass, const std::string &user) {
const common::dataStructures::TapeCopyToPoolMap copyToPoolMap =
getTapeCopyToPoolMap(storageClass);
common::dataStructures::MountPolicy mountPolicy;
const uint64_t expectedNbRoutes = getExpectedNbArchiveRoutes(storageClass);
// Check that the number of archive routes is correct
if(copyToPoolMap.empty()) {
exception::Exception ex;
ex.getMessage() << "Storage class " << storageClass << " has no archive"
" routes";
throw ex;
}
if(copyToPoolMap.size() != expectedNbRoutes) {
exception::Exception ex;
ex.getMessage() << "Storage class " << storageClass << " does not have the"
" expected number of archive routes routes: expected=" << expectedNbRoutes
<< ", actual=" << copyToPoolMap.size();
throw ex;
}
common::dataStructures::MountPolicy mountPolicy = getArchiveMountPolicy(user);
// 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 = m_nextArchiveFileId++;
const common::dataStructures::ArchiveFileQueueCriteria queueCriteria(
archiveFileId, copyToPoolMap, mountPolicy);
return common::dataStructures::ArchiveFileQueueCriteria();
return common::dataStructures::ArchiveFileQueueCriteria(archiveFileId,
copyToPoolMap, mountPolicy);
}
//------------------------------------------------------------------------------
......@@ -2086,7 +2106,7 @@ uint64_t cta::catalogue::SqliteCatalogue::getExpectedNbArchiveRoutes(
uint64_t nbRoutes = 0;
const char *const sql =
"SELECT "
"COUNT(*) AS NB_ROUTES"
"COUNT(*) AS NB_ROUTES "
"FROM ARCHIVE_ROUTE WHERE "
"STORAGE_CLASS_NAME = :STORAGE_CLASS_NAME;";
std::unique_ptr<SqliteStmt> stmt(m_conn.createStmt(sql));
......@@ -2105,18 +2125,74 @@ uint64_t cta::catalogue::SqliteCatalogue::getExpectedNbArchiveRoutes(
// getArchiveMountPolicy
//------------------------------------------------------------------------------
cta::common::dataStructures::MountPolicy cta::catalogue::SqliteCatalogue::
getArchiveMountPolicy(const common::dataStructures::UserIdentity &requester)
const {
return common::dataStructures::MountPolicy();
getArchiveMountPolicy(const std::string &user) const {
const char *const sql =
"SELECT "
"ARCHIVE_PRIORITY AS ARCHIVE_PRIORITY,"
"MIN_ARCHIVE_FILES_QUEUED AS MIN_ARCHIVE_FILES_QUEUED,"
"MIN_ARCHIVE_BYTES_QUEUED AS MIN_ARCHIVE_BYTES_QUEUED,"
"MIN_ARCHIVE_REQUEST_AGE AS MIN_ARCHIVE_REQUEST_AGE,"
"MAX_DRIVES_ALLOWED AS MAX_DRIVES_ALLOWED "
"FROM MOUNT_GROUP INNER JOIN END_USER ON "
"MOUNT_GROUP.MOUNT_GROUP_NAME = END_USER.MOUNT_GROUP_NAME "
"WHERE "
"USER_NAME = :USER_NAME;";
std::unique_ptr<SqliteStmt> stmt(m_conn.createStmt(sql));
stmt->bind(":USER_NAME", user);
ColumnNameToIdx nameToIdx;
if(SQLITE_ROW == stmt->step()) {
nameToIdx = stmt->getColumnNameToIdx();
common::dataStructures::MountPolicy policy;
policy.priority = stmt->columnUint64(nameToIdx["ARCHIVE_PRIORITY"]);
policy.minFilesQueued = stmt->columnUint64(nameToIdx["MIN_ARCHIVE_FILES_QUEUED"]);
policy.minBytesQueued = stmt->columnUint64(nameToIdx["MIN_ARCHIVE_BYTES_QUEUED"]);
policy.minRequestAge = stmt->columnUint64(nameToIdx["MIN_ARCHIVE_REQUEST_AGE"]);
policy.maxDrives = stmt->columnUint64(nameToIdx["MAX_DRIVES_ALLOWED"]);
return policy;
} else {
exception::Exception ex;
ex.getMessage() << "Failed to find an archive mount policy for user " <<
user;
throw ex;
}
}
//------------------------------------------------------------------------------
// getRetrieveMountPolicy
//------------------------------------------------------------------------------
cta::common::dataStructures::MountPolicy cta::catalogue::SqliteCatalogue::
getRetrieveMountPolicy(const common::dataStructures::UserIdentity &requester)
const {
return common::dataStructures::MountPolicy();
getRetrieveMountPolicy(const std::string &user) const {
const char *const sql =
"SELECT "
"RETRIEVE_PRIORITY AS RETRIEVE_PRIORITY,"
"MIN_RETRIEVE_FILES_QUEUED AS MIN_RETRIEVE_FILES_QUEUED,"
"MIN_RETRIEVE_BYTES_QUEUED AS MIN_RETRIEVE_BYTES_QUEUED,"
"MIN_RETRIEVE_REQUEST_AGE AS MIN_RETRIEVE_REQUEST_AGE,"
"MAX_DRIVES_ALLOWED AS MAX_DRIVES_ALLOWED "
"FROM MOUNT_GROUP INNER JOIN END_USER ON "
"MOUNT_GROUP.MOUNT_GROUP_NAME = END_USER.MOUNT_GROUP_NAME "
"WHERE "
"USER_NAME = :USER_NAME;";
std::unique_ptr<SqliteStmt> stmt(m_conn.createStmt(sql));
stmt->bind(":USER_NAME", user);
ColumnNameToIdx nameToIdx;
if(SQLITE_ROW == stmt->step()) {
nameToIdx = stmt->getColumnNameToIdx();
common::dataStructures::MountPolicy policy;
policy.priority = stmt->columnUint64(nameToIdx["RETRIEVE_PRIORITY"]);
policy.minFilesQueued = stmt->columnUint64(nameToIdx["MIN_RETRIEVE_FILES_QUEUED"]);
policy.minBytesQueued = stmt->columnUint64(nameToIdx["MIN_RETRIEVE_BYTES_QUEUED"]);
policy.minRequestAge = stmt->columnUint64(nameToIdx["MIN_RETRIEVE_REQUEST_AGE"]);
policy.maxDrives = stmt->columnUint64(nameToIdx["MAX_DRIVES_ALLOWED"]);
return policy;
} else {
exception::Exception ex;
ex.getMessage() << "Failed to find a retrieve mount policy for user " <<
user;
throw ex;
}
}
//------------------------------------------------------------------------------
......
......@@ -177,8 +177,25 @@ public:
prepareForNewFile(const std::string &storageClass, const std::string &user);
virtual cta::common::dataStructures::TapeCopyToPoolMap getTapeCopyToPoolMap(const std::string &storageClass) const;
virtual cta::common::dataStructures::MountPolicy getArchiveMountPolicy(const cta::common::dataStructures::UserIdentity &requester) const;
virtual cta::common::dataStructures::MountPolicy getRetrieveMountPolicy(const cta::common::dataStructures::UserIdentity &requester) const;
/**
* Returns the archive mount policy for the specified end user.
*
* @param user The name of the end user.
* @return The archive mount policy.
*/
virtual cta::common::dataStructures::MountPolicy getArchiveMountPolicy(
const std::string &user) const;
/**
* Returns the retrieve mount policy for the specified end user.
*
* @param user The name of the end user.
* @return The retrieve mount policy.
*/
virtual cta::common::dataStructures::MountPolicy getRetrieveMountPolicy(
const std::string &user) const;
virtual bool isAdmin(const cta::common::dataStructures::SecurityIdentity &cliIdentity) const;
private:
......
......@@ -789,9 +789,9 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createUser) {
"create mount group");
const std::string comment = "create user";
const std::string name = "name";
const std::string userName = "user_name";
const std::string group = "group";
catalogue.createUser(m_cliSI, name, group, mountGroupName, comment);
catalogue.createUser(m_cliSI, userName, group, mountGroupName, comment);
std::list<common::dataStructures::User> users;
users = catalogue.getUsers();
......@@ -799,13 +799,31 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createUser) {
const common::dataStructures::User user = users.front();
ASSERT_EQ(name, user.name);
ASSERT_EQ(userName, user.name);
ASSERT_EQ(group, user.group);
ASSERT_EQ(mountGroupName, user.mountGroupName);
ASSERT_EQ(comment, user.comment);
ASSERT_EQ(m_cliSI.user, user.creationLog.user);
ASSERT_EQ(m_cliSI.host, user.creationLog.host);
ASSERT_EQ(user.creationLog, user.lastModificationLog);
const common::dataStructures::MountPolicy archivePolicy =
catalogue.getArchiveMountPolicy(userName);
ASSERT_EQ(archivePriority, archivePolicy.priority);
ASSERT_EQ(minArchiveFilesQueued, archivePolicy.minFilesQueued);
ASSERT_EQ(minArchiveBytesQueued, archivePolicy.minBytesQueued);
ASSERT_EQ(minArchiveRequestAge, archivePolicy.minRequestAge);
ASSERT_EQ(maxDrivesAllowed, archivePolicy.maxDrives);
const common::dataStructures::MountPolicy retrievePolicy =
catalogue.getRetrieveMountPolicy(userName);
ASSERT_EQ(retrievePriority, retrievePolicy.priority);
ASSERT_EQ(minRetrieveFilesQueued, retrievePolicy.minFilesQueued);
ASSERT_EQ(minRetrieveBytesQueued, retrievePolicy.minBytesQueued);
ASSERT_EQ(minRetrieveRequestAge, retrievePolicy.minRequestAge);
ASSERT_EQ(maxDrivesAllowed, retrievePolicy.maxDrives);
}
TEST_F(cta_catalogue_SqliteCatalogueTest, createUser_same_twice) {
......@@ -925,4 +943,132 @@ TEST_F(cta_catalogue_SqliteCatalogueTest, createArchiveFile_same_twice) {
ASSERT_THROW(catalogue.createArchiveFile(file), exception::Exception);
}
TEST_F(cta_catalogue_SqliteCatalogueTest, prepareForNewFile) {
using namespace cta;
catalogue::SqliteCatalogue catalogue;
ASSERT_TRUE(catalogue.getUsers().empty());
const std::string mountGroupName = "mount_group";
const uint64_t archivePriority = 1;
const uint64_t minArchiveFilesQueued = 2;
const uint64_t minArchiveBytesQueued = 3;
const uint64_t minArchiveRequestAge = 4;
const uint64_t retrievePriority = 5;
const uint64_t minRetrieveFilesQueued = 6;
const uint64_t minRetrieveBytesQueued = 7;
const uint64_t minRetrieveRequestAge = 8;
const uint64_t maxDrivesAllowed = 9;
catalogue.createMountGroup(
m_cliSI,
mountGroupName,
archivePriority,
minArchiveFilesQueued,
minArchiveBytesQueued,
minArchiveRequestAge,
retrievePriority,
minRetrieveFilesQueued,
minRetrieveBytesQueued,
minRetrieveRequestAge,
maxDrivesAllowed,
"create mount group");
const std::string userComment = "create user";
const std::string userName = "user_name";
const std::string group = "group";
catalogue.createUser(m_cliSI, userName, group, mountGroupName, userComment);
std::list<common::dataStructures::User> users;
users = catalogue.getUsers();
ASSERT_EQ(1, users.size());
const common::dataStructures::User user = users.front();
ASSERT_EQ(userName, user.name);
ASSERT_EQ(group, user.group);
ASSERT_EQ(mountGroupName, user.mountGroupName);
ASSERT_EQ(userComment, user.comment);
ASSERT_EQ(m_cliSI.user, user.creationLog.user);
ASSERT_EQ(m_cliSI.host, user.creationLog.host);
ASSERT_EQ(user.creationLog, user.lastModificationLog);
const common::dataStructures::MountPolicy archivePolicy =
catalogue.getArchiveMountPolicy(userName);
ASSERT_EQ(archivePriority, archivePolicy.priority);
ASSERT_EQ(minArchiveFilesQueued, archivePolicy.minFilesQueued);
ASSERT_EQ(minArchiveBytesQueued, archivePolicy.minBytesQueued);
ASSERT_EQ(minArchiveRequestAge, archivePolicy.minRequestAge);
ASSERT_EQ(maxDrivesAllowed, archivePolicy.maxDrives);
const common::dataStructures::MountPolicy retrievePolicy =
catalogue.getRetrieveMountPolicy(userName);
ASSERT_EQ(retrievePriority, retrievePolicy.priority);
ASSERT_EQ(minRetrieveFilesQueued, retrievePolicy.minFilesQueued);
ASSERT_EQ(minRetrieveBytesQueued, retrievePolicy.minBytesQueued);
ASSERT_EQ(minRetrieveRequestAge, retrievePolicy.minRequestAge);
ASSERT_EQ(maxDrivesAllowed, retrievePolicy.maxDrives);
ASSERT_TRUE(catalogue.getArchiveRoutes().empty());
const std::string storageClassName = "storage_class";
const uint64_t nbCopies = 2;
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;
catalogue.createTapePool(m_cliSI, tapePoolName, nbPartialTapes, is_encrypted,
"create tape pool");
const uint64_t copyNb = 1;
const std::string archiveRouteComment = "create archive route";
catalogue.createArchiveRoute(m_cliSI, storageClassName, copyNb, tapePoolName,
archiveRouteComment);
const std::list<common::dataStructures::ArchiveRoute> routes =
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.user.name, creationLog.user.name);
ASSERT_EQ(m_cliSI.user.group, creationLog.user.group);
ASSERT_EQ(m_cliSI.host, creationLog.host);
const common::dataStructures::EntryLog lastModificationLog =
route.lastModificationLog;
ASSERT_EQ(creationLog, lastModificationLog);
common::dataStructures::TapeCopyToPoolMap copyToPoolMap =
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);
const common::dataStructures::ArchiveFileQueueCriteria queueCriteria =
catalogue.prepareForNewFile(storageClassName, userName);
ASSERT_EQ(1, 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.priority);
ASSERT_EQ(minArchiveFilesQueued, queueCriteria.mountPolicy.minFilesQueued);
ASSERT_EQ(minArchiveBytesQueued, queueCriteria.mountPolicy.minBytesQueued);
ASSERT_EQ(minArchiveRequestAge, queueCriteria.mountPolicy.minRequestAge);
ASSERT_EQ(maxDrivesAllowed, queueCriteria.mountPolicy.maxDrives);
}
} // namespace unitTests
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