From 68bf9a5856142e2ef01878950ea884c65f23ff1a Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Fri, 6 Feb 2015 10:16:29 +0100 Subject: [PATCH] Added empty methods to ClientAPI to create, delete and get tape pools --- libs/client/CMakeLists.txt | 1 + libs/client/ClientAPI.hpp | 36 +++++- libs/client/MockClientAPI.cpp | 23 ++++ libs/client/MockClientAPI.hpp | 33 ++++++ libs/client/MockClientAPITest.cpp | 191 ++++++++++++++++++++++++++++++ libs/client/TapePool.cpp | 50 ++++++++ libs/client/TapePool.hpp | 85 +++++++++++++ 7 files changed, 418 insertions(+), 1 deletion(-) create mode 100644 libs/client/TapePool.cpp create mode 100644 libs/client/TapePool.hpp diff --git a/libs/client/CMakeLists.txt b/libs/client/CMakeLists.txt index a3f99beeb2..0af157fac0 100644 --- a/libs/client/CMakeLists.txt +++ b/libs/client/CMakeLists.txt @@ -13,6 +13,7 @@ set (CLIENT_LIB_SRC_FILES MockClientAPI.cpp SecurityIdentity.cpp StorageClass.cpp + TapePool.cpp UserIdentity.cpp) add_library (ctaclient SHARED diff --git a/libs/client/ClientAPI.hpp b/libs/client/ClientAPI.hpp index 81b3c8d7f0..b11f2a4c78 100644 --- a/libs/client/ClientAPI.hpp +++ b/libs/client/ClientAPI.hpp @@ -3,6 +3,7 @@ #include "DirectoryIterator.hpp" #include "SecurityIdentity.hpp" #include "StorageClass.hpp" +#include "TapePool.hpp" #include "UserIdentity.hpp" #include <list> @@ -113,12 +114,45 @@ public: /** * Gets the current list of storage classes in lexicographical order. * - * @param requester The identity of the user requesting list. + * @param requester The identity of the user requesting the list. * @return The current list of storage classes in lexicographical order. */ virtual std::list<StorageClass> getStorageClasses( const SecurityIdentity &requester) const = 0; + /** + * Creates a tape pool with the specifed name. + * + * @param requester The identity of the user requesting the creation of the + * tape pool. + * @param name The name of the tape pool. + * @param comment The comment describing the tape pool. + */ + virtual void createTapePool( + const SecurityIdentity &requester, + const std::string &name, + const std::string &comment) = 0; + + /** + * Delete the tape pool with the specifed name. + * + * @param requester The identity of the user requesting the deletion of the + * tape pool. + * @param name The name of the tape pool. + */ + virtual void deleteTapePool( + const SecurityIdentity &requester, + const std::string &name) = 0; + + /** + * Gets the current list of tape pools in lexicographical order. + * + * @param requester The identity of the user requesting the list. + * @return The current list of tape pools in lexicographical order. + */ + virtual std::list<TapePool> getTapePools( + const SecurityIdentity &requester) const = 0; + /** * Creates the specified directory. * diff --git a/libs/client/MockClientAPI.cpp b/libs/client/MockClientAPI.cpp index 5aedf43676..95ffdb310d 100644 --- a/libs/client/MockClientAPI.cpp +++ b/libs/client/MockClientAPI.cpp @@ -151,6 +151,29 @@ std::list<cta::StorageClass> cta::MockClientAPI::getStorageClasses( return m_storageClasses.getStorageClasses(); } +//------------------------------------------------------------------------------ +// createTapePool +//------------------------------------------------------------------------------ +void cta::MockClientAPI::createTapePool(const SecurityIdentity &requester, + const std::string &name, const std::string &comment) { +} + +//------------------------------------------------------------------------------ +// deleteTapePool +//------------------------------------------------------------------------------ +void cta::MockClientAPI::deleteTapePool(const SecurityIdentity &requester, + const std::string &name) { +} + +//------------------------------------------------------------------------------ +// getTapePools +//------------------------------------------------------------------------------ +std::list<cta::TapePool> cta::MockClientAPI::getTapePools( + const SecurityIdentity &requester) const { + std::list<cta::TapePool> tapePools; + return tapePools; +} + //------------------------------------------------------------------------------ // createDirectory //------------------------------------------------------------------------------ diff --git a/libs/client/MockClientAPI.hpp b/libs/client/MockClientAPI.hpp index cb6aaffcd0..5864b791a9 100644 --- a/libs/client/MockClientAPI.hpp +++ b/libs/client/MockClientAPI.hpp @@ -122,6 +122,39 @@ public: std::list<StorageClass> getStorageClasses( const SecurityIdentity &requester) const; + /** + * Creates a tape pool with the specifed name. + * + * @param requester The identity of the user requesting the creation of the + * tape pool. + * @param name The name of the tape pool. + * @param comment The comment describing the tape pool. + */ + void createTapePool( + const SecurityIdentity &requester, + const std::string &name, + const std::string &comment); + + /** + * Delete the tape pool with the specifed name. + * + * @param requester The identity of the user requesting the deletion of the + * tape pool. + * @param name The name of the tape pool. + */ + void deleteTapePool( + const SecurityIdentity &requester, + const std::string &name); + + /** + * Gets the current list of tape pools in lexicographical order. + * + * @param requester The identity of the user requesting the list. + * @return The current list of tape pools in lexicographical order. + */ + std::list<TapePool> getTapePools( + const SecurityIdentity &requester) const; + /** * Creates the specified directory. * diff --git a/libs/client/MockClientAPITest.cpp b/libs/client/MockClientAPITest.cpp index 83f1fab6bd..df7c20d9b5 100644 --- a/libs/client/MockClientAPITest.cpp +++ b/libs/client/MockClientAPITest.cpp @@ -408,6 +408,197 @@ TEST_F(cta_client_MockClientAPITest, deleteStorageClass_non_existing) { } } +TEST_F(cta_client_MockClientAPITest, createTapePool_new) { + using namespace cta; + + TestingMockClientAPI api; + const SecurityIdentity requester; + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_TRUE(tapePools.empty()); + } + + const std::string name = "TestTapePool"; + const std::string comment = "Comment"; + ASSERT_NO_THROW(api.createTapePool(requester, name, comment)); + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_EQ(1, tapePools.size()); + + TapePool tapePool; + ASSERT_NO_THROW(tapePool = tapePools.front()); + ASSERT_EQ(name, tapePool.getName()); + } +} + +TEST_F(cta_client_MockClientAPITest, createTapePool_already_existing) { + using namespace cta; + + TestingMockClientAPI api; + const SecurityIdentity requester; + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_TRUE(tapePools.empty()); + } + + const std::string name = "TestTapePool"; + const std::string comment = "Comment"; + ASSERT_NO_THROW(api.createTapePool(requester, name, comment)); + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_EQ(1, tapePools.size()); + + TapePool tapePool; + ASSERT_NO_THROW(tapePool = tapePools.front()); + ASSERT_EQ(name, tapePool.getName()); + } + + ASSERT_THROW(api.createTapePool(requester, name, comment), std::exception); +} + +TEST_F(cta_client_MockClientAPITest, createTapePool_lexicographical_order) { + using namespace cta; + + TestingMockClientAPI api; + const SecurityIdentity requester; + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_TRUE(tapePools.empty()); + } + + ASSERT_NO_THROW(api.createTapePool(requester, "d", "Comment d")); + ASSERT_NO_THROW(api.createTapePool(requester, "b", "Comment b")); + ASSERT_NO_THROW(api.createTapePool(requester, "a", "Comment a")); + ASSERT_NO_THROW(api.createTapePool(requester, "c", "Comment c")); + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_EQ(4, tapePools.size()); + + ASSERT_EQ(std::string("a"), tapePools.front().getName()); + tapePools.pop_front(); + ASSERT_EQ(std::string("b"), tapePools.front().getName()); + tapePools.pop_front(); + ASSERT_EQ(std::string("c"), tapePools.front().getName()); + tapePools.pop_front(); + ASSERT_EQ(std::string("d"), tapePools.front().getName()); + } +} + +TEST_F(cta_client_MockClientAPITest, deleteTapePool_existing) { + using namespace cta; + + TestingMockClientAPI api; + const SecurityIdentity requester; + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_TRUE(tapePools.empty()); + } + + const std::string name = "TestTapePool"; + const std::string comment = "Comment"; + ASSERT_NO_THROW(api.createTapePool(requester, name, comment)); + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_EQ(1, tapePools.size()); + + TapePool tapePool; + ASSERT_NO_THROW(tapePool = tapePools.front()); + ASSERT_EQ(name, tapePool.getName()); + + ASSERT_NO_THROW(api.deleteTapePool(requester, name)); + } + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_TRUE(tapePools.empty()); + } +} + +/* +TEST_F(cta_client_MockClientAPITest, deleteTapePool_in_use) { + using namespace cta; + + TestingMockClientAPI api; + const SecurityIdentity requester; + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_TRUE(tapePools.empty()); + } + + const std::string name = "TestTapePool"; + const uint8_t nbCopies = 2; + const std::string comment = "Comment"; + ASSERT_NO_THROW(api.createTapePool(requester, name, nbCopies, comment)); + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_EQ(1, tapePools.size()); + + TapePool tapePool; + ASSERT_NO_THROW(tapePool = tapePools.front()); + ASSERT_EQ(name, tapePool.getName()); + ASSERT_EQ(nbCopies, tapePool.getNbCopies()); + } + + ASSERT_NO_THROW(api.setDirectoryTapePool(requester, "/", name)); + + ASSERT_THROW(api.deleteTapePool(requester, name), std::exception); + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_EQ(1, tapePools.size()); + + TapePool tapePool; + ASSERT_NO_THROW(tapePool = tapePools.front()); + ASSERT_EQ(name, tapePool.getName()); + ASSERT_EQ(nbCopies, tapePool.getNbCopies()); + } +} +*/ + +TEST_F(cta_client_MockClientAPITest, deleteTapePool_non_existing) { + using namespace cta; + + TestingMockClientAPI api; + const SecurityIdentity requester; + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_TRUE(tapePools.empty()); + } + + const std::string name = "TestTapePool"; + ASSERT_THROW(api.deleteTapePool(requester, name), std::exception); + + { + std::list<TapePool> tapePools; + ASSERT_NO_THROW(tapePools = api.getTapePools(requester)); + ASSERT_TRUE(tapePools.empty()); + } +} + TEST_F(cta_client_MockClientAPITest, getDirectoryContents_root_dir_is_empty) { using namespace cta; diff --git a/libs/client/TapePool.cpp b/libs/client/TapePool.cpp new file mode 100644 index 0000000000..9e2080848b --- /dev/null +++ b/libs/client/TapePool.cpp @@ -0,0 +1,50 @@ +#include "TapePool.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::TapePool::TapePool(): + m_creationTime(time(NULL)) { +} + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::TapePool::TapePool( + const std::string &name, + const UserIdentity &creator, + const std::string &comment): + m_name(name), + m_creationTime(time(NULL)), + m_creator(creator), + m_comment(comment) { +} + +//------------------------------------------------------------------------------ +// getName +//------------------------------------------------------------------------------ +const std::string &cta::TapePool::getName() const throw() { + return m_name; +} + +//------------------------------------------------------------------------------ +// getCreationTime +//------------------------------------------------------------------------------ +time_t cta::TapePool::getCreationTime() const throw() { + return m_creationTime; +} + +//------------------------------------------------------------------------------ +// getCreator +//------------------------------------------------------------------------------ +const cta::UserIdentity &cta::TapePool::getCreator() + const throw() { + return m_creator; +} + +//------------------------------------------------------------------------------ +// getComment +//------------------------------------------------------------------------------ +const std::string &cta::TapePool::getComment() const throw() { + return m_comment; +} diff --git a/libs/client/TapePool.hpp b/libs/client/TapePool.hpp new file mode 100644 index 0000000000..2fdea769e6 --- /dev/null +++ b/libs/client/TapePool.hpp @@ -0,0 +1,85 @@ +#pragma once + +#include "UserIdentity.hpp" + +#include <stdint.h> +#include <string> + +namespace cta { + +/** + * Class representing a tape pool. + */ +class TapePool { +public: + + /** + * Constructor. + */ + TapePool(); + + /** + * Constructor. + * + * @param name The name of the tape pool. + * @param creator The identity of the user that created the tape pool. + * @param comment The comment describing the tape pool. + */ + TapePool( + const std::string &name, + const UserIdentity &creator, + const std::string &comment); + + /** + * Returns the name of the tape pool. + * + * @return The name of the tape pool. + */ + const std::string &getName() const throw(); + + /** + * Returns the time when the tape pool was created. + * + * @return The time when the tape pool was created. + */ + time_t getCreationTime() const throw(); + + /** + * Returns the identity of the user that created the tape pool. + * + * @return The identity of the user that created the tape pool. + */ + const UserIdentity &getCreator() const throw(); + + /** + * Returns the comment describing the tape pool. + * + * @return The comment describing the tape pool. + */ + const std::string &getComment() const throw(); + +private: + + /** + * The name of the tape pool. + */ + std::string m_name; + + /** + * The time when the tape pool was created. + */ + time_t m_creationTime; + + /** + * The identity of the user that created the tape pool. + */ + UserIdentity m_creator; + + /** + * Comment describing the tape pool. + */ + std::string m_comment; + +}; // class TapePool + +} // namespace cta -- GitLab