From 894e1872f200fb13c1a0a135b3af99f11f860c9a Mon Sep 17 00:00:00 2001
From: Steven Murray <Steven.Murray@cern.ch>
Date: Tue, 14 Nov 2017 09:47:32 +0100
Subject: [PATCH] Moved TapePool from common::dataStructures:: to catalogue::
 because it belongs to the Catalogue interface

---
 catalogue/Catalogue.hpp                       |  4 +-
 catalogue/CatalogueTest.cpp                   | 36 ++++++-----
 catalogue/DummyCatalogue.hpp                  |  2 +-
 catalogue/RdbmsCatalogue.cpp                  |  6 +-
 catalogue/RdbmsCatalogue.hpp                  |  2 +-
 .../dataStructures => catalogue}/TapePool.cpp | 21 +++----
 .../dataStructures => catalogue}/TapePool.hpp | 59 ++++++++++++++++---
 common/CMakeLists.txt                         |  2 +-
 xroot_plugins/XrdCtaFile.cpp                  |  2 +-
 xroot_plugins/XrdSsiCtaRequestMessage.cpp     |  2 +-
 10 files changed, 85 insertions(+), 51 deletions(-)
 rename {common/dataStructures => catalogue}/TapePool.cpp (80%)
 rename {common/dataStructures => catalogue}/TapePool.hpp (55%)

diff --git a/catalogue/Catalogue.hpp b/catalogue/Catalogue.hpp
index 6da0e0ff1b..bdddd9746c 100644
--- a/catalogue/Catalogue.hpp
+++ b/catalogue/Catalogue.hpp
@@ -22,6 +22,7 @@
 #include "catalogue/TapeFileSearchCriteria.hpp"
 #include "catalogue/TapeFileWritten.hpp"
 #include "catalogue/TapeForWriting.hpp"
+#include "catalogue/TapePool.hpp"
 #include "catalogue/TapeSearchCriteria.hpp"
 #include "common/dataStructures/AdminHost.hpp"
 #include "common/dataStructures/AdminUser.hpp"
@@ -51,7 +52,6 @@
 #include "common/dataStructures/Tape.hpp"
 #include "common/dataStructures/TapeCopyToPoolMap.hpp"
 #include "common/dataStructures/TapeFile.hpp"
-#include "common/dataStructures/TapePool.hpp"
 #include "common/dataStructures/UpdateFileInfoRequest.hpp"
 #include "common/dataStructures/UserIdentity.hpp"
 #include "common/dataStructures/VerifyInfo.hpp"
@@ -255,7 +255,7 @@ public:
 
   virtual void createTapePool(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t nbPartialTapes, const bool encryptionValue, const std::string &comment) = 0;
   virtual void deleteTapePool(const std::string &name) = 0;
-  virtual std::list<common::dataStructures::TapePool> getTapePools() const = 0;
+  virtual std::list<TapePool> getTapePools() const = 0;
   virtual void modifyTapePoolNbPartialTapes(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t nbPartialTapes) = 0;
   virtual void modifyTapePoolComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) = 0;
   virtual void setTapePoolEncryption(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool encryptionValue) = 0;
diff --git a/catalogue/CatalogueTest.cpp b/catalogue/CatalogueTest.cpp
index 6d854d42c1..df7b788e29 100644
--- a/catalogue/CatalogueTest.cpp
+++ b/catalogue/CatalogueTest.cpp
@@ -113,7 +113,7 @@ void cta_catalogue_CatalogueTest::SetUp() {
       }
     }
     {
-      const std::list<common::dataStructures::TapePool> tapePools = m_catalogue->getTapePools();
+      const std::list<TapePool> tapePools = m_catalogue->getTapePools();
       for(auto &tapePool: tapePools) {
         m_catalogue->deleteTapePool(tapePool.name);
       }
@@ -796,12 +796,11 @@ TEST_P(cta_catalogue_CatalogueTest, createTapePool) {
 
   ASSERT_TRUE(m_catalogue->tapePoolExists(tapePoolName));
       
-  const std::list<common::dataStructures::TapePool> pools =
-    m_catalogue->getTapePools();
+  const std::list<catalogue::TapePool> pools = m_catalogue->getTapePools();
       
   ASSERT_EQ(1, pools.size());
       
-  const common::dataStructures::TapePool pool = pools.front();
+  const catalogue::TapePool pool = pools.front();
   ASSERT_EQ(tapePoolName, pool.name);
   ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
   ASSERT_EQ(isEncrypted, pool.encryption);
@@ -841,12 +840,11 @@ TEST_P(cta_catalogue_CatalogueTest, deleteTapePool) {
   m_catalogue->createTapePool(m_admin, tapePoolName, nbPartialTapes, isEncrypted,
     comment);
 
-  const std::list<common::dataStructures::TapePool> pools =
-    m_catalogue->getTapePools();
+  const std::list<catalogue::TapePool> pools = m_catalogue->getTapePools();
 
   ASSERT_EQ(1, pools.size());
 
-  const common::dataStructures::TapePool pool = pools.front();
+  const catalogue::TapePool pool = pools.front();
   ASSERT_EQ(tapePoolName, pool.name);
   ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
   ASSERT_EQ(isEncrypted, pool.encryption);
@@ -883,11 +881,11 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapePoolNbPartialTapes) {
   m_catalogue->createTapePool(m_admin, tapePoolName, nbPartialTapes, isEncrypted, comment);
 
   {
-    const std::list<common::dataStructures::TapePool> pools = m_catalogue->getTapePools();
+    const std::list<catalogue::TapePool> pools = m_catalogue->getTapePools();
       
     ASSERT_EQ(1, pools.size());
       
-    const common::dataStructures::TapePool pool = pools.front();
+    const catalogue::TapePool pool = pools.front();
     ASSERT_EQ(tapePoolName, pool.name);
     ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
     ASSERT_EQ(isEncrypted, pool.encryption);
@@ -905,11 +903,11 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapePoolNbPartialTapes) {
   m_catalogue->modifyTapePoolNbPartialTapes(m_admin, tapePoolName, modifiedNbPartialTapes);
 
   {
-    const std::list<common::dataStructures::TapePool> pools = m_catalogue->getTapePools();
+    const std::list<catalogue::TapePool> pools = m_catalogue->getTapePools();
       
     ASSERT_EQ(1, pools.size());
       
-    const common::dataStructures::TapePool pool = pools.front();
+    const catalogue::TapePool pool = pools.front();
     ASSERT_EQ(tapePoolName, pool.name);
     ASSERT_EQ(modifiedNbPartialTapes, pool.nbPartialTapes);
     ASSERT_EQ(isEncrypted, pool.encryption);
@@ -944,11 +942,11 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapePoolComment) {
   m_catalogue->createTapePool(m_admin, tapePoolName, nbPartialTapes, isEncrypted, comment);
 
   {
-    const std::list<common::dataStructures::TapePool> pools = m_catalogue->getTapePools();
+    const std::list<catalogue::TapePool> pools = m_catalogue->getTapePools();
       
     ASSERT_EQ(1, pools.size());
 
-    const common::dataStructures::TapePool pool = pools.front();
+    const catalogue::TapePool pool = pools.front();
     ASSERT_EQ(tapePoolName, pool.name);
     ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
     ASSERT_EQ(isEncrypted, pool.encryption);
@@ -966,11 +964,11 @@ TEST_P(cta_catalogue_CatalogueTest, modifyTapePoolComment) {
   m_catalogue->modifyTapePoolComment(m_admin, tapePoolName, modifiedComment);
 
   {
-    const std::list<common::dataStructures::TapePool> pools = m_catalogue->getTapePools();
+    const std::list<catalogue::TapePool> pools = m_catalogue->getTapePools();
       
     ASSERT_EQ(1, pools.size());
       
-    const common::dataStructures::TapePool pool = pools.front();
+    const catalogue::TapePool pool = pools.front();
     ASSERT_EQ(tapePoolName, pool.name);
     ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
     ASSERT_EQ(isEncrypted, pool.encryption);
@@ -1004,11 +1002,11 @@ TEST_P(cta_catalogue_CatalogueTest, setTapePoolEncryption) {
   m_catalogue->createTapePool(m_admin, tapePoolName, nbPartialTapes, isEncrypted, comment);
 
   {
-    const std::list<common::dataStructures::TapePool> pools = m_catalogue->getTapePools();
+    const std::list<catalogue::TapePool> pools = m_catalogue->getTapePools();
       
     ASSERT_EQ(1, pools.size());
 
-    const common::dataStructures::TapePool pool = pools.front();
+    const catalogue::TapePool pool = pools.front();
     ASSERT_EQ(tapePoolName, pool.name);
     ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
     ASSERT_EQ(isEncrypted, pool.encryption);
@@ -1026,11 +1024,11 @@ TEST_P(cta_catalogue_CatalogueTest, setTapePoolEncryption) {
   m_catalogue->setTapePoolEncryption(m_admin, tapePoolName, modifiedIsEncrypted);
 
   {
-    const std::list<common::dataStructures::TapePool> pools = m_catalogue->getTapePools();
+    const std::list<catalogue::TapePool> pools = m_catalogue->getTapePools();
       
     ASSERT_EQ(1, pools.size());
       
-    const common::dataStructures::TapePool pool = pools.front();
+    const catalogue::TapePool pool = pools.front();
     ASSERT_EQ(tapePoolName, pool.name);
     ASSERT_EQ(nbPartialTapes, pool.nbPartialTapes);
     ASSERT_EQ(modifiedIsEncrypted, pool.encryption);
diff --git a/catalogue/DummyCatalogue.hpp b/catalogue/DummyCatalogue.hpp
index 8855e6c5c4..1e84cf92ad 100644
--- a/catalogue/DummyCatalogue.hpp
+++ b/catalogue/DummyCatalogue.hpp
@@ -68,7 +68,7 @@ public:
   std::list<common::dataStructures::RequesterMountRule> getRequesterMountRules() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
   std::list<common::dataStructures::StorageClass> getStorageClasses() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
   common::dataStructures::ArchiveFileSummary getTapeFileSummary(const TapeFileSearchCriteria& searchCriteria) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
-  std::list<common::dataStructures::TapePool> getTapePools() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
+  std::list<TapePool> getTapePools() const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
   std::list<common::dataStructures::Tape> getTapes(const TapeSearchCriteria& searchCriteria) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
  // getTapesByVid is implemented below (and works).
   std::list<TapeForWriting> getTapesForWriting(const std::string& logicalLibraryName) const { throw exception::Exception(std::string("In ")+__PRETTY_FUNCTION__+": not implemented"); }
diff --git a/catalogue/RdbmsCatalogue.cpp b/catalogue/RdbmsCatalogue.cpp
index a73bc58724..e728e83c5e 100644
--- a/catalogue/RdbmsCatalogue.cpp
+++ b/catalogue/RdbmsCatalogue.cpp
@@ -946,9 +946,9 @@ void RdbmsCatalogue::deleteTapePool(const std::string &name) {
 //------------------------------------------------------------------------------
 // getTapePools
 //------------------------------------------------------------------------------
-std::list<common::dataStructures::TapePool> RdbmsCatalogue::getTapePools() const {
+std::list<TapePool> RdbmsCatalogue::getTapePools() const {
   try {
-    std::list<common::dataStructures::TapePool> pools;
+    std::list<TapePool> pools;
     const char *const sql =
       "SELECT "
         "TAPE_POOL_NAME AS TAPE_POOL_NAME,"
@@ -972,7 +972,7 @@ std::list<common::dataStructures::TapePool> RdbmsCatalogue::getTapePools() const
     auto stmt = conn.createStmt(sql, rdbms::Stmt::AutocommitMode::OFF);
     auto rset = stmt->executeQuery();
     while (rset.next()) {
-      common::dataStructures::TapePool pool;
+      TapePool pool;
 
       pool.name = rset.columnString("TAPE_POOL_NAME");
       pool.nbPartialTapes = rset.columnUint64("NB_PARTIAL_TAPES");
diff --git a/catalogue/RdbmsCatalogue.hpp b/catalogue/RdbmsCatalogue.hpp
index 6853f39b77..c2318545d9 100644
--- a/catalogue/RdbmsCatalogue.hpp
+++ b/catalogue/RdbmsCatalogue.hpp
@@ -244,7 +244,7 @@ public:
 
   void createTapePool(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t nbPartialTapes, const bool encryptionValue, const std::string &comment) override;
   void deleteTapePool(const std::string &name) override;
-  std::list<common::dataStructures::TapePool> getTapePools() const override;
+  std::list<TapePool> getTapePools() const override;
   void modifyTapePoolNbPartialTapes(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const uint64_t nbPartialTapes) override;
   void modifyTapePoolComment(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const std::string &comment) override;
   void setTapePoolEncryption(const common::dataStructures::SecurityIdentity &admin, const std::string &name, const bool encryptionValue) override;
diff --git a/common/dataStructures/TapePool.cpp b/catalogue/TapePool.cpp
similarity index 80%
rename from common/dataStructures/TapePool.cpp
rename to catalogue/TapePool.cpp
index 83b0afbecf..fd03c1316f 100644
--- a/common/dataStructures/TapePool.cpp
+++ b/catalogue/TapePool.cpp
@@ -16,30 +16,24 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "common/dataStructures/TapePool.hpp"
-#include "common/dataStructures/utils.hpp"
-#include "common/exception/Exception.hpp"
+#include "catalogue/TapePool.hpp"
 
 namespace cta {
-namespace common {
-namespace dataStructures {
+namespace catalogue {
 
 //------------------------------------------------------------------------------
 // constructor
 //------------------------------------------------------------------------------
 TapePool::TapePool():
-  nbPartialTapes(0) {}
+  nbPartialTapes(0),
+  encryption(false) {
+}
 
 //------------------------------------------------------------------------------
 // operator==
 //------------------------------------------------------------------------------
 bool TapePool::operator==(const TapePool &rhs) const {
-  return name==rhs.name
-      && nbPartialTapes==rhs.nbPartialTapes
-      && encryption==rhs.encryption
-      && creationLog==rhs.creationLog
-      && lastModificationLog==rhs.lastModificationLog
-      && comment==rhs.comment;
+  return name == rhs.name;
 }
 
 //------------------------------------------------------------------------------
@@ -62,6 +56,5 @@ std::ostream &operator<<(std::ostream &os, const TapePool &obj) {
   return os;
 }
 
-} // namespace dataStructures
-} // namespace common
+} // namespace catalogue
 } // namespace cta
diff --git a/common/dataStructures/TapePool.hpp b/catalogue/TapePool.hpp
similarity index 55%
rename from common/dataStructures/TapePool.hpp
rename to catalogue/TapePool.hpp
index f7f05be909..e3cfe20093 100644
--- a/common/dataStructures/TapePool.hpp
+++ b/catalogue/TapePool.hpp
@@ -18,16 +18,14 @@
 
 #pragma once
 
-#include <list>
-#include <map>
+#include <ostream>
 #include <stdint.h>
 #include <string>
 
 #include "common/dataStructures/EntryLog.hpp"
 
 namespace cta {
-namespace common {
-namespace dataStructures {
+namespace catalogue {
 
 /**
  * A tape pool is a logical grouping of tapes, it is used to separate VOs, types 
@@ -35,23 +33,68 @@ namespace dataStructures {
  */
 struct TapePool {
 
+  /**
+   * Constructor that sets all integer member-variables to 0 and booleans to
+   * false.
+   */
   TapePool();
 
+  /**
+   * Comparison operator.
+   *
+   * @return True if the names of both tape pools are equal.
+   */
   bool operator==(const TapePool &rhs) const;
 
+  /**
+   * Comparison operator.
+   *
+   * @return True if the names of both tape pools are not equal.
+   */
   bool operator!=(const TapePool &rhs) const;
 
+  /**
+   * The name of the tape pool.
+   */
   std::string name;
+
+  /**
+   * The desired number of tapes that should be empty or partially filled.
+   */
   uint64_t nbPartialTapes;
+
+  /**
+   * True if the tapes within this tape pool should be encrypted.
+   */
   bool encryption;
-  EntryLog creationLog;
-  EntryLog lastModificationLog;
+
+  /**
+   * The creation log.
+   */
+  common::dataStructures::EntryLog creationLog;
+
+  /**
+   * The last modification log.
+   */
+  common::dataStructures::EntryLog lastModificationLog;
+
+  /**
+   * The comment.
+   */
   std::string comment;
 
 }; // struct TapePool
 
+/**
+ * Output stream operator for a TapePool object.
+ *
+ * This function writes a human readable form of the specified object to the
+ * specified output stream.
+ *
+ * @param os The output stream.
+ * @param obj The object.
+ */
 std::ostream &operator<<(std::ostream &os, const TapePool &obj);
 
-} // namespace dataStructures
-} // namespace common
+} // namespace catalogue
 } // namespace cta
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index e3c32e713a..8e101bb968 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -61,7 +61,7 @@ set (COMMON_LIB_SRC_FILES
   dataStructures/Tape.cpp
   dataStructures/TapeFile.cpp
   dataStructures/TapeLog.cpp
-  dataStructures/TapePool.cpp
+        ../catalogue/TapePool.cpp
   dataStructures/TestSourceType.cpp
   dataStructures/UpdateFileInfoRequest.cpp
   dataStructures/UpdateFileStorageClassRequest.cpp
diff --git a/xroot_plugins/XrdCtaFile.cpp b/xroot_plugins/XrdCtaFile.cpp
index d0882e0d96..f194928720 100644
--- a/xroot_plugins/XrdCtaFile.cpp
+++ b/xroot_plugins/XrdCtaFile.cpp
@@ -836,7 +836,7 @@ std::string XrdCtaFile::xCom_tapepool() {
     }
   }
   else if("ls" == m_requestTokens.at(2)) { //ls
-    std::list<cta::common::dataStructures::TapePool> list= m_catalogue->getTapePools();
+    const std::list<cta::catalogue::TapePool> list= m_catalogue->getTapePools();
     if(list.size()>0) {
       std::vector<std::vector<std::string>> responseTable;
       std::vector<std::string> header = {"name","# partial tapes","encrypt","c.user","c.host","c.time","m.user","m.host","m.time","comment"};
diff --git a/xroot_plugins/XrdSsiCtaRequestMessage.cpp b/xroot_plugins/XrdSsiCtaRequestMessage.cpp
index 1a1adc7b79..fdf2dec498 100644
--- a/xroot_plugins/XrdSsiCtaRequestMessage.cpp
+++ b/xroot_plugins/XrdSsiCtaRequestMessage.cpp
@@ -1936,7 +1936,7 @@ void RequestMessage::processTapePool_Ls(const cta::admin::AdminCmd &admincmd, ct
 
    std::stringstream cmdlineOutput;
 
-   std::list<cta::common::dataStructures::TapePool> list= m_catalogue.getTapePools();
+   const std::list<cta::catalogue::TapePool> list= m_catalogue.getTapePools();
 
    if(!list.empty())
    {
-- 
GitLab