From 10a3c8b054af084052cbfa425780c27423a19a88 Mon Sep 17 00:00:00 2001 From: Victor Kotlyar <Victor.Kotlyar@cern.ch> Date: Wed, 3 Jul 2019 16:54:25 +0200 Subject: [PATCH] #533: Add methods to modify DISK_SYSTEM table values to the catalogue interface. Implement methods to modify values for FILE_REGEXP, FREE_SPACE_QUERY_URL, REFRESH_INTERVAL, TARGETED_FREE_SPACE, USER_COMMENT --- catalogue/Catalogue.hpp | 13 +- catalogue/CatalogueRetryWrapper.hpp | 21 + catalogue/CatalogueTest.cpp | 605 ++++++++++++++++++++++++++++ catalogue/DummyCatalogue.hpp | 7 +- catalogue/RdbmsCatalogue.cpp | 205 ++++++++++ catalogue/RdbmsCatalogue.hpp | 13 +- 6 files changed, 861 insertions(+), 3 deletions(-) diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index fbc85e4542..481276347a 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -530,8 +530,19 @@ public: * * @param name The name of the disk system. */ - virtual void deleteDiskSystem(const std::string &name) = 0; + virtual void deleteDiskSystem(const std::string &name) = 0; + virtual void modifyDiskSystemFileRegexp(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &fileRegexp) = 0; + virtual void modifyDiskSystemFreeSpaceQueryURL(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &freeSpaceQueryURL) = 0; + virtual void modifyDiskSystemRefreshInterval(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const uint64_t refreshInterval) = 0; + virtual void modifyDiskSystemTargetedFreeSpace(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const uint64_t targetedFreeSpace) = 0; + virtual void modifyDiskSystemComment(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &comment) = 0; + /** * Returns the specified archive files. Please note that the list of files * is ordered by archive file ID. diff --git a/catalogue/CatalogueRetryWrapper.hpp b/catalogue/CatalogueRetryWrapper.hpp index 12802504e5..6a52405ba9 100644 --- a/catalogue/CatalogueRetryWrapper.hpp +++ b/catalogue/CatalogueRetryWrapper.hpp @@ -368,10 +368,31 @@ public: void createDiskSystem(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &fileRegexp, const std::string &freeSpaceQueryURL, const uint64_t refreshInterval, const uint64_t targetedFreeSpace, const std::string &comment) override { return retryOnLostConnection(m_log, [&]{return m_catalogue->createDiskSystem(admin, name, fileRegexp, freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment);}, m_maxTriesToConnect); } + void deleteDiskSystem(const std::string &name) override { return retryOnLostConnection(m_log, [&]{return m_catalogue->deleteDiskSystem(name);}, m_maxTriesToConnect); } + + void modifyDiskSystemFileRegexp(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &fileRegexp) override { + return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyDiskSystemFileRegexp(admin, name, fileRegexp);}, m_maxTriesToConnect); + } + void modifyDiskSystemFreeSpaceQueryURL(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &freeSpaceQueryURL) override { + return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyDiskSystemFreeSpaceQueryURL(admin, name, freeSpaceQueryURL);}, m_maxTriesToConnect); + } + + void modifyDiskSystemRefreshInterval(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t refreshInterval) override { + return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyDiskSystemRefreshInterval(admin, name, refreshInterval);}, m_maxTriesToConnect); + } + + void modifyDiskSystemTargetedFreeSpace(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t targetedFreeSpace) override { + return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyDiskSystemTargetedFreeSpace(admin, name, targetedFreeSpace);}, m_maxTriesToConnect); + } + + void modifyDiskSystemComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) override { + return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyDiskSystemComment(admin, name, comment);}, m_maxTriesToConnect); + } + ArchiveFileItor getArchiveFilesItor(const TapeFileSearchCriteria &searchCriteria = TapeFileSearchCriteria()) const override { return retryOnLostConnection(m_log, [&]{return m_catalogue->getArchiveFilesItor(searchCriteria);}, m_maxTriesToConnect); } diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index ebb5de8600..98376c73d2 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -11702,6 +11702,611 @@ TEST_P(cta_catalogue_CatalogueTest, deleteDiskSystem_non_existant) { ASSERT_THROW(m_catalogue->deleteDiskSystem("non_exsitant_disk_system"), catalogue::UserSpecifiedANonExistentDiskSystem); } +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemFileRegexp) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const std::string modifiedFileRegexp = "modified_fileRegexp"; + m_catalogue->modifyDiskSystemFileRegexp(m_admin, name, modifiedFileRegexp); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(modifiedFileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemFileRegexp_emptyStringDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = ""; + const std::string modifiedFileRegexp = "modified_fileRegexp"; + ASSERT_THROW(m_catalogue->modifyDiskSystemFileRegexp(m_admin, diskSystemName, modifiedFileRegexp), + catalogue::UserSpecifiedAnEmptyStringDiskSystemName); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemFileRegexp_nonExistentDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = "dummyDiskSystemName"; + const std::string modifiedFileRegexp = "modified_fileRegexp"; + ASSERT_THROW(m_catalogue->modifyDiskSystemFileRegexp(m_admin, diskSystemName, modifiedFileRegexp), + catalogue::UserSpecifiedANonExistentDiskSystem); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemFileRegexp_emptyStringFileRegexp) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const std::string modifiedFileRegexp = ""; + ASSERT_THROW(m_catalogue->modifyDiskSystemFileRegexp(m_admin, name, modifiedFileRegexp), + catalogue::UserSpecifiedAnEmptyStringFileRegexp); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemFreeSpaceQueryURL) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const std::string modifiedFreeSpaceQueryURL = "modified_freeSpaceQueryURL"; + m_catalogue->modifyDiskSystemFreeSpaceQueryURL(m_admin, name, modifiedFreeSpaceQueryURL); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(modifiedFreeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemFreeSpaceQueryURL_emptyStringDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = ""; + const std::string modifiedFreeSpaceQueryURL = "modified_freeSpaceQueryURL"; + ASSERT_THROW(m_catalogue->modifyDiskSystemFreeSpaceQueryURL(m_admin, diskSystemName, modifiedFreeSpaceQueryURL), + catalogue::UserSpecifiedAnEmptyStringDiskSystemName); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemFreeSpaceQueryURL_nonExistentDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = "dummyDiskSystemName"; + const std::string modifiedFreeSpaceQueryURL = "modified_freeSpaceQueryURL"; + ASSERT_THROW(m_catalogue->modifyDiskSystemFreeSpaceQueryURL(m_admin, diskSystemName, modifiedFreeSpaceQueryURL), + catalogue::UserSpecifiedANonExistentDiskSystem); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemFreeSpaceQueryURL_emptyStringFreeSpaceQueryURL) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const std::string modifiedFreeSpaceQueryURL = ""; + ASSERT_THROW(m_catalogue->modifyDiskSystemFreeSpaceQueryURL(m_admin, name, modifiedFreeSpaceQueryURL), + catalogue::UserSpecifiedAnEmptyStringFreeSpaceQueryURL); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemRefreshInterval) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const uint64_t modifiedRefreshInterval = 128; + m_catalogue->modifyDiskSystemRefreshInterval(m_admin, name, modifiedRefreshInterval); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(modifiedRefreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemRefreshInterval_emptyStringDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = ""; + const uint64_t modifiedRefreshInterval = 128; + ASSERT_THROW(m_catalogue->modifyDiskSystemRefreshInterval(m_admin, diskSystemName, modifiedRefreshInterval), + catalogue::UserSpecifiedAnEmptyStringDiskSystemName); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemRefreshInterval_nonExistentDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = "dummyDiskSystemName"; + const uint64_t modifiedRefreshInterval = 128; + ASSERT_THROW(m_catalogue->modifyDiskSystemRefreshInterval(m_admin, diskSystemName, modifiedRefreshInterval), + catalogue::UserSpecifiedANonExistentDiskSystem); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemRefreshInterval_zeroRefreshInterval) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const uint64_t modifiedRefreshInterval = 0; + ASSERT_THROW(m_catalogue->modifyDiskSystemRefreshInterval(m_admin, name, modifiedRefreshInterval), + catalogue::UserSpecifiedAZeroRefreshInterval); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemTargetedFreeSpace) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const uint64_t modifiedTargetedFreeSpace = 128; + m_catalogue->modifyDiskSystemTargetedFreeSpace(m_admin, name, modifiedTargetedFreeSpace); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(modifiedTargetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemTargetedFreeSpace_emptyStringDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = ""; + const uint64_t modifiedTargetedFreeSpace = 128; + ASSERT_THROW(m_catalogue->modifyDiskSystemTargetedFreeSpace(m_admin, diskSystemName, modifiedTargetedFreeSpace), + catalogue::UserSpecifiedAnEmptyStringDiskSystemName); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemTargetedFreeSpace_nonExistentDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = "dummyDiskSystemName"; + const uint64_t modifiedTargetedFreeSpace = 128; + ASSERT_THROW(m_catalogue->modifyDiskSystemTargetedFreeSpace(m_admin, diskSystemName, modifiedTargetedFreeSpace), + catalogue::UserSpecifiedANonExistentDiskSystem); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemTargetedFreeSpace_zeroTargetedFreeSpace) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const uint64_t modifiedTargetedFreeSpace = 0; + ASSERT_THROW(m_catalogue->modifyDiskSystemTargetedFreeSpace(m_admin, name, modifiedTargetedFreeSpace), + catalogue::UserSpecifiedAZeroTargetedFreeSpace); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemComment) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const std::string modifiedComment = "modified_comment"; + m_catalogue->modifyDiskSystemComment(m_admin, name, modifiedComment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(modifiedComment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemComment_emptyStringDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = ""; + const std::string modifiedComment = "modified_comment"; + ASSERT_THROW(m_catalogue->modifyDiskSystemComment(m_admin, diskSystemName, modifiedComment), + catalogue::UserSpecifiedAnEmptyStringDiskSystemName); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemComment_nonExistentDiskSystemName) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string diskSystemName = "dummyDiskSystemName"; + const std::string modifiedComment = "modified_comment"; + ASSERT_THROW(m_catalogue->modifyDiskSystemComment(m_admin, diskSystemName, modifiedComment), + catalogue::UserSpecifiedANonExistentDiskSystem); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyDiskSystemCommentL_emptyStringComment) { + using namespace cta; + + ASSERT_TRUE(m_catalogue->getAllDiskSystems().empty()); + + const std::string name = "disk_system_name"; + const std::string fileRegexp = "file_regexp"; + const std::string freeSpaceQueryURL = "free_space_query_url"; + const uint64_t refreshInterval = 32; + const uint64_t targetedFreeSpace = 64; + const std::string comment = "disk system comment"; + + m_catalogue->createDiskSystem(m_admin, name, fileRegexp, + freeSpaceQueryURL, refreshInterval, targetedFreeSpace, comment); + + { + const auto diskSystemList = m_catalogue->getAllDiskSystems(); + ASSERT_EQ(1, diskSystemList.size()); + + const auto &diskSystem = diskSystemList.front(); + ASSERT_EQ(name, diskSystem.name); + ASSERT_EQ(fileRegexp, diskSystem.fileRegexp); + ASSERT_EQ(freeSpaceQueryURL, diskSystem.freeSpaceQueryURL); + ASSERT_EQ(refreshInterval, diskSystem.refreshInterval); + ASSERT_EQ(targetedFreeSpace, diskSystem.targetedFreeSpace); + ASSERT_EQ(comment, diskSystem.comment); + + const auto creationLog = diskSystem.creationLog; + ASSERT_EQ(m_admin.username, creationLog.username); + ASSERT_EQ(m_admin.host, creationLog.host); + + const auto lastModificationLog = diskSystem.lastModificationLog; + ASSERT_EQ(creationLog, lastModificationLog); + } + + const std::string modifiedComment = ""; + ASSERT_THROW(m_catalogue->modifyDiskSystemComment(m_admin, name, modifiedComment), + catalogue::UserSpecifiedAnEmptyStringComment); +} + TEST_P(cta_catalogue_CatalogueTest, reclaimTape_full_lastFSeq_0_no_tape_files) { using namespace cta; diff --git a/catalogue/DummyCatalogue.hpp b/catalogue/DummyCatalogue.hpp index 5c09a0ca92..33f7f07666 100644 --- a/catalogue/DummyCatalogue.hpp +++ b/catalogue/DummyCatalogue.hpp @@ -59,7 +59,12 @@ public: std::list<common::dataStructures::ActivitiesFairShareWeights> getActivitiesFairShareWeights() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } common::dataStructures::DiskSystemList getAllDiskSystems() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } void createDiskSystem(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &fileRegexp, const std::string &freeSpaceQueryURL, const uint64_t refreshInterval, const uint64_t targetedFreeSpace, const std::string &comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } - void deleteDiskSystem(const std::string &name) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } + void deleteDiskSystem(const std::string &name) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } + void modifyDiskSystemFileRegexp(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &fileRegexp) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");} + void modifyDiskSystemFreeSpaceQueryURL(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &freeSpaceQueryURL) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");} + void modifyDiskSystemRefreshInterval(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t refreshInterval) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");} + void modifyDiskSystemTargetedFreeSpace(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t targetedFreeSpace) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");} + void modifyDiskSystemComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented");} std::list<common::dataStructures::AdminUser> getAdminUsers() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } common::dataStructures::ArchiveFile getArchiveFileById(const uint64_t id) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } ArchiveFileItor getArchiveFilesItor(const TapeFileSearchCriteria& searchCriteria) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index a0856c4aa9..eab628f86b 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -4430,6 +4430,211 @@ void RdbmsCatalogue::deleteDiskSystem(const std::string &name) { } } +void RdbmsCatalogue::modifyDiskSystemFileRegexp(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &fileRegexp) { + try { + if(name.empty()) { + throw UserSpecifiedAnEmptyStringDiskSystemName("Cannot modify disk system" + " because the disk system name is an empty string"); + } + if(fileRegexp.empty()) { + throw UserSpecifiedAnEmptyStringFileRegexp("Cannot modify disk system " + "because the new fileRegexp is an empty string"); + } + + const time_t now = time(nullptr); + const char *const sql = + "UPDATE DISK_SYSTEM SET " + "FILE_REGEXP = :FILE_REGEXP," + "LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME," + "LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME," + "LAST_UPDATE_TIME = :LAST_UPDATE_TIME " + "WHERE " + "DISK_SYSTEM_NAME = :DISK_SYSTEM_NAME"; + auto conn = m_connPool.getConn(); + auto stmt = conn.createStmt(sql); + stmt.bindString(":FILE_REGEXP", fileRegexp); + stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); + stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); + stmt.bindUint64(":LAST_UPDATE_TIME", now); + stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.executeNonQuery(); + + if(0 == stmt.getNbAffectedRows()) { + throw UserSpecifiedANonExistentDiskSystem(std::string("Cannot modify disk system ") + name + " because it does not exist"); + } + } catch(exception::UserError &) { + throw; + } catch(exception::Exception &ex) { + ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str()); + throw; + } +} + +void RdbmsCatalogue::modifyDiskSystemFreeSpaceQueryURL(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &freeSpaceQueryURL) { + try { + if(name.empty()) { + throw UserSpecifiedAnEmptyStringDiskSystemName("Cannot modify disk system" + " because the disk system name is an empty string"); + } + if(freeSpaceQueryURL.empty()) { + throw UserSpecifiedAnEmptyStringFreeSpaceQueryURL("Cannot modify disk system " + "because the new freeSpaceQueryURL is an empty string"); + } + + const time_t now = time(nullptr); + const char *const sql = + "UPDATE DISK_SYSTEM SET " + "FREE_SPACE_QUERY_URL = :FREE_SPACE_QUERY_URL," + "LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME," + "LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME," + "LAST_UPDATE_TIME = :LAST_UPDATE_TIME " + "WHERE " + "DISK_SYSTEM_NAME = :DISK_SYSTEM_NAME"; + auto conn = m_connPool.getConn(); + auto stmt = conn.createStmt(sql); + stmt.bindString(":FREE_SPACE_QUERY_URL", freeSpaceQueryURL); + stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); + stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); + stmt.bindUint64(":LAST_UPDATE_TIME", now); + stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.executeNonQuery(); + + if(0 == stmt.getNbAffectedRows()) { + throw UserSpecifiedANonExistentDiskSystem(std::string("Cannot modify disk system ") + name + " because it does not exist"); + } + } catch(exception::UserError &) { + throw; + } catch(exception::Exception &ex) { + ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str()); + throw; + } +} + +void RdbmsCatalogue::modifyDiskSystemRefreshInterval(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const uint64_t refreshInterval) { + try { + if(name.empty()) { + throw UserSpecifiedAnEmptyStringDiskSystemName("Cannot modify disk system" + " because the disk system name is an empty string"); + } + if(0 == refreshInterval) { + throw UserSpecifiedAZeroRefreshInterval("Cannot modify disk system " + "because the new refresh interval has zero value"); + } + + const time_t now = time(nullptr); + const char *const sql = + "UPDATE DISK_SYSTEM SET " + "REFRESH_INTERVAL = :REFRESH_INTERVAL," + "LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME," + "LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME," + "LAST_UPDATE_TIME = :LAST_UPDATE_TIME " + "WHERE " + "DISK_SYSTEM_NAME = :DISK_SYSTEM_NAME"; + auto conn = m_connPool.getConn(); + auto stmt = conn.createStmt(sql); + stmt.bindUint64(":REFRESH_INTERVAL", refreshInterval); + stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); + stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); + stmt.bindUint64(":LAST_UPDATE_TIME", now); + stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.executeNonQuery(); + + if(0 == stmt.getNbAffectedRows()) { + throw UserSpecifiedANonExistentDiskSystem(std::string("Cannot modify disk system ") + name + " because it does not exist"); + } + } catch(exception::UserError &) { + throw; + } catch(exception::Exception &ex) { + ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str()); + throw; + } +} + +void RdbmsCatalogue::modifyDiskSystemTargetedFreeSpace(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const uint64_t targetedFreeSpace) { + try { + if(name.empty()) { + throw UserSpecifiedAnEmptyStringDiskSystemName("Cannot modify disk system" + " because the disk system name is an empty string"); + } + if(0 == targetedFreeSpace) { + throw UserSpecifiedAZeroTargetedFreeSpace("Cannot modify disk system " + "because the new targeted free space has zero value"); + } + + const time_t now = time(nullptr); + const char *const sql = + "UPDATE DISK_SYSTEM SET " + "TARGETED_FREE_SPACE = :TARGETED_FREE_SPACE," + "LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME," + "LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME," + "LAST_UPDATE_TIME = :LAST_UPDATE_TIME " + "WHERE " + "DISK_SYSTEM_NAME = :DISK_SYSTEM_NAME"; + auto conn = m_connPool.getConn(); + auto stmt = conn.createStmt(sql); + stmt.bindUint64(":TARGETED_FREE_SPACE", targetedFreeSpace); + stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); + stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); + stmt.bindUint64(":LAST_UPDATE_TIME", now); + stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.executeNonQuery(); + + if(0 == stmt.getNbAffectedRows()) { + throw UserSpecifiedANonExistentDiskSystem(std::string("Cannot modify disk system ") + name + " because it does not exist"); + } + } catch(exception::UserError &) { + throw; + } catch(exception::Exception &ex) { + ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str()); + throw; + } +} + +void RdbmsCatalogue::modifyDiskSystemComment(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &comment) { + try { + if(name.empty()) { + throw UserSpecifiedAnEmptyStringDiskSystemName("Cannot modify disk system" + " because the disk system name is an empty string"); + } + if(comment.empty()) { + throw UserSpecifiedAnEmptyStringComment("Cannot modify disk system " + "because the new comment is an empty string"); + } + + const time_t now = time(nullptr); + const char *const sql = + "UPDATE DISK_SYSTEM SET " + "USER_COMMENT = :USER_COMMENT," + "LAST_UPDATE_USER_NAME = :LAST_UPDATE_USER_NAME," + "LAST_UPDATE_HOST_NAME = :LAST_UPDATE_HOST_NAME," + "LAST_UPDATE_TIME = :LAST_UPDATE_TIME " + "WHERE " + "DISK_SYSTEM_NAME = :DISK_SYSTEM_NAME"; + auto conn = m_connPool.getConn(); + auto stmt = conn.createStmt(sql); + stmt.bindString(":USER_COMMENT", comment); + stmt.bindString(":LAST_UPDATE_USER_NAME", admin.username); + stmt.bindString(":LAST_UPDATE_HOST_NAME", admin.host); + stmt.bindUint64(":LAST_UPDATE_TIME", now); + stmt.bindString(":DISK_SYSTEM_NAME", name); + stmt.executeNonQuery(); + + if(0 == stmt.getNbAffectedRows()) { + throw UserSpecifiedANonExistentDiskSystem(std::string("Cannot modify disk system ") + name + " because it does not exist"); + } + } catch(exception::UserError &) { + throw; + } catch(exception::Exception &ex) { + ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str()); + throw; + } +} + //------------------------------------------------------------------------------ // insertArchiveFile //------------------------------------------------------------------------------ diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index a6188c64e2..341b897ad0 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -543,7 +543,18 @@ public: * * @param name The name of the disk system. */ - void deleteDiskSystem(const std::string &name) override; + void deleteDiskSystem(const std::string &name) override; + + void modifyDiskSystemFileRegexp(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &fileRegexp) override; + void modifyDiskSystemFreeSpaceQueryURL(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &freeSpaceQueryURL) override; + void modifyDiskSystemRefreshInterval(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const uint64_t refreshInterval) override; + void modifyDiskSystemTargetedFreeSpace(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const uint64_t targetedFreeSpace) override; + void modifyDiskSystemComment(const common::dataStructures::SecurityIdentity &admin, + const std::string &name, const std::string &comment) override; /** * Throws a UserError exception if the specified searchCriteria is not valid -- GitLab