From 6060c05a924b3796c640a2c79e8dfde252e3189d Mon Sep 17 00:00:00 2001 From: Cedric CAFFY <cedric.caffy@cern.ch> Date: Wed, 4 Mar 2020 17:35:07 +0100 Subject: [PATCH] Implemented Catalogue::modifyVirtualOrganizationComment() + unit tests --- catalogue/Catalogue.hpp | 7 ++++ catalogue/CatalogueRetryWrapper.hpp | 4 +++ catalogue/CatalogueTest.cpp | 23 ++++++++++++- catalogue/DummyCatalogue.hpp | 1 + catalogue/RdbmsCatalogue.cpp | 34 +++++++++++++++++++ catalogue/RdbmsCatalogue.hpp | 10 +++++- .../orchestration/tests/archive_retrieve.sh | 3 -- .../tests/repack_systemtest_wrapper.sh | 6 +--- 8 files changed, 78 insertions(+), 10 deletions(-) diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp index 483c29b121..332a81b014 100644 --- a/catalogue/Catalogue.hpp +++ b/catalogue/Catalogue.hpp @@ -253,6 +253,13 @@ public: */ virtual void modifyVirtualOrganizationName(const common::dataStructures::SecurityIdentity &admin, const std::string ¤tVoName, const std::string &newVoName) = 0; + /** + * Modifies the comment of the specified Virtual Organization + * + * @param voName The name of the Virtual Organization. + * @param comment The new comment of the Virtual Organization. + */ + virtual void modifyVirtualOrganizationComment(const common::dataStructures::SecurityIdentity &admin, const std::string &voName, const std::string &comment) = 0; /** * Creates the specified storage class. * diff --git a/catalogue/CatalogueRetryWrapper.hpp b/catalogue/CatalogueRetryWrapper.hpp index 0c405e6a56..4a4e9ce268 100644 --- a/catalogue/CatalogueRetryWrapper.hpp +++ b/catalogue/CatalogueRetryWrapper.hpp @@ -131,6 +131,10 @@ public: void modifyVirtualOrganizationName(const common::dataStructures::SecurityIdentity &admin, const std::string ¤tVoName, const std::string &newVoName) override { return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyVirtualOrganizationName(admin,currentVoName,newVoName);}, m_maxTriesToConnect); } + + void modifyVirtualOrganizationComment(const common::dataStructures::SecurityIdentity &admin, const std::string &voName, const std::string &comment) override { + return retryOnLostConnection(m_log, [&]{return m_catalogue->modifyVirtualOrganizationComment(admin,voName,comment);}, 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 29f3c16a9c..18a19b82eb 100644 --- a/catalogue/CatalogueTest.cpp +++ b/catalogue/CatalogueTest.cpp @@ -15421,7 +15421,28 @@ TEST_P(cta_catalogue_CatalogueTest, modifyVirtualOrganizationNameThatAlreadyExis vo.name = vo2Name; ASSERT_NO_THROW(m_catalogue->createVirtualOrganization(m_admin,vo)); - ASSERT_THROW(m_catalogue->modifyVirtualOrganizationName(m_admin,"vo","vo2"),cta::exception::UserError); + ASSERT_THROW(m_catalogue->modifyVirtualOrganizationName(m_admin,voName,vo2Name),cta::exception::UserError); +} + +TEST_P(cta_catalogue_CatalogueTest, modifyVirtualOrganizationComment) { + using namespace cta; + + common::dataStructures::VirtualOrganization vo; + vo.name = "vo"; + vo.comment = "comment"; + + ASSERT_NO_THROW(m_catalogue->createVirtualOrganization(m_admin,vo)); + + std::string newComment = "newComment"; + + ASSERT_NO_THROW(m_catalogue->modifyVirtualOrganizationComment(m_admin,vo.name,newComment)); + + auto vos = m_catalogue->getVirtualOrganizations(); + auto &frontVo = vos.front(); + + ASSERT_EQ(newComment,frontVo.comment); + + ASSERT_THROW(m_catalogue->modifyVirtualOrganizationComment(m_admin,"DOES not exists","COMMENT_DOES_NOT_EXIST"),cta::exception::UserError); } } // namespace unitTests diff --git a/catalogue/DummyCatalogue.hpp b/catalogue/DummyCatalogue.hpp index 5621dc5dcf..973d441637 100644 --- a/catalogue/DummyCatalogue.hpp +++ b/catalogue/DummyCatalogue.hpp @@ -92,6 +92,7 @@ public: 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 modifyVirtualOrganizationName(const common::dataStructures::SecurityIdentity &admin, const std::string ¤tVoName, const std::string &newVoName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); } + void modifyVirtualOrganizationComment(const common::dataStructures::SecurityIdentity &admin, const std::string &voName, const std::string &comment) 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 8992d6507d..2c5ebfa0d4 100644 --- a/catalogue/RdbmsCatalogue.cpp +++ b/catalogue/RdbmsCatalogue.cpp @@ -525,6 +525,40 @@ void RdbmsCatalogue::modifyVirtualOrganizationName(const common::dataStructures: } } +void RdbmsCatalogue::modifyVirtualOrganizationComment(const common::dataStructures::SecurityIdentity& admin, const std::string& voName, const std::string& comment) { +try { + const time_t now = time(nullptr); + const char *const sql = + "UPDATE VIRTUAL_ORGANIZATION 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 " + "VIRTUAL_ORGANIZATION_NAME = :VIRTUAL_ORGANIZATION_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(":VIRTUAL_ORGANIZATION_NAME", voName); + stmt.executeNonQuery(); + + if(0 == stmt.getNbAffectedRows()) { + throw exception::UserError(std::string("Cannot modify virtual organization : ") + voName + + " because it does not exist"); + } + } 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 b1eed37ee4..e1f1c443e5 100644 --- a/catalogue/RdbmsCatalogue.hpp +++ b/catalogue/RdbmsCatalogue.hpp @@ -238,7 +238,15 @@ public: * @param newVoName The new name of the Virtual Organization. */ void modifyVirtualOrganizationName(const common::dataStructures::SecurityIdentity &admin, const std::string ¤tVoName, const std::string &newVoName) override; - + + /** + * Modifies the comment of the specified Virtual Organization + * + * @param voName The name of the Virtual Organization. + * @param comment The new comment of the Virtual Organization. + */ + void modifyVirtualOrganizationComment(const common::dataStructures::SecurityIdentity &admin, const std::string &voName, const std::string &comment) override; + /** * Creates the specified storage class. * diff --git a/continuousintegration/orchestration/tests/archive_retrieve.sh b/continuousintegration/orchestration/tests/archive_retrieve.sh index ccd693f847..1dbd6a0ec5 100755 --- a/continuousintegration/orchestration/tests/archive_retrieve.sh +++ b/continuousintegration/orchestration/tests/archive_retrieve.sh @@ -59,7 +59,4 @@ kubectl -n ${NAMESPACE} exec client -- bash /root/client_ar.sh -n ${NB_FILES} -s kubectl -n ${NAMESPACE} exec ctaeos -- bash /root/grep_xrdlog_mgm_for_error.sh || exit 1 -# Cleaning catalogue content -echo 'yes' | kubectl -n ${NAMESPACE} exec ctafrontend -i /usr/bin/cta-catalogue-schema-drop /etc/cta/cta-catalogue.conf - exit 0 diff --git a/continuousintegration/orchestration/tests/repack_systemtest_wrapper.sh b/continuousintegration/orchestration/tests/repack_systemtest_wrapper.sh index 1b649c3d7c..ad7f6885e5 100755 --- a/continuousintegration/orchestration/tests/repack_systemtest_wrapper.sh +++ b/continuousintegration/orchestration/tests/repack_systemtest_wrapper.sh @@ -476,8 +476,4 @@ repackJustMove 3 repackTapeRepair 4 repackJustAddCopies 5 repackCancellation 6 -# repackMoveAndAddCopies 7 - -#Cleaning catalogue content - -echo 'yes' | kubectl -n ${NAMESPACE} exec ctafrontend -i /usr/bin/cta-catalogue-schema-drop /etc/cta/cta-catalogue.conf +# repackMoveAndAddCopies 7 \ No newline at end of file -- GitLab