diff --git a/libs/client/ClientAPI.hpp b/libs/client/ClientAPI.hpp index 7e9d82ebfc5b626c2ecec5157abaff72554feffe..ba67ac3153328860ce12cc36e15f4457a5a1d150 100644 --- a/libs/client/ClientAPI.hpp +++ b/libs/client/ClientAPI.hpp @@ -12,7 +12,7 @@ namespace cta { /** - * Abstract class that specifies the client ClientAPI of the CERN Tape Archive + * Abstract class that specifies the client API of the CERN Tape Archive * project. */ class ClientAPI { diff --git a/libs/client/FileSystemNode.hpp b/libs/client/FileSystemNode.hpp index 21639296c58eb6ffbf90e82a422f7d45da348003..24f4c4975987c27bdff0df822c74c37e37f3a18d 100644 --- a/libs/client/FileSystemNode.hpp +++ b/libs/client/FileSystemNode.hpp @@ -36,7 +36,7 @@ public: FileSystemNode &getParent(); /** - * Gets the parent of this node or throiws an exception if this node does not + * Gets the parent of this node or throws an exception if this node does not * have a parent. */ const FileSystemNode &getParent() const; diff --git a/libs/client/MockClientAPI.cpp b/libs/client/MockClientAPI.cpp index c88eec73dc47bb30f774f1a8d2d583aef03d708b..cb61b59487f665913e36258444ec229dd4b7e666 100644 --- a/libs/client/MockClientAPI.cpp +++ b/libs/client/MockClientAPI.cpp @@ -147,7 +147,7 @@ void cta::MockClientAPI::createStorageClass(const SecurityIdentity &requester, //------------------------------------------------------------------------------ void cta::MockClientAPI::checkStorageClassDoesNotAlreadyExist( const std::string &name) const { - std::map<std::string, StorageClass>::const_iterator itor = + std::map<std::string, StorageClassAndUsageCount>::const_iterator itor = m_storageClasses.find(name); if(itor != m_storageClasses.end()) { std::ostringstream msg; @@ -176,7 +176,7 @@ void cta::MockClientAPI::deleteStorageClass(const SecurityIdentity &requester, //------------------------------------------------------------------------------ void cta::MockClientAPI::checkStorageClassExists( const std::string &name) const { - std::map<std::string, StorageClass>::const_iterator itor = + std::map<std::string, StorageClassAndUsageCount>::const_iterator itor = m_storageClasses.find(name); if(itor == m_storageClasses.end()) { std::ostringstream msg; @@ -190,6 +190,19 @@ void cta::MockClientAPI::checkStorageClassExists( //------------------------------------------------------------------------------ void cta::MockClientAPI::checkStorageClassIsNotInUse( const std::string &name) const { + std::map<std::string, StorageClassAndUsageCount>::const_iterator itor = + m_storageClasses.find(name); + + // If the storage class does not exists then it cannot be in use + if(itor == m_storageClasses.end()) { + return; + } + + if(itor->second.getUsageCount() > 0) { + std::ostringstream message; + message << "Storage class " << name << " is in use"; + throw Exception(message.str()); + } } //------------------------------------------------------------------------------ @@ -198,9 +211,9 @@ void cta::MockClientAPI::checkStorageClassIsNotInUse( std::list<cta::StorageClass> cta::MockClientAPI::getStorageClasses( const SecurityIdentity &requester) const { std::list<StorageClass> storageClasses; - for(std::map<std::string, StorageClass>::const_iterator itor = + for(std::map<std::string, StorageClassAndUsageCount>::const_iterator itor = m_storageClasses.begin(); itor != m_storageClasses.end(); itor++) { - storageClasses.push_back(itor->second); + storageClasses.push_back(itor->second.getStorageClass()); } return storageClasses; } @@ -394,6 +407,28 @@ const cta::FileSystemNode &cta::MockClientAPI::getFileSystemNode( return *node; } +//------------------------------------------------------------------------------ +// incStorageClassUsageCount +//------------------------------------------------------------------------------ +void cta::MockClientAPI::incStorageClassUsageCount(const std::string &name) { + // If no storage class has been specified then there is no usage count to + // increment + if(name.empty()) { + return; + } + + std::map<std::string, StorageClassAndUsageCount>::iterator itor = + m_storageClasses.find(name); + + if(itor == m_storageClasses.end()) { + std::ostringstream message; + message << "Storage class " << name << " does not exist"; + throw Exception(message.str()); + } + + itor->second.incUsageCount(); +} + //------------------------------------------------------------------------------ // deleteDirectory //------------------------------------------------------------------------------ diff --git a/libs/client/MockClientAPI.hpp b/libs/client/MockClientAPI.hpp index b35931c73614c1c27c219a761b79826f034ca338..4925cf3a94cf5ba8ae49586c9010f6a0c41e8241 100644 --- a/libs/client/MockClientAPI.hpp +++ b/libs/client/MockClientAPI.hpp @@ -2,6 +2,8 @@ #include "ClientAPI.hpp" #include "FileSystemNode.hpp" +#include "StorageClass.hpp" +#include "StorageClassAndUsageCount.hpp" #include <map> #include <vector> @@ -227,9 +229,10 @@ protected: std::list<std::string> m_adminHosts; /** - * The current mapping from storage class name to storage classes. + * The current mapping from storage class names to storage classes and their + * usage counts. */ - std::map<std::string, StorageClass> m_storageClasses; + std::map<std::string, StorageClassAndUsageCount> m_storageClasses; /** * The root node of the file-system. @@ -377,6 +380,14 @@ protected: void splitString(const std::string &str, const char separator, std::vector<std::string> &result) const throw(); + /** + * Increments the usage count of the specified storage class. + * + * @param name The name of the storage class. If this parameter is set to the + * empty string then this method does nothing. + */ + void incStorageClassUsageCount(const std::string &name); + }; // class MockClientAPI } // namespace cta