diff --git a/libs/client/CMakeLists.txt b/libs/client/CMakeLists.txt index e128d00bfd392c59a3b5838f4bd7e7c3d87a0b3e..7c9a5a51982e55fa648f582148af0d16bab3dca6 100644 --- a/libs/client/CMakeLists.txt +++ b/libs/client/CMakeLists.txt @@ -6,7 +6,7 @@ set (CLIENT_LIB_SRC_FILES DirectoryIterator.cpp Exception.cpp MockClientAPI.cpp - MockAPITest.cpp +# MockAPITest.cpp StorageClass.cpp) add_library (ctaclient SHARED diff --git a/xroot_clients/CTACmd.cpp b/xroot_clients/CTACmd.cpp index eb1e47d7f88fd8250197b380fc5feb65e956f22a..d1aeebc62af6590061d20dec80d3b2607749d1a0 100644 --- a/xroot_clients/CTACmd.cpp +++ b/xroot_clients/CTACmd.cpp @@ -57,13 +57,14 @@ int CTACmd::executeCommand(const int argc, char **argv) { XrdCl::FileSystem fs(XrdCl::URL("localhost")); std::string queryString = "/"; queryString += argv[1]; - queryString += "?"; - for(int i=2; i<argc-1; i++) { - queryString += argv[i]; - queryString += "+"; - } - queryString += argv[argc-1]; - + queryString += "?"; + if(argc > 2) { + for(int i=2; i<argc-1; i++) { + queryString += argv[i]; + queryString += "+"; + } + queryString += argv[argc-1]; + } XrdCl::Buffer arg; arg.FromString(queryString.c_str()); XrdCl::Buffer* response = 0; diff --git a/xroot_plugins/CMakeLists.txt b/xroot_plugins/CMakeLists.txt index c33b24a1f9c5d119e6ae3d8f0801d2c3a1969bf0..c68aefd0003dec650b499938fa7d8a8c1aa68085 100644 --- a/xroot_plugins/CMakeLists.txt +++ b/xroot_plugins/CMakeLists.txt @@ -5,3 +5,4 @@ find_package (xrootd REQUIRED) include_directories (${XROOTD_INCLUDE_DIR} ${XROOTD_PRIVATE_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}) add_library (XrdProFst MODULE XrdProFilesystem.cpp ParsedRequest.cpp) +target_link_libraries (XrdProFst ctaclient) \ No newline at end of file diff --git a/xroot_plugins/XrdProFilesystem.cpp b/xroot_plugins/XrdProFilesystem.cpp index 9453fc26eb82cd6a1032de546e7aea86a1099fd0..02ca09501dc03b44656992a39edd21322b514472 100644 --- a/xroot_plugins/XrdProFilesystem.cpp +++ b/xroot_plugins/XrdProFilesystem.cpp @@ -3,6 +3,7 @@ #include "XrdOuc/XrdOucString.hh" #include "XrdSec/XrdSecEntity.hh" #include "XrdVersion.hh" +#include "libs/client/Exception.hpp" #include <iostream> #include <pwd.h> @@ -99,17 +100,37 @@ int XrdProFilesystem::executeArchiveCommand(ParsedRequest &req, XrdOucErrInfo &e eInfo.setErrInfo(response.length(), response.c_str()); return SFS_DATA; } - std::string response = "[OK] Requested archival of the following files:\n"; - for(int i=0; i<req.args.size()-1; i++) { + try { + std::list<std::string> sourceFiles; + std::string destinationPath = req.args.at(req.args.size()-1); + for(int i=0; i<req.args.size()-1; i++) { + sourceFiles.push_back(req.args.at(i)); + } + std::string jobID = m_clientAPI->archiveToTape(sourceFiles, destinationPath); + std::string response = "[OK] Requested archival of the following files:\n\n"; + for(std::list<std::string>::iterator it = sourceFiles.begin(); it != sourceFiles.end(); it++) { + response += "[OK]\t"; + response += *it; + response += "\n"; + } + response += "\n[OK] To the following directory:\n\n"; response += "[OK]\t"; - response += req.args.at(i); - response += "\n"; - } - response += "[OK] To the following directory:\n"; - response += "[OK]\t"; - response += req.args.at(req.args.size()-1); - eInfo.setErrInfo(response.length(), response.c_str()); - return SFS_DATA; + response += destinationPath; + response += "\n\n[OK] JobID: "; + response += jobID; + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } } //------------------------------------------------------------------------------ @@ -121,13 +142,29 @@ int XrdProFilesystem::executeCreateStorageClassCommand(ParsedRequest &req, XrdOu eInfo.setErrInfo(response.length(), response.c_str()); return SFS_DATA; } - std::string response = "[OK] Created storage class "; - response += req.args.at(0); - response += " with "; - response += req.args.at(1); - response += " tape copies"; - eInfo.setErrInfo(response.length(), response.c_str()); - return SFS_DATA; + try { + uint8_t numberOfCopies; + std::istringstream ss(req.args.at(1)); + ss >> numberOfCopies; + m_clientAPI->createStorageClass(req.args.at(0), numberOfCopies); + std::string response = "[OK] Created storage class "; + response += req.args.at(0); + response += " with "; + response += req.args.at(1); + response += " tape copies"; + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } } //------------------------------------------------------------------------------ @@ -139,12 +176,24 @@ int XrdProFilesystem::executeChangeStorageClassCommand(ParsedRequest &req, XrdOu eInfo.setErrInfo(response.length(), response.c_str()); return SFS_DATA; } - std::string response = "[OK] Changed storage class of directory "; - response += req.args.at(0); - response += " to "; - response += req.args.at(1); - eInfo.setErrInfo(response.length(), response.c_str()); - return SFS_DATA; + try { + std::string response = "[OK] Changed storage class of directory "; + response += req.args.at(0); + response += " to "; + response += req.args.at(1); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } } //------------------------------------------------------------------------------ @@ -156,11 +205,24 @@ int XrdProFilesystem::executeDeleteStorageClassCommand(ParsedRequest &req, XrdOu eInfo.setErrInfo(response.length(), response.c_str()); return SFS_DATA; } - std::string response = "[OK] Storage class "; - response += req.args.at(0); - response += " deleted"; - eInfo.setErrInfo(response.length(), response.c_str()); - return SFS_DATA; + try { + m_clientAPI->deleteStorageClass(req.args.at(0)); + std::string response = "[OK] Storage class "; + response += req.args.at(0); + response += " deleted"; + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } } //------------------------------------------------------------------------------ @@ -172,9 +234,28 @@ int XrdProFilesystem::executeListStorageClassCommand(ParsedRequest &req, XrdOucE eInfo.setErrInfo(response.length(), response.c_str()); return SFS_DATA; } - std::string response = "[OK] Requested listing of the storage classes"; - eInfo.setErrInfo(response.length(), response.c_str()); - return SFS_DATA; + try { + cta::StorageClassList stgList = m_clientAPI->getStorageClasses(); + std::string response = "[OK] Listing of the storage class names and no of copies:"; + for(cta::StorageClassList::iterator it = stgList.begin(); it != stgList.end(); it++) { + response += "\n"; + response += it->name; + response += " "; + response += it->nbCopies; + } + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } } //------------------------------------------------------------------------------ @@ -186,11 +267,23 @@ int XrdProFilesystem::executeMkdirCommand(ParsedRequest &req, XrdOucErrInfo &eIn eInfo.setErrInfo(response.length(), response.c_str()); return SFS_DATA; } - std::string response = "[OK] Directory "; - response += req.args.at(0); - response += " created"; - eInfo.setErrInfo(response.length(), response.c_str()); - return SFS_DATA; + try { + std::string response = "[OK] Directory "; + response += req.args.at(0); + response += " created"; + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } } //------------------------------------------------------------------------------ @@ -202,11 +295,23 @@ int XrdProFilesystem::executeRmdirCommand(ParsedRequest &req, XrdOucErrInfo &eIn eInfo.setErrInfo(response.length(), response.c_str()); return SFS_DATA; } - std::string response = "[OK] Directory "; - response += req.args.at(0); - response += " removed"; - eInfo.setErrInfo(response.length(), response.c_str()); - return SFS_DATA; + try { + std::string response = "[OK] Directory "; + response += req.args.at(0); + response += " removed"; + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (cta::Exception &ex) { + std::string response = "[ERROR] CTA exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } catch (std::exception &ex) { + std::string response = "[ERROR] Exception caught: "; + response += ex.what(); + eInfo.setErrInfo(response.length(), response.c_str()); + return SFS_DATA; + } } //------------------------------------------------------------------------------ @@ -449,9 +554,13 @@ void XrdProFilesystem::EnvInfo(XrdOucEnv *envP) //------------------------------------------------------------------------------ // constructor //------------------------------------------------------------------------------ -XrdProFilesystem::XrdProFilesystem() {} +XrdProFilesystem::XrdProFilesystem() { + m_clientAPI = new cta::MockClientAPI(); +} //------------------------------------------------------------------------------ // destructor //------------------------------------------------------------------------------ -XrdProFilesystem::~XrdProFilesystem() {} \ No newline at end of file +XrdProFilesystem::~XrdProFilesystem() { + delete m_clientAPI; +} \ No newline at end of file diff --git a/xroot_plugins/XrdProFilesystem.hpp b/xroot_plugins/XrdProFilesystem.hpp index d679c3e9327d99a5187c11bfd46f5a9a36979d1e..94c96ddd73b66176713dd9831e585aa75387c7b2 100644 --- a/xroot_plugins/XrdProFilesystem.hpp +++ b/xroot_plugins/XrdProFilesystem.hpp @@ -1,5 +1,6 @@ #pragma once +#include "libs/client/MockClientAPI.hpp" #include "XrdSfs/XrdSfsInterface.hh" #include "ParsedRequest.hpp" @@ -29,6 +30,11 @@ public: ~XrdProFilesystem(); protected: + + /** + * Pointer to the client API object + */ + cta::ClientAPI *m_clientAPI; /** * Parses the query into the request structure