diff --git a/libs/client/CMakeLists.txt b/libs/client/CMakeLists.txt index bd7529444771046d7f230ad619a0c4869053200b..e128d00bfd392c59a3b5838f4bd7e7c3d87a0b3e 100644 --- a/libs/client/CMakeLists.txt +++ b/libs/client/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required (VERSION 2.6) set (CLIENT_LIB_SRC_FILES - API.cpp + ClientAPI.cpp DirectoryEntry.cpp DirectoryIterator.cpp Exception.cpp - MockAPI.cpp + MockClientAPI.cpp MockAPITest.cpp StorageClass.cpp) diff --git a/libs/client/API.cpp b/libs/client/ClientAPI.cpp similarity index 73% rename from libs/client/API.cpp rename to libs/client/ClientAPI.cpp index 09505cdfdeb0265636e5f9367d099c70c6c25aa7..0c026b2d9c711bc85ff9a73a0ad8b97497ee57fc 100644 --- a/libs/client/API.cpp +++ b/libs/client/ClientAPI.cpp @@ -1,7 +1,7 @@ -#include "API.hpp" +#include "ClientAPI.hpp" //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -cta::API::~API() throw() { +cta::ClientAPI::~ClientAPI() throw() { } diff --git a/libs/client/API.hpp b/libs/client/ClientAPI.hpp similarity index 92% rename from libs/client/API.hpp rename to libs/client/ClientAPI.hpp index dbfe946c26cf23197ff5550635173d0e9e888e9b..7de9755ac68a09c9718c1403eb7b712a01567f90 100644 --- a/libs/client/API.hpp +++ b/libs/client/ClientAPI.hpp @@ -11,15 +11,15 @@ namespace cta { /** - * Abstract class that specifies the client API of the CERN Tape Archive project. + * Abstract class that specifies the client ClientAPI of the CERN Tape Archive project. */ -class API { +class ClientAPI { public: /** * Destructor. */ - virtual ~API() throw() = 0; + virtual ~ClientAPI() throw() = 0; /** * Creates the specified storage class. @@ -75,6 +75,6 @@ public: virtual std::string archiveToTape(const std::list<std::string> &srcUrls, std::string dst) = 0; -}; // class API +}; // class ClientAPI } // namespace cta diff --git a/libs/client/FileAttribute.cpp b/libs/client/FileAttribute.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d934deb9c14ce20c3cfbe3824609f59f8a53cd83 --- /dev/null +++ b/libs/client/FileAttribute.cpp @@ -0,0 +1,14 @@ +#include "FileAttribute.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::FileAtribute::FileAtribute() { +} + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +cta::FileAtribute::FileAtribute(const std::string &name, + const std::string &value): name(name), value(value) { +} diff --git a/libs/client/FileAttribute.hpp b/libs/client/FileAttribute.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6b8f1d927424f57d7b28a90154abe831de9a8d7c --- /dev/null +++ b/libs/client/FileAttribute.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include <string> + +namespace cta { + +/** + * Class representing a file atrribute. + */ +struct FileAtribute { + + /** + * The name of the attribute. + */ + std::string name; + + /** + * The value of the attribute. + */ + std::string value; + + /** + * Constructor. + */ + FileAtribute(); + + /** + * Constructor. + * + * @param name The name of the attribute. + * @param value value of the attribute. + */ + FileAtribute(const std::string &name, const std::string &value); + +}; // struct FileAtribute + +} // namespace cta diff --git a/libs/client/MockAPITest.cpp b/libs/client/MockAPITest.cpp index acdc90569973064ac07f0149daa82fe0f8a6e184..441bc29d823f2bd4161b725d41e318e0850ddb9e 100644 --- a/libs/client/MockAPITest.cpp +++ b/libs/client/MockAPITest.cpp @@ -1,10 +1,10 @@ -#include "MockAPI.hpp" +#include "MockClientAPI.hpp" #include <gtest/gtest.h> namespace unitTests { -class cta_client_MockAPITest: public ::testing::Test { +class cta_client_MockClientAPITest: public ::testing::Test { protected: virtual void SetUp() { @@ -14,10 +14,10 @@ protected: } }; -TEST_F(cta_client_MockAPITest, createStorageClass_new) { +TEST_F(cta_client_MockClientAPITest, createStorageClass_new) { using namespace cta; - MockAPI api; + MockClientAPI api; ASSERT_TRUE(api.getStorageClasses().empty()); @@ -32,10 +32,10 @@ TEST_F(cta_client_MockAPITest, createStorageClass_new) { ASSERT_EQ(nbCopies, storageClass.nbCopies); } -TEST_F(cta_client_MockAPITest, createStorageClass_already_existing) { +TEST_F(cta_client_MockClientAPITest, createStorageClass_already_existing) { using namespace cta; - MockAPI api; + MockClientAPI api; ASSERT_TRUE(api.getStorageClasses().empty()); @@ -52,10 +52,10 @@ TEST_F(cta_client_MockAPITest, createStorageClass_already_existing) { ASSERT_THROW(api.createStorageClass(name, nbCopies), std::exception); } -TEST_F(cta_client_MockAPITest, createStorageClass_lexicographical_order) { +TEST_F(cta_client_MockClientAPITest, createStorageClass_lexicographical_order) { using namespace cta; - MockAPI api; + MockClientAPI api; ASSERT_TRUE(api.getStorageClasses().empty()); @@ -77,10 +77,10 @@ TEST_F(cta_client_MockAPITest, createStorageClass_lexicographical_order) { ASSERT_EQ(std::string("d"), storageClasses.front().name); } -TEST_F(cta_client_MockAPITest, deleteStorageClass_existing) { +TEST_F(cta_client_MockClientAPITest, deleteStorageClass_existing) { using namespace cta; - MockAPI api; + MockClientAPI api; ASSERT_TRUE(api.getStorageClasses().empty()); @@ -99,10 +99,10 @@ TEST_F(cta_client_MockAPITest, deleteStorageClass_existing) { ASSERT_TRUE(api.getStorageClasses().empty()); } -TEST_F(cta_client_MockAPITest, deleteStorageClass_non_existing) { +TEST_F(cta_client_MockClientAPITest, deleteStorageClass_non_existing) { using namespace cta; - MockAPI api; + MockClientAPI api; ASSERT_TRUE(api.getStorageClasses().empty()); @@ -112,10 +112,10 @@ TEST_F(cta_client_MockAPITest, deleteStorageClass_non_existing) { ASSERT_TRUE(api.getStorageClasses().empty()); } -TEST_F(cta_client_MockAPITest, getDirectoryIterator_empty) { +TEST_F(cta_client_MockClientAPITest, getDirectoryIterator_empty) { using namespace cta; - MockAPI api; + MockClientAPI api; ASSERT_NO_THROW(api.getDirectoryIterator("/")); } diff --git a/libs/client/MockAPI.cpp b/libs/client/MockClientAPI.cpp similarity index 86% rename from libs/client/MockAPI.cpp rename to libs/client/MockClientAPI.cpp index 3c365c73ba544a72b198e022d157f2def294f163..b7ca0d1468259ec7179968d33d4e05bef67837e8 100644 --- a/libs/client/MockAPI.cpp +++ b/libs/client/MockClientAPI.cpp @@ -1,4 +1,4 @@ -#include "MockAPI.hpp" +#include "MockClientAPI.hpp" #include "Exception.hpp" #include <sstream> @@ -6,19 +6,19 @@ //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -cta::MockAPI::MockAPI() { +cta::MockClientAPI::MockClientAPI() { } //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -cta::MockAPI::~MockAPI() throw() { +cta::MockClientAPI::~MockClientAPI() throw() { } //------------------------------------------------------------------------------ // createStorageClass //------------------------------------------------------------------------------ -void cta::MockAPI::createStorageClass(const std::string &name, +void cta::MockClientAPI::createStorageClass(const std::string &name, const uint8_t nbCopies) { try { checkStorageClassDoesNotAlreadyExist(name); @@ -33,7 +33,7 @@ void cta::MockAPI::createStorageClass(const std::string &name, //------------------------------------------------------------------------------ // checkStorageClassDoesNotAlreadyExist //------------------------------------------------------------------------------ -void cta::MockAPI::checkStorageClassDoesNotAlreadyExist( +void cta::MockClientAPI::checkStorageClassDoesNotAlreadyExist( const std::string &name) const { std::map<std::string, StorageClass>::const_iterator itor = m_storageClasses.find(name); @@ -47,7 +47,7 @@ void cta::MockAPI::checkStorageClassDoesNotAlreadyExist( //------------------------------------------------------------------------------ // deleteStorageClass //------------------------------------------------------------------------------ -void cta::MockAPI::deleteStorageClass(const std::string &name) { +void cta::MockClientAPI::deleteStorageClass(const std::string &name) { try { checkStorageClassExists(name); m_storageClasses.erase(name); @@ -60,7 +60,7 @@ void cta::MockAPI::deleteStorageClass(const std::string &name) { //------------------------------------------------------------------------------ // checkStorageClassExists //------------------------------------------------------------------------------ -void cta::MockAPI::checkStorageClassExists( +void cta::MockClientAPI::checkStorageClassExists( const std::string &name) const { std::map<std::string, StorageClass>::const_iterator itor = m_storageClasses.find(name); @@ -74,7 +74,7 @@ void cta::MockAPI::checkStorageClassExists( //------------------------------------------------------------------------------ // getStorageClasses //------------------------------------------------------------------------------ -std::list<cta::StorageClass> cta::MockAPI::getStorageClasses() const { +std::list<cta::StorageClass> cta::MockClientAPI::getStorageClasses() const { std::list<StorageClass> storageClasses; for(std::map<std::string, StorageClass>::const_iterator itor = m_storageClasses.begin(); itor != m_storageClasses.end(); itor++) { @@ -86,7 +86,7 @@ std::list<cta::StorageClass> cta::MockAPI::getStorageClasses() const { //------------------------------------------------------------------------------ // getDirectoryIterator //------------------------------------------------------------------------------ -cta::DirectoryIterator cta::MockAPI:: +cta::DirectoryIterator cta::MockClientAPI:: getDirectoryIterator(const std::string &dirPath) const { std::list<DirectoryEntry> entries; @@ -97,7 +97,7 @@ cta::DirectoryIterator cta::MockAPI:: //------------------------------------------------------------------------------ // archiveToTape //------------------------------------------------------------------------------ -std::string cta::MockAPI::archiveToTape( +std::string cta::MockClientAPI::archiveToTape( const std::list<std::string> &srcUrls, std::string dst) { return "Funny_Job_ID"; } diff --git a/libs/client/MockAPI.hpp b/libs/client/MockClientAPI.hpp similarity index 91% rename from libs/client/MockAPI.hpp rename to libs/client/MockClientAPI.hpp index 8b0ca5dde322789edc05fe10e06c79d9cf673d7f..1e115f959f6f55ce87501677af1ac3daa7e6cc1d 100644 --- a/libs/client/MockAPI.hpp +++ b/libs/client/MockClientAPI.hpp @@ -1,26 +1,26 @@ #pragma once -#include "API.hpp" +#include "ClientAPI.hpp" #include <map> namespace cta { /** - * A mock entry point to the client API of the CERN Tape Archive project. + * A mock entry point to the client ClientAPI of the CERN Tape Archive project. */ -class MockAPI: public API { +class MockClientAPI: public ClientAPI { public: /** * Constructor. */ - MockAPI(); + MockClientAPI(); /** * Destructor. */ - ~MockAPI() throw(); + ~MockClientAPI() throw(); /** * Creates the specified storage class. @@ -97,6 +97,6 @@ private: */ void checkStorageClassExists(const std::string &name) const; -}; // class MockAPI +}; // class MockClientAPI } // namespace cta diff --git a/xroot_clients/CTACmd.cpp b/xroot_clients/CTACmd.cpp index 409a8b3b6c17cb464401b0042446cefc1566f794..92c390b9bc6633f8df76afeacfa1e8a9b8f7ca02 100644 --- a/xroot_clients/CTACmd.cpp +++ b/xroot_clients/CTACmd.cpp @@ -19,7 +19,11 @@ CTACmd::CTACmd() throw(): m_programName("CTA_cmd") { void CTACmd::usage(std::ostream &os) const throw() { os << "Usage:\n" - "\t" << m_programName << " archive <source_file1> [<source_file2> [<source_file3> [...]]] <destination_path>\n"; + "\t" << m_programName << " archive <source_file1> [<source_file2> [<source_file3> [...]]] <destination_path>\n" + "\t" << m_programName << " create-storage-class <storage_class_name> <number_of_tape_copies>\n" + "\t" << m_programName << " delete-storage-class <storage_class_name>\n" + "\t" << m_programName << " mkdir <directory_name>\n" + "\t" << m_programName << " rmdir <directory_name>\n"; } //------------------------------------------------------------------------------ diff --git a/xroot_plugins/CMakeLists.txt b/xroot_plugins/CMakeLists.txt index 4f48fc86433a58760c98a92da3c7ca87163c4dbf..1b76e31e46d954cf9ddcc161eca3ff7472b4d17c 100644 --- a/xroot_plugins/CMakeLists.txt +++ b/xroot_plugins/CMakeLists.txt @@ -4,4 +4,4 @@ list (APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) find_package (xrootd REQUIRED) include_directories (${XROOTD_INCLUDE_DIR} ${XROOTD_PRIVATE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}) -add_library (XrdProFst MODULE XrdProFilesystem.cpp ParsedArchiveCmdLine.cpp ParsedCreateStorageClassCmdLine.cpp) +add_library (XrdProFst MODULE XrdProFilesystem.cpp ParsedArchiveCmdLine.cpp ParsedCreateStorageClassCmdLine.cpp ParsedDeleteStorageClassCmdLine.cpp ParsedMkdirCmdLine.cpp ParsedRmdirCmdLine.cpp ParsedChangeStorageClassCmdLine.cpp) diff --git a/xroot_plugins/ParsedChangeStorageClassCmdLine.cpp b/xroot_plugins/ParsedChangeStorageClassCmdLine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cab5e123056695751bda3dd5741d9a46bc663b80 --- /dev/null +++ b/xroot_plugins/ParsedChangeStorageClassCmdLine.cpp @@ -0,0 +1,9 @@ +#include "ParsedChangeStorageClassCmdLine.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +ParsedChangeStorageClassCmdLine::ParsedChangeStorageClassCmdLine() throw() +{ + +} diff --git a/xroot_plugins/ParsedChangeStorageClassCmdLine.hpp b/xroot_plugins/ParsedChangeStorageClassCmdLine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ce41c6f60caaab3030384607e27e58bd515a8183 --- /dev/null +++ b/xroot_plugins/ParsedChangeStorageClassCmdLine.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "XrdOuc/XrdOucString.hh" + +#include <list> +#include <string> + +/** + * Data type used to store the results of parsing the create-storage-class command-line. + */ +struct ParsedChangeStorageClassCmdLine { + + /** + * The directory name + */ + std::string dirName; + + /** + * The storage class name + */ + std::string storageClassName; + + /** + * Constructor. + */ + ParsedChangeStorageClassCmdLine() throw(); + +}; // struct ParsedChangeStorageClassCmdLine + diff --git a/xroot_plugins/ParsedCreateStorageClassCmdLine.cpp b/xroot_plugins/ParsedCreateStorageClassCmdLine.cpp index c70efdd3521fa6490199629302669ce49448bdab..894682037a3e345284247b8464d08310f6a2b025 100644 --- a/xroot_plugins/ParsedCreateStorageClassCmdLine.cpp +++ b/xroot_plugins/ParsedCreateStorageClassCmdLine.cpp @@ -3,7 +3,7 @@ //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -ParsedCreateStorageClassCmdLine::ParsedCreateStorageClassCmdLine() throw() +ParsedCreateStorageClassCmdLine::ParsedCreateStorageClassCmdLine() throw(): numberOfCopies(0) { } diff --git a/xroot_plugins/ParsedCreateStorageClassCmdLine.hpp b/xroot_plugins/ParsedCreateStorageClassCmdLine.hpp index 70d8a7ac916798e1f4662b1c2464541c6ce48e28..a573e27fc3b948f2d17536ca9115c1b5706e2b3f 100644 --- a/xroot_plugins/ParsedCreateStorageClassCmdLine.hpp +++ b/xroot_plugins/ParsedCreateStorageClassCmdLine.hpp @@ -15,6 +15,11 @@ struct ParsedCreateStorageClassCmdLine { */ std::string storageClassName; + /** + * The number of copies on tape + */ + int numberOfCopies; + /** * Constructor. */ diff --git a/xroot_plugins/ParsedDeleteStorageClassCmdLine.cpp b/xroot_plugins/ParsedDeleteStorageClassCmdLine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..80c1730a24cdb98563a90cd9fd3fa5d3fc4205f9 --- /dev/null +++ b/xroot_plugins/ParsedDeleteStorageClassCmdLine.cpp @@ -0,0 +1,9 @@ +#include "ParsedDeleteStorageClassCmdLine.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +ParsedDeleteStorageClassCmdLine::ParsedDeleteStorageClassCmdLine() throw() +{ + +} diff --git a/xroot_plugins/ParsedDeleteStorageClassCmdLine.hpp b/xroot_plugins/ParsedDeleteStorageClassCmdLine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..72756f976ed7c10cbc9c39212a6ff6dcdf2e7af7 --- /dev/null +++ b/xroot_plugins/ParsedDeleteStorageClassCmdLine.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "XrdOuc/XrdOucString.hh" + +#include <list> +#include <string> + +/** + * Data type used to store the results of parsing the delete-storage-class command-line. + */ +struct ParsedDeleteStorageClassCmdLine { + + /** + * The storage class name + */ + std::string storageClassName; + + /** + * Constructor. + */ + ParsedDeleteStorageClassCmdLine() throw(); + +}; // struct ParsedDeleteStorageClassCmdLine + diff --git a/xroot_plugins/ParsedMkdirCmdLine.cpp b/xroot_plugins/ParsedMkdirCmdLine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a773c6ea312a64fe7abf83053ab4f3520a26e046 --- /dev/null +++ b/xroot_plugins/ParsedMkdirCmdLine.cpp @@ -0,0 +1,9 @@ +#include "ParsedMkdirCmdLine.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +ParsedMkdirCmdLine::ParsedMkdirCmdLine() throw() +{ + +} diff --git a/xroot_plugins/ParsedMkdirCmdLine.hpp b/xroot_plugins/ParsedMkdirCmdLine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4a239a6f98f7e0cb20237875a56eae4d439b53f2 --- /dev/null +++ b/xroot_plugins/ParsedMkdirCmdLine.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "XrdOuc/XrdOucString.hh" + +#include <list> +#include <string> + +/** + * Data type used to store the results of parsing the mkdir command-line. + */ +struct ParsedMkdirCmdLine { + + /** + * The directory name + */ + std::string dirName; + + /** + * Constructor. + */ + ParsedMkdirCmdLine() throw(); + +}; // struct ParsedMkdirCmdLine + diff --git a/xroot_plugins/ParsedRmdirCmdLine.cpp b/xroot_plugins/ParsedRmdirCmdLine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edf69858793f40d0430ac6250ce0bb8c53e57be2 --- /dev/null +++ b/xroot_plugins/ParsedRmdirCmdLine.cpp @@ -0,0 +1,9 @@ +#include "ParsedRmdirCmdLine.hpp" + +//------------------------------------------------------------------------------ +// constructor +//------------------------------------------------------------------------------ +ParsedRmdirCmdLine::ParsedRmdirCmdLine() throw() +{ + +} diff --git a/xroot_plugins/ParsedRmdirCmdLine.hpp b/xroot_plugins/ParsedRmdirCmdLine.hpp new file mode 100644 index 0000000000000000000000000000000000000000..95594d04e2887a14cb89b44332903dbcb2f9d59e --- /dev/null +++ b/xroot_plugins/ParsedRmdirCmdLine.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "XrdOuc/XrdOucString.hh" + +#include <list> +#include <string> + +/** + * Data type used to store the results of parsing the rmdir command-line. + */ +struct ParsedRmdirCmdLine { + + /** + * The directory name + */ + std::string dirName; + + /** + * Constructor. + */ + ParsedRmdirCmdLine() throw(); + +}; // struct ParsedRmdirCmdLine + diff --git a/xroot_plugins/XrdProFilesystem.cpp b/xroot_plugins/XrdProFilesystem.cpp index 772cb211a53df0f44a462e27891361b4c525c23e..9b71f49d6aa064db3842e08f5981b6e7e0ea0602 100644 --- a/xroot_plugins/XrdProFilesystem.cpp +++ b/xroot_plugins/XrdProFilesystem.cpp @@ -123,7 +123,9 @@ int XrdProFilesystem::parseCreateStorageClassRequest(const XrdSfsFSctl &args, Pa getline(ss, s, '?'); getline(ss, s, '+'); cmdLine.storageClassName = s; - if(cmdLine.storageClassName.empty()) { + getline(ss, s, '+'); + cmdLine.numberOfCopies = atoi(s.c_str()); + if(cmdLine.storageClassName.empty() || cmdLine.numberOfCopies==0) { eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); return SFS_ERROR; } @@ -136,6 +138,110 @@ int XrdProFilesystem::parseCreateStorageClassRequest(const XrdSfsFSctl &args, Pa int XrdProFilesystem::executeCreateStorageClassCommand(ParsedCreateStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { std::cout << "create-storage-class request received:\n"; std::cout << "NAME: " << cmdLine.storageClassName << std::endl; + std::cout << "Number of copies on tape: " << cmdLine.numberOfCopies << std::endl; + return SFS_OK; +} + +//------------------------------------------------------------------------------ +// parseChangeStorageClassRequest +//------------------------------------------------------------------------------ +int XrdProFilesystem::parseChangeStorageClassRequest(const XrdSfsFSctl &args, ParsedChangeStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::stringstream ss(args.Arg1); + std::string s; + getline(ss, s, '?'); + getline(ss, s, '+'); + cmdLine.dirName = s; + getline(ss, s, '+'); + cmdLine.storageClassName = s; + if(cmdLine.storageClassName.empty() || cmdLine.dirName.empty()) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); + return SFS_ERROR; + } + return SFS_OK; +} + +//------------------------------------------------------------------------------ +// executeCreateStorageClassCommand +//------------------------------------------------------------------------------ +int XrdProFilesystem::executeChangeStorageClassCommand(ParsedChangeStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::cout << "change-storage-class request received:\n"; + std::cout << "DIR: " << cmdLine.dirName << std::endl; + std::cout << "NAME: " << cmdLine.storageClassName << std::endl; + return SFS_OK; +} + +//------------------------------------------------------------------------------ +// parseDeleteStorageClassRequest +//------------------------------------------------------------------------------ +int XrdProFilesystem::parseDeleteStorageClassRequest(const XrdSfsFSctl &args, ParsedDeleteStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::stringstream ss(args.Arg1); + std::string s; + getline(ss, s, '?'); + getline(ss, s, '+'); + cmdLine.storageClassName = s; + if(cmdLine.storageClassName.empty()) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); + return SFS_ERROR; + } + return SFS_OK; +} + +//------------------------------------------------------------------------------ +// executeDeleteStorageClassCommand +//------------------------------------------------------------------------------ +int XrdProFilesystem::executeDeleteStorageClassCommand(ParsedDeleteStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::cout << "delete-storage-class request received:\n"; + std::cout << "NAME: " << cmdLine.storageClassName << std::endl; + return SFS_OK; +} + +//------------------------------------------------------------------------------ +// parseMkdirRequest +//------------------------------------------------------------------------------ +int XrdProFilesystem::parseMkdirRequest(const XrdSfsFSctl &args, ParsedMkdirCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::stringstream ss(args.Arg1); + std::string s; + getline(ss, s, '?'); + getline(ss, s, '+'); + cmdLine.dirName = s; + if(cmdLine.dirName.empty()) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); + return SFS_ERROR; + } + return SFS_OK; +} + +//------------------------------------------------------------------------------ +// executeMkdirCommand +//------------------------------------------------------------------------------ +int XrdProFilesystem::executeMkdirCommand(ParsedMkdirCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::cout << "mkdir request received:\n"; + std::cout << "DIR: " << cmdLine.dirName << std::endl; + return SFS_OK; +} + +//------------------------------------------------------------------------------ +// parseRmdirRequest +//------------------------------------------------------------------------------ +int XrdProFilesystem::parseRmdirRequest(const XrdSfsFSctl &args, ParsedRmdirCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::stringstream ss(args.Arg1); + std::string s; + getline(ss, s, '?'); + getline(ss, s, '+'); + cmdLine.dirName = s; + if(cmdLine.dirName.empty()) { + eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied"); + return SFS_ERROR; + } + return SFS_OK; +} + +//------------------------------------------------------------------------------ +// executeRmdirCommand +//------------------------------------------------------------------------------ +int XrdProFilesystem::executeRmdirCommand(ParsedRmdirCmdLine &cmdLine, XrdOucErrInfo &eInfo) { + std::cout << "rmdir request received:\n"; + std::cout << "DIR: " << cmdLine.dirName << std::endl; return SFS_OK; } @@ -168,6 +274,58 @@ int XrdProFilesystem::dispatchRequest(XrdSfsFSctl &args, XrdOucErrInfo &eInfo) { return checkExecute; } return SFS_OK; + } + else if(strncmp(args.Arg1, "/change-storage-class?", strlen("/change-storage-class?")) == 0) + { + ParsedChangeStorageClassCmdLine cmdLine; + int checkParse = parseChangeStorageClassRequest(args, cmdLine, eInfo); + if(SFS_OK!=checkParse) { + return checkParse; + } + int checkExecute = executeChangeStorageClassCommand(cmdLine, eInfo); + if(SFS_OK!=checkExecute) { + return checkExecute; + } + return SFS_OK; + } + else if(strncmp(args.Arg1, "/delete-storage-class?", strlen("/delete-storage-class?")) == 0) + { + ParsedDeleteStorageClassCmdLine cmdLine; + int checkParse = parseDeleteStorageClassRequest(args, cmdLine, eInfo); + if(SFS_OK!=checkParse) { + return checkParse; + } + int checkExecute = executeDeleteStorageClassCommand(cmdLine, eInfo); + if(SFS_OK!=checkExecute) { + return checkExecute; + } + return SFS_OK; + } + else if(strncmp(args.Arg1, "/mkdir?", strlen("/mkdir?")) == 0) + { + ParsedMkdirCmdLine cmdLine; + int checkParse = parseMkdirRequest(args, cmdLine, eInfo); + if(SFS_OK!=checkParse) { + return checkParse; + } + int checkExecute = executeMkdirCommand(cmdLine, eInfo); + if(SFS_OK!=checkExecute) { + return checkExecute; + } + return SFS_OK; + } + else if(strncmp(args.Arg1, "/rmdir?", strlen("/rmdir?")) == 0) + { + ParsedRmdirCmdLine cmdLine; + int checkParse = parseRmdirRequest(args, cmdLine, eInfo); + if(SFS_OK!=checkParse) { + return checkParse; + } + int checkExecute = executeRmdirCommand(cmdLine, eInfo); + if(SFS_OK!=checkExecute) { + return checkExecute; + } + return SFS_OK; } else { diff --git a/xroot_plugins/XrdProFilesystem.hpp b/xroot_plugins/XrdProFilesystem.hpp index e39d153ebb527de1af38973f43a71827b20d23c0..2cd194ea4f9b49749c6b19e6e01fa11f1253d950 100644 --- a/xroot_plugins/XrdProFilesystem.hpp +++ b/xroot_plugins/XrdProFilesystem.hpp @@ -4,6 +4,10 @@ #include "ParsedArchiveCmdLine.hpp" #include "ParsedCreateStorageClassCmdLine.hpp" +#include "ParsedDeleteStorageClassCmdLine.hpp" +#include "ParsedChangeStorageClassCmdLine.hpp" +#include "ParsedMkdirCmdLine.hpp" +#include "ParsedRmdirCmdLine.hpp" class XrdProFilesystem : public XrdSfsFileSystem { public: @@ -86,6 +90,82 @@ protected: */ int executeCreateStorageClassCommand(ParsedCreateStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + /** + * Parses the change-storage-class request into the command line structure + * + * @param args the request string + * @param cmdLine the resulting command line structure + * @param eInfo Error information + * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise + */ + int parseChangeStorageClassRequest(const XrdSfsFSctl &args, ParsedChangeStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + + /** + * Executes the command contained within the command line structure + * + * @param cmdLine command to execute + * @param eInfo Error information + * @return SFS_OK in case executed correctly, SFS_ERROR otherwise + */ + int executeChangeStorageClassCommand(ParsedChangeStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + + /** + * Parses the delete-storage-class request into the command line structure + * + * @param args the request string + * @param cmdLine the resulting command line structure + * @param eInfo Error information + * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise + */ + int parseDeleteStorageClassRequest(const XrdSfsFSctl &args, ParsedDeleteStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + + /** + * Executes the command contained within the command line structure + * + * @param cmdLine command to execute + * @param eInfo Error information + * @return SFS_OK in case executed correctly, SFS_ERROR otherwise + */ + int executeDeleteStorageClassCommand(ParsedDeleteStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo); + + /** + * Parses the mkdir request into the command line structure + * + * @param args the request string + * @param cmdLine the resulting command line structure + * @param eInfo Error information + * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise + */ + int parseMkdirRequest(const XrdSfsFSctl &args, ParsedMkdirCmdLine &cmdLine, XrdOucErrInfo &eInfo); + + /** + * Executes the command contained within the command line structure + * + * @param cmdLine command to execute + * @param eInfo Error information + * @return SFS_OK in case executed correctly, SFS_ERROR otherwise + */ + int executeMkdirCommand(ParsedMkdirCmdLine &cmdLine, XrdOucErrInfo &eInfo); + + /** + * Parses the rmdir request into the command line structure + * + * @param args the request string + * @param cmdLine the resulting command line structure + * @param eInfo Error information + * @return SFS_OK in case parsing is done correctly, SFS_ERROR otherwise + */ + int parseRmdirRequest(const XrdSfsFSctl &args, ParsedRmdirCmdLine &cmdLine, XrdOucErrInfo &eInfo); + + /** + * Executes the command contained within the command line structure + * + * @param cmdLine command to execute + * @param eInfo Error information + * @return SFS_OK in case executed correctly, SFS_ERROR otherwise + */ + int executeRmdirCommand(ParsedRmdirCmdLine &cmdLine, XrdOucErrInfo &eInfo); + /** * Dispatches the request based on the query *