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

Factorised out FileSystemStorageClasses

parent e49016aa
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ set (CLIENT_LIB_SRC_FILES
Exception.cpp
FileAttribute.cpp
FileSystemNode.cpp
FileSystemStorageClasses.cpp
MockClientAPI.cpp
SecurityIdentity.cpp
StorageClass.cpp
......
#include "Exception.hpp"
#include "FileSystemStorageClasses.hpp"
#include <sstream>
//------------------------------------------------------------------------------
// createStorageClass
//------------------------------------------------------------------------------
void cta::FileSystemStorageClasses::createStorageClass(
const SecurityIdentity &requester,
const std::string &name,
const uint8_t nbCopies) {
try {
checkStorageClassDoesNotAlreadyExist(name);
StorageClass storageClass(name, nbCopies);
m_storageClasses[name] = storageClass;
} catch(std::exception &ex) {
throw Exception(std::string("Failed to create storage class: ") +
ex.what());
}
}
//------------------------------------------------------------------------------
// checkStorageClassDoesNotAlreadyExist
//------------------------------------------------------------------------------
void cta::FileSystemStorageClasses::checkStorageClassDoesNotAlreadyExist(
const std::string &name) const {
std::map<std::string, StorageClassAndUsageCount>::const_iterator itor =
m_storageClasses.find(name);
if(itor != m_storageClasses.end()) {
std::ostringstream msg;
msg << "Storage class " << name << " already exists";
throw Exception(msg.str());
}
}
//------------------------------------------------------------------------------
// deleteStorageClass
//------------------------------------------------------------------------------
void cta::FileSystemStorageClasses::deleteStorageClass(
const std::string &name) {
try {
checkStorageClassExists(name);
checkStorageClassIsNotInUse(name);
m_storageClasses.erase(name);
} catch(std::exception &ex) {
throw Exception(std::string("Failed to delete storage class: ") +
ex.what());
}
}
//------------------------------------------------------------------------------
// checkStorageClassExists
//------------------------------------------------------------------------------
void cta::FileSystemStorageClasses::checkStorageClassExists(
const std::string &name) const {
std::map<std::string, StorageClassAndUsageCount>::const_iterator itor =
m_storageClasses.find(name);
if(itor == m_storageClasses.end()) {
std::ostringstream msg;
msg << "Storage class " << name << " does not exist";
throw Exception(msg.str());
}
}
//------------------------------------------------------------------------------
// checkStorageClassIsNotInUse
//------------------------------------------------------------------------------
void cta::FileSystemStorageClasses::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());
}
}
//------------------------------------------------------------------------------
// getStorageClasses
//------------------------------------------------------------------------------
std::list<cta::StorageClass> cta::FileSystemStorageClasses::getStorageClasses()
const {
std::list<StorageClass> storageClasses;
for(std::map<std::string, StorageClassAndUsageCount>::const_iterator itor =
m_storageClasses.begin(); itor != m_storageClasses.end(); itor++) {
storageClasses.push_back(itor->second.getStorageClass());
}
return storageClasses;
}
//------------------------------------------------------------------------------
// incStorageClassUsageCount
//------------------------------------------------------------------------------
void cta::FileSystemStorageClasses::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();
}
//------------------------------------------------------------------------------
// decStorageClassUsageCount
//------------------------------------------------------------------------------
void cta::FileSystemStorageClasses::decStorageClassUsageCount(
const std::string &name) {
// If no storage class has been specified then there is no usage count to
// decrement
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.decUsageCount();
}
#pragma once
#include "SecurityIdentity.hpp"
#include "StorageClassAndUsageCount.hpp"
#include <list>
#include <map>
namespace cta {
/**
* Container ofthe storage classes current used in the file system.
*/
class FileSystemStorageClasses {
public:
/**
* Creates the specified storage class.
*
* @param requester The identity of the user requesting the creation of the
* storage class.
* @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.
*/
void createStorageClass(
const SecurityIdentity &requester,
const std::string &name,
const uint8_t nbCopies);
/**
* Deletes the specified storage class.
*
* @param requester The identity of the user requesting the deletion of the
* storage class.
* @param name The name of the storage class.
*/
void deleteStorageClass(const std::string &name);
/**
* Gets the current list of storage classes in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of storage classes in lexicographical order.
*/
std::list<StorageClass> getStorageClasses() const;
/**
* Throws an exception if the specified storage class does not exist.
*
* @param name The name of the storage class.
*/
void checkStorageClassExists(const std::string &name) const;
/**
* 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);
/**
* Decrements 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 decStorageClassUsageCount(const std::string &name);
/**
* Throws an exception if the specified storage class is use.
*
* @param name The name of the storage class.
*/
void checkStorageClassIsNotInUse(const std::string &name) const;
protected:
/**
* The current mapping from storage class names to storage classes and their
* usage counts.
*/
std::map<std::string, StorageClassAndUsageCount> m_storageClasses;
/**
* Throws an exception if the specified storage class already exists.
*
* @param name The name of teh storage class.
*/
void checkStorageClassDoesNotAlreadyExist(const std::string &name) const;
}; // class FileSystemStorageClasses
} // namespace cta
......@@ -132,28 +132,7 @@ std::list<std::string> cta::MockClientAPI::getAdminHosts(
//------------------------------------------------------------------------------
void cta::MockClientAPI::createStorageClass(const SecurityIdentity &requester,
const std::string &name, const uint8_t nbCopies) {
try {
checkStorageClassDoesNotAlreadyExist(name);
StorageClass storageClass(name, nbCopies);
m_storageClasses[name] = storageClass;
} catch(std::exception &ex) {
throw Exception(std::string("Failed to create storage class: ") +
ex.what());
}
}
//------------------------------------------------------------------------------
// checkStorageClassDoesNotAlreadyExist
//------------------------------------------------------------------------------
void cta::MockClientAPI::checkStorageClassDoesNotAlreadyExist(
const std::string &name) const {
std::map<std::string, StorageClassAndUsageCount>::const_iterator itor =
m_storageClasses.find(name);
if(itor != m_storageClasses.end()) {
std::ostringstream msg;
msg << "Storage class " << name << " already exists";
throw Exception(msg.str());
}
m_storageClasses.createStorageClass(requester, name, nbCopies);
}
//------------------------------------------------------------------------------
......@@ -161,48 +140,7 @@ void cta::MockClientAPI::checkStorageClassDoesNotAlreadyExist(
//------------------------------------------------------------------------------
void cta::MockClientAPI::deleteStorageClass(const SecurityIdentity &requester,
const std::string &name) {
try {
checkStorageClassExists(name);
checkStorageClassIsNotInUse(name);
m_storageClasses.erase(name);
} catch(std::exception &ex) {
throw Exception(std::string("Failed to delete storage class: ") +
ex.what());
}
}
//------------------------------------------------------------------------------
// checkStorageClassExists
//------------------------------------------------------------------------------
void cta::MockClientAPI::checkStorageClassExists(
const std::string &name) const {
std::map<std::string, StorageClassAndUsageCount>::const_iterator itor =
m_storageClasses.find(name);
if(itor == m_storageClasses.end()) {
std::ostringstream msg;
msg << "Storage class " << name << " does not exist";
throw Exception(msg.str());
}
}
//------------------------------------------------------------------------------
// checkStorageClassIsNotInUse
//------------------------------------------------------------------------------
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());
}
m_storageClasses.deleteStorageClass(name);
}
//------------------------------------------------------------------------------
......@@ -210,12 +148,7 @@ void cta::MockClientAPI::checkStorageClassIsNotInUse(
//------------------------------------------------------------------------------
std::list<cta::StorageClass> cta::MockClientAPI::getStorageClasses(
const SecurityIdentity &requester) const {
std::list<StorageClass> storageClasses;
for(std::map<std::string, StorageClassAndUsageCount>::const_iterator itor =
m_storageClasses.begin(); itor != m_storageClasses.end(); itor++) {
storageClasses.push_back(itor->second.getStorageClass());
}
return storageClasses;
return m_storageClasses.getStorageClasses();
}
//------------------------------------------------------------------------------
......@@ -407,28 +340,6 @@ 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
//------------------------------------------------------------------------------
......@@ -537,7 +448,7 @@ void cta::MockClientAPI::setDirectoryStorageClass(
const SecurityIdentity &requester,
const std::string &dirPath,
const std::string &storageClassName) {
checkStorageClassExists(storageClassName);
m_storageClasses.checkStorageClassExists(storageClassName);
FileSystemNode &dirNode = getFileSystemNode(dirPath);
if(DirectoryEntry::ENTRYTYPE_DIRECTORY != dirNode.getEntry().entryType) {
......
......@@ -2,6 +2,7 @@
#include "ClientAPI.hpp"
#include "FileSystemNode.hpp"
#include "FileSystemStorageClasses.hpp"
#include "StorageClass.hpp"
#include "StorageClassAndUsageCount.hpp"
......@@ -229,10 +230,9 @@ protected:
std::list<std::string> m_adminHosts;
/**
* The current mapping from storage class names to storage classes and their
* usage counts.
* Container of the storage classes used by the file system.
*/
std::map<std::string, StorageClassAndUsageCount> m_storageClasses;
FileSystemStorageClasses m_storageClasses;
/**
* The root node of the file-system.
......@@ -253,27 +253,6 @@ protected:
*/
void checkAdminHostDoesNotAlreadyExist(const std::string &adminHost);
/**
* Throws an exception if the specified storage class already exists.
*
* @param name The name of teh storage class.
*/
void checkStorageClassDoesNotAlreadyExist(const std::string &name) const;
/**
* Throws an exception if the specified storage class does not exist.
*
* @param name The name of the storage class.
*/
void checkStorageClassExists(const std::string &name) const;
/**
* Throws an exception if the specified storage class is use.
*
* @param name The name of the storage class.
*/
void checkStorageClassIsNotInUse(const std::string &name) const;
/**
* Throws an exception if the specified absolute path constains a
* syntax error.
......
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