diff --git a/libs/client/CMakeLists.txt b/libs/client/CMakeLists.txt index c0b12225499082e31e86e1e14985c7bf00c9c2bf..9d5cfe4d1860142228b4bc2a98b444520668792a 100644 --- a/libs/client/CMakeLists.txt +++ b/libs/client/CMakeLists.txt @@ -7,11 +7,11 @@ set (CLIENT_LIB_SRC_FILES Exception.cpp FileAttribute.cpp FileSystemNode.cpp + FileSystemStorageClass.cpp FileSystemStorageClasses.cpp MockClientAPI.cpp SecurityIdentity.cpp StorageClass.cpp - StorageClassAndUsageCount.cpp UserIdentity.cpp) add_library (ctaclient SHARED diff --git a/libs/client/StorageClassAndUsageCount.cpp b/libs/client/FileSystemStorageClass.cpp similarity index 73% rename from libs/client/StorageClassAndUsageCount.cpp rename to libs/client/FileSystemStorageClass.cpp index d26df6319bf3ee520e05b3b1cf709d461398b152..3269d6d7e639edc66fa1c92e1e71d1a10dbb924d 100644 --- a/libs/client/StorageClassAndUsageCount.cpp +++ b/libs/client/FileSystemStorageClass.cpp @@ -1,18 +1,18 @@ #define __STDC_LIMIT_MACROS -#include "StorageClassAndUsageCount.hpp" +#include "FileSystemStorageClass.hpp" //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -cta::StorageClassAndUsageCount::StorageClassAndUsageCount(): +cta::FileSystemStorageClass::FileSystemStorageClass(): m_usageCount(0) { } //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -cta::StorageClassAndUsageCount::StorageClassAndUsageCount( +cta::FileSystemStorageClass::FileSystemStorageClass( const StorageClass &storageClass): m_storageClass(storageClass), m_usageCount(0) { @@ -21,7 +21,7 @@ cta::StorageClassAndUsageCount::StorageClassAndUsageCount( //------------------------------------------------------------------------------ // getStorageClass //------------------------------------------------------------------------------ -const cta::StorageClass &cta::StorageClassAndUsageCount::getStorageClass() +const cta::StorageClass &cta::FileSystemStorageClass::getStorageClass() const throw() { return m_storageClass; } @@ -29,19 +29,19 @@ const cta::StorageClass &cta::StorageClassAndUsageCount::getStorageClass() //------------------------------------------------------------------------------ // getUsageCount //------------------------------------------------------------------------------ -uint64_t cta::StorageClassAndUsageCount::getUsageCount() const throw() { +uint64_t cta::FileSystemStorageClass::getUsageCount() const throw() { return m_usageCount; } //------------------------------------------------------------------------------ // incUsageCount //------------------------------------------------------------------------------ -void cta::StorageClassAndUsageCount::incUsageCount() { +void cta::FileSystemStorageClass::incUsageCount() { if(UINT64_MAX == m_usageCount) { std::ostringstream message; message << "Cannot increment usage count of storage class " << - m_storageClass.name << " because its maximum value of UINT64_MAX has " - "already been reached"; + m_storageClass.getName() << " because its maximum value of UINT64_MAX" + " has already been reached"; throw Exception(message.str()); } m_usageCount++; @@ -50,11 +50,11 @@ void cta::StorageClassAndUsageCount::incUsageCount() { //------------------------------------------------------------------------------ // decUsageCount //------------------------------------------------------------------------------ -void cta::StorageClassAndUsageCount::decUsageCount() { +void cta::FileSystemStorageClass::decUsageCount() { if(0 == m_usageCount) { std::ostringstream message; message << "Cannot decrement usage count of storage class " << - m_storageClass.name << " because it is already at zero"; + m_storageClass.getName() << " because it is already at zero"; throw Exception(message.str()); } m_usageCount--; diff --git a/libs/client/StorageClassAndUsageCount.hpp b/libs/client/FileSystemStorageClass.hpp similarity index 70% rename from libs/client/StorageClassAndUsageCount.hpp rename to libs/client/FileSystemStorageClass.hpp index 91b3ea05d3e0c9939e686db66210cd81eb4bb9c3..a61b2abb5b99f54efd07734b689ca1d998b53bec 100644 --- a/libs/client/StorageClassAndUsageCount.hpp +++ b/libs/client/FileSystemStorageClass.hpp @@ -2,15 +2,19 @@ #include "Exception.hpp" #include "StorageClass.hpp" +#include "UserIdentity.hpp" #include <sstream> +#include <string> +#include <time.h> namespace cta { /** - * Class used to store a storage class and it usage count. + * Class used to store a storage class together with the other information + * required by the file system. */ -class StorageClassAndUsageCount { +class FileSystemStorageClass { public: /** @@ -18,14 +22,14 @@ public: * * Initialisez the usage count to 0. */ - StorageClassAndUsageCount(); + FileSystemStorageClass(); /** * Constructor. * * Initialisez the usage count to 0. */ - StorageClassAndUsageCount(const StorageClass &storageClass); + FileSystemStorageClass(const StorageClass &storageClass); /** * Returns the storage class. @@ -59,6 +63,6 @@ private: */ uint64_t m_usageCount; -}; // class StorageClassAndUsageCount +}; // class FileSystemStorageClass } // namespace cta diff --git a/libs/client/FileSystemStorageClasses.cpp b/libs/client/FileSystemStorageClasses.cpp index e8370bfec0669b1b324cbe47741b83957a89e78c..8ca582b7aab27918c75044cb0d516740832cb3eb 100644 --- a/libs/client/FileSystemStorageClasses.cpp +++ b/libs/client/FileSystemStorageClasses.cpp @@ -25,7 +25,7 @@ void cta::FileSystemStorageClasses::createStorageClass( //------------------------------------------------------------------------------ void cta::FileSystemStorageClasses::checkStorageClassDoesNotAlreadyExist( const std::string &name) const { - std::map<std::string, StorageClassAndUsageCount>::const_iterator itor = + std::map<std::string, FileSystemStorageClass>::const_iterator itor = m_storageClasses.find(name); if(itor != m_storageClasses.end()) { std::ostringstream msg; @@ -54,7 +54,7 @@ void cta::FileSystemStorageClasses::deleteStorageClass( //------------------------------------------------------------------------------ void cta::FileSystemStorageClasses::checkStorageClassExists( const std::string &name) const { - std::map<std::string, StorageClassAndUsageCount>::const_iterator itor = + std::map<std::string, FileSystemStorageClass>::const_iterator itor = m_storageClasses.find(name); if(itor == m_storageClasses.end()) { std::ostringstream msg; @@ -68,7 +68,7 @@ void cta::FileSystemStorageClasses::checkStorageClassExists( //------------------------------------------------------------------------------ void cta::FileSystemStorageClasses::checkStorageClassIsNotInUse( const std::string &name) const { - std::map<std::string, StorageClassAndUsageCount>::const_iterator itor = + std::map<std::string, FileSystemStorageClass>::const_iterator itor = m_storageClasses.find(name); // If the storage class does not exists then it cannot be in use @@ -89,7 +89,7 @@ void cta::FileSystemStorageClasses::checkStorageClassIsNotInUse( std::list<cta::StorageClass> cta::FileSystemStorageClasses::getStorageClasses() const { std::list<StorageClass> storageClasses; - for(std::map<std::string, StorageClassAndUsageCount>::const_iterator itor = + for(std::map<std::string, FileSystemStorageClass>::const_iterator itor = m_storageClasses.begin(); itor != m_storageClasses.end(); itor++) { storageClasses.push_back(itor->second.getStorageClass()); } @@ -107,7 +107,7 @@ void cta::FileSystemStorageClasses::incStorageClassUsageCount( return; } - std::map<std::string, StorageClassAndUsageCount>::iterator itor = + std::map<std::string, FileSystemStorageClass>::iterator itor = m_storageClasses.find(name); if(itor == m_storageClasses.end()) { @@ -130,7 +130,7 @@ void cta::FileSystemStorageClasses::decStorageClassUsageCount( return; } - std::map<std::string, StorageClassAndUsageCount>::iterator itor = + std::map<std::string, FileSystemStorageClass>::iterator itor = m_storageClasses.find(name); if(itor == m_storageClasses.end()) { diff --git a/libs/client/FileSystemStorageClasses.hpp b/libs/client/FileSystemStorageClasses.hpp index a87eae7a4db5db9818550adf1f9b78784b0437d5..8de9b591d011a0e6e1e67df962cf720bd4e5456a 100644 --- a/libs/client/FileSystemStorageClasses.hpp +++ b/libs/client/FileSystemStorageClasses.hpp @@ -1,7 +1,7 @@ #pragma once +#include "FileSystemStorageClass.hpp" #include "SecurityIdentity.hpp" -#include "StorageClassAndUsageCount.hpp" #include <list> #include <map> @@ -81,7 +81,7 @@ protected: * The current mapping from storage class names to storage classes and their * usage counts. */ - std::map<std::string, StorageClassAndUsageCount> m_storageClasses; + std::map<std::string, FileSystemStorageClass> m_storageClasses; /** * Throws an exception if the specified storage class already exists. diff --git a/libs/client/MockClientAPI.hpp b/libs/client/MockClientAPI.hpp index 4f54f10b7ba31a2d0a831eeb7786fb30351f0ef5..4491555f2d8095d67bd16adba3f65452ec0e1684 100644 --- a/libs/client/MockClientAPI.hpp +++ b/libs/client/MockClientAPI.hpp @@ -4,9 +4,7 @@ #include "FileSystemNode.hpp" #include "FileSystemStorageClasses.hpp" #include "StorageClass.hpp" -#include "StorageClassAndUsageCount.hpp" -#include <map> #include <vector> namespace cta { diff --git a/libs/client/MockClientAPITest.cpp b/libs/client/MockClientAPITest.cpp index 931980c5690d772dd50bbaf77eb54c7efd02d9e8..299ecef5629a537307abbc9fac793a17da5de838 100644 --- a/libs/client/MockClientAPITest.cpp +++ b/libs/client/MockClientAPITest.cpp @@ -235,8 +235,8 @@ TEST_F(cta_client_MockClientAPITest, createStorageClass_new) { StorageClass storageClass; ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(name, storageClass.name); - ASSERT_EQ(nbCopies, storageClass.nbCopies); + ASSERT_EQ(name, storageClass.getName()); + ASSERT_EQ(nbCopies, storageClass.getNbCopies()); } } @@ -263,8 +263,8 @@ TEST_F(cta_client_MockClientAPITest, createStorageClass_already_existing) { StorageClass storageClass; ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(name, storageClass.name); - ASSERT_EQ(nbCopies, storageClass.nbCopies); + ASSERT_EQ(name, storageClass.getName()); + ASSERT_EQ(nbCopies, storageClass.getNbCopies()); } ASSERT_THROW(api.createStorageClass(requester, name, nbCopies), @@ -293,13 +293,13 @@ TEST_F(cta_client_MockClientAPITest, createStorageClass_lexicographical_order) { ASSERT_NO_THROW(storageClasses = api.getStorageClasses(requester)); ASSERT_EQ(4, storageClasses.size()); - ASSERT_EQ(std::string("a"), storageClasses.front().name); + ASSERT_EQ(std::string("a"), storageClasses.front().getName()); storageClasses.pop_front(); - ASSERT_EQ(std::string("b"), storageClasses.front().name); + ASSERT_EQ(std::string("b"), storageClasses.front().getName()); storageClasses.pop_front(); - ASSERT_EQ(std::string("c"), storageClasses.front().name); + ASSERT_EQ(std::string("c"), storageClasses.front().getName()); storageClasses.pop_front(); - ASSERT_EQ(std::string("d"), storageClasses.front().name); + ASSERT_EQ(std::string("d"), storageClasses.front().getName()); } } @@ -326,8 +326,8 @@ TEST_F(cta_client_MockClientAPITest, deleteStorageClass_existing) { StorageClass storageClass; ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(name, storageClass.name); - ASSERT_EQ(nbCopies, storageClass.nbCopies); + ASSERT_EQ(name, storageClass.getName()); + ASSERT_EQ(nbCopies, storageClass.getNbCopies()); ASSERT_NO_THROW(api.deleteStorageClass(requester, name)); } @@ -362,8 +362,8 @@ TEST_F(cta_client_MockClientAPITest, deleteStorageClass_in_use) { StorageClass storageClass; ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(name, storageClass.name); - ASSERT_EQ(nbCopies, storageClass.nbCopies); + ASSERT_EQ(name, storageClass.getName()); + ASSERT_EQ(nbCopies, storageClass.getNbCopies()); } ASSERT_NO_THROW(api.setDirectoryStorageClass(requester, "/", name)); @@ -377,8 +377,8 @@ TEST_F(cta_client_MockClientAPITest, deleteStorageClass_in_use) { StorageClass storageClass; ASSERT_NO_THROW(storageClass = storageClasses.front()); - ASSERT_EQ(name, storageClass.name); - ASSERT_EQ(nbCopies, storageClass.nbCopies); + ASSERT_EQ(name, storageClass.getName()); + ASSERT_EQ(nbCopies, storageClass.getNbCopies()); } } diff --git a/libs/client/StorageClass.cpp b/libs/client/StorageClass.cpp index 763d3060485cce66af0fee711a4024e60cf7ef4d..6e066b18eed1411a1a327590e61ced3f7ed4ca92 100644 --- a/libs/client/StorageClass.cpp +++ b/libs/client/StorageClass.cpp @@ -3,12 +3,68 @@ //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -cta::StorageClass::StorageClass(): nbCopies(0) { +cta::StorageClass::StorageClass(): + m_nbCopies(0), + m_creationTime(time(NULL)) { } //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ cta::StorageClass::StorageClass(const std::string &name, - const uint8_t nbCopies): name(name), nbCopies(nbCopies) { + const uint8_t nbCopies): + m_name(name), + m_nbCopies(nbCopies), + m_creationTime(time(NULL)) { +} + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::StorageClass::StorageClass( + const std::string &name, + const uint8_t nbCopies, + const UserIdentity &creator, + const std::string &comment): + m_name(name), + m_nbCopies(nbCopies), + m_creationTime(time(NULL)), + m_creator(creator), + m_comment(comment) { +} + +//------------------------------------------------------------------------------ +// getName +//------------------------------------------------------------------------------ +const std::string &cta::StorageClass::getName() const throw() { + return m_name; +} + +//------------------------------------------------------------------------------ +// getNbCopies +//------------------------------------------------------------------------------ +uint8_t cta::StorageClass::getNbCopies() const throw() { + return m_nbCopies; +} + +//------------------------------------------------------------------------------ +// getCreationTime +//------------------------------------------------------------------------------ +time_t cta::StorageClass::getCreationTime() const throw() { + return m_creationTime; +} + +//------------------------------------------------------------------------------ +// getCreator +//------------------------------------------------------------------------------ +const cta::UserIdentity &cta::StorageClass::getCreator() + const throw() { + return m_creator; +} + +//------------------------------------------------------------------------------ +// getComment +//------------------------------------------------------------------------------ +const std::string &cta::StorageClass::getComment() const throw() { + return m_comment; } diff --git a/libs/client/StorageClass.hpp b/libs/client/StorageClass.hpp index a7b0f1f303b59626507457df8c2f1a6491dbfa2a..15e87f2c92b11dfd03c29b782ce05513b1bcc132 100644 --- a/libs/client/StorageClass.hpp +++ b/libs/client/StorageClass.hpp @@ -1,5 +1,7 @@ #pragma once +#include "UserIdentity.hpp" + #include <stdint.h> #include <string> @@ -11,31 +13,98 @@ namespace cta { struct StorageClass { /** - * The name of the storage class. + * Constructor. */ - std::string name; + StorageClass(); /** - * The number of copies a file associated with this storage + * Constructor. + * + * @param name The name of the storage class. + * @param nbCopies The number of copies a file associated with this storage * class should have on tape. */ - uint8_t nbCopies; + StorageClass(const std::string &name, const uint8_t nbCopies); /** * Constructor. * - * Initialises nbCopies to 0. + * @param name The name of the storage class. + * @param nbCopies The number of copies a file associated with this storage + * class should have on tape. + * @param creator The identity of the user that created the storage class. + * @param comment The comment describing the storage class. */ - StorageClass(); + StorageClass( + const std::string &name, + const uint8_t nbCopies, + const UserIdentity &creator, + const std::string &comment); /** - * Constructor. + * Returns the name of the storage class. * - * @param name The name of the storage class. - * @param nbCopies The number of copies a file associated with this storage + * @return The name of the storage class. + */ + const std::string &getName() const throw(); + + /** + * Returns the number of copies a file associated with this storage + * class should have on tape. + * + * @return The number of copies a file associated with this storage * class should have on tape. */ - StorageClass(const std::string &name, const uint8_t nbCopies); + uint8_t getNbCopies() const throw(); + + /** + * Returns the time when the storage class was created. + * + * @return The time when the storage class was created. + */ + time_t getCreationTime() const throw(); + + /** + * Returns the identity of the user that created the storage class. + * + * @return The identity of the user that created the storage class. + */ + const UserIdentity &getCreator() const throw(); + + /** + * Returns the comment describing the storage class. + * + * @return The comment describing the storage class. + */ + const std::string &getComment() const throw(); + +private: + + /** + * The name of the storage class. + */ + std::string m_name; + + /** + * The number of copies a file associated with this storage + * class should have on tape. + */ + uint8_t m_nbCopies; + + /** + * The time when the storage class was created. + */ + time_t m_creationTime; + + /** + * The identity of the user that created the storage class. + */ + UserIdentity m_creator; + + /** + * Comment describing the storage class. + */ + std::string m_comment; }; // struct StorageClass diff --git a/xroot_plugins/XrdProFilesystem.cpp b/xroot_plugins/XrdProFilesystem.cpp index 4184c4bd9cb07f6af38059f63b8236a0b06dcf6a..3a356d4e62e08a152efbe4495f8554317f7ab04a 100644 --- a/xroot_plugins/XrdProFilesystem.cpp +++ b/xroot_plugins/XrdProFilesystem.cpp @@ -319,7 +319,7 @@ int XrdProFilesystem::executeLsclassCommand(const ParsedRequest &req, XrdOucErrI std::ostringstream responseSS; responseSS << "[OK] Listing of the storage class names and no of copies:"; for(std::list<cta::StorageClass>::iterator it = stgList.begin(); it != stgList.end(); it++) { - responseSS << "\n" << it->name << " " << it->nbCopies; + responseSS << "\n" << it->getName() << " " << it->getNbCopies(); } eInfo.setErrInfo(responseSS.str().length()+1, responseSS.str().c_str()); return SFS_DATA;