From 52e5ec67079be9c1057a61ce43956e5cab688f6e Mon Sep 17 00:00:00 2001 From: Cedric CAFFY <cedric.caffy@cern.ch> Date: Wed, 4 Mar 2020 11:37:12 +0100 Subject: [PATCH] Implemented Catalogue::getVirtualOrganizations() + unit test Added deletion of existing VOs in the SetUp() method of CatalogueTest --- catalogue/Catalogue.hpp | 6 +++ catalogue/CatalogueRetryWrapper.hpp | 4 ++ catalogue/CatalogueTest.cpp | 32 ++++++++++++ catalogue/DummyCatalogue.hpp | 1 + catalogue/RdbmsCatalogue.cpp | 52 +++++++++++++++++++ catalogue/RdbmsCatalogue.hpp | 6 +++ common/dataStructures/VirtualOrganization.hpp | 10 ++++ 7 files changed, 111 insertions(+) diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index 37fcc0e2f3..b0bc95b3c6 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -239,6 +239,12 @@ public: */ virtual void deleteVirtualOrganization(const std::string &voName) = 0; + /** + * Get all the Virtual Organizations from the Catalogue + * @return the list of all the Virtual Organizations + */ + virtual std::list<common::dataStructures::VirtualOrganization> getVirtualOrganizations() const = 0; + /** * Creates the specified storage class. * diff --git a/catalogue/CatalogueRetryWrapper.hpp b/catalogue/CatalogueRetryWrapper.hpp index 7919c7d1fe..2da57cb123 100644 --- a/catalogue/CatalogueRetryWrapper.hpp +++ b/catalogue/CatalogueRetryWrapper.hpp @@ -123,6 +123,10 @@ public: void deleteVirtualOrganization(const std::string &voName) override { return retryOnLostConnection(m_log, [&]{return m_catalogue->deleteVirtualOrganization(voName);}, m_maxTriesToConnect); } + + std::list<common::dataStructures::VirtualOrganization> getVirtualOrganizations() const override { + return retryOnLostConnection(m_log, [&]{return m_catalogue->getVirtualOrganizations();}, m_maxTriesToConnect); + } void createStorageClass(const common::dataStructures::SecurityIdentity &admin, const common::dataStructures::StorageClass &storageClass) override { return retryOnLostConnection(m_log, [&]{return m_catalogue->createStorageClass(admin, storageClass);}, m_maxTriesToConnect); diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp index 9413b1ea60..0720529395 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -180,6 +180,12 @@ void cta_catalogue_CatalogueTest::SetUp() { m_catalogue->deleteDiskSystem(ds.name); } } + { + const auto virtualOrganizations = m_catalogue->getVirtualOrganizations(); + for(auto &vo: virtualOrganizations) { + m_catalogue->deleteVirtualOrganization(vo.name); + } + } } catch(exception::Exception &ex) { throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str()); } @@ -15349,4 +15355,30 @@ TEST_P(cta_catalogue_CatalogueTest, deleteVirtualOrganizationNameDoesNotExist) { ASSERT_THROW(m_catalogue->deleteVirtualOrganization("DOES_NOT_EXIST"),cta::exception::UserError); } +TEST_P(cta_catalogue_CatalogueTest, getVirtualOrganizations) { + using namespace cta; + + common::dataStructures::VirtualOrganization vo; + vo.name = "vo"; + vo.comment = "comment"; + + ASSERT_NO_THROW(m_catalogue->createVirtualOrganization(m_admin,vo)); + + std::list<common::dataStructures::VirtualOrganization> vos = m_catalogue->getVirtualOrganizations(); + ASSERT_EQ(1,vos.size()); + + auto &voRetrieved = vos.front(); + ASSERT_EQ(vo.name,voRetrieved.name); + ASSERT_EQ(vo.comment,voRetrieved.comment); + ASSERT_EQ(m_admin.host,voRetrieved.creationLog.host); + ASSERT_EQ(m_admin.username,voRetrieved.creationLog.username); + ASSERT_EQ(m_admin.host,voRetrieved.lastModificationLog.host); + ASSERT_EQ(m_admin.username,voRetrieved.lastModificationLog.username); + + + ASSERT_NO_THROW(m_catalogue->deleteVirtualOrganization(vo.name)); + vos = m_catalogue->getVirtualOrganizations(); + ASSERT_EQ(0,vos.size()); +} + } // namespace unitTests diff --git a/catalogue/DummyCatalogue.hpp b/catalogue/DummyCatalogue.hpp index 204070ee42..550d21a567 100644 --- a/catalogue/DummyCatalogue.hpp +++ b/catalogue/DummyCatalogue.hpp @@ -90,6 +90,7 @@ public: void createVirtualOrganization(const common::dataStructures::SecurityIdentity &admin, const common::dataStructures::VirtualOrganization &vo) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } void deleteVirtualOrganization(const std::string &voName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } + std::list<common::dataStructures::VirtualOrganization> getVirtualOrganizations() const override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } void modifyArchiveRouteComment(const common::dataStructures::SecurityIdentity& admin, const std::string& storageClassName, const uint32_t copyNb, const std::string& comment) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } void modifyArchiveRouteTapePoolName(const common::dataStructures::SecurityIdentity& admin, const std::string& storageClassName, const uint32_t copyNb, const std::string& tapePoolName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } void modifyLogicalLibraryName(const common::dataStructures::SecurityIdentity &admin, const std::string ¤tName, const std::string &newName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp index e19a1eb3f4..90c09b1168 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -434,6 +434,58 @@ void RdbmsCatalogue::deleteVirtualOrganization(const std::string &voName){ } } +//------------------------------------------------------------------------------ +// getVirtualOrganizations +//------------------------------------------------------------------------------ +std::list<common::dataStructures::VirtualOrganization> RdbmsCatalogue::getVirtualOrganizations() const { + try { + std::list<common::dataStructures::VirtualOrganization> virtualOrganizations; + const char *const sql = + "SELECT " + "VIRTUAL_ORGANIZATION_NAME AS VIRTUAL_ORGANIZATION_NAME," + + "USER_COMMENT AS USER_COMMENT," + + "CREATION_LOG_USER_NAME AS CREATION_LOG_USER_NAME," + "CREATION_LOG_HOST_NAME AS CREATION_LOG_HOST_NAME," + "CREATION_LOG_TIME AS CREATION_LOG_TIME," + + "LAST_UPDATE_USER_NAME AS LAST_UPDATE_USER_NAME," + "LAST_UPDATE_HOST_NAME AS LAST_UPDATE_HOST_NAME," + "LAST_UPDATE_TIME AS LAST_UPDATE_TIME " + "FROM " + "VIRTUAL_ORGANIZATION " + "ORDER BY " + "VIRTUAL_ORGANIZATION_NAME"; + auto conn = m_connPool.getConn(); + auto stmt = conn.createStmt(sql); + auto rset = stmt.executeQuery(); + while (rset.next()) { + common::dataStructures::VirtualOrganization virtualOrganization; + + virtualOrganization.name = rset.columnString("VIRTUAL_ORGANIZATION_NAME"); + + virtualOrganization.comment = rset.columnString("USER_COMMENT"); + virtualOrganization.creationLog.username = rset.columnString("CREATION_LOG_USER_NAME"); + virtualOrganization.creationLog.host = rset.columnString("CREATION_LOG_HOST_NAME"); + virtualOrganization.creationLog.time = rset.columnUint64("CREATION_LOG_TIME"); + virtualOrganization.lastModificationLog.username = rset.columnString("LAST_UPDATE_USER_NAME"); + virtualOrganization.lastModificationLog.host = rset.columnString("LAST_UPDATE_HOST_NAME"); + virtualOrganization.lastModificationLog.time = rset.columnUint64("LAST_UPDATE_TIME"); + + virtualOrganizations.push_back(virtualOrganization); + } + + return virtualOrganizations; + } catch(exception::UserError &) { + throw; + } catch(exception::Exception &ex) { + ex.getMessage().str(std::string(__FUNCTION__) + ": " + ex.getMessage().str()); + throw; + } +} + + //------------------------------------------------------------------------------ // createStorageClass //------------------------------------------------------------------------------ diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp index 26f0bd358e..fe7a17dddc 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -224,6 +224,12 @@ public: * @param voName the name of the VirtualOrganization to delete */ void deleteVirtualOrganization(const std::string &voName) override; + + /** + * Get all the Virtual Organizations from the Catalogue + * @return the list of all the Virtual Organizations + */ + std::list<common::dataStructures::VirtualOrganization> getVirtualOrganizations() const override; /** * Creates the specified storage class. diff --git a/common/dataStructures/VirtualOrganization.hpp b/common/dataStructures/VirtualOrganization.hpp index 07c2440130..5584ae85f0 100644 --- a/common/dataStructures/VirtualOrganization.hpp +++ b/common/dataStructures/VirtualOrganization.hpp @@ -19,6 +19,7 @@ #pragma once #include <string> +#include "EntryLog.hpp" namespace cta { namespace common { @@ -33,6 +34,15 @@ struct VirtualOrganization { * The comment. */ std::string comment; + /** + * The creation log. + */ + EntryLog creationLog; + + /** + * The last modification log. + */ + EntryLog lastModificationLog; }; }}} -- GitLab