Skip to content
Snippets Groups Projects
Commit 68bf9a58 authored by Steven Murray's avatar Steven Murray
Browse files

Added empty methods to ClientAPI to create, delete and get tape pools

parent a05a7b1a
Branches
Tags
No related merge requests found
......@@ -13,6 +13,7 @@ set (CLIENT_LIB_SRC_FILES
MockClientAPI.cpp
SecurityIdentity.cpp
StorageClass.cpp
TapePool.cpp
UserIdentity.cpp)
add_library (ctaclient SHARED
......
......@@ -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.
*
......
......@@ -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
//------------------------------------------------------------------------------
......
......@@ -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.
*
......
......@@ -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;
......
#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;
}
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment