Commit c50d3a88 authored by Cedric CAFFY's avatar Cedric CAFFY
Browse files

Implemented Catalogue::getVirtualOrganizations() + unit test

Added deletion of existing VOs in the SetUp() method of CatalogueTest
parent 3aaa2823
......@@ -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.
*
......
......@@ -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);
......
......@@ -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
......@@ -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 &currentName, const std::string &newName) override { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
......
......@@ -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
//------------------------------------------------------------------------------
......
......@@ -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.
......
......@@ -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;
};
}}}
......
Markdown is supported
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