Commit 4f25117a authored by Cedric CAFFY's avatar Cedric CAFFY
Browse files

Implemented Catalogue::modifyVirtualOrganizationComment() + unit tests

parent b4222f5f
......@@ -253,6 +253,13 @@ public:
*/
virtual void modifyVirtualOrganizationName(const common::dataStructures::SecurityIdentity &admin, const std::string &currentVoName, 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.
*
......
......@@ -131,6 +131,10 @@ public:
void modifyVirtualOrganizationName(const common::dataStructures::SecurityIdentity &admin, const std::string &currentVoName, 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);
......
......@@ -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
......@@ -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 &currentVoName, 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 &currentName, const std::string &newName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -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
//------------------------------------------------------------------------------
......
......@@ -238,7 +238,15 @@ public:
* @param newVoName The new name of the Virtual Organization.
*/
void modifyVirtualOrganizationName(const common::dataStructures::SecurityIdentity &admin, const std::string &currentVoName, 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.
*
......
......@@ -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
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment