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

Renamed StorageClassAndUsageCount to FileSystemStorageClass

parent 7bea63e4
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
#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--;
......
......@@ -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
......@@ -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()) {
......
#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.
......
......@@ -4,9 +4,7 @@
#include "FileSystemNode.hpp"
#include "FileSystemStorageClasses.hpp"
#include "StorageClass.hpp"
#include "StorageClassAndUsageCount.hpp"
#include <map>
#include <vector>
namespace cta {
......
......@@ -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());
}
}
......
......@@ -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;
}
#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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment