diff --git a/libs/middletier/CMakeLists.txt b/libs/middletier/CMakeLists.txt index 06d656a090279448e212a8def69b32019e168122..8bafe4336b233c4bdcb2853bd928df0f3b85819b 100644 --- a/libs/middletier/CMakeLists.txt +++ b/libs/middletier/CMakeLists.txt @@ -21,18 +21,6 @@ set (MIDDLE_TIER_LIB_SRC_FILES LogicalLibrary.cpp MiddleTierAdmin.cpp MiddleTierUser.cpp - MockArchivalJobTable.cpp - MockArchiveRouteTable.cpp - MockAdminHostTable.cpp - MockAdminUserTable.cpp - MockDatabase.cpp - MockLogicalLibraryTable.cpp - MockMiddleTierAdmin.cpp - MockMiddleTierUser.cpp - MockMiddleTierUser.cpp - MockRetrievalJobTable.cpp - MockTapeTable.cpp - MockTapePoolTable.cpp RetrievalJob.cpp RetrievalJobState.cpp SecurityIdentity.cpp @@ -52,14 +40,6 @@ add_library (ctamiddletier SHARED target_link_libraries (ctamiddletier ${SQLITE3_LIBRARY_RELEASE}) set (MIDDLE_TIER_UNIT_TESTS_LIB_SRC_FILES - MockAdminHostTableTest.cpp - MockAdminUserTableTest.cpp - MockArchivalJobTableTest.cpp - MockLogicalLibraryTableTest.cpp - MockMiddleTierAdminTest.cpp - MockMiddleTierUserTest.cpp - MockTapeTableTest.cpp - MockTapePoolTableTest.cpp SqliteMiddleTierAdminTest.cpp SqliteMiddleTierUserTest.cpp UtilsTest.cpp diff --git a/libs/middletier/MockAdminHostTable.cpp b/libs/middletier/MockAdminHostTable.cpp deleted file mode 100644 index 2385363ba4cbcd7bf7257cd1353a36b8b94cc740..0000000000000000000000000000000000000000 --- a/libs/middletier/MockAdminHostTable.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "Exception.hpp" -#include "MockAdminHostTable.hpp" - -#include <sstream> - -//------------------------------------------------------------------------------ -// createAdminHost -//------------------------------------------------------------------------------ -void cta::MockAdminHostTable::createAdminHost( - const SecurityIdentity &requester, - const std::string &hostName, - const std::string &comment) { - checkAdminHostDoesNotAlreadyExist(hostName); - AdminHost adminHost(hostName, requester.user, time(NULL), comment); - m_adminHosts[hostName] = adminHost; -} - -//------------------------------------------------------------------------------ -// checkAdminHostDoesNotAlreadyExist -//------------------------------------------------------------------------------ -void cta::MockAdminHostTable::checkAdminHostDoesNotAlreadyExist( - const std::string &hostName) const { - std::map<std::string, AdminHost>::const_iterator itor = - m_adminHosts.find(hostName); - if(itor != m_adminHosts.end()) { - std::ostringstream message; - message << "Administration host " << hostName << " already exists"; - throw(Exception(message.str())); - } -} - -//------------------------------------------------------------------------------ -// deleteAdminHost -//------------------------------------------------------------------------------ -void cta::MockAdminHostTable::deleteAdminHost( - const SecurityIdentity &requester, - const std::string &hostName) { - for(std::map<std::string, AdminHost>::iterator itor = m_adminHosts.begin(); - itor != m_adminHosts.end(); itor++) { - if(hostName == itor->first) { - m_adminHosts.erase(itor); - return; - } - } - - // Reaching this point means the administration host to be deleted does not - // exist - std::ostringstream message; - message << "Administration host " << hostName << " does not exist"; - throw Exception(message.str()); -} - -//------------------------------------------------------------------------------ -// getAdminHosts -//------------------------------------------------------------------------------ -std::list<cta::AdminHost> cta::MockAdminHostTable::getAdminHosts( - const SecurityIdentity &requester) const { - std::list<cta::AdminHost> hosts; - for(std::map<std::string, AdminHost>::const_iterator itor = - m_adminHosts.begin(); itor != m_adminHosts.end(); itor++) { - hosts.push_back(itor->second); - } - return hosts; -} diff --git a/libs/middletier/MockAdminHostTable.hpp b/libs/middletier/MockAdminHostTable.hpp deleted file mode 100644 index 843adda18b4d5b1b7c96eddb80de99f29aab5544..0000000000000000000000000000000000000000 --- a/libs/middletier/MockAdminHostTable.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include "AdminHost.hpp" -#include "SecurityIdentity.hpp" - -#include <list> -#include <map> -#include <string> - -namespace cta { - -/** - * Mock database-table of administration hosts. - */ -class MockAdminHostTable { -public: - - /** - * Creates the specified administration host. - * - * @param requester The identity of the user requesting the creation of the - * administration host. - * @param hostName The network name of the administration host. - * @param comment The comment describing the administration host. - */ - void createAdminHost( - const SecurityIdentity &requester, - const std::string &hostName, - const std::string &comment); - - /** - * Throws an exception if the specified administration host already exists. - * - * @param hostName The network name of the administration host. - */ - void checkAdminHostDoesNotAlreadyExist(const std::string &hostName) const; - - /** - * Deletes the specified administration host. - * - * @param requester The identity of the user requesting the deletion of the - * administration host. - * @param hostName The network name of the administration host. - * @param comment The comment describing the administration host. - */ - void deleteAdminHost( - const SecurityIdentity &requester, - const std::string &hostName); - - /** - * Returns the current list of administration hosts. - * - * @param requester The identity of the user requesting the list. - */ - std::list<AdminHost> getAdminHosts(const SecurityIdentity &requester) const; - -private: - - /** - * Mapping from administration host-name to administration host. - */ - std::map<std::string, AdminHost> m_adminHosts; - -}; // class MockAdminHostTable - -} // namespace cta diff --git a/libs/middletier/MockAdminHostTableTest.cpp b/libs/middletier/MockAdminHostTableTest.cpp deleted file mode 100644 index 1482bdfe0fc5232e3770e9b7789a189af3f5a687..0000000000000000000000000000000000000000 --- a/libs/middletier/MockAdminHostTableTest.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "MockAdminHostTable.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class cta_client_MockAdminHostTableTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(cta_client_MockAdminHostTableTest, createAdminHost_new) { - using namespace cta; - - MockAdminHostTable table; - const SecurityIdentity requester; - - { - std::list<AdminHost> adminHosts; - ASSERT_NO_THROW(adminHosts = table.getAdminHosts(requester)); - ASSERT_TRUE(adminHosts.empty()); - } - - const std::string adminHost1 = "adminHost1"; - const std::string comment = "Comment"; - ASSERT_NO_THROW(table.createAdminHost(requester, adminHost1, comment)); - - { - std::list<AdminHost> adminHosts; - ASSERT_NO_THROW(adminHosts = table.getAdminHosts(requester)); - ASSERT_EQ(1, adminHosts.size()); - - ASSERT_EQ(adminHost1, adminHosts.front().getName()); - ASSERT_EQ(comment, adminHosts.front().getComment()); - } -} - -TEST_F(cta_client_MockAdminHostTableTest, deleteAdminHost_existing) { - using namespace cta; - - MockAdminHostTable table; - const SecurityIdentity requester; - - { - std::list<AdminHost> adminHosts; - ASSERT_NO_THROW(adminHosts = table.getAdminHosts(requester)); - ASSERT_TRUE(adminHosts.empty()); - } - - const std::string adminHost1 = "adminHost1"; - const std::string comment = "Comment"; - ASSERT_NO_THROW(table.createAdminHost(requester, adminHost1, comment)); - - { - std::list<AdminHost> adminHosts; - ASSERT_NO_THROW(adminHosts = table.getAdminHosts(requester)); - ASSERT_EQ(1, adminHosts.size()); - - ASSERT_EQ(adminHost1, adminHosts.front().getName()); - ASSERT_EQ(comment, adminHosts.front().getComment()); - } - - ASSERT_NO_THROW(table.deleteAdminHost(requester, adminHost1)); - - { - std::list<AdminHost> adminHosts; - ASSERT_NO_THROW(adminHosts = table.getAdminHosts(requester)); - ASSERT_TRUE(adminHosts.empty()); - } -} - -TEST_F(cta_client_MockAdminHostTableTest, deleteAdminHost_non_existing) { - using namespace cta; - - MockAdminHostTable table; - const SecurityIdentity requester; - - { - std::list<AdminHost> adminHosts; - ASSERT_NO_THROW(adminHosts = table.getAdminHosts(requester)); - ASSERT_TRUE(adminHosts.empty()); - } - - const std::string adminHost1 = "adminHost1"; - ASSERT_THROW(table.deleteAdminHost(requester, adminHost1), std::exception); - - { - std::list<AdminHost> adminHosts; - ASSERT_NO_THROW(adminHosts = table.getAdminHosts(requester)); - ASSERT_TRUE(adminHosts.empty()); - } -} - -} // namespace unitTests diff --git a/libs/middletier/MockAdminUserTable.cpp b/libs/middletier/MockAdminUserTable.cpp deleted file mode 100644 index d80044aabcbead566973ce1388e4d250c9e5f585..0000000000000000000000000000000000000000 --- a/libs/middletier/MockAdminUserTable.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "Exception.hpp" -#include "MockAdminUserTable.hpp" - -#include <iostream> -#include <memory> -#include <sstream> - -//------------------------------------------------------------------------------ -// createAdminUser -//------------------------------------------------------------------------------ -void cta::MockAdminUserTable::createAdminUser( - const SecurityIdentity &requester, - const UserIdentity &user, - const std::string &comment) { - checkAdminUserDoesNotAlreadyExist(user); - AdminUser adminUser(user, requester.user, time(NULL), comment); - m_adminUsers[user.getUid()] = adminUser; -} - -//------------------------------------------------------------------------------ -// checkAdminUserDoesNotAlreadyExist -//------------------------------------------------------------------------------ -void cta::MockAdminUserTable::checkAdminUserDoesNotAlreadyExist( - const UserIdentity &user) const { - std::map<uint32_t, AdminUser>::const_iterator itor = - m_adminUsers.find(user.getUid()); - if(itor != m_adminUsers.end()) { - std::ostringstream message; - message << "Administrator with uid " << user.getUid() << - " already exists"; - throw(Exception(message.str())); - } -} - -//------------------------------------------------------------------------------ -// deleteAdminUser -//------------------------------------------------------------------------------ -void cta::MockAdminUserTable::deleteAdminUser( - const SecurityIdentity &requester, - const UserIdentity &user) { - for(std::map<uint32_t, AdminUser>::iterator itor = m_adminUsers.begin(); - itor != m_adminUsers.end(); itor++) { - if(user.getUid() == itor->first) { - m_adminUsers.erase(itor); - return; - } - } - - // Reaching this point means the administrator to be deleted does not exist - std::ostringstream message; - message << "Administration with uid " << user.getUid() << " does not exist"; - throw Exception(message.str()); -} - -//------------------------------------------------------------------------------ -// getAdminUsers -//------------------------------------------------------------------------------ -std::list<cta::AdminUser> cta::MockAdminUserTable::getAdminUsers( - const SecurityIdentity &requester) const { - std::list<cta::AdminUser> users; - for(std::map<uint32_t, AdminUser>::const_iterator itor = - m_adminUsers.begin(); itor != m_adminUsers.end(); itor++) { - users.push_back(itor->second); - } - return users; -} diff --git a/libs/middletier/MockAdminUserTable.hpp b/libs/middletier/MockAdminUserTable.hpp deleted file mode 100644 index 271029aad086e3cfb07783d5e49ba4b6fab3f911..0000000000000000000000000000000000000000 --- a/libs/middletier/MockAdminUserTable.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once - -#include "AdminUser.hpp" -#include "SecurityIdentity.hpp" -#include "UserIdentity.hpp" - -#include <list> -#include <map> - -namespace cta { - -/** - * Mock database-table of admin users. - */ -class MockAdminUserTable { -public: - - /** - * Creates the specified administrator. - * - * @param requester The identity of the user requesting the creation of the - * administrator. - * @param user The identity of the administrator. - * @param comment The comment describing the sministrator. - */ - void createAdminUser( - const SecurityIdentity &requester, - const UserIdentity &user, - const std::string &comment); - - /** - * Deletes the specified administrator. - * - * @param requester The identity of the user requesting the deletion of the - * administrator. - * @param user The identity of the administrator. - */ - void deleteAdminUser( - const SecurityIdentity &requester, - const UserIdentity &user); - - /** - * Returns the current list of administrators in lexicographical order. - * - * @param requester The identity of the user requesting the list. - * @return The current list of administrators in lexicographical order. - */ - std::list<AdminUser> getAdminUsers(const SecurityIdentity &requester) const; - - /** - * Throws an exception if the specified administrator already exists. - * - * @param user The identity of the administrator. - */ - void checkAdminUserDoesNotAlreadyExist(const UserIdentity &user) const; - -private: - - /** - * Mapping from administrator uid to administrator. - */ - std::map<uint32_t, AdminUser> m_adminUsers; - -}; // MockAdminUserTable - -} // namespace cta diff --git a/libs/middletier/MockAdminUserTableTest.cpp b/libs/middletier/MockAdminUserTableTest.cpp deleted file mode 100644 index 0ece18d2996e98cb2a3dcf054a0a6249ce70cba7..0000000000000000000000000000000000000000 --- a/libs/middletier/MockAdminUserTableTest.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "MockAdminUserTable.hpp" -#include "MockMiddleTierUser.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class cta_client_MockAdminUserTableTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(cta_client_MockAdminUserTableTest, createAdminUser_new) { - using namespace cta; - - MockAdminUserTable table; - const SecurityIdentity requester; - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_TRUE(adminUsers.empty()); - } - - const uint16_t adminUser1Uid = 1234; - const uint16_t adminUser1Gid = 5678; - const UserIdentity adminUser1(adminUser1Uid, adminUser1Gid); - const std::string comment = "Comment"; - ASSERT_NO_THROW(table.createAdminUser(requester, adminUser1, comment)); - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_EQ(1, adminUsers.size()); - - ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().getUid()); - ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().getGid()); - ASSERT_EQ(comment, adminUsers.front().getComment()); - } -} - -TEST_F(cta_client_MockAdminUserTableTest, createAdminUser_already_existing) { - using namespace cta; - - MockAdminUserTable table; - const SecurityIdentity requester; - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_TRUE(adminUsers.empty()); - } - - const uint16_t adminUser1Uid = 1234; - const uint16_t adminUser1Gid = 5678; - const UserIdentity adminUser1(adminUser1Uid, adminUser1Gid); - const std::string comment = "Comment"; - ASSERT_NO_THROW(table.createAdminUser(requester, adminUser1, comment)); - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_EQ(1, adminUsers.size()); - - ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().getUid()); - ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().getGid()); - ASSERT_EQ(comment, adminUsers.front().getComment()); - } - - ASSERT_THROW(table.createAdminUser(requester, adminUser1, comment), - std::exception); - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_EQ(1, adminUsers.size()); - } -} - -TEST_F(cta_client_MockAdminUserTableTest, deleteAdminUser_existing) { - using namespace cta; - - MockAdminUserTable table; - const SecurityIdentity requester; - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_TRUE(adminUsers.empty()); - } - - const uint16_t adminUser1Uid = 1234; - const uint16_t adminUser1Gid = 5678; - const UserIdentity adminUser1(adminUser1Uid, adminUser1Gid); - const std::string comment = "Comment"; - ASSERT_NO_THROW(table.createAdminUser(requester, adminUser1, comment)); - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_EQ(1, adminUsers.size()); - - ASSERT_EQ(adminUser1Uid, adminUsers.front().getUser().getUid()); - ASSERT_EQ(adminUser1Gid, adminUsers.front().getUser().getGid()); - ASSERT_EQ(comment, adminUsers.front().getComment()); - } - - ASSERT_NO_THROW(table.deleteAdminUser(requester, adminUser1)); - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_TRUE(adminUsers.empty()); - } -} - -TEST_F(cta_client_MockAdminUserTableTest, deleteAdminUser_non_existing) { - using namespace cta; - - MockAdminUserTable table; - const SecurityIdentity requester; - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_TRUE(adminUsers.empty()); - } - - const uint16_t adminUser1Uid = 1234; - const uint16_t adminUser1Gid = 5678; - const UserIdentity adminUser1(adminUser1Uid, adminUser1Gid); - ASSERT_THROW(table.deleteAdminUser(requester, adminUser1), std::exception); - - { - std::list<AdminUser> adminUsers; - ASSERT_NO_THROW(adminUsers = table.getAdminUsers(requester)); - ASSERT_TRUE(adminUsers.empty()); - } -} - -} // namespace unitTests diff --git a/libs/middletier/MockArchivalJobTable.cpp b/libs/middletier/MockArchivalJobTable.cpp deleted file mode 100644 index b2abcf7fc82b8c343246b911fea2b3c8b279ec15..0000000000000000000000000000000000000000 --- a/libs/middletier/MockArchivalJobTable.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "Exception.hpp" -#include "MockArchivalJobTable.hpp" - -#include <iostream> -#include <sstream> - -//------------------------------------------------------------------------------ -// createArchivalJob -//------------------------------------------------------------------------------ -void cta::MockArchivalJobTable::createArchivalJob( - const SecurityIdentity &requester, - const std::string &tapePoolName, - const std::string &srcUrl, - const std::string &dstPath) { - checkArchivalJobDoesNotAlreadyExist(dstPath); - - ArchivalJob job(ArchivalJobState::PENDING, srcUrl, dstPath, requester.user, - time(NULL)); - - std::map<std::string, std::list<ArchivalJob> >::iterator poolItor = - m_jobsTree.find(tapePoolName); - - if(poolItor == m_jobsTree.end()) { - std::list<ArchivalJob> jobs; - jobs.push_back(job); - m_jobsTree[tapePoolName] = jobs; - } else { - std::list<ArchivalJob> &jobs = poolItor->second; - jobs.push_back(job); - } -} - -//------------------------------------------------------------------------------ -// checkArchivalJobDoesNotAlreadyExist -//------------------------------------------------------------------------------ -void cta::MockArchivalJobTable::checkArchivalJobDoesNotAlreadyExist( - const std::string &dstPath) const { - for(std::map<std::string, std::list<ArchivalJob> >::const_iterator - poolItor = m_jobsTree.begin(); poolItor != m_jobsTree.end(); poolItor++) { - const std::list<ArchivalJob> &jobs = poolItor->second; - for(std::list<ArchivalJob>::const_iterator jobItor = jobs.begin(); - jobItor != jobs.end(); jobItor++) { - const ArchivalJob &job = *jobItor; - if(dstPath == job.getDstPath()) { - std::ostringstream message; - message << "An archival job for destination path " << dstPath << - " already exists"; - throw(Exception(message.str())); - } - } - } -} - -//------------------------------------------------------------------------------ -// deleteArchivalJob -//------------------------------------------------------------------------------ -void cta::MockArchivalJobTable::deleteArchivalJob( - const SecurityIdentity &requester, - const std::string &dstPath) { - for(std::map<std::string, std::list<ArchivalJob> >::iterator - poolItor = m_jobsTree.begin(); poolItor != m_jobsTree.end(); poolItor++) { - std::list<ArchivalJob> &jobs = poolItor->second; - for(std::list<ArchivalJob>::iterator jobItor = jobs.begin(); - jobItor != jobs.end(); jobItor++) { - const ArchivalJob &job = *jobItor; - if(dstPath == job.getDstPath()) { - jobs.erase(jobItor); - if(jobs.empty()) { - m_jobsTree.erase(poolItor); - } - return; - } - } - } - - std::ostringstream message; - message << "An archival job for destination path " << dstPath << - " does not exist"; - throw(Exception(message.str())); -} - -//------------------------------------------------------------------------------ -// getArchivalJobs -//------------------------------------------------------------------------------ -const std::map<std::string, std::list<cta::ArchivalJob> > - &cta::MockArchivalJobTable::getArchivalJobs( - const SecurityIdentity &requester) const { - return m_jobsTree; -} - -//------------------------------------------------------------------------------ -// getArchivalJobs -//------------------------------------------------------------------------------ -std::list<cta::ArchivalJob> cta::MockArchivalJobTable::getArchivalJobs( - const SecurityIdentity &requester, - const std::string &tapePoolName) const { - const std::map<std::string, std::list<ArchivalJob> >::const_iterator - poolItor = m_jobsTree.find(tapePoolName); - return poolItor->second; -} diff --git a/libs/middletier/MockArchivalJobTable.hpp b/libs/middletier/MockArchivalJobTable.hpp deleted file mode 100644 index da0671f6215c2d7d41f1cc1a8f3402d7546fca27..0000000000000000000000000000000000000000 --- a/libs/middletier/MockArchivalJobTable.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#pragma once - -#include "ArchivalJob.hpp" -#include "TapePool.hpp" -#include "SecurityIdentity.hpp" - -#include <list> -#include <map> -#include <string> - -namespace cta { - -/** - * Mock database-table of archival jobs. - */ -class MockArchivalJobTable { -public: - - /** - * Creates an archival job. - * - * @param requester The identity of the user requesting the creation of the - * job. - * @param tapePoolName The name of the destination tape pool. - * @param srcUrl The URL of the source file. - * @param dstPath The full path of the destination file within the archive. - */ - void createArchivalJob( - const SecurityIdentity &requester, - const std::string &tapePoolName, - const std::string &srcUrl, - const std::string &dstPath); - - /** - * Throws an exception if the specified archival job already exists. - * - * @param dstPath The full path of the destination file within the archive. - */ - void checkArchivalJobDoesNotAlreadyExist(const std::string &dstPath) const; - - /** - * Deletes the specified archival job. - * - * @param requester The identity of the user requesting the deletion of the - * job. - * @param dstPath The full path of the destination file within the archive. - */ - void deleteArchivalJob( - const SecurityIdentity &requester, - const std::string &dstPath); - - /** - * Returns all of the existing archival jobs grouped by tape pool name and - * then sorted by creation time in ascending order (oldest first). - * - * @param requester The identity of the user requesting the list. - * @return All of the existing archival jobs grouped by tape pool and then - * sorted by creation time in ascending order (oldest first). - */ - const std::map<std::string, std::list<ArchivalJob> > - &getArchivalJobs(const SecurityIdentity &requester) const; - - /** - * Returns the list of archival jobs associated with the specified tape pool - * sorted by creation time in ascending order (oldest first). - * - * @param requester The identity of the user requesting the list. - * @param tapePoolName The name of the tape pool. - * @return The list of archival jobs associated with the specified tape pool - * sorted by creation time in ascending order (oldest first). - */ - std::list<ArchivalJob> getArchivalJobs( - const SecurityIdentity &requester, - const std::string &tapePoolName) const; - -private: - - /** - * All of the existing archival jobs grouped by tape pool name and then - * sorted by creation time in ascending order (oldest first). - */ - std::map<std::string, std::list<ArchivalJob> > m_jobsTree; - -}; // class MockArchivalJobTable - -} // namespace cta diff --git a/libs/middletier/MockArchivalJobTableTest.cpp b/libs/middletier/MockArchivalJobTableTest.cpp deleted file mode 100644 index 6a601646e80693803cca872a7c8dda7ff7d62063..0000000000000000000000000000000000000000 --- a/libs/middletier/MockArchivalJobTableTest.cpp +++ /dev/null @@ -1,164 +0,0 @@ -#include "MockArchivalJobTable.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class cta_client_MockArchivalJobTableTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(cta_client_MockArchivalJobTableTest, createArchivalJob_new) { - using namespace cta; - - MockArchivalJobTable table; - const SecurityIdentity requester; - - { - std::map<std::string, std::list<ArchivalJob> > pools; - ASSERT_NO_THROW(pools = table.getArchivalJobs(requester)); - ASSERT_TRUE(pools.empty()); - } - - const std::string tapePoolName = "tapePool"; - const std::string srcUrl = "diskUrl"; - const std::string dstPath = "/tapeFilePath"; - ASSERT_NO_THROW(table.createArchivalJob(requester, tapePoolName, srcUrl, - dstPath)); - - { - std::map<std::string, std::list<ArchivalJob> > pools; - ASSERT_NO_THROW(pools = table.getArchivalJobs(requester)); - ASSERT_EQ(1, pools.size()); - std::map<std::string, std::list<ArchivalJob> >::const_iterator - poolItor = pools.find(tapePoolName); - ASSERT_FALSE(poolItor == pools.end()); - const std::list<ArchivalJob> &jobs = poolItor->second; - ASSERT_EQ(1, jobs.size()); - const ArchivalJob &job = jobs.front(); - ASSERT_EQ(srcUrl, job.getSrcUrl()); - ASSERT_EQ(dstPath, job.getDstPath()); - } - - { - const std::list<ArchivalJob> &jobs = table.getArchivalJobs(requester, - tapePoolName); - ASSERT_EQ(1, jobs.size()); - const ArchivalJob &job = jobs.front(); - ASSERT_EQ(srcUrl, job.getSrcUrl()); - ASSERT_EQ(dstPath, job.getDstPath()); - } -} - -TEST_F(cta_client_MockArchivalJobTableTest, createArchivalJob_already_existing) { - using namespace cta; - - MockArchivalJobTable table; - const SecurityIdentity requester; - - { - std::map<std::string, std::list<ArchivalJob> > pools; - ASSERT_NO_THROW(pools = table.getArchivalJobs(requester)); - ASSERT_TRUE(pools.empty()); - } - - const std::string tapePoolName = "tapePool"; - const std::string srcUrl = "diskUrl"; - const std::string dstPath = "/tapeFilePath"; - ASSERT_NO_THROW(table.createArchivalJob(requester, tapePoolName, srcUrl, - dstPath)); - - { - std::map<std::string, std::list<ArchivalJob> > pools; - ASSERT_NO_THROW(pools = table.getArchivalJobs(requester)); - ASSERT_EQ(1, pools.size()); - std::map<std::string, std::list<ArchivalJob> >::const_iterator - poolItor = pools.find(tapePoolName); - ASSERT_FALSE(poolItor == pools.end()); - const std::list<ArchivalJob> &jobs = poolItor->second; - ASSERT_EQ(1, jobs.size()); - const ArchivalJob &job = jobs.front(); - ASSERT_EQ(srcUrl, job.getSrcUrl()); - ASSERT_EQ(dstPath, job.getDstPath()); - } - - { - const std::list<ArchivalJob> &jobs = table.getArchivalJobs(requester, - tapePoolName); - ASSERT_EQ(1, jobs.size()); - const ArchivalJob &job = jobs.front(); - ASSERT_EQ(srcUrl, job.getSrcUrl()); - ASSERT_EQ(dstPath, job.getDstPath()); - } - - ASSERT_THROW(table.createArchivalJob(requester, tapePoolName, srcUrl, - dstPath), std::exception); -} - -TEST_F(cta_client_MockArchivalJobTableTest, deleteTape_existing) { - using namespace cta; - - MockArchivalJobTable table; - const SecurityIdentity requester; - - { - std::map<std::string, std::list<ArchivalJob> > pools; - ASSERT_NO_THROW(pools = table.getArchivalJobs(requester)); - ASSERT_TRUE(pools.empty()); - } - - const std::string tapePoolName = "tapePool"; - const std::string srcUrl = "diskUrl"; - const std::string dstPath = "/tapeFilePath"; - ASSERT_NO_THROW(table.createArchivalJob(requester, tapePoolName, srcUrl, - dstPath)); - - { - std::map<std::string, std::list<ArchivalJob> > pools; - ASSERT_NO_THROW(pools = table.getArchivalJobs(requester)); - ASSERT_EQ(1, pools.size()); - std::map<std::string, std::list<ArchivalJob> >::const_iterator - poolItor = pools.find(tapePoolName); - ASSERT_FALSE(poolItor == pools.end()); - const std::list<ArchivalJob> &jobs = poolItor->second; - ASSERT_EQ(1, jobs.size()); - const ArchivalJob &job = jobs.front(); - ASSERT_EQ(srcUrl, job.getSrcUrl()); - ASSERT_EQ(dstPath, job.getDstPath()); - } - - { - const std::list<ArchivalJob> &jobs = table.getArchivalJobs(requester, - tapePoolName); - ASSERT_EQ(1, jobs.size()); - const ArchivalJob &job = jobs.front(); - ASSERT_EQ(srcUrl, job.getSrcUrl()); - ASSERT_EQ(dstPath, job.getDstPath()); - } - - ASSERT_NO_THROW(table.deleteArchivalJob(requester, dstPath)); - - { - std::map<std::string, std::list<ArchivalJob> > pools; - ASSERT_NO_THROW(pools = table.getArchivalJobs(requester)); - ASSERT_TRUE(pools.empty()); - } -} - -TEST_F(cta_client_MockArchivalJobTableTest, deleteTape_non_existing) { - using namespace cta; - - MockArchivalJobTable table; - const SecurityIdentity requester; - const std::string dstPath = "/tapeFilePath"; - - ASSERT_THROW(table.deleteArchivalJob(requester, dstPath), std::exception); -} - -} // namespace unitTests diff --git a/libs/middletier/MockArchiveRouteTable.cpp b/libs/middletier/MockArchiveRouteTable.cpp deleted file mode 100644 index d4344f1062ff2ac878254373754bc064087ebe31..0000000000000000000000000000000000000000 --- a/libs/middletier/MockArchiveRouteTable.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include "Exception.hpp" -#include "MockArchiveRouteTable.hpp" - -#include <sstream> - -//------------------------------------------------------------------------------ -// createArchiveRoute -//------------------------------------------------------------------------------ -void cta::MockArchiveRouteTable::createArchiveRoute( - const std::string &storageClassName, - const uint16_t copyNb, - const std::string &tapePoolName, - const UserIdentity &creator, - const std::string &comment) { - const ArchiveRouteId routeId(storageClassName, copyNb); - checkArchiveRouteDoesNotAlreadyExists(routeId); - ArchiveRoute route( - storageClassName, - copyNb, - tapePoolName, - creator, - time(NULL), - comment); - m_archiveRoutes[routeId] = route; -} - -//------------------------------------------------------------------------------ -// checkArchiveRouteDoesNotAlreadyExists -//------------------------------------------------------------------------------ -void cta::MockArchiveRouteTable::checkArchiveRouteDoesNotAlreadyExists( - const ArchiveRouteId &routeId) const { - std::map<ArchiveRouteId, ArchiveRoute>::const_iterator itor = - m_archiveRoutes.find(routeId); - if(itor != m_archiveRoutes.end()) { - std::ostringstream message; - message << "A archive route for storage class " << - routeId.getStorageClassName() << " and copy number " << - routeId.getCopyNb() << " already exists"; - throw Exception(message.str()); - } -} - -//------------------------------------------------------------------------------ -// deleteArchiveRoute -//------------------------------------------------------------------------------ -void cta::MockArchiveRouteTable::deleteArchiveRoute( - const std::string &storageClassName, - const uint16_t copyNb) { - const ArchiveRouteId routeId(storageClassName, copyNb); - std::map<ArchiveRouteId, ArchiveRoute>::iterator itor = - m_archiveRoutes.find(routeId); - if(itor == m_archiveRoutes.end()) { - std::ostringstream message; - message << "A archive route for storage class " << - routeId.getStorageClassName() << " and copy number " << - routeId.getCopyNb() << " does not exist"; - throw Exception(message.str()); - } - m_archiveRoutes.erase(routeId); -} - -//------------------------------------------------------------------------------ -// getArchiveRoutes -//------------------------------------------------------------------------------ -std::list<cta::ArchiveRoute> cta::MockArchiveRouteTable:: - getArchiveRoutes() const { - std::list<cta::ArchiveRoute> routes; - for(std::map<ArchiveRouteId, ArchiveRoute>::const_iterator itor = - m_archiveRoutes.begin(); itor != m_archiveRoutes.end(); itor++) { - routes.push_back(itor->second); - } - return routes; -} - -//------------------------------------------------------------------------------ -// getArchiveRoute -//------------------------------------------------------------------------------ -const cta::ArchiveRoute &cta::MockArchiveRouteTable::getArchiveRoute( - const std::string &storageClassName, - const uint16_t copyNb) const { - const ArchiveRouteId routeId(storageClassName, copyNb); - std::map<ArchiveRouteId, ArchiveRoute>::const_iterator itor = - m_archiveRoutes.find(routeId); - if(itor == m_archiveRoutes.end()) { - std::ostringstream message; - message << "No archive route for storage class " << storageClassName << - " copy number " << copyNb; - throw Exception(message.str()); - } - return itor->second; -} - -//------------------------------------------------------------------------------ -// checkArchiveRouteExists -//------------------------------------------------------------------------------ -void cta::MockArchiveRouteTable::checkArchiveRouteExists( - const std::string &storageClassName, const uint16_t copyNb) const { -} - -//------------------------------------------------------------------------------ -// tapePoolIsInAArchiveRoute -//------------------------------------------------------------------------------ -bool cta::MockArchiveRouteTable::tapePoolIsInAArchiveRoute( - const std::string &name) const { - for(std::map<ArchiveRouteId, ArchiveRoute>::const_iterator itor = - m_archiveRoutes.begin(); itor != m_archiveRoutes.end(); itor++) { - if(name == itor->second.getTapePoolName()) { - return true; - } - } - return false; -} - -//------------------------------------------------------------------------------ -// storageClassIsInAArchiveRoute -//------------------------------------------------------------------------------ -bool cta::MockArchiveRouteTable::storageClassIsInAArchiveRoute( - const std::string &name) const { - for(std::map<ArchiveRouteId, ArchiveRoute>::const_iterator itor = - m_archiveRoutes.begin(); itor != m_archiveRoutes.end(); itor++) { - if(name == itor->second.getStorageClassName()) { - return true; - } - } - return false; -} diff --git a/libs/middletier/MockArchiveRouteTable.hpp b/libs/middletier/MockArchiveRouteTable.hpp deleted file mode 100644 index 2e9a996135dd2e916dcab2b4119719b3c0c92e41..0000000000000000000000000000000000000000 --- a/libs/middletier/MockArchiveRouteTable.hpp +++ /dev/null @@ -1,109 +0,0 @@ -#pragma once - -#include "ArchiveRoute.hpp" -#include "ArchiveRouteId.hpp" - -#include <list> -#include <map> -#include <stdint.h> -#include <string> - -namespace cta { - -/** - * Mock database-table of archive routes. - */ -class MockArchiveRouteTable { -public: - - /** - * Creates the specified archive route. - * - * @param storageClassName The name of the storage class that identifies the - * source disk files. - * @param copyNb The tape copy number. - * @param tapePoolName The name of the destination tape pool. - * @param creator The identity of the user that created the storage class. - * @param comment Comment describing the storage class. - */ - void createArchiveRoute( - const std::string &storageClassName, - const uint16_t copyNb, - const std::string &tapePoolName, - const UserIdentity &creator, - const std::string &comment); - - /** - * Deletes the specified archive route. - * - * @param storageClassName The name of the storage class that identifies the - * source disk files. - * @param copyNb The tape copy number. - */ - void deleteArchiveRoute( - const std::string &storageClassName, - const uint16_t copyNb); - - /** - * Gets the current list of archive routes. - * - * @return The current list of archive routes. - */ - std::list<ArchiveRoute> getArchiveRoutes() const; - - /** - * Returns the specified archive route. - * - * @param storageClassName The name of the storage class that identifies the - * source disk files. - * @param copyNb The tape copy number. - * @return The specified archive route. - */ - const ArchiveRoute &getArchiveRoute( - const std::string &storageClassName, - const uint16_t copyNb) const; - - /** - * Throws an exception if the specified archive route does not exist. - * - * @param storageClassName The name of the storage class that identifies the - * source disk files. - * @param copyNb The tape copy number. - */ - void checkArchiveRouteExists(const std::string &storageClassName, - const uint16_t copyNb) const; - - /** - * Returns true if the specified tape pool is in one of the current archive - * routes. - * - * @param name The name of the tape pool. - */ - bool tapePoolIsInAArchiveRoute(const std::string &name) const; - - /** - * Returns true if the specified storage class is in one of the current - * archive routes. - * - * @param name The name of the storage class. - */ - bool storageClassIsInAArchiveRoute(const std::string &name) const; - -private: - - /** - * The current mapping from archive-route identifier to archive route. - */ - std::map<ArchiveRouteId, ArchiveRoute> m_archiveRoutes; - - /** - * Throws an exception if the specified archive route already exists. - * - * @param routeId The identity of the archive route. - */ - void checkArchiveRouteDoesNotAlreadyExists(const ArchiveRouteId &routeId) - const; - -}; // class MockArchiveRouteTable - -} // namespace cta diff --git a/libs/middletier/MockDatabase.cpp b/libs/middletier/MockDatabase.cpp deleted file mode 100644 index 54ca00e285be1537820581605d5915564eb3d669..0000000000000000000000000000000000000000 --- a/libs/middletier/MockDatabase.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "Exception.hpp" -#include "MockDatabase.hpp" - -#include <iostream> -#include <memory> -#include <sstream> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::MockDatabase::MockDatabase(): - fileSystemRoot(storageClasses, - DirectoryEntry(DirectoryEntry::ENTRYTYPE_DIRECTORY, "/", "")) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::MockDatabase::~MockDatabase() throw() { -} diff --git a/libs/middletier/MockDatabase.hpp b/libs/middletier/MockDatabase.hpp deleted file mode 100644 index 05e9afe2f4dcfc26967fa4bd688a48f676e27966..0000000000000000000000000000000000000000 --- a/libs/middletier/MockDatabase.hpp +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once - -#include "FileSystemNode.hpp" -#include "FileSystemStorageClasses.hpp" -#include "MockAdminHostTable.hpp" -#include "MockAdminUserTable.hpp" -#include "MockArchivalJobTable.hpp" -#include "MockArchiveRouteTable.hpp" -#include "MockLogicalLibraryTable.hpp" -#include "MockRetrievalJobTable.hpp" -#include "MockTapeTable.hpp" -#include "MockTapePoolTable.hpp" - -namespace cta { - -/** - * Mock database. - */ -struct MockDatabase { - /** - * Constructor. - * - * Creates the root directory "/" owned by user root and with no file - * attributes or permissions. - */ - MockDatabase(); - - /** - * Destructor. - */ - ~MockDatabase() throw(); - - /** - * Table of administrators. - */ - MockAdminUserTable adminUsers; - - /** - * Table of administration hosts. - */ - MockAdminHostTable adminHosts; - - /** - * Container of the storage classes used by the file system. - */ - FileSystemStorageClasses storageClasses; - - /** - * Table of tape pools. - */ - MockTapePoolTable tapePools; - - /** - * Container of archive routes. - */ - MockArchiveRouteTable archiveRoutes; - - /** - * The root node of the file-system. - */ - FileSystemNode fileSystemRoot; - - /** - * Table of logical libraries. - */ - MockLogicalLibraryTable libraries; - - /** - * Table of tapes. - */ - MockTapeTable tapes; - - /** - * Table of archival jobs. - */ - MockArchivalJobTable archivalJobs; - - /** - * Table of retrieval jobs. - */ - MockRetrievalJobTable retrievalJobs; - -}; // struct MockDatabase - -} // namespace cta diff --git a/libs/middletier/MockLogicalLibraryTable.cpp b/libs/middletier/MockLogicalLibraryTable.cpp deleted file mode 100644 index 5de950930633f64b2f616a1bb1f712d7a6d37641..0000000000000000000000000000000000000000 --- a/libs/middletier/MockLogicalLibraryTable.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "Exception.hpp" -#include "MockLogicalLibraryTable.hpp" - -#include <iostream> -#include <memory> -#include <sstream> - -//------------------------------------------------------------------------------ -// createLogicalLibrary -//------------------------------------------------------------------------------ -void cta::MockLogicalLibraryTable::createLogicalLibrary( - const SecurityIdentity &requester, - const std::string &name, - const std::string &comment) { - checkLogicalLibraryDoesNotAlreadyExist(name); - LogicalLibrary logicalLibrary(name, requester.user, time(NULL), comment); - m_libraries[name] = logicalLibrary; -} - -//------------------------------------------------------------------------------ -// checkLogicalLibraryDoesNotAlreadyExist -//------------------------------------------------------------------------------ -void cta::MockLogicalLibraryTable::checkLogicalLibraryDoesNotAlreadyExist( - const std::string &name) const { - std::map<std::string, LogicalLibrary>::const_iterator itor = - m_libraries.find(name); - if(itor != m_libraries.end()) { - std::ostringstream message; - message << "Logical library " << name << " already exists"; - throw(Exception(message.str())); - } -} - -//------------------------------------------------------------------------------ -// checkLogicalLibraryExists -//------------------------------------------------------------------------------ -void cta::MockLogicalLibraryTable::checkLogicalLibraryExists( - const std::string &name) const { - std::map<std::string, LogicalLibrary>::const_iterator itor = - m_libraries.find(name); - if(itor == m_libraries.end()) { - std::ostringstream message; - message << "Logical library " << name << " does not exist"; - throw(Exception(message.str())); - } -} - -//------------------------------------------------------------------------------ -// deleteLogicalLibrary -//------------------------------------------------------------------------------ -void cta::MockLogicalLibraryTable::deleteLogicalLibrary( - const SecurityIdentity &requester, - const std::string &name) { - for(std::map<std::string, LogicalLibrary>::iterator itor = - m_libraries.begin(); itor != m_libraries.end(); - itor++) { - if(name == itor->first) { - m_libraries.erase(itor); - return; - } - } - - // Reaching this point means the logical library to be deleted does not - // exist - std::ostringstream message; - message << "Logical library " << name << " does not exist"; - throw Exception(message.str()); -} - -//------------------------------------------------------------------------------ -// getLogicalLibraries -//------------------------------------------------------------------------------ -std::list<cta::LogicalLibrary> cta::MockLogicalLibraryTable::getLogicalLibraries( - const SecurityIdentity &requester) const { - std::list<LogicalLibrary> libraries; - - for(std::map<std::string, LogicalLibrary>::const_iterator itor = - m_libraries.begin(); itor != m_libraries.end(); - itor++) { - libraries.push_back(itor->second); - } - return libraries; -} diff --git a/libs/middletier/MockLogicalLibraryTable.hpp b/libs/middletier/MockLogicalLibraryTable.hpp deleted file mode 100644 index 96eba2759b6749aa7899547b6a65d1edb21aeedf..0000000000000000000000000000000000000000 --- a/libs/middletier/MockLogicalLibraryTable.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include "LogicalLibrary.hpp" -#include "SecurityIdentity.hpp" - -#include <list> -#include <map> -#include <string> - -namespace cta { - -/** - * Mock database-table logical libraries. - */ -class MockLogicalLibraryTable { -public: - - /** - * Creates a logical library with the specified name. - * - * @param requester The identity of the user requesting the creation of the - * logical library. - * @param name The name of the logical library. - * @param comment The comment describing the logical library. - */ - void createLogicalLibrary( - const SecurityIdentity &requester, - const std::string &name, - const std::string &comment); - - /** - * Throws an exception if the specified logical library already exists. - * - * @param name The name of the logical library. - */ - void checkLogicalLibraryDoesNotAlreadyExist(const std::string &name) const; - - /** - * Throws an exception if the specified logical library does not exists. - * - * @param name The name of the logical library. - */ - void checkLogicalLibraryExists(const std::string &name) const; - - /** - * Deletes the logical library with the specified name. - * - * @param requester The identity of the user requesting the deletion of the - * logical library. - * @param name The name of the logical library. - */ - void deleteLogicalLibrary( - const SecurityIdentity &requester, - const std::string &name); - - /** - * Returns the current list of libraries in lexicographical order. - * - * @param requester The identity of the user requesting the list. - * @return The current list of libraries in lexicographical order. - */ - std::list<LogicalLibrary> getLogicalLibraries( - const SecurityIdentity &requester) const; - -private: - - /** - * Mapping from logical-library name to logical library. - */ - std::map<std::string, LogicalLibrary> m_libraries; - -}; // class MockLogicalLibraryTable - -} // namespace cta diff --git a/libs/middletier/MockLogicalLibraryTableTest.cpp b/libs/middletier/MockLogicalLibraryTableTest.cpp deleted file mode 100644 index 077724d584ba53ab7fe5a05708cae8eb31bedc75..0000000000000000000000000000000000000000 --- a/libs/middletier/MockLogicalLibraryTableTest.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include "MockLogicalLibraryTable.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class cta_client_MockLogicalLibraryTableTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(cta_client_MockLogicalLibraryTableTest, createLogicalLibrary_new) { - using namespace cta; - - MockLogicalLibraryTable table; - const SecurityIdentity requester; - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - - ASSERT_THROW(table.checkLogicalLibraryExists(libraryName), std::exception); - - const std::string libraryComment = "Comment"; - ASSERT_NO_THROW(table.createLogicalLibrary(requester, libraryName, - libraryComment)); - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_EQ(1, libraries.size()); - - LogicalLibrary logicalLibrary; - ASSERT_NO_THROW(logicalLibrary = libraries.front()); - ASSERT_EQ(libraryName, logicalLibrary.getName()); - ASSERT_EQ(libraryComment, logicalLibrary.getComment()); - } - - ASSERT_NO_THROW(table.checkLogicalLibraryExists(libraryName)); -} - -TEST_F(cta_client_MockLogicalLibraryTableTest, - createLogicalLibrary_already_existing) { - using namespace cta; - - MockLogicalLibraryTable table; - const SecurityIdentity requester; - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - const std::string libraryComment = "Comment"; - ASSERT_NO_THROW(table.createLogicalLibrary(requester, libraryName, - libraryComment)); - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_EQ(1, libraries.size()); - - LogicalLibrary logicalLibrary; - ASSERT_NO_THROW(logicalLibrary = libraries.front()); - ASSERT_EQ(libraryName, logicalLibrary.getName()); - ASSERT_EQ(libraryComment, logicalLibrary.getComment()); - } - - ASSERT_THROW(table.createLogicalLibrary(requester, libraryName, - libraryComment), std::exception); -} - -TEST_F(cta_client_MockLogicalLibraryTableTest, - createLogicalLibrary_lexicographical_order) { - using namespace cta; - - MockLogicalLibraryTable table; - const SecurityIdentity requester; - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } - - ASSERT_NO_THROW(table.createLogicalLibrary(requester, "d", "Comment d")); - ASSERT_NO_THROW(table.createLogicalLibrary(requester, "b", "Comment b")); - ASSERT_NO_THROW(table.createLogicalLibrary(requester, "a", "Comment a")); - ASSERT_NO_THROW(table.createLogicalLibrary(requester, "c", "Comment c")); - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_EQ(4, libraries.size()); - - ASSERT_EQ(std::string("a"), libraries.front().getName()); - libraries.pop_front(); - ASSERT_EQ(std::string("b"), libraries.front().getName()); - libraries.pop_front(); - ASSERT_EQ(std::string("c"), libraries.front().getName()); - libraries.pop_front(); - ASSERT_EQ(std::string("d"), libraries.front().getName()); - } -} - -TEST_F(cta_client_MockLogicalLibraryTableTest, deleteLogicalLibrary_existing) { - using namespace cta; - - MockLogicalLibraryTable table; - const SecurityIdentity requester; - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - const std::string libraryComment = "Comment"; - ASSERT_NO_THROW(table.createLogicalLibrary(requester, libraryName, - libraryComment)); - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_EQ(1, libraries.size()); - - LogicalLibrary logicalLibrary; - ASSERT_NO_THROW(logicalLibrary = libraries.front()); - ASSERT_EQ(libraryName, logicalLibrary.getName()); - ASSERT_EQ(libraryComment, logicalLibrary.getComment()); - - ASSERT_NO_THROW(table.deleteLogicalLibrary(requester, libraryName)); - } - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } -} - -TEST_F(cta_client_MockLogicalLibraryTableTest, - deleteLogicalLibrary_non_existing) { - using namespace cta; - - MockLogicalLibraryTable table; - const SecurityIdentity requester; - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - ASSERT_THROW(table.deleteLogicalLibrary(requester, libraryName), - std::exception); - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = table.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } -} - -} // namespace unitTests diff --git a/libs/middletier/MockMiddleTierAdmin.cpp b/libs/middletier/MockMiddleTierAdmin.cpp deleted file mode 100644 index eec5cbbcfc5cee013f396fbc133be8ed56c1bf9e..0000000000000000000000000000000000000000 --- a/libs/middletier/MockMiddleTierAdmin.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#include "Exception.hpp" -#include "MockMiddleTierAdmin.hpp" - -#include <iostream> -#include <memory> -#include <sstream> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::MockMiddleTierAdmin::MockMiddleTierAdmin(MockDatabase &database): - m_db(database) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::MockMiddleTierAdmin::~MockMiddleTierAdmin() throw() { -} - -//------------------------------------------------------------------------------ -// createAdminUser -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::createAdminUser( - const SecurityIdentity &requester, - const UserIdentity &user, - const std::string &comment) { - m_db.adminUsers.createAdminUser(requester, user, comment); -} - -//------------------------------------------------------------------------------ -// deleteAdminUser -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::deleteAdminUser( - const SecurityIdentity &requester, - const UserIdentity &user) { - m_db.adminUsers.deleteAdminUser(requester, user); -} - -//------------------------------------------------------------------------------ -// getAdminUsers -//------------------------------------------------------------------------------ -std::list<cta::AdminUser> cta::MockMiddleTierAdmin::getAdminUsers( - const SecurityIdentity &requester) const { - return m_db.adminUsers.getAdminUsers(requester); -} - -//------------------------------------------------------------------------------ -// createAdminHost -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::createAdminHost( - const SecurityIdentity &requester, - const std::string &hostName, - const std::string &comment) { - m_db.adminHosts.createAdminHost(requester, hostName, comment); -} - -//------------------------------------------------------------------------------ -// deleteAdminHost -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::deleteAdminHost( - const SecurityIdentity &requester, - const std::string &hostName) { - m_db.adminHosts.deleteAdminHost(requester, hostName); -} - -//------------------------------------------------------------------------------ -// getAdminHosts -//------------------------------------------------------------------------------ -std::list<cta::AdminHost> cta::MockMiddleTierAdmin::getAdminHosts( - const SecurityIdentity &requester) const { - return m_db.adminHosts.getAdminHosts(requester); -} - -//------------------------------------------------------------------------------ -// createStorageClass -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::createStorageClass( - const SecurityIdentity &requester, const std::string &name, - const uint16_t nbCopies, const std::string &comment) { - m_db.storageClasses.createStorageClass(name, nbCopies, requester.user, - comment); -} - -//------------------------------------------------------------------------------ -// deleteStorageClass -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::deleteStorageClass(const SecurityIdentity &requester, - const std::string &name) { - checkStorageClassIsNotInAArchiveRoute(name); - m_db.storageClasses.deleteStorageClass(name); -} - -//------------------------------------------------------------------------------ -// checkStorageClassIsNotInAArchiveRoute -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::checkStorageClassIsNotInAArchiveRoute( - const std::string &name) const { - if(m_db.archiveRoutes.storageClassIsInAArchiveRoute(name)) { - std::ostringstream message; - message << "The " << name << " storage class is in use"; - throw Exception(message.str()); - } -} - -//------------------------------------------------------------------------------ -// getStorageClasses -//------------------------------------------------------------------------------ -std::list<cta::StorageClass> cta::MockMiddleTierAdmin::getStorageClasses( - const SecurityIdentity &requester) const { - return m_db.storageClasses.getStorageClasses(); -} - -//------------------------------------------------------------------------------ -// createTapePool -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::createTapePool( - const SecurityIdentity &requester, - const std::string &name, - const uint16_t nbDrives, - const uint32_t nbPartialTapes, - const std::string &comment) { - m_db.tapePools.createTapePool(requester, name, nbDrives, nbPartialTapes, - comment); -} - -//------------------------------------------------------------------------------ -// deleteTapePool -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::deleteTapePool(const SecurityIdentity &requester, - const std::string &name) { - checkTapePoolIsNotInUse(name); - m_db.tapePools.deleteTapePool(requester, name); -} - -//------------------------------------------------------------------------------ -// checkTapePoolIsNotInUse -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::checkTapePoolIsNotInUse(const std::string &name) - const { - if(m_db.archiveRoutes.tapePoolIsInAArchiveRoute(name)) { - std::ostringstream message; - message << "The " << name << " tape pool is in use"; - throw Exception(message.str()); - } -} - -//------------------------------------------------------------------------------ -// getTapePools -//------------------------------------------------------------------------------ -std::list<cta::TapePool> cta::MockMiddleTierAdmin::getTapePools( - const SecurityIdentity &requester) const { - return m_db.tapePools.getTapePools(requester); -} - -//------------------------------------------------------------------------------ -// createArchiveRoute -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::createArchiveRoute( - const SecurityIdentity &requester, - const std::string &storageClassName, - const uint16_t copyNb, - const std::string &tapePoolName, - const std::string &comment) { - return m_db.archiveRoutes.createArchiveRoute( - storageClassName, - copyNb, - tapePoolName, - requester.user, - comment); -} - -//------------------------------------------------------------------------------ -// deleteArchiveRoute -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::deleteArchiveRoute( - const SecurityIdentity &requester, - const std::string &storageClassName, - const uint16_t copyNb) { - return m_db.archiveRoutes.deleteArchiveRoute(storageClassName, copyNb); -} - -//------------------------------------------------------------------------------ -// getArchiveRoutes -//------------------------------------------------------------------------------ -std::list<cta::ArchiveRoute> cta::MockMiddleTierAdmin::getArchiveRoutes( - const SecurityIdentity &requester) const { - return m_db.archiveRoutes.getArchiveRoutes(); -} - -//------------------------------------------------------------------------------ -// createLogicalLibrary -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::createLogicalLibrary( - const SecurityIdentity &requester, - const std::string &name, - const std::string &comment) { - m_db.libraries.createLogicalLibrary(requester, name, comment); -} - -//------------------------------------------------------------------------------ -// deleteLogicalLibrary -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::deleteLogicalLibrary( - const SecurityIdentity &requester, - const std::string &name) { - m_db.libraries.deleteLogicalLibrary(requester, name); -} - -//------------------------------------------------------------------------------ -// getLogicalLibraries -//------------------------------------------------------------------------------ -std::list<cta::LogicalLibrary> cta::MockMiddleTierAdmin::getLogicalLibraries( - const SecurityIdentity &requester) const { - return m_db.libraries.getLogicalLibraries(requester); -} - -//------------------------------------------------------------------------------ -// createTape -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::createTape( - const SecurityIdentity &requester, - const std::string &vid, - const std::string &logicalLibraryName, - const std::string &tapePoolName, - const uint64_t capacityInBytes, - const std::string &comment) { - m_db.libraries.checkLogicalLibraryExists(logicalLibraryName); - m_db.tapePools.checkTapePoolExists(tapePoolName); - m_db.tapes.createTape(requester, vid, logicalLibraryName, tapePoolName, - capacityInBytes, comment); -} - -//------------------------------------------------------------------------------ -// deleteTape -//------------------------------------------------------------------------------ -void cta::MockMiddleTierAdmin::deleteTape( - const SecurityIdentity &requester, - const std::string &vid) { - m_db.tapes.deleteTape(requester, vid); -} - -//------------------------------------------------------------------------------ -// getTapes -//------------------------------------------------------------------------------ -std::list<cta::Tape> cta::MockMiddleTierAdmin::getTapes( - const SecurityIdentity &requester) const { - return m_db.tapes.getTapes(requester); -} diff --git a/libs/middletier/MockMiddleTierAdmin.hpp b/libs/middletier/MockMiddleTierAdmin.hpp deleted file mode 100644 index 25357dcd7367bbac5ca3736540ee17f2c242b60e..0000000000000000000000000000000000000000 --- a/libs/middletier/MockMiddleTierAdmin.hpp +++ /dev/null @@ -1,331 +0,0 @@ -#pragma once - -#include "MiddleTierAdmin.hpp" -#include "MockDatabase.hpp" - -namespace cta { - -/** - * The administration API of the mock middle-tier. - */ -class MockMiddleTierAdmin: public MiddleTierAdmin { -public: - - /** - * Constructor. - * - * @param db The database of the mock middle-tier. - */ - MockMiddleTierAdmin(MockDatabase &db); - - /** - * Destructor. - */ - ~MockMiddleTierAdmin() throw(); - - /** - * Creates the specified administrator. - * - * @param requester The identity of the user requesting the creation of the - * administrator. - * @param user The identity of the administrator. - * @param comment The comment describing te administator. - */ - void createAdminUser( - const SecurityIdentity &requester, - const UserIdentity &user, - const std::string &comment); - - /** - * Deletes the specified administrator. - * - * @param requester The identity of the user requesting the deletion of the - * administrator. - * @param user The identity of the administrator. - */ - void deleteAdminUser( - const SecurityIdentity &requester, - const UserIdentity &user); - - /** - * Returns the current list of administrators in lexicographical order. - * - * @param requester The identity of the user requesting the list. - * @return The current list of administrators in lexicographical order. - */ - std::list<AdminUser> getAdminUsers(const SecurityIdentity &requester) const; - - /** - * Creates the specified administration host. - * - * @param requester The identity of the user requesting the creation of the - * administration host. - * @param hostName The network name of the administration host. - * @param comment The comment describing the administration host. - */ - void createAdminHost( - const SecurityIdentity &requester, - const std::string &hostName, - const std::string &comment); - - /** - * Deletes the specified administration host. - * - * @param requester The identity of the user requesting the deletion of the - * administration host. - * @param hostName The network name of the administration host. - * @param comment The comment describing the administration host. - */ - void deleteAdminHost( - const SecurityIdentity &requester, - const std::string &hostName); - - /** - * Returns the current list of administration hosts. - * - * @param requester The identity of the user requesting the list. - */ - std::list<AdminHost> getAdminHosts(const SecurityIdentity &requester) const; - - /** - * Creates the specified storage class. - * - * @param requester The identity of the user requesting the creation of the - * storage class. - * @param name The name of the storage class. - * @param nbCopies The number of copies a file associated with this storage - * class should have on tape. - * @param comment The comment describing the storage class. - */ - void createStorageClass( - const SecurityIdentity &requester, - const std::string &name, - const uint16_t nbCopies, - const std::string &comment); - - /** - * Deletes the specified storage class. - * - * @param requester The identity of the user requesting the deletion of the - * storage class. - * @param name The name of the storage class. - */ - void deleteStorageClass( - const SecurityIdentity &requester, - const std::string &name); - - /** - * Gets the current list of storage classes in lexicographical order. - * - * @param requester The identity of the user requesting the list. - * @return The current list of storage classes in lexicographical order. - */ - std::list<StorageClass> getStorageClasses( - const SecurityIdentity &requester) const; - - /** - * Creates a tape pool with the specifed name. - * - * @param requester The identity of the user requesting the creation of the - * tape pool. - * @param name The name of the tape pool. - * @param nbDrives The maximum number of drives that can be concurrently - * assigned to this pool independent of whether they are archiving or - * retrieving files. - * @param nbPartialTapes The maximum number of tapes that can be partially - * full at any moment in time. - * @param comment The comment describing the tape pool. - */ - void createTapePool( - const SecurityIdentity &requester, - const std::string &name, - const uint16_t nbDrives, - const uint32_t nbPartialTapes, - const std::string &comment); - - /** - * Delete the tape pool with the specifed name. - * - * @param requester The identity of the user requesting the deletion of the - * tape pool. - * @param name The name of the tape pool. - */ - void deleteTapePool( - const SecurityIdentity &requester, - const std::string &name); - - /** - * Gets the current list of tape pools in lexicographical order. - * - * @param requester The identity of the user requesting the list. - * @return The current list of tape pools in lexicographical order. - */ - std::list<TapePool> getTapePools( - const SecurityIdentity &requester) const; - - /** - * Creates the specified archive route. - * - * @param requester The identity of the user requesting the creation of the - * archive route. - * @param storageClassName The name of the storage class that identifies the - * source disk files. - * @param copyNb The tape copy number. - * @param tapePoolName The name of the destination tape pool. - * @param comment The comment describing the archive route. - */ - void createArchiveRoute( - const SecurityIdentity &requester, - const std::string &storageClassName, - const uint16_t copyNb, - const std::string &tapePoolName, - const std::string &comment); - - /** - * Deletes the specified archive route. - * - * @param requester The identity of the user requesting the deletion of the - * archive route. - * @param storageClassName The name of the storage class that identifies the - * source disk files. - * @param copyNb The tape copy number. - */ - void deleteArchiveRoute( - const SecurityIdentity &requester, - const std::string &storageClassName, - const uint16_t copyNb); - - /** - * Gets the current list of archive routes. - * - * @param requester The identity of the user requesting the list. - */ - std::list<ArchiveRoute> getArchiveRoutes( - const SecurityIdentity &requester) const; - - /** - * Creates a logical library with the specified name. - * - * @param requester The identity of the user requesting the creation of the - * logical library. - * @param name The name of the logical library. - * @param comment The comment describing the logical library. - */ - void createLogicalLibrary( - const SecurityIdentity &requester, - const std::string &name, - const std::string &comment); - - /** - * Deletes the logical library with the specified name. - * - * @param requester The identity of the user requesting the deletion of the - * logical library. - * @param name The name of the logical library. - */ - void deleteLogicalLibrary( - const SecurityIdentity &requester, - const std::string &name); - - /** - * Returns the current list of libraries in lexicographical order. - * - * @param requester The identity of the user requesting the list. - * @return The current list of libraries in lexicographical order. - */ - std::list<LogicalLibrary> getLogicalLibraries( - const SecurityIdentity &requester) const; - - /** - * Creates a tape. - * - * @param requester The identity of the user requesting the creation of the - * tape. - * @param vid The volume identifier of the tape. - * @param logicalLibrary The name of the logical library to which the tape - * belongs. - * @param tapePoolName The name of the tape pool to which the tape belongs. - * @param capacityInBytes The capacity of the tape. - * @param comment The comment describing the logical library. - */ - void createTape( - const SecurityIdentity &requester, - const std::string &vid, - const std::string &logicalLibraryName, - const std::string &tapePoolName, - const uint64_t capacityInBytes, - const std::string &comment); - - /** - * Deletes the tape with the specified volume identifier. - * - * @param requester The identity of the user requesting the deletion of the - * tape. - * @param vid The volume identifier of the tape. - */ - void deleteTape( - const SecurityIdentity &requester, - const std::string &vid); - - /** - * Returns the current list of tapes in the lexicographical order of their - * volume identifiers. - * - * @param requester The identity of the user requesting the list. - * @return The current list of tapes in the lexicographical order of their - * volume identifiers. - */ - std::list<Tape> getTapes( - const SecurityIdentity &requester) const; - -protected: - - /** - * Gets the file system node corresponding to the specified path. - * - * @path The path. - * @return The corresponding file system node. - */ - FileSystemNode &getFileSystemNode(const std::string &path); - - /** - * Gets the file system node corresponding to the specified path. - * - * @path The path. - * @return The corresponding file system node. - */ - const FileSystemNode &getFileSystemNode(const std::string &path) const; - - /** - * Throws an exception if the specified tape pool is in use. - * - * @param name The name of the tape pool. - */ - void checkTapePoolIsNotInUse(const std::string &name) const; - - /** - * Throws an exception if the specified storage class is used in an archive - * route. - * - * @param name The name of the storage class. - */ - void checkStorageClassIsNotInAArchiveRoute(const std::string &name) const; - - /** - * Returns true if the specified absolute path is that of an existing - * directory within the archive namepsace. - * - * @param path The specified absolute path. - * @return True if the specified absolute path is that of an existing - * directory within the archive namepsace. - */ - bool isAnExistingDirectory(const std::string &path) const throw(); - - /** - * The database of the mock middle-tier. - */ - MockDatabase &m_db; - -}; // class MockMiddleTierAdmin - -} // namespace cta diff --git a/libs/middletier/MockMiddleTierAdminTest.cpp b/libs/middletier/MockMiddleTierAdminTest.cpp deleted file mode 100644 index ff60b4547728dd55fec7d110e80fbc2be94743f1..0000000000000000000000000000000000000000 --- a/libs/middletier/MockMiddleTierAdminTest.cpp +++ /dev/null @@ -1,746 +0,0 @@ -#include "MockMiddleTierAdmin.hpp" -#include "MockMiddleTierUser.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class cta_client_MockMiddleTierAdminTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(cta_client_MockMiddleTierAdminTest, createStorageClass_new) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } - - const std::string name = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string comment = "Comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, name, nbCopies, - comment)); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_EQ(1, storageClasses.size()); - - StorageClass storageClass; - ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(name, storageClass.getName()); - ASSERT_EQ(nbCopies, storageClass.getNbCopies()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, - createStorageClass_already_existing) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } - - const std::string name = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string comment = "Comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, name, nbCopies, comment)); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_EQ(1, storageClasses.size()); - - StorageClass storageClass; - ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(name, storageClass.getName()); - ASSERT_EQ(nbCopies, storageClass.getNbCopies()); - } - - ASSERT_THROW(adminApi.createStorageClass(requester, name, nbCopies, comment), - std::exception); -} - -TEST_F(cta_client_MockMiddleTierAdminTest, - createStorageClass_lexicographical_order) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } - - ASSERT_NO_THROW(adminApi.createStorageClass(requester, "d", 1, "Comment d")); - ASSERT_NO_THROW(adminApi.createStorageClass(requester, "b", 1, "Comment b")); - ASSERT_NO_THROW(adminApi.createStorageClass(requester, "a", 1, "Comment a")); - ASSERT_NO_THROW(adminApi.createStorageClass(requester, "c", 1, "Comment c")); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_EQ(4, storageClasses.size()); - - ASSERT_EQ(std::string("a"), storageClasses.front().getName()); - storageClasses.pop_front(); - ASSERT_EQ(std::string("b"), storageClasses.front().getName()); - storageClasses.pop_front(); - ASSERT_EQ(std::string("c"), storageClasses.front().getName()); - storageClasses.pop_front(); - ASSERT_EQ(std::string("d"), storageClasses.front().getName()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, deleteStorageClass_existing) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } - - const std::string name = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string comment = "Comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, name, nbCopies, comment)); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_EQ(1, storageClasses.size()); - - StorageClass storageClass; - ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(name, storageClass.getName()); - ASSERT_EQ(nbCopies, storageClass.getNbCopies()); - - ASSERT_NO_THROW(adminApi.deleteStorageClass(requester, name)); - } - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, - deleteStorageClass_in_use_by_directory) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string comment = "Comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, nbCopies, - comment)); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_EQ(1, storageClasses.size()); - - StorageClass storageClass; - ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(storageClassName, storageClass.getName()); - ASSERT_EQ(nbCopies, storageClass.getNbCopies()); - } - - MockMiddleTierUser userApi(db); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, "/", - storageClassName)); - - ASSERT_THROW(adminApi.deleteStorageClass(requester, storageClassName), - std::exception); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_EQ(1, storageClasses.size()); - - StorageClass storageClass; - ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(storageClassName, storageClass.getName()); - ASSERT_EQ(nbCopies, storageClass.getNbCopies()); - } - - ASSERT_NO_THROW(userApi.clearDirectoryStorageClass(requester, "/")); - - ASSERT_NO_THROW(adminApi.deleteStorageClass(requester, storageClassName)); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, deleteStorageClass_in_use_by_route) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string comment = "Comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, nbCopies, - comment)); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_EQ(1, storageClasses.size()); - - StorageClass storageClass; - ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(storageClassName, storageClass.getName()); - ASSERT_EQ(nbCopies, storageClass.getNbCopies()); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = adminApi.getTapePools(requester)); - ASSERT_EQ(1, tapePools.size()); - - TapePool tapePool; - ASSERT_NO_THROW(tapePool = tapePools.front()); - ASSERT_EQ(tapePoolName, tapePool.getName()); - } - - const uint16_t copyNb = 1; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, comment)); - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_EQ(1, archiveRoutes.size()); - - ArchiveRoute archiveRoute; - ASSERT_NO_THROW(archiveRoute = archiveRoutes.front()); - ASSERT_EQ(storageClassName, archiveRoute.getStorageClassName()); - ASSERT_EQ(copyNb, archiveRoute.getCopyNb()); - ASSERT_EQ(tapePoolName, archiveRoute.getTapePoolName()); - } - - ASSERT_THROW(adminApi.deleteStorageClass(requester, storageClassName), - std::exception); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_EQ(1, storageClasses.size()); - - StorageClass storageClass; - ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(storageClassName, storageClass.getName()); - ASSERT_EQ(nbCopies, storageClass.getNbCopies()); - } - - ASSERT_NO_THROW(adminApi.deleteArchiveRoute(requester, storageClassName, - copyNb)); - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_TRUE(archiveRoutes.empty()); - } - - ASSERT_NO_THROW(adminApi.deleteStorageClass(requester, storageClassName)); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, deleteStorageClass_non_existing) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } - - const std::string name = "TestStorageClass"; - ASSERT_THROW(adminApi.deleteStorageClass(requester, name), std::exception); - - { - std::list<StorageClass> storageClasses; - ASSERT_NO_THROW(storageClasses = adminApi.getStorageClasses(requester)); - ASSERT_TRUE(storageClasses.empty()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, deleteTapePool_in_use) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_TRUE(archiveRoutes.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const std::string comment = "Comment"; - { - const uint16_t nbCopies = 2; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, comment)); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - const uint16_t copyNb = 1; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, comment)); - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_EQ(1, archiveRoutes.size()); - - ArchiveRoute archiveRoute; - ASSERT_NO_THROW(archiveRoute = archiveRoutes.front()); - ASSERT_EQ(storageClassName, archiveRoute.getStorageClassName()); - ASSERT_EQ(copyNb, archiveRoute.getCopyNb()); - ASSERT_EQ(tapePoolName, archiveRoute.getTapePoolName()); - } - - ASSERT_THROW(adminApi.deleteTapePool(requester, tapePoolName), std::exception); - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_EQ(1, archiveRoutes.size()); - - ArchiveRoute archiveRoute; - ASSERT_NO_THROW(archiveRoute = archiveRoutes.front()); - ASSERT_EQ(storageClassName, archiveRoute.getStorageClassName()); - ASSERT_EQ(copyNb, archiveRoute.getCopyNb()); - ASSERT_EQ(tapePoolName, archiveRoute.getTapePoolName()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, createArchiveRoute_new) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_TRUE(archiveRoutes.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const std::string comment = "Comment"; - { - const uint16_t nbCopies = 2; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, comment)); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - const uint16_t copyNb = 1; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, comment)); - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_EQ(1, archiveRoutes.size()); - - ArchiveRoute archiveRoute; - ASSERT_NO_THROW(archiveRoute = archiveRoutes.front()); - ASSERT_EQ(storageClassName, archiveRoute.getStorageClassName()); - ASSERT_EQ(copyNb, archiveRoute.getCopyNb()); - ASSERT_EQ(tapePoolName, archiveRoute.getTapePoolName()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, - createArchiveRoute_already_existing) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_TRUE(archiveRoutes.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const std::string comment = "Comment"; - { - const uint16_t nbCopies = 2; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, comment)); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - const uint16_t copyNb = 1; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, comment)); - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_EQ(1, archiveRoutes.size()); - - ArchiveRoute archiveRoute; - ASSERT_NO_THROW(archiveRoute = archiveRoutes.front()); - ASSERT_EQ(storageClassName, archiveRoute.getStorageClassName()); - ASSERT_EQ(copyNb, archiveRoute.getCopyNb()); - ASSERT_EQ(tapePoolName, archiveRoute.getTapePoolName()); - } - - ASSERT_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, comment), std::exception); -} - -TEST_F(cta_client_MockMiddleTierAdminTest, deleteArchiveRoute_existing) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_TRUE(archiveRoutes.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const std::string comment = "Comment"; - { - const uint16_t nbCopies = 2; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, comment)); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - const uint16_t copyNb = 1; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, comment)); - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_EQ(1, archiveRoutes.size()); - - ArchiveRoute archiveRoute; - ASSERT_NO_THROW(archiveRoute = archiveRoutes.front()); - ASSERT_EQ(storageClassName, archiveRoute.getStorageClassName()); - ASSERT_EQ(copyNb, archiveRoute.getCopyNb()); - ASSERT_EQ(tapePoolName, archiveRoute.getTapePoolName()); - } - - ASSERT_NO_THROW(adminApi.deleteArchiveRoute(requester, storageClassName, - copyNb)); - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_TRUE(archiveRoutes.empty()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, deleteArchiveRoute_non_existing) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<ArchiveRoute> archiveRoutes; - ASSERT_NO_THROW(archiveRoutes = adminApi.getArchiveRoutes(requester)); - ASSERT_TRUE(archiveRoutes.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const std::string comment = "Comment"; - { - const uint16_t nbCopies = 2; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, comment)); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - const uint16_t copyNb = 1; - ASSERT_THROW(adminApi.deleteArchiveRoute(requester, tapePoolName, copyNb), - std::exception); -} - -TEST_F(cta_client_MockMiddleTierAdminTest, createTape_new) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = adminApi.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } - - { - std::list<TapePool> pools; - ASSERT_NO_THROW(pools = adminApi.getTapePools(requester)); - ASSERT_TRUE(pools.empty()); - } - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = adminApi.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - const std::string libraryComment = "Library comment"; - ASSERT_NO_THROW(adminApi.createLogicalLibrary(requester, libraryName, - libraryComment)); - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = adminApi.getLogicalLibraries(requester)); - ASSERT_EQ(1, libraries.size()); - - LogicalLibrary logicalLibrary; - ASSERT_NO_THROW(logicalLibrary = libraries.front()); - ASSERT_EQ(libraryName, logicalLibrary.getName()); - ASSERT_EQ(libraryComment, logicalLibrary.getComment()); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string comment = "Tape pool omment"; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = adminApi.getTapePools(requester)); - ASSERT_EQ(1, tapePools.size()); - - TapePool tapePool; - ASSERT_NO_THROW(tapePool = tapePools.front()); - ASSERT_EQ(tapePoolName, tapePool.getName()); - ASSERT_EQ(comment, tapePool.getComment()); - } - - const std::string vid = "TestVid"; - const uint64_t capacityInBytes = 12345678; - const std::string tapeComment = "Tape comment"; - ASSERT_NO_THROW(adminApi.createTape(requester, vid, libraryName, tapePoolName, - capacityInBytes, tapeComment)); - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = adminApi.getTapes(requester)); - ASSERT_EQ(1, tapes.size()); - - Tape tape; - ASSERT_NO_THROW(tape = tapes.front()); - ASSERT_EQ(vid, tape.getVid()); - ASSERT_EQ(libraryName, tape.getLogicalLibraryName()); - ASSERT_EQ(tapePoolName, tape.getTapePoolName()); - ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes()); - ASSERT_EQ(0, tape.getDataOnTapeInBytes()); - ASSERT_EQ(tapeComment, tape.getComment()); - } -} - -TEST_F(cta_client_MockMiddleTierAdminTest, - createTape_new_non_existing_library) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = adminApi.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } - - { - std::list<TapePool> pools; - ASSERT_NO_THROW(pools = adminApi.getTapePools(requester)); - ASSERT_TRUE(pools.empty()); - } - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = adminApi.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string comment = "Tape pool omment"; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = adminApi.getTapePools(requester)); - ASSERT_EQ(1, tapePools.size()); - - TapePool tapePool; - ASSERT_NO_THROW(tapePool = tapePools.front()); - ASSERT_EQ(tapePoolName, tapePool.getName()); - ASSERT_EQ(comment, tapePool.getComment()); - } - - const std::string vid = "TestVid"; - const uint64_t capacityInBytes = 12345678; - const std::string tapeComment = "Tape comment"; - ASSERT_THROW(adminApi.createTape(requester, vid, libraryName, tapePoolName, - capacityInBytes, tapeComment), std::exception); -} - -TEST_F(cta_client_MockMiddleTierAdminTest, createTape_new_non_existing_pool) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - const SecurityIdentity requester; - - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = adminApi.getLogicalLibraries(requester)); - ASSERT_TRUE(libraries.empty()); - } - - { - std::list<TapePool> pools; - ASSERT_NO_THROW(pools = adminApi.getTapePools(requester)); - ASSERT_TRUE(pools.empty()); - } - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = adminApi.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - const std::string libraryComment = "Library comment"; - ASSERT_NO_THROW(adminApi.createLogicalLibrary(requester, libraryName, - libraryComment)); - { - std::list<LogicalLibrary> libraries; - ASSERT_NO_THROW(libraries = adminApi.getLogicalLibraries(requester)); - ASSERT_EQ(1, libraries.size()); - - LogicalLibrary logicalLibrary; - ASSERT_NO_THROW(logicalLibrary = libraries.front()); - ASSERT_EQ(libraryName, logicalLibrary.getName()); - ASSERT_EQ(libraryComment, logicalLibrary.getComment()); - } - - const std::string tapePoolName = "TestTapePool"; - - const std::string vid = "TestVid"; - const uint64_t capacityInBytes = 12345678; - const std::string tapeComment = "Tape comment"; - ASSERT_THROW(adminApi.createTape(requester, vid, libraryName, tapePoolName, - capacityInBytes, tapeComment), std::exception); -} - -} // namespace unitTests diff --git a/libs/middletier/MockMiddleTierUser.cpp b/libs/middletier/MockMiddleTierUser.cpp deleted file mode 100644 index 9905f167b676d9f8c55d392c43aff2ec9368490b..0000000000000000000000000000000000000000 --- a/libs/middletier/MockMiddleTierUser.cpp +++ /dev/null @@ -1,478 +0,0 @@ -#include "Exception.hpp" -#include "MockMiddleTierUser.hpp" -#include "Utils.hpp" - -#include <iostream> -#include <memory> -#include <sstream> - -//------------------------------------------------------------------------------ -// constructor -//------------------------------------------------------------------------------ -cta::MockMiddleTierUser::MockMiddleTierUser(MockDatabase &db): - m_db(db) { -} - -//------------------------------------------------------------------------------ -// destructor -//------------------------------------------------------------------------------ -cta::MockMiddleTierUser::~MockMiddleTierUser() throw() { -} - -//------------------------------------------------------------------------------ -// createDirectory -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::createDirectory(const SecurityIdentity &requester, - const std::string &dirPath) { - Utils::checkAbsolutePathSyntax(dirPath); - - if(dirPath == "/") { - throw Exception("Root directory already exists"); - } - - const std::string enclosingPath = Utils::getEnclosingDirPath(dirPath); - - FileSystemNode &enclosingNode = getFileSystemNode(enclosingPath); - if(DirectoryEntry::ENTRYTYPE_DIRECTORY != - enclosingNode.getFileSystemEntry().getEntry().getType()) { - std::ostringstream message; - message << enclosingPath << " is not a directory"; - throw Exception(message.str()); - } - - const std::string dirName = Utils::getEnclosedName(dirPath); - - if(enclosingNode.childExists(dirName)) { - throw Exception("A file or directory already exists with the same name"); - } - - const std::string inheritedStorageClassName = - enclosingNode.getFileSystemEntry().getEntry().getStorageClassName(); - DirectoryEntry dirEntry(DirectoryEntry::ENTRYTYPE_DIRECTORY, dirName, - inheritedStorageClassName); - enclosingNode.addChild(new FileSystemNode(m_db.storageClasses, dirEntry)); -} - -//------------------------------------------------------------------------------ -// getFileSystemNode -//------------------------------------------------------------------------------ -cta::FileSystemNode &cta::MockMiddleTierUser::getFileSystemNode( - const std::string &path) { - FileSystemNode *node = &m_db.fileSystemRoot; - - if(path == "/") { - return *node; - } - - const std::string trimmedDirPath = Utils::trimSlashes(path); - std::vector<std::string> pathComponents; - Utils::splitString(trimmedDirPath, '/', pathComponents); - - for(std::vector<std::string>::const_iterator itor = pathComponents.begin(); - itor != pathComponents.end(); itor++) { - node = &node->getChild(*itor); - } - return *node; -} - -//------------------------------------------------------------------------------ -// getFileSystemNode -//------------------------------------------------------------------------------ -const cta::FileSystemNode &cta::MockMiddleTierUser::getFileSystemNode( - const std::string &path) const { - const FileSystemNode *node = &m_db.fileSystemRoot; - - if(path == "/") { - return *node; - } - - const std::string trimmedDirPath = Utils::trimSlashes(path); - std::vector<std::string> pathComponents; - Utils::splitString(trimmedDirPath, '/', pathComponents); - - for(std::vector<std::string>::const_iterator itor = pathComponents.begin(); - itor != pathComponents.end(); itor++) { - node = &node->getChild(*itor); - } - return *node; -} - -//------------------------------------------------------------------------------ -// deleteDirectory -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::deleteDirectory(const SecurityIdentity &requester, - const std::string &dirPath) { - Utils::checkAbsolutePathSyntax(dirPath); - - if(dirPath == "/") { - throw Exception("The root directory can never be deleted"); - } - - FileSystemNode &dirNode = getFileSystemNode(dirPath); - - if(DirectoryEntry::ENTRYTYPE_DIRECTORY != - dirNode.getFileSystemEntry().getEntry().getType()) { - std::ostringstream message; - message << "The absolute path " << dirPath << " is not a directory"; - throw(message.str()); - } - - if(dirNode.hasAtLeastOneChild()) { - throw Exception("Directory is not empty"); - } - - FileSystemNode &parentNode = dirNode.getParent(); - parentNode.deleteChild(dirNode.getFileSystemEntry().getEntry().getName()); -} - -//------------------------------------------------------------------------------ -// getDirectoryContents -//------------------------------------------------------------------------------ -cta::DirectoryIterator cta::MockMiddleTierUser::getDirectoryContents( - const SecurityIdentity &requester, const std::string &dirPath) const { - Utils::checkAbsolutePathSyntax(dirPath); - - if(dirPath == "/") { - return DirectoryIterator(m_db.fileSystemRoot.getDirectoryEntries()); - } - - const FileSystemNode &dirNode = getFileSystemNode(dirPath); - - if(DirectoryEntry::ENTRYTYPE_DIRECTORY != - dirNode.getFileSystemEntry().getEntry().getType()) { - std::ostringstream message; - message << "The absolute path " << dirPath << " is not a directory"; - throw(message.str()); - } - - return DirectoryIterator(dirNode.getDirectoryEntries()); -} - -//------------------------------------------------------------------------------ -// stat -//------------------------------------------------------------------------------ -cta::DirectoryEntry cta::MockMiddleTierUser::stat( - const SecurityIdentity &requester, - const std::string path) const { - Utils::checkAbsolutePathSyntax(path); - - const FileSystemNode &node = getFileSystemNode(path); - return node.getFileSystemEntry().getEntry(); -} - -//------------------------------------------------------------------------------ -// setDirectoryStorageClass -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::setDirectoryStorageClass( - const SecurityIdentity &requester, - const std::string &dirPath, - const std::string &storageClassName) { - m_db.storageClasses.checkStorageClassExists(storageClassName); - - FileSystemNode &dirNode = getFileSystemNode(dirPath); - if(DirectoryEntry::ENTRYTYPE_DIRECTORY != - dirNode.getFileSystemEntry().getEntry().getType()) { - std::ostringstream message; - message << dirPath << " is not a directory"; - throw Exception(message.str()); - } - - dirNode.getFileSystemEntry().setStorageClassName(storageClassName); -} - -//------------------------------------------------------------------------------ -// clearDirectoryStorageClass -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::clearDirectoryStorageClass( - const SecurityIdentity &requester, - const std::string &dirPath) { - FileSystemNode &dirNode = getFileSystemNode(dirPath); - if(DirectoryEntry::ENTRYTYPE_DIRECTORY != - dirNode.getFileSystemEntry().getEntry().getType()) { - std::ostringstream message; - message << dirPath << " is not a directory"; - throw Exception(message.str()); - } - - dirNode.getFileSystemEntry().setStorageClassName(""); -} - -//------------------------------------------------------------------------------ -// getDirectoryStorageClass -//------------------------------------------------------------------------------ -std::string cta::MockMiddleTierUser::getDirectoryStorageClass( - const SecurityIdentity &requester, - const std::string &dirPath) const { - const FileSystemNode &dirNode = getFileSystemNode(dirPath); - if(DirectoryEntry::ENTRYTYPE_DIRECTORY != - dirNode.getFileSystemEntry().getEntry().getType()) { - std::ostringstream message; - message << dirPath << " is not a directory"; - throw Exception(message.str()); - } - - return dirNode.getFileSystemEntry().getEntry().getStorageClassName(); -} - -//------------------------------------------------------------------------------ -// archive -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::archive(const SecurityIdentity &requester, - const std::list<std::string> &srcUrls, const std::string &dstPath) { - Utils::checkAbsolutePathSyntax(dstPath); - if(isAnExistingDirectory(dstPath)) { - return archiveToDirectory(requester, srcUrls, dstPath); - } else { - return archiveToFile(requester, srcUrls, dstPath); - } -} - -//------------------------------------------------------------------------------ -// isAnExistingDirectory -//------------------------------------------------------------------------------ -bool cta::MockMiddleTierUser::isAnExistingDirectory(const std::string &path) - const throw() { - try { - const FileSystemNode &node = getFileSystemNode(path); - const DirectoryEntry &entry = node.getFileSystemEntry().getEntry(); - if(DirectoryEntry::ENTRYTYPE_DIRECTORY == entry.getType()) { - return true; - } - } catch(...) { - } - return false; -} - -//------------------------------------------------------------------------------ -// archiveToDirectory -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::archiveToDirectory( - const SecurityIdentity &requester, - const std::list<std::string> &srcUrls, - const std::string &dstDir) { - if(0 == srcUrls.size()) { - throw Exception("At least one source file should be provided"); - } - - FileSystemNode &dstDirNode = getFileSystemNode(dstDir); - checkUserIsAuthorisedToArchive(requester, dstDirNode); - - const std::string inheritedStorageClassName = dstDirNode.getFileSystemEntry(). - getEntry().getStorageClassName(); - if(inheritedStorageClassName.empty()) { - std::ostringstream message; - message << "Directory " << inheritedStorageClassName << " does not have a " - "storage class"; - throw Exception(message.str()); - } - - const StorageClass storageClass = m_db.storageClasses.getStorageClass( - inheritedStorageClassName); - if(0 == storageClass.getNbCopies()) { - std::ostringstream message; - message << "Storage class " << inheritedStorageClassName << " of directory " - << dstDir << " has zero tape copies"; - throw Exception(message.str()); - } - - checkStorageClassIsFullyRouted(storageClass); - - const std::list<std::string> dstFileNames = Utils::getEnclosedNames(srcUrls); - checkDirNodeDoesNotContainFiles(dstDir, dstDirNode, dstFileNames); - - std::list<std::string>::const_iterator srcItor = srcUrls.begin(); - const bool dstPathEndsWithASlash = dstDir.rfind('/') == dstDir.size() - 1; - for(std::list<std::string>::const_iterator dstItor = dstFileNames.begin(); - dstItor != dstFileNames.end(); srcItor++, dstItor++) { - const std::string &srcUrl = *srcItor; - const std::string &dstFileName = *dstItor; - const std::string dstPath = dstPathEndsWithASlash ? dstDir + dstFileName : - dstDir + "/" + dstFileName; - - for(uint16_t copyNb = 1; copyNb <= storageClass.getNbCopies(); copyNb++) { - const ArchiveRoute &route = m_db.archiveRoutes.getArchiveRoute( - inheritedStorageClassName, copyNb); - m_db.archivalJobs.createArchivalJob(requester, route.getTapePoolName(), - srcUrl, dstPath); - } - - DirectoryEntry dirEntry(DirectoryEntry::ENTRYTYPE_FILE, dstFileName, - inheritedStorageClassName); - dstDirNode.addChild(new FileSystemNode(m_db.storageClasses, dirEntry)); - } -} - -//------------------------------------------------------------------------------ -// checkDirNodeDoesNotContainFiles -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::checkDirNodeDoesNotContainFiles( - const std::string &dirPath, - const FileSystemNode &dirNode, - const std::list<std::string> &fileNames) { - for(std::list<std::string>::const_iterator itor = fileNames.begin(); - itor != fileNames.end(); itor++) { - const std::string &fileName = *itor; - if(dirNode.childExists(fileName)) { - std::ostringstream message; - message << dirPath << fileName << " already exists"; - throw(Exception(message.str())); - } - } -} - -//------------------------------------------------------------------------------ -// checkStorageClassIsFullyRouted -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::checkStorageClassIsFullyRouted( - const StorageClass &storageClass) const { - for(uint16_t copyNb = 1; copyNb <= storageClass.getNbCopies(); copyNb++) { - m_db.archiveRoutes.checkArchiveRouteExists(storageClass.getName(), - copyNb); - } -} - -//------------------------------------------------------------------------------ -// archiveToFile -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::archiveToFile( - const SecurityIdentity &requester, - const std::list<std::string> &srcUrls, - const std::string &dstFile) { - if(1 != srcUrls.size()) { - throw Exception("One and only one source file must be provided when " - "archiving to a single destination file"); - } - - const std::string enclosingDir = Utils::getEnclosingDirPath(dstFile); - const std::string enclosedName = Utils::getEnclosedName(dstFile); - FileSystemNode &enclosingNode = getFileSystemNode(enclosingDir); - checkUserIsAuthorisedToArchive(requester, enclosingNode); - if(enclosingNode.childExists(enclosedName)) { - std::ostringstream message; - message << "A file or directory with the name " << enclosedName << - " already exists"; - throw Exception(message.str()); - } - - const std::string inheritedStorageClassName = - enclosingNode.getFileSystemEntry().getEntry().getStorageClassName(); - - if(inheritedStorageClassName.empty()) { - std::ostringstream message; - message << "Directory " << inheritedStorageClassName << " does not have a " - "storage class"; - throw Exception(message.str()); - } - - const StorageClass &storageClass = m_db.storageClasses.getStorageClass( - inheritedStorageClassName); - if(0 == storageClass.getNbCopies()) { - std::ostringstream message; - message << "Storage class " << inheritedStorageClassName << " of directory " - << enclosingDir << " has zero tape copies"; - throw Exception(message.str()); - } - - checkStorageClassIsFullyRouted(storageClass); - - const std::string &srcUrl = srcUrls.front(); - for(uint16_t copyNb = 1; copyNb <= storageClass.getNbCopies(); copyNb++) { - const ArchiveRoute &route = m_db.archiveRoutes.getArchiveRoute( - inheritedStorageClassName, copyNb); - m_db.archivalJobs.createArchivalJob(requester, route.getTapePoolName(), - srcUrl, dstFile); - } - - DirectoryEntry dirEntry(DirectoryEntry::ENTRYTYPE_FILE, enclosedName, - inheritedStorageClassName); - enclosingNode.addChild(new FileSystemNode(m_db.storageClasses, dirEntry)); -} - -//------------------------------------------------------------------------------ -// checkUserIsAuthorisedToArchive -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::checkUserIsAuthorisedToArchive( - const SecurityIdentity &user, - const FileSystemNode &dstDir) { - // TO BE DONE -} - -//------------------------------------------------------------------------------ -// getArchivalJobs -//------------------------------------------------------------------------------ -std::map<cta::TapePool, std::list<cta::ArchivalJob> > - cta::MockMiddleTierUser::getArchivalJobs( - const SecurityIdentity &requester) const { - const std::map<std::string, std::list<ArchivalJob> > jobsByPoolName = - m_db.archivalJobs.getArchivalJobs(requester); - - std::map<TapePool, std::list<ArchivalJob> > allJobs; - - for(std::map<std::string, std::list<ArchivalJob> >::const_iterator - poolItor = jobsByPoolName.begin(); - poolItor != jobsByPoolName.end(); - poolItor++) { - const std::string &tapePoolName = poolItor->first; - const std::list<ArchivalJob> &poolJobs = poolItor->second; - if(!poolJobs.empty()) { - const TapePool tapePool = m_db.tapePools.getTapePool(tapePoolName); - allJobs[tapePool] = poolJobs; - } - } - - return allJobs; -} - -//------------------------------------------------------------------------------ -// getArchivalJobs -//------------------------------------------------------------------------------ -std::list<cta::ArchivalJob> cta::MockMiddleTierUser::getArchivalJobs( - const SecurityIdentity &requester, - const std::string &tapePoolName) const { - return m_db.archivalJobs.getArchivalJobs(requester, tapePoolName); -} - -//------------------------------------------------------------------------------ -// deleteArchivalJob -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::deleteArchivalJob( - const SecurityIdentity &requester, - const std::string &dstPath) { - m_db.archivalJobs.deleteArchivalJob(requester, dstPath); -} - -//------------------------------------------------------------------------------ -// retrieve -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::retrieve( - const SecurityIdentity &requester, - const std::list<std::string> &srcPaths, - const std::string &dstUrl) { -} - -//------------------------------------------------------------------------------ -// getRetrievalJobs -//------------------------------------------------------------------------------ -std::map<cta::Tape, std::list<cta::RetrievalJob> > - cta::MockMiddleTierUser::getRetrievalJobs( - const SecurityIdentity &requester) const { - return m_db.retrievalJobs.getRetrievalJobs(requester); -} - -//------------------------------------------------------------------------------ -// getRetrievalJobs -//------------------------------------------------------------------------------ -std::list<cta::RetrievalJob> cta::MockMiddleTierUser::getRetrievalJobs( - const SecurityIdentity &requester, - const std::string &vid) const { - return m_db.retrievalJobs.getRetrievalJobs(requester, vid); -} - -//------------------------------------------------------------------------------ -// deleteRetrievalJob -//------------------------------------------------------------------------------ -void cta::MockMiddleTierUser::deleteRetrievalJob( - const SecurityIdentity &requester, - const std::string &dstUrl) { - m_db.retrievalJobs.deleteRetrievalJob(requester, dstUrl); -} diff --git a/libs/middletier/MockMiddleTierUser.hpp b/libs/middletier/MockMiddleTierUser.hpp deleted file mode 100644 index 6a1dc907c9ae608aaab49daae496b267daed6270..0000000000000000000000000000000000000000 --- a/libs/middletier/MockMiddleTierUser.hpp +++ /dev/null @@ -1,330 +0,0 @@ -#pragma once - -#include "FileSystemNode.hpp" -#include "FileSystemStorageClasses.hpp" -#include "MiddleTierUser.hpp" -#include "MockDatabase.hpp" -#include "StorageClass.hpp" - -namespace cta { - -/** - * A user API of the mock middle-tier. - */ -class MockMiddleTierUser: public MiddleTierUser { -public: - - /** - * Constructor. - * - * @param db The database of the mock middle-tier. - */ - MockMiddleTierUser(MockDatabase &db); - - /** - * Destructor. - */ - ~MockMiddleTierUser() throw(); - - /** - * Creates the specified directory. - * - * @param requester The identity of the user requesting the creation of the - * directory. - * @param dirPath The absolute path of the directory. - */ - void createDirectory( - const SecurityIdentity &requester, - const std::string &dirPath); - - /** - * Deletes the specified directory. - * - * @param requester The identity of the user requesting the deletion of the - * directory. - * @param dirPath The absolute path of the directory. - */ - void deleteDirectory( - const SecurityIdentity &requester, - const std::string &dirPath); - - /** - * Gets the contents of the specified directory. - * - * @param requester The identity of the user requesting the contents of the - * directory. - * @param dirPath The absolute path of the directory. - * @return An iterator over the contents of the directory. - */ - DirectoryIterator getDirectoryContents( - const SecurityIdentity &requester, - const std::string &dirPath) const; - - /** - * Returns the directory entry information for the specified directory or file - * within the archive namespace. - * - * @param requester The identity of the user requesting the directory entry. - * @param path The absolute path of the directory or file within the archive - * namespace. - * @return The directory entry information for the specified directory or file - * within the archive namespace. - */ - DirectoryEntry stat( - const SecurityIdentity &requester, - const std::string path) const; - - /** - * Sets the storage class of the specified directory to the specified value. - * - * @param requester The identity of the user requesting the setting of the - * directory's storage class. - * @param dirPath The absolute path of the directory. - * @param storageClassName The name of the storage class. - */ - void setDirectoryStorageClass( - const SecurityIdentity &requester, - const std::string &dirPath, - const std::string &storageClassName); - - /** - * Clears the storage class of the specified directory. - * - * @param requester The identity of the user requesting the storage class of - * the directory to be cleared. - * @param dirPath The absolute path of the directory. - */ - void clearDirectoryStorageClass( - const SecurityIdentity &requester, - const std::string &dirPath); - - /** - * Gets the storage class if of the specified directory if the directory has - * one. - * - * @param requester The identity of the user requesting the storage class of - * the directory. - * @param dirPath The absolute path of the directory. - * @return The name of the storage class if the directory has one, else an - * empty string. - */ - std::string getDirectoryStorageClass( - const SecurityIdentity &requester, - const std::string &dirPath) const; - - /** - * Creates an archival job to asynchronously archive the specified source - * files to the specified destination within the archive. - * - * If there is more than one source file then the destination must be a - * directory. - * - * If there is only one source file then the destination can be either a file - * or a directory. - * - * The storage class of the archived file will be inherited from its - * destination directory. - * - * @param requester The identity of the user requesting the archival. - * @param srcUrls List of one or more source files. - * @param dstPath The absolute path of the destination file or directory - * within the archive namespace. - */ - void archive( - const SecurityIdentity &requester, - const std::list<std::string> &srcUrls, - const std::string &dstPath); - - /** - * Returns all of the existing archival jobs grouped by tape pool and then - * sorted by creation time in ascending order (oldest first). - * - * @param requester The identity of the user requesting the list. - * @return All of the existing archival jobs grouped by tape pool and then - * sorted by creation time in ascending order (oldest first). - */ - std::map<TapePool, std::list<ArchivalJob> > getArchivalJobs( - const SecurityIdentity &requester) const; - - /** - * Returns the list of archival jobs associated with the specified tape pool - * sorted by creation time in ascending order (oldest first). - * - * @param requester The identity of the user requesting the list. - * @param tapePoolName The name of the tape pool. - * @return The list of archival jobs associated with the specified tape pool - * sorted by creation time in ascending order (oldest first). - */ - std::list<ArchivalJob> getArchivalJobs( - const SecurityIdentity &requester, - const std::string &tapePoolName) const; - - /** - * Deletes the specified archival job. - * - * @param requester The identity of the user requesting the deletion of the - * job. - * @param dstPath The absolute path of the destination file within the - * archive namespace. - */ - void deleteArchivalJob( - const SecurityIdentity &requester, - const std::string &dstPath); - - /** - * Creates a retrieval job to asynchronously retrieve the specified archived - * files and copy them to the specified destination URL. - * - * If there is more than one archived file then the destination must be a - * directory. - * - * If there is only one archived file then the destination can be either a - * file or a directory. - * - * @param requester The identity of the user requesting the retrieval. - * @param srcPaths The list of one of more archived files. - * @param dstUrl The URL of the destination file or directory. - */ - void retrieve( - const SecurityIdentity &requester, - const std::list<std::string> &srcPaths, - const std::string &dstUrl); - - /** - * Returns all of the existing retrieval jobs grouped by tape and then - * sorted by creation time in ascending order (oldest first). - * - * @param requester The identity of the user requesting the list. - * @return All of the existing retrieval jobs grouped by tape and then - * sorted by creation time in ascending order (oldest first). - */ - std::map<Tape, std::list<RetrievalJob> > getRetrievalJobs( - const SecurityIdentity &requester) const; - - /** - * Returns the list of retrieval jobs associated with the specified tape - * sorted by creation time in ascending order (oldest first). - * - * @param requester The identity of the user requesting the list. - * @param vid The volume identifier of the tape. - * @return The list of retrieval jobs associated with the specified tape - * sorted by creation time in ascending order (oldest first). - */ - std::list<RetrievalJob> getRetrievalJobs( - const SecurityIdentity &requester, - const std::string &vid) const; - - /** - * Deletes the specified retrieval job. - * - * @param requester The identity of the user requesting the deletion of the - * job. - * @param dstUrl The URL of the destination file or directory. - */ - void deleteRetrievalJob( - const SecurityIdentity &requester, - const std::string &dstUrl); - -private: - - /** - * The database of the mock middle-tier. - */ - MockDatabase &m_db; - - /** - * Gets the file system node corresponding to the specified path. - * - * @path The path. - * @return The corresponding file system node. - */ - FileSystemNode &getFileSystemNode(const std::string &path); - - /** - * Gets the file system node corresponding to the specified path. - * - * @path The path. - * @return The corresponding file system node. - */ - const FileSystemNode &getFileSystemNode(const std::string &path) const; - - /** - * Returns true if the specified absolute path is that of an existing - * directory within the archive namepsace. - * - * @param path The specified absolute path. - * @return True if the specified absolute path is that of an existing - * directory within the archive namepsace. - */ - bool isAnExistingDirectory(const std::string &path) const throw(); - - /** - * Archives the specified list of source files to the specified destination - * directory within the archive namespace. - * - * The list of source files should contain at least one file. - * - * The storage class of the archived file will be inherited from its - * destination directory. - * - * @param requester The identity of the user requesting the archival. - * @param srcUrls List of one or more source files. - * @param dstDir Destination directory within the archive namespace. - */ - void archiveToDirectory( - const SecurityIdentity &requester, - const std::list<std::string> &srcUrls, - const std::string &dstDir); - - /** - * Throws an exception if the specified storage class is not fully routed. - * - * @param storageClass The storage class; - */ - void checkStorageClassIsFullyRouted(const StorageClass &storageClass) const; - - /** - * Archives the specified list of source files to the specified destination - * file within the archive namespace. - * - * The list of source files should contain one and only one file. - * - * The storage class of the archived file will be inherited from its - * destination directory. - * - * @param requester The identity of the user requesting the archival. - * @param srcUrls List of one or more source files. - * @param dstFile Destination file within the archive namespace. - */ - void archiveToFile( - const SecurityIdentity &requester, - const std::list<std::string> &srcUrls, - const std::string &dstFile); - - /** - * Throws an exception if the specified requester is not authorised to archive - * a file to the specified destination directory within the archive namespace. - * - * @param requester The identity of the user requesting the archival. - * @param dstDir Destination directory within the archive namespace. - */ - void checkUserIsAuthorisedToArchive( - const SecurityIdentity &user, - const FileSystemNode &dstDir); - - /** - * Throws an exception if at least one of the the specified file names are - * contained within the specified directory. - * - * @param dirPath The absolute path of the directory. - * @param dirNode The file-system node representing the directory. - * @param fileNames The file names to be searched for. - */ - void checkDirNodeDoesNotContainFiles( - const std::string &dirPath, - const FileSystemNode &dirNode, - const std::list<std::string> &fileNames); - -}; // class MockMiddleTierUser - -} // namespace cta diff --git a/libs/middletier/MockMiddleTierUserTest.cpp b/libs/middletier/MockMiddleTierUserTest.cpp deleted file mode 100644 index 2868279109f1634ffda8ba03e008e500f6aa519e..0000000000000000000000000000000000000000 --- a/libs/middletier/MockMiddleTierUserTest.cpp +++ /dev/null @@ -1,953 +0,0 @@ -#include "MockMiddleTierAdmin.hpp" -#include "MockMiddleTierUser.hpp" - -#include <gtest/gtest.h> -#include <set> - -namespace unitTests { - -class cta_client_MockMiddleTierUserTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(cta_client_MockMiddleTierUserTest, - getDirectoryContents_root_dir_is_empty) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = "/"; - - DirectoryIterator itor; - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - ASSERT_FALSE(itor.hasMore()); -} - -TEST_F(cta_client_MockMiddleTierUserTest, createDirectory_empty_string) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = ""; - - ASSERT_THROW(userApi.createDirectory(requester, dirPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, - createDirectory_consecutive_slashes) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = "//"; - - ASSERT_THROW(userApi.createDirectory(requester, dirPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, createDirectory_invalid_chars) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = "/grandparent/?parent"; - - ASSERT_THROW(userApi.createDirectory(requester, dirPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, createDirectory_top_level) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = "/grandparent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); -} - -TEST_F(cta_client_MockMiddleTierUserTest, createDirectory_second_level) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - ASSERT_TRUE(userApi.getDirectoryStorageClass(requester, "/").empty()); - - { - const std::string topLevelDirPath = "/grandparent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, topLevelDirPath)); - } - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - } - - ASSERT_TRUE(userApi.getDirectoryStorageClass(requester, "/grandparent").empty()); - - { - const std::string secondLevelDirPath = "/grandparent/parent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, secondLevelDirPath)); - } - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - } - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/grandparent")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("parent"), entry.getName()); - } - - ASSERT_TRUE(userApi.getDirectoryStorageClass(requester, - "/grandparent/parent").empty()); -} - -TEST_F(cta_client_MockMiddleTierUserTest, - createDirectory_inherit_storage_class) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - ASSERT_TRUE(userApi.getDirectoryStorageClass(requester, "/").empty()); - - { - MockMiddleTierAdmin adminApi(db); - const std::string name = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string comment = "Comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, name, nbCopies, comment)); - } - - { - const std::string topLevelDirPath = "/grandparent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, topLevelDirPath)); - } - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - - ASSERT_TRUE(userApi.getDirectoryStorageClass(requester, "/grandparent").empty()); - - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, "/grandparent", - "TestStorageClass")); - } - - ASSERT_EQ(std::string("TestStorageClass"), - userApi.getDirectoryStorageClass(requester, "/grandparent")); - - { - const std::string secondLevelDirPath = "/grandparent/parent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, secondLevelDirPath)); - } - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - } - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/grandparent")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("parent"), entry.getName()); - } - - ASSERT_EQ(std::string("TestStorageClass"), - userApi.getDirectoryStorageClass(requester, "/grandparent/parent")); -} - -TEST_F(cta_client_MockMiddleTierUserTest, deleteDirectory_root) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = "/"; - - ASSERT_THROW(userApi.deleteDirectory(requester, "/"), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, deleteDirectory_existing_top_level) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = "/grandparent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - } - - ASSERT_NO_THROW(userApi.deleteDirectory(requester, "/grandparent")); - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_FALSE(itor.hasMore()); - } -} - -TEST_F(cta_client_MockMiddleTierUserTest, - deleteDirectory_non_empty_top_level) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - { - const std::string topLevelDirPath = "/grandparent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, topLevelDirPath)); - - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - } - - { - const std::string secondLevelDirPath = "/grandparent/parent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, secondLevelDirPath)); - - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - } - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/grandparent")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("parent"), entry.getName()); - } - - ASSERT_THROW(userApi.deleteDirectory(requester, "/grandparent"), std::exception); - - { - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/grandparent")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("parent"), entry.getName()); - } -} - -TEST_F(cta_client_MockMiddleTierUserTest, - deleteDirectory_non_existing_top_level) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - ASSERT_THROW(userApi.deleteDirectory(requester, "/grandparent"), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, setDirectoryStorageClass_top_level) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = "/grandparent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - - { - std::string name; - ASSERT_NO_THROW(name = userApi.getDirectoryStorageClass(requester, dirPath)); - ASSERT_TRUE(name.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string comment = "Comment"; - { - MockMiddleTierAdmin adminApi(db); - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, comment)); - } - - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - { - std::string name; - ASSERT_NO_THROW(name = userApi.getDirectoryStorageClass(requester, dirPath)); - ASSERT_EQ(storageClassName, name); - } -} - -TEST_F(cta_client_MockMiddleTierUserTest, - clearDirectoryStorageClass_top_level) { - using namespace cta; - - MockDatabase db; - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - const std::string dirPath = "/grandparent"; - - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - - DirectoryIterator itor; - - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - - ASSERT_TRUE(itor.hasMore()); - - DirectoryEntry entry; - - ASSERT_NO_THROW(entry = itor.next()); - - ASSERT_EQ(std::string("grandparent"), entry.getName()); - - { - std::string name; - ASSERT_NO_THROW(name = userApi.getDirectoryStorageClass(requester, dirPath)); - ASSERT_TRUE(name.empty()); - } - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string comment = "Comment"; - MockMiddleTierAdmin adminApi(db); - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, comment)); - - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - { - std::string name; - ASSERT_NO_THROW(name = userApi.getDirectoryStorageClass(requester, dirPath)); - ASSERT_EQ(storageClassName, name); - } - - ASSERT_THROW(adminApi.deleteStorageClass(requester, storageClassName), - std::exception); - - ASSERT_NO_THROW(userApi.clearDirectoryStorageClass(requester, dirPath)); - - { - std::string name; - ASSERT_NO_THROW(name = userApi.getDirectoryStorageClass(requester, dirPath)); - ASSERT_TRUE(name.empty()); - } - - ASSERT_NO_THROW(adminApi.deleteStorageClass(requester, storageClassName)); -} - -TEST_F(cta_client_MockMiddleTierUserTest, archive_to_new_file) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 1; - const std::string storageClassComment = "Storage-class comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, storageClassComment)); - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string tapePoolComment = "Tape-pool comment"; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, tapePoolComment)); - - const uint16_t copyNb = 1; - const std::string archiveRouteComment = "Archive-route comment"; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, archiveRouteComment)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl"); - const std::string dstPath = "/grandparent/parent_file"; - ASSERT_NO_THROW(userApi.archive(requester, srcUrls, dstPath)); - - { - DirectoryIterator itor; - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - ASSERT_TRUE(itor.hasMore()); - DirectoryEntry entry; - ASSERT_NO_THROW(entry = itor.next()); - ASSERT_EQ(std::string("grandparent"), entry.getName()); - ASSERT_EQ(DirectoryEntry::ENTRYTYPE_DIRECTORY, entry.getType()); - ASSERT_EQ(storageClassName, entry.getStorageClassName()); - } - - { - DirectoryIterator itor; - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, - "/grandparent")); - ASSERT_TRUE(itor.hasMore()); - DirectoryEntry entry; - ASSERT_NO_THROW(entry = itor.next()); - ASSERT_EQ(std::string("parent_file"), entry.getName()); - ASSERT_EQ(DirectoryEntry::ENTRYTYPE_FILE, entry.getType()); - ASSERT_EQ(storageClassName, entry.getStorageClassName()); - } - - { - DirectoryEntry entry; - ASSERT_NO_THROW(entry = userApi.stat(requester, dstPath)); - ASSERT_EQ(DirectoryEntry::ENTRYTYPE_FILE, entry.getType()); - ASSERT_EQ(storageClassName, entry.getStorageClassName()); - } - - { - const std::map<TapePool, std::list<ArchivalJob> > allJobs = - userApi.getArchivalJobs(requester); - ASSERT_EQ(1, allJobs.size()); - std::map<TapePool, std::list<ArchivalJob> >::const_iterator - poolItor = allJobs.begin(); - ASSERT_FALSE(poolItor == allJobs.end()); - const TapePool &pool = poolItor->first; - ASSERT_TRUE(tapePoolName == pool.getName()); - const std::list<ArchivalJob> &poolJobs = poolItor->second; - ASSERT_EQ(1, poolJobs.size()); - std::set<std::string> srcUrls; - std::set<std::string> dstPaths; - for(std::list<ArchivalJob>::const_iterator jobItor = poolJobs.begin(); - jobItor != poolJobs.end(); jobItor++) { - ASSERT_EQ(ArchivalJobState::PENDING, jobItor->getState()); - srcUrls.insert(jobItor->getSrcUrl()); - dstPaths.insert(jobItor->getDstPath()); - } - ASSERT_EQ(1, srcUrls.size()); - ASSERT_FALSE(srcUrls.find("diskUrl") == srcUrls.end()); - ASSERT_EQ(1, dstPaths.size()); - ASSERT_FALSE(dstPaths.find("/grandparent/parent_file") == dstPaths.end()); - } - - { - const std::list<ArchivalJob> poolJobs = userApi.getArchivalJobs(requester, - tapePoolName); - ASSERT_EQ(1, poolJobs.size()); - std::set<std::string> srcUrls; - std::set<std::string> dstPaths; - for(std::list<ArchivalJob>::const_iterator jobItor = poolJobs.begin(); - jobItor != poolJobs.end(); jobItor++) { - ASSERT_EQ(ArchivalJobState::PENDING, jobItor->getState()); - srcUrls.insert(jobItor->getSrcUrl()); - dstPaths.insert(jobItor->getDstPath()); - } - ASSERT_EQ(1, srcUrls.size()); - ASSERT_FALSE(srcUrls.find("diskUrl") == srcUrls.end()); - ASSERT_EQ(1, dstPaths.size()); - ASSERT_FALSE(dstPaths.find("/grandparent/parent_file") == dstPaths.end()); - } -} - -TEST_F(cta_client_MockMiddleTierUserTest, - archive_to_new_file_with_no_storage_class) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl"); - const std::string dstPath = "/grandparent/parent_file"; - ASSERT_THROW(userApi.archive(requester, srcUrls, dstPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, - archive_to_new_file_with_zero_copy_storage_class) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 0; - const std::string storageClassComment = "Storage-class comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, storageClassComment)); - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl"); - const std::string dstPath = "/grandparent/parent_file"; - ASSERT_THROW(userApi.archive(requester, srcUrls, dstPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, archive_to_new_file_with_no_route) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 1; - const std::string storageClassComment = "Storage-class comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, storageClassComment)); - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string tapePoolComment = "Tape-pool comment"; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, tapePoolComment)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl"); - const std::string dstPath = "/grandparent/parent_file"; - ASSERT_THROW(userApi.archive(requester, srcUrls, dstPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, - archive_to_new_file_with_incomplete_routing) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string storageClassComment = "Storage-class comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, storageClassComment)); - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string tapePoolComment = "Tape-pool comment"; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, tapePoolComment)); - - const uint16_t copyNb = 1; - const std::string archiveRouteComment = "Archive-route comment"; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, archiveRouteComment)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl"); - const std::string dstPath = "/grandparent/parent_file"; - ASSERT_THROW(userApi.archive(requester, srcUrls, dstPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, archive_to_directory) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 1; - const std::string storageClassComment = "Storage-class comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, storageClassComment)); - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string tapePoolComment = "Tape-pool comment"; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, tapePoolComment)); - - const uint16_t copyNb = 1; - const std::string archiveRouteComment = "Archive-route comment"; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, archiveRouteComment)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl1"); - srcUrls.push_back("diskUrl2"); - srcUrls.push_back("diskUrl3"); - srcUrls.push_back("diskUrl4"); - const std::string dstPath = "/grandparent"; - ASSERT_NO_THROW(userApi.archive(requester, srcUrls, dstPath)); - - { - DirectoryIterator itor; - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, "/")); - ASSERT_TRUE(itor.hasMore()); - DirectoryEntry entry; - ASSERT_NO_THROW(entry = itor.next()); - ASSERT_EQ(std::string("grandparent"), entry.getName()); - ASSERT_EQ(DirectoryEntry::ENTRYTYPE_DIRECTORY, entry.getType()); - ASSERT_EQ(storageClassName, entry.getStorageClassName()); - } - - { - std::set<std::string> archiveFileNames; - DirectoryIterator itor; - ASSERT_NO_THROW(itor = userApi.getDirectoryContents(requester, - "/grandparent")); - while(itor.hasMore()) { - const DirectoryEntry entry = itor.next(); - archiveFileNames.insert(entry.getName()); - } - ASSERT_EQ(4, archiveFileNames.size()); - ASSERT_TRUE(archiveFileNames.find("diskUrl1") != archiveFileNames.end()); - ASSERT_TRUE(archiveFileNames.find("diskUrl2") != archiveFileNames.end()); - ASSERT_TRUE(archiveFileNames.find("diskUrl3") != archiveFileNames.end()); - ASSERT_TRUE(archiveFileNames.find("diskUrl4") != archiveFileNames.end()); - } - - { - const std::map<TapePool, std::list<ArchivalJob> > allJobs = - userApi.getArchivalJobs(requester); - ASSERT_EQ(1, allJobs.size()); - std::map<TapePool, std::list<ArchivalJob> >::const_iterator - poolItor = allJobs.begin(); - ASSERT_FALSE(poolItor == allJobs.end()); - const TapePool &pool = poolItor->first; - ASSERT_TRUE(tapePoolName == pool.getName()); - const std::list<ArchivalJob> &poolJobs = poolItor->second; - ASSERT_EQ(4, poolJobs.size()); - std::set<std::string> srcUrls; - std::set<std::string> dstPaths; - for(std::list<ArchivalJob>::const_iterator jobItor = poolJobs.begin(); - jobItor != poolJobs.end(); jobItor++) { - ASSERT_EQ(ArchivalJobState::PENDING, jobItor->getState()); - srcUrls.insert(jobItor->getSrcUrl()); - dstPaths.insert(jobItor->getDstPath()); - } - ASSERT_EQ(4, srcUrls.size()); - ASSERT_FALSE(srcUrls.find("diskUrl1") == srcUrls.end()); - ASSERT_FALSE(srcUrls.find("diskUrl2") == srcUrls.end()); - ASSERT_FALSE(srcUrls.find("diskUrl3") == srcUrls.end()); - ASSERT_FALSE(srcUrls.find("diskUrl4") == srcUrls.end()); - ASSERT_EQ(4, dstPaths.size()); - ASSERT_FALSE(dstPaths.find("/grandparent/diskUrl1") == srcUrls.end()); - ASSERT_FALSE(dstPaths.find("/grandparent/diskUrl2") == srcUrls.end()); - ASSERT_FALSE(dstPaths.find("/grandparent/diskUrl3") == srcUrls.end()); - ASSERT_FALSE(dstPaths.find("/grandparent/diskUrl4") == srcUrls.end()); - } - - { - const std::list<ArchivalJob> poolJobs = userApi.getArchivalJobs(requester, - tapePoolName); - ASSERT_EQ(4, poolJobs.size()); - std::set<std::string> srcUrls; - std::set<std::string> dstPaths; - for(std::list<ArchivalJob>::const_iterator jobItor = poolJobs.begin(); - jobItor != poolJobs.end(); jobItor++) { - ASSERT_EQ(ArchivalJobState::PENDING, jobItor->getState()); - srcUrls.insert(jobItor->getSrcUrl()); - dstPaths.insert(jobItor->getDstPath()); - } - ASSERT_EQ(4, srcUrls.size()); - ASSERT_FALSE(srcUrls.find("diskUrl1") == srcUrls.end()); - ASSERT_FALSE(srcUrls.find("diskUrl2") == srcUrls.end()); - ASSERT_FALSE(srcUrls.find("diskUrl3") == srcUrls.end()); - ASSERT_FALSE(srcUrls.find("diskUrl4") == srcUrls.end()); - ASSERT_EQ(4, dstPaths.size()); - ASSERT_FALSE(dstPaths.find("/grandparent/diskUrl1") == srcUrls.end()); - ASSERT_FALSE(dstPaths.find("/grandparent/diskUrl2") == srcUrls.end()); - ASSERT_FALSE(dstPaths.find("/grandparent/diskUrl3") == srcUrls.end()); - ASSERT_FALSE(dstPaths.find("/grandparent/diskUrl4") == srcUrls.end()); - } -} - -TEST_F(cta_client_MockMiddleTierUserTest, - archive_to_directory_without_storage_class) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl1"); - srcUrls.push_back("diskUrl2"); - srcUrls.push_back("diskUrl3"); - srcUrls.push_back("diskUrl4"); - const std::string dstPath = "/grandparent"; - ASSERT_THROW(userApi.archive(requester, srcUrls, dstPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, - archive_to_directory_with_zero_copy_storage_class) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 0; - const std::string storageClassComment = "Storage-class comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, storageClassComment)); - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl1"); - srcUrls.push_back("diskUrl2"); - srcUrls.push_back("diskUrl3"); - srcUrls.push_back("diskUrl4"); - const std::string dstPath = "/grandparent"; - ASSERT_THROW(userApi.archive(requester, srcUrls, dstPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, archive_to_directory_with_no_route) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 1; - const std::string storageClassComment = "Storage-class comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, storageClassComment)); - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string tapePoolComment = "Tape-pool comment"; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, tapePoolComment)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl1"); - srcUrls.push_back("diskUrl2"); - srcUrls.push_back("diskUrl3"); - srcUrls.push_back("diskUrl4"); - const std::string dstPath = "/grandparent"; - ASSERT_THROW(userApi.archive(requester, srcUrls, dstPath), std::exception); -} - -TEST_F(cta_client_MockMiddleTierUserTest, - archive_to_directory_with_incomplete_routing) { - using namespace cta; - - MockDatabase db; - MockMiddleTierAdmin adminApi(db); - MockMiddleTierUser userApi(db); - const SecurityIdentity requester; - - const std::string storageClassName = "TestStorageClass"; - const uint16_t nbCopies = 2; - const std::string storageClassComment = "Storage-class comment"; - ASSERT_NO_THROW(adminApi.createStorageClass(requester, storageClassName, - nbCopies, storageClassComment)); - - const std::string dirPath = "/grandparent"; - ASSERT_NO_THROW(userApi.createDirectory(requester, dirPath)); - ASSERT_NO_THROW(userApi.setDirectoryStorageClass(requester, dirPath, - storageClassName)); - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string tapePoolComment = "Tape-pool comment"; - ASSERT_NO_THROW(adminApi.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, tapePoolComment)); - - const uint16_t copyNb = 1; - const std::string archiveRouteComment = "Archive-route comment"; - ASSERT_NO_THROW(adminApi.createArchiveRoute(requester, storageClassName, - copyNb, tapePoolName, archiveRouteComment)); - - std::list<std::string> srcUrls; - srcUrls.push_back("diskUrl1"); - srcUrls.push_back("diskUrl2"); - srcUrls.push_back("diskUrl3"); - srcUrls.push_back("diskUrl4"); - const std::string dstPath = "/grandparent"; - ASSERT_THROW(userApi.archive(requester, srcUrls, dstPath), std::exception); -} - -} // namespace unitTests diff --git a/libs/middletier/MockRetrievalJobTable.cpp b/libs/middletier/MockRetrievalJobTable.cpp deleted file mode 100644 index 44ad18ef117681ed1a3915b5244bcb6db4f93afa..0000000000000000000000000000000000000000 --- a/libs/middletier/MockRetrievalJobTable.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "Exception.hpp" -#include "MockRetrievalJobTable.hpp" - -//------------------------------------------------------------------------------ -// createRetrievalJob -//------------------------------------------------------------------------------ -void cta::MockRetrievalJobTable::createRetrievalJob( - const SecurityIdentity &requester, - const std::string &srcPath, - const std::string &dstUrl) { -} - -//------------------------------------------------------------------------------ -// checkRetrievalJobDoesNotAlreadyExist -//------------------------------------------------------------------------------ -void cta::MockRetrievalJobTable::checkRetrievalJobDoesNotAlreadyExist( - const std::string &dstUrl) const { -} - -//------------------------------------------------------------------------------ -// deleteRetrievalJob -//------------------------------------------------------------------------------ -void cta::MockRetrievalJobTable::deleteRetrievalJob( - const SecurityIdentity &requester, - const std::string &dstPath) { -} - -//------------------------------------------------------------------------------ -// getRetrievalJobs -//------------------------------------------------------------------------------ -const std::map<cta::Tape, std::list<cta::RetrievalJob> > - cta::MockRetrievalJobTable::getRetrievalJobs( - const SecurityIdentity &requester) const { - std::map<cta::Tape, std::list<cta::RetrievalJob> > jobs; - return jobs; -} - -//------------------------------------------------------------------------------ -// getRetrievalJobs -//------------------------------------------------------------------------------ -std::list<cta::RetrievalJob> cta::MockRetrievalJobTable::getRetrievalJobs( - const SecurityIdentity &requester, - const std::string &vid) const { - std::list<cta::RetrievalJob> jobs; - return jobs; -} diff --git a/libs/middletier/MockRetrievalJobTable.hpp b/libs/middletier/MockRetrievalJobTable.hpp deleted file mode 100644 index d59769c6c86ed7a1ee835cf01563631bdbaf1572..0000000000000000000000000000000000000000 --- a/libs/middletier/MockRetrievalJobTable.hpp +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -#include "RetrievalJob.hpp" -#include "Tape.hpp" -#include "SecurityIdentity.hpp" - -#include <list> -#include <map> -#include <string> - -namespace cta { - -/** - * Mock database-table of retrieval jobs. - */ -class MockRetrievalJobTable { -public: - - /** - * Creates a retrival job. - * - * @param requester The identity of the user requesting the creation of the - * job. - * @param srcPath The full path of the source file within the archive. - * @param dstUrl The URL of the destination file. - */ - void createRetrievalJob( - const SecurityIdentity &requester, - const std::string &srcPath, - const std::string &dstUrl); - - /** - * Throws an exception if the specified retrieval job already exists. - * - * @param dstUrl The URL of the destination file. - */ - void checkRetrievalJobDoesNotAlreadyExist(const std::string &dstUrl) const; - - /** - * Deletes the specified retrieval job. - * - * @param requester The identity of the user requesting the deletion of the - * job. - * @param dstPath The full path of the destination file within the archive. - */ - void deleteRetrievalJob( - const SecurityIdentity &requester, - const std::string &dstPath); - - /** - * Returns all of the existing retrieval jobs grouped by tape and then - * sorted by creation time in ascending order (oldest first). - * - * @param requester The identity of the user requesting the list. - * @return All of the existing retrieval jobs grouped by tape and then - * sorted by creation time in ascending order (oldest first). - */ - const std::map<Tape, std::list<RetrievalJob> > getRetrievalJobs( - const SecurityIdentity &requester) const; - - /** - * Returns the list of retrieval jobs associated with the specified tape - * sorted by creation time in ascending order (oldest first). - * - * @param requester The identity of the user requesting the list. - * @param vid The volume identifier of the tape. - * @return The list of retrieval jobs associated with the specified tape - * sorted by creation time in ascending order (oldest first). - */ - std::list<RetrievalJob> getRetrievalJobs( - const SecurityIdentity &requester, - const std::string &vid) const; - -private: - - /** - * All of the existing retrieval jobs grouped by tape and then - * sorted by creation time in ascending order (oldest first). - */ - std::map<Tape, std::map<time_t, RetrievalJob> > m_jobs; - -}; // class MockRetrievalJobTable - -} // namespace cta diff --git a/libs/middletier/MockTapePoolTable.cpp b/libs/middletier/MockTapePoolTable.cpp deleted file mode 100644 index 3a0e17bf48050b59cc5eb48c6e237d09ea18ff06..0000000000000000000000000000000000000000 --- a/libs/middletier/MockTapePoolTable.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "Exception.hpp" -#include "MockTapePoolTable.hpp" - -#include <sstream> - -//------------------------------------------------------------------------------ -// createTapePool -//------------------------------------------------------------------------------ -void cta::MockTapePoolTable::createTapePool( - const SecurityIdentity &requester, - const std::string &name, - const uint16_t nbDrives, - const uint32_t nbPartialTapes, - const std::string &comment) { - checkTapePoolDoesNotAlreadyExist(name); - TapePool tapePool(name, nbDrives, nbPartialTapes,requester.user, time(NULL), comment); - m_tapePools[name] = tapePool; -} - -//------------------------------------------------------------------------------ -// checkTapePoolDoesNotAlreadyExist -//------------------------------------------------------------------------------ -void cta::MockTapePoolTable::checkTapePoolDoesNotAlreadyExist( - const std::string &name) const { - std::map<std::string, TapePool>::const_iterator itor = - m_tapePools.find(name); - if(itor != m_tapePools.end()) { - std::ostringstream message; - message << "The " << name << " tape pool already exists"; - throw Exception(message.str()); - } -} - -//------------------------------------------------------------------------------ -// checkTapePoolExists -//------------------------------------------------------------------------------ -void cta::MockTapePoolTable::checkTapePoolExists( - const std::string &name) const { - std::map<std::string, TapePool>::const_iterator itor = - m_tapePools.find(name); - if(itor == m_tapePools.end()) { - std::ostringstream message; - message << "The " << name << " tape pool does not exist"; - throw Exception(message.str()); - } -} - -//------------------------------------------------------------------------------ -// deleteTapePool -//------------------------------------------------------------------------------ -void cta::MockTapePoolTable::deleteTapePool(const SecurityIdentity &requester, - const std::string &name) { - std::map<std::string, TapePool>::iterator itor = m_tapePools.find(name); - if(itor == m_tapePools.end()) { - std::ostringstream message; - message << "The " << name << " tape pool does not exist"; - throw Exception(message.str()); - } - m_tapePools.erase(itor); -} - -//------------------------------------------------------------------------------ -// getTapePools -//------------------------------------------------------------------------------ -std::list<cta::TapePool> cta::MockTapePoolTable::getTapePools( - const SecurityIdentity &requester) const { - std::list<cta::TapePool> tapePools; - - for(std::map<std::string, TapePool>::const_iterator itor = - m_tapePools.begin(); itor != m_tapePools.end(); itor++) { - tapePools.push_back(itor->second); - } - return tapePools; -} - -//------------------------------------------------------------------------------ -// getTapePool -//------------------------------------------------------------------------------ -const cta::TapePool &cta::MockTapePoolTable::getTapePool( - const std::string &name) const { - std::map<std::string, TapePool>::const_iterator itor = m_tapePools.find(name); - if(itor == m_tapePools.end()) { - std::ostringstream message; - message << "Tape pool " << name << " does not exist"; - throw(Exception(message.str())); - } - return itor->second; -} diff --git a/libs/middletier/MockTapePoolTable.hpp b/libs/middletier/MockTapePoolTable.hpp deleted file mode 100644 index e280299348f5c86442e71922dce930df5f7b55ef..0000000000000000000000000000000000000000 --- a/libs/middletier/MockTapePoolTable.hpp +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include "SecurityIdentity.hpp" -#include "TapePool.hpp" - -#include <list> -#include <map> -#include <string> - -namespace cta { - -/** - * Mock database-table of tape pools. - */ -class MockTapePoolTable { -public: - - /** - * Creates a tape pool with the specifed name. - * - * @param requester The identity of the user requesting the creation of the - * tape pool. - * @param name The name of the tape pool. - * @param nbDrives The maximum number of drives that can be concurrently - * assigned to this pool independent of whether they are archiving or - * retrieving files. - * @param nbPartialTapes The maximum number of tapes that can be partially - * full at any moment in time. - * @param comment The comment describing the tape pool. - */ - void createTapePool( - const SecurityIdentity &requester, - const std::string &name, - const uint16_t nbDrives, - const uint32_t nbPartialTapes, - const std::string &comment); - - /** - * Throws an exception if the specified tape pool already exists. - * - * @param name The name of the tape pool. - */ - void checkTapePoolDoesNotAlreadyExist(const std::string &name) const; - - /** - * Throws an exception if the specified tape pool does not exist. - * - * @param name The name of the tape pool. - */ - void checkTapePoolExists(const std::string &name) const; - - /** - * Delete the tape pool with the specifed name. - * - * @param requester The identity of the user requesting the deletion of the - * tape pool. - * @param name The name of the tape pool. - */ - void deleteTapePool( - const SecurityIdentity &requester, - const std::string &name); - - /** - * Gets the current list of tape pools in lexicographical order. - * - * @param requester The identity of the user requesting the list. - * @return The current list of tape pools in lexicographical order. - */ - std::list<TapePool> getTapePools( - const SecurityIdentity &requester) const; - - /** - * Returns the specified tape pool. - * - * @param name The name of the tape pool. - * @return The specified tape pool. - */ - const TapePool &getTapePool(const std::string &name) const; - -private: - - /** - * Mapping from tape pool name to tape pool. - */ - std::map<std::string, TapePool> m_tapePools; - -}; // class MockTapePoolTable - -} // namespace cta diff --git a/libs/middletier/MockTapePoolTableTest.cpp b/libs/middletier/MockTapePoolTableTest.cpp deleted file mode 100644 index 786cf1b9a24284dd2e6ac159c38eafb5609c23dc..0000000000000000000000000000000000000000 --- a/libs/middletier/MockTapePoolTableTest.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include "MockTapePoolTable.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class cta_client_MockTapePoolTableTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(cta_client_MockTapePoolTableTest, createTapePool_new) { - using namespace cta; - - MockTapePoolTable table; - const SecurityIdentity requester; - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_TRUE(tapePools.empty()); - } - - const std::string tapePoolName = "TestTapePool"; - - ASSERT_THROW(table.checkTapePoolExists(tapePoolName), std::exception); - - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string comment = "Comment"; - ASSERT_NO_THROW(table.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_EQ(1, tapePools.size()); - - TapePool tapePool; - ASSERT_NO_THROW(tapePool = tapePools.front()); - ASSERT_EQ(tapePoolName, tapePool.getName()); - ASSERT_EQ(comment, tapePool.getComment()); - } - - ASSERT_NO_THROW(table.checkTapePoolExists(tapePoolName)); -} - -TEST_F(cta_client_MockTapePoolTableTest, createTapePool_already_existing) { - using namespace cta; - - MockTapePoolTable table; - const SecurityIdentity requester; - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_TRUE(tapePools.empty()); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string comment = "Comment"; - ASSERT_NO_THROW(table.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_EQ(1, tapePools.size()); - - TapePool tapePool; - ASSERT_NO_THROW(tapePool = tapePools.front()); - ASSERT_EQ(tapePoolName, tapePool.getName()); - ASSERT_EQ(comment, tapePool.getComment()); - } - - ASSERT_THROW(table.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment), std::exception); -} - -TEST_F(cta_client_MockTapePoolTableTest, createTapePool_lexicographical_order) { - using namespace cta; - - MockTapePoolTable table; - const SecurityIdentity requester; - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_TRUE(tapePools.empty()); - } - - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - - ASSERT_NO_THROW(table.createTapePool(requester, "d", nbDrives, nbPartialTapes, - "Comment d")); - ASSERT_NO_THROW(table.createTapePool(requester, "b", nbDrives, nbPartialTapes, - "Comment b")); - ASSERT_NO_THROW(table.createTapePool(requester, "a", nbDrives, nbPartialTapes, - "Comment a")); - ASSERT_NO_THROW(table.createTapePool(requester, "c", nbDrives, nbPartialTapes, - "Comment c")); - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_EQ(4, tapePools.size()); - - ASSERT_EQ(std::string("a"), tapePools.front().getName()); - tapePools.pop_front(); - ASSERT_EQ(std::string("b"), tapePools.front().getName()); - tapePools.pop_front(); - ASSERT_EQ(std::string("c"), tapePools.front().getName()); - tapePools.pop_front(); - ASSERT_EQ(std::string("d"), tapePools.front().getName()); - } -} - -TEST_F(cta_client_MockTapePoolTableTest, deleteTapePool_existing) { - using namespace cta; - - MockTapePoolTable table; - const SecurityIdentity requester; - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_TRUE(tapePools.empty()); - } - - const std::string tapePoolName = "TestTapePool"; - const uint16_t nbDrives = 1; - const uint16_t nbPartialTapes = 1; - const std::string comment = "Comment"; - ASSERT_NO_THROW(table.createTapePool(requester, tapePoolName, nbDrives, - nbPartialTapes, comment)); - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_EQ(1, tapePools.size()); - - TapePool tapePool; - ASSERT_NO_THROW(tapePool = tapePools.front()); - ASSERT_EQ(tapePoolName, tapePool.getName()); - ASSERT_EQ(comment, tapePool.getComment()); - - ASSERT_NO_THROW(table.deleteTapePool(requester, tapePoolName)); - } - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_TRUE(tapePools.empty()); - } -} - -TEST_F(cta_client_MockTapePoolTableTest, deleteTapePool_non_existing) { - using namespace cta; - - MockTapePoolTable table; - const SecurityIdentity requester; - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_TRUE(tapePools.empty()); - } - - const std::string name = "TestTapePool"; - ASSERT_THROW(table.deleteTapePool(requester, name), std::exception); - - { - std::list<TapePool> tapePools; - ASSERT_NO_THROW(tapePools = table.getTapePools(requester)); - ASSERT_TRUE(tapePools.empty()); - } -} - -} // namespace unitTests diff --git a/libs/middletier/MockTapeTable.cpp b/libs/middletier/MockTapeTable.cpp deleted file mode 100644 index f3c9c60ed4efff54648c25addd6a3ffff43dc51b..0000000000000000000000000000000000000000 --- a/libs/middletier/MockTapeTable.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "Exception.hpp" -#include "MockTapeTable.hpp" - -#include <sstream> - -//------------------------------------------------------------------------------ -// createTape -//------------------------------------------------------------------------------ -void cta::MockTapeTable::createTape( - const SecurityIdentity &requester, - const std::string &vid, - const std::string &logicalLibraryName, - const std::string &tapePoolName, - const uint64_t capacityInBytes, - const std::string &comment) { - checkTapeDoesNotAlreadyExist(vid); - Tape tape( - vid, - logicalLibraryName, - tapePoolName, - capacityInBytes, - 0, - requester.user, - time(NULL), - comment); - m_tapes[vid] = tape; -} - -//------------------------------------------------------------------------------ -// checkTapeDoesNotAlreadyExist -//------------------------------------------------------------------------------ -void cta::MockTapeTable::checkTapeDoesNotAlreadyExist( - const std::string &vid) const { - std::map<std::string, Tape>::const_iterator itor = - m_tapes.find(vid); - if(itor != m_tapes.end()) { - std::ostringstream message; - message << "Tape with vid " << vid << " already exists"; - throw(Exception(message.str())); - } -} - -//------------------------------------------------------------------------------ -// deleteTape -//------------------------------------------------------------------------------ -void cta::MockTapeTable::deleteTape( - const SecurityIdentity &requester, - const std::string &vid) { - for(std::map<std::string, Tape>::iterator itor = m_tapes.begin(); - itor != m_tapes.end(); itor++) { - if(vid == itor->first) { - m_tapes.erase(itor); - return; - } - } - - // Reaching this point means the tape to be deleted does not - // exist - std::ostringstream message; - message << "Tape with volume identifier " << vid << " does not exist"; - throw Exception(message.str()); -} - -//------------------------------------------------------------------------------ -// getTapes -//------------------------------------------------------------------------------ -std::list<cta::Tape> cta::MockTapeTable::getTapes( - const SecurityIdentity &requester) const { - std::list<cta::Tape> tapes; - - for(std::map<std::string, Tape>::const_iterator itor = m_tapes.begin(); - itor != m_tapes.end(); itor++) { - tapes.push_back(itor->second); - } - - return tapes; -} diff --git a/libs/middletier/MockTapeTable.hpp b/libs/middletier/MockTapeTable.hpp deleted file mode 100644 index 183dc568365f32976e1df86c0c71c576c0d56393..0000000000000000000000000000000000000000 --- a/libs/middletier/MockTapeTable.hpp +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once - -#include "SecurityIdentity.hpp" -#include "Tape.hpp" - -#include <list> -#include <map> -#include <string> - -namespace cta { - -/** - * Mock database-table of tapes. - */ -class MockTapeTable { -public: - - /** - * Creates a tape. - * - * @param requester The identity of the user requesting the creation of the - * tape. - * @param vid The volume identifier of the tape. - * @param logicalLibrary The name of the logical library to which the tape - * belongs. - * @param tapePoolName The name of the tape pool to which the tape belongs. - * @param capacityInBytes The capacity of the tape. - * @param comment The comment describing the logical library. - */ - void createTape( - const SecurityIdentity &requester, - const std::string &vid, - const std::string &logicalLibraryName, - const std::string &tapePoolName, - const uint64_t capacityInBytes, - const std::string &comment); - - /** - * Throws an exception if the specified tape already exists. - * - * @param vid The volume identifier of the tape. - */ - void checkTapeDoesNotAlreadyExist(const std::string &vid) const; - - /** - * Deletes the tape with the specified volume identifier. - * - * @param requester The identity of the user requesting the deletion of the - * tape. - * @param vid The volume identifier of the tape. - */ - void deleteTape( - const SecurityIdentity &requester, - const std::string &vid); - - /** - * Returns the current list of tapes in the lexicographical order of their - * volume identifiers. - * - * @param requester The identity of the user requesting the list. - * @return The current list of tapes in the lexicographical order of their - * volume identifiers. - */ - std::list<Tape> getTapes( - const SecurityIdentity &requester) const; - -private: - - /** - * Mapping from volume identiifer to tape. - */ - std::map<std::string, Tape> m_tapes; - -}; // class MockTapeTable - -} // namespace cta diff --git a/libs/middletier/MockTapeTableTest.cpp b/libs/middletier/MockTapeTableTest.cpp deleted file mode 100644 index ac9734a8770becc6a2c7761da746a27cb1966f0a..0000000000000000000000000000000000000000 --- a/libs/middletier/MockTapeTableTest.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include "MockTapeTable.hpp" - -#include <gtest/gtest.h> - -namespace unitTests { - -class cta_client_MockTapeTableTest: public ::testing::Test { -protected: - - virtual void SetUp() { - } - - virtual void TearDown() { - } -}; - -TEST_F(cta_client_MockTapeTableTest, createTape_new) { - using namespace cta; - - MockTapeTable table; - const SecurityIdentity requester; - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - const std::string poolName = "TestTapePool"; - const std::string vid = "TestVid"; - const uint64_t capacityInBytes = 12345678; - const std::string tapeComment = "Tape comment"; - ASSERT_NO_THROW(table.createTape(requester, vid, libraryName, poolName, - capacityInBytes, tapeComment)); - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_EQ(1, tapes.size()); - - Tape tape; - ASSERT_NO_THROW(tape = tapes.front()); - ASSERT_EQ(vid, tape.getVid()); - ASSERT_EQ(libraryName, tape.getLogicalLibraryName()); - ASSERT_EQ(poolName, tape.getTapePoolName()); - ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes()); - ASSERT_EQ(0, tape.getDataOnTapeInBytes()); - ASSERT_EQ(tapeComment, tape.getComment()); - } -} - -TEST_F(cta_client_MockTapeTableTest, createTape_already_existing) { - using namespace cta; - - MockTapeTable table; - const SecurityIdentity requester; - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - const std::string poolName = "TestTapePool"; - const std::string vid = "TestVid"; - const uint64_t capacityInBytes = 12345678; - const std::string tapeComment = "Tape comment"; - ASSERT_NO_THROW(table.createTape(requester, vid, libraryName, poolName, - capacityInBytes, tapeComment)); - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_EQ(1, tapes.size()); - - Tape tape; - ASSERT_NO_THROW(tape = tapes.front()); - ASSERT_EQ(vid, tape.getVid()); - ASSERT_EQ(libraryName, tape.getLogicalLibraryName()); - ASSERT_EQ(poolName, tape.getTapePoolName()); - ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes()); - ASSERT_EQ(0, tape.getDataOnTapeInBytes()); - ASSERT_EQ(tapeComment, tape.getComment()); - } - - ASSERT_THROW(table.createTape(requester, vid, libraryName, poolName, - capacityInBytes, tapeComment), std::exception); - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_EQ(1, tapes.size()); - - Tape tape; - ASSERT_NO_THROW(tape = tapes.front()); - ASSERT_EQ(vid, tape.getVid()); - ASSERT_EQ(libraryName, tape.getLogicalLibraryName()); - ASSERT_EQ(poolName, tape.getTapePoolName()); - ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes()); - ASSERT_EQ(0, tape.getDataOnTapeInBytes()); - ASSERT_EQ(tapeComment, tape.getComment()); - } -} - -TEST_F(cta_client_MockTapeTableTest, createTape_lexicographical_order) { - using namespace cta; - - MockTapeTable table; - const SecurityIdentity requester; - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - const std::string poolName = "TestTapePool"; - const uint64_t capacityInBytes = 12345678; - ASSERT_NO_THROW(table.createTape(requester, "d", libraryName, poolName, capacityInBytes, - "Comment d")); - ASSERT_NO_THROW(table.createTape(requester, "b", libraryName, poolName, capacityInBytes, - "Comment b")); - ASSERT_NO_THROW(table.createTape(requester, "a", libraryName, poolName, capacityInBytes, - "Comment a")); - ASSERT_NO_THROW(table.createTape(requester, "c", libraryName, poolName, capacityInBytes, - "Comment c")); - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_EQ(4, tapes.size()); - - ASSERT_EQ(std::string("a"), tapes.front().getVid()); - tapes.pop_front(); - ASSERT_EQ(std::string("b"), tapes.front().getVid()); - tapes.pop_front(); - ASSERT_EQ(std::string("c"), tapes.front().getVid()); - tapes.pop_front(); - ASSERT_EQ(std::string("d"), tapes.front().getVid()); - } -} - -TEST_F(cta_client_MockTapeTableTest, deleteTape_existing) { - using namespace cta; - - MockTapeTable table; - const SecurityIdentity requester; - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } - - const std::string libraryName = "TestLogicalLibrary"; - const std::string poolName = "TestTapePool"; - const std::string vid = "TestVid"; - const uint64_t capacityInBytes = 12345678; - const std::string tapeComment = "Tape comment"; - ASSERT_NO_THROW(table.createTape(requester, vid, libraryName, poolName, - capacityInBytes, tapeComment)); - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_EQ(1, tapes.size()); - - Tape tape; - ASSERT_NO_THROW(tape = tapes.front()); - ASSERT_EQ(vid, tape.getVid()); - ASSERT_EQ(libraryName, tape.getLogicalLibraryName()); - ASSERT_EQ(poolName, tape.getTapePoolName()); - ASSERT_EQ(capacityInBytes, tape.getCapacityInBytes()); - ASSERT_EQ(0, tape.getDataOnTapeInBytes()); - ASSERT_EQ(tapeComment, tape.getComment()); - } - - ASSERT_THROW(table.createTape(requester, vid, libraryName, poolName, - capacityInBytes, tapeComment), std::exception); - - ASSERT_NO_THROW(table.deleteTape(requester, vid)); - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } -} - -TEST_F(cta_client_MockTapeTableTest, deleteTape_non_existing) { - using namespace cta; - - MockTapeTable table; - const SecurityIdentity requester; - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } - - const std::string vid = "TestVid"; - ASSERT_THROW(table.deleteTape(requester, vid), std::exception); - - { - std::list<Tape> tapes; - ASSERT_NO_THROW(tapes = table.getTapes(requester)); - ASSERT_TRUE(tapes.empty()); - } -} - -} // namespace unitTests diff --git a/libs/middletier/SqliteMiddleTierAdmin.hpp b/libs/middletier/SqliteMiddleTierAdmin.hpp index 9d7a4b5446b5450a984b58a84bbdb3c77117956b..bff3f2fb0a3d04e4cb0bd5af19370059b333303f 100644 --- a/libs/middletier/SqliteMiddleTierAdmin.hpp +++ b/libs/middletier/SqliteMiddleTierAdmin.hpp @@ -1,7 +1,6 @@ #pragma once #include "MiddleTierAdmin.hpp" -#include "MockDatabase.hpp" #include "SqliteDatabase.hpp" #include "Vfs.hpp" @@ -281,39 +280,6 @@ public: const SecurityIdentity &requester) const; protected: - - /** - * Gets the file system node corresponding to the specified path. - * - * @path The path. - * @return The corresponding file system node. - */ - FileSystemNode &getFileSystemNode(const std::string &path); - - /** - * Gets the file system node corresponding to the specified path. - * - * @path The path. - * @return The corresponding file system node. - */ - const FileSystemNode &getFileSystemNode(const std::string &path) const; - - /** - * Throws an exception if the specified tape pool is in use. - * - * @param name The name of the tape pool. - */ - void checkTapePoolIsNotInUse(const std::string &name) const; - - /** - * Returns true if the specified absolute path is that of an existing - * directory within the archive namepsace. - * - * @param path The specified absolute path. - * @return True if the specified absolute path is that of an existing - * directory within the archive namepsace. - */ - bool isAnExistingDirectory(const std::string &path) const throw(); SqliteDatabase &m_sqlite_db; diff --git a/libs/middletier/SqliteMiddleTierAdminTest.cpp b/libs/middletier/SqliteMiddleTierAdminTest.cpp index 060055d8b28417eb226243e5a93af5045aa1e9f2..a2fc3bf1de03aae77de9a48604514ad2dfc0f3ca 100644 --- a/libs/middletier/SqliteMiddleTierAdminTest.cpp +++ b/libs/middletier/SqliteMiddleTierAdminTest.cpp @@ -1,5 +1,3 @@ -#include "MockMiddleTierAdmin.hpp" -#include "MockMiddleTierUser.hpp" #include "SqliteMiddleTierAdmin.hpp" #include "SqliteMiddleTierUser.hpp" diff --git a/libs/middletier/SqliteMiddleTierUser.hpp b/libs/middletier/SqliteMiddleTierUser.hpp index 456280c8d88e0997229daa6af2be653caba3e32b..394decb934ff572eb04a2f46fbafda1b42c57baf 100644 --- a/libs/middletier/SqliteMiddleTierUser.hpp +++ b/libs/middletier/SqliteMiddleTierUser.hpp @@ -3,7 +3,6 @@ #include "FileSystemNode.hpp" #include "FileSystemStorageClasses.hpp" #include "MiddleTierUser.hpp" -#include "MockDatabase.hpp" #include "SqliteDatabase.hpp" #include "StorageClass.hpp" #include "Vfs.hpp" @@ -233,22 +232,6 @@ private: Vfs &m_vfs; - /** - * Gets the file system node corresponding to the specified path. - * - * @path The path. - * @return The corresponding file system node. - */ - FileSystemNode &getFileSystemNode(const std::string &path); - - /** - * Gets the file system node corresponding to the specified path. - * - * @path The path. - * @return The corresponding file system node. - */ - const FileSystemNode &getFileSystemNode(const std::string &path) const; - /** * Returns true if the specified absolute path is that of an existing * directory within the archive namepsace.