Skip to content
Snippets Groups Projects
Commit abb19888 authored by Daniele Kruse's avatar Daniele Kruse
Browse files

Added the create storage class command plus refactoring

parent 05e3687b
Branches
Tags
No related merge requests found
......@@ -4,5 +4,5 @@ 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_executable (xrd_pro_client xrd_pro_client.cpp ArchiveCmd.cpp ../xroot_utils/ParsedArchiveCmdLine.cpp)
target_link_libraries (xrd_pro_client ${XROOTD_XRDCL_LIB})
add_executable (CTA_cmd CTACmdMain.cpp CTACmd.cpp)
target_link_libraries (CTA_cmd ${XROOTD_XRDCL_LIB})
#include "ArchiveCmd.hpp"
#include "CTACmd.hpp"
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdOuc/XrdOucString.hh"
......@@ -10,67 +10,33 @@
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
ArchiveCmd::ArchiveCmd() throw(): m_programName("xrd_pro_client") {
}
//------------------------------------------------------------------------------
// parseCommandLine
//------------------------------------------------------------------------------
void ArchiveCmd::parseCommandLine(const int argc, char **argv) {
if(argc < 3) {
throw wrongArgumentsException();
}
m_cmdLine.dstPath = argv[argc-1];
for(int i=1; i<argc-1; i++) {
m_cmdLine.srcFiles.push_back(argv[i]);
}
CTACmd::CTACmd() throw(): m_programName("CTA_cmd") {
}
//------------------------------------------------------------------------------
// usage
//------------------------------------------------------------------------------
void ArchiveCmd::usage(std::ostream &os) const throw() {
void CTACmd::usage(std::ostream &os) const throw() {
os <<
"Usage:\n"
"\t" << m_programName << " <source_file> <destination_file>\n"
"Or:\n"
"\t" << m_programName << " <source_file1> [<source_file2> [<source_file3> [...]]] <destination_dir>\n"
"Where:\n"
"\t<source_fileX> Full path of the source file(s)\n"
"\t<destination_file> Full path of the destination file\n"
"\t<destination_dir> Full path of the destination directory (must end with a /)\n";
"\t" << m_programName << " archive <source_file1> [<source_file2> [<source_file3> [...]]] <destination_path>\n";
}
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int ArchiveCmd::main(const int argc, char **argv) throw() {
// Parse the command line
try {
parseCommandLine(argc, argv);
} catch (std::exception &ex) {
std::cerr
<< std::endl
<< "Failed to parse the command-line:\n\n"
<< ex.what() << std::endl
<< std::endl;
int CTACmd::main(const int argc, char **argv) throw() {
if(argc < 3) {
usage(std::cerr);
std::cerr << std::endl;
return 1;
}
int rc = 1;
// Execute the command
try {
rc = executeCommand();
rc = executeCommand(argc, argv);
} catch(std::exception &ex) {
std::cerr
<< std::endl
<< "Failed to execute the archive command:\n\n"
<< ex.what() << std::endl
<< std::endl;
std::cerr << std::endl << "Failed to execute the archive command:\n\n" << ex.what() << std::endl;
return 1;
}
......@@ -80,16 +46,17 @@ int ArchiveCmd::main(const int argc, char **argv) throw() {
//------------------------------------------------------------------------------
// executeCommand
//------------------------------------------------------------------------------
int ArchiveCmd::executeCommand() {
int CTACmd::executeCommand(const int argc, char **argv) {
XrdCl::FileSystem fs(XrdCl::URL("localhost"));
std::string queryString = "/archive?";
for(std::list<std::string>::iterator it = m_cmdLine.srcFiles.begin(); it != m_cmdLine.srcFiles.end(); it++) {
queryString += *it;
std::string queryString = "/";
queryString += argv[1];
queryString += "?";
for(int i=2; i<argc-1; i++) {
queryString += argv[i];
queryString += "+";
}
queryString += m_cmdLine.dstPath;
queryString += argv[argc-1];
XrdCl::Buffer arg;
arg.FromString(queryString.c_str());
......
#pragma once
#include "xroot_utils/ParsedArchiveCmdLine.hpp"
#include <exception>
#include <istream>
#include <ostream>
#include <string>
struct wrongArgumentsException : public std::exception
{
const char * what() const throw()
{
return "Wrong arguments supplied";
}
};
/**
* Class implementing the business logic of the archive command-line tool.
*/
class ArchiveCmd {
class CTACmd {
public:
/**
* Constructor.
*/
ArchiveCmd() throw();
CTACmd() throw();
/**
* The entry function of the command.
......@@ -39,19 +29,6 @@ protected:
* The name of the program.
*/
const std::string m_programName;
/**
* The command line structure
*/
ParsedArchiveCmdLine m_cmdLine;
/**
* Parses the specified command-line arguments.
*
* @param argc Argument count from the executable's entry function: main().
* @param argv Argument vector from the executable's entry function: main().
*/
void parseCommandLine(const int argc, char **argv);
/**
* Writes the command-line usage message of to the specified output stream.
......@@ -62,9 +39,11 @@ protected:
/**
* Sends the archive request and waits for the reply
*
*
* @param argc The number of command-line arguments.
* @param argv The command-line arguments.
* @return the return code
*/
int executeCommand() ;
int executeCommand(const int argc, char **argv) ;
}; // class LabelCmd
#include "ArchiveCmd.hpp"
#include "CTACmd.hpp"
//------------------------------------------------------------------------------
// main
//------------------------------------------------------------------------------
int main(int argc, char **argv) {
ArchiveCmd command;
CTACmd command;
return command.main(argc, argv);
}
......@@ -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 ../xroot_utils/ParsedArchiveCmdLine.cpp)
add_library (XrdProFst MODULE XrdProFilesystem.cpp ParsedArchiveCmdLine.cpp ParsedCreateStorageClassCmdLine.cpp)
#include "ParsedCreateStorageClassCmdLine.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
ParsedCreateStorageClassCmdLine::ParsedCreateStorageClassCmdLine() throw()
{
}
#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 ParsedCreateStorageClassCmdLine {
/**
* The storage class name
*/
std::string storageClassName;
/**
* Constructor.
*/
ParsedCreateStorageClassCmdLine() throw();
}; // struct ParsedCreateStorageClassCmdLine
......@@ -31,7 +31,7 @@ bool XrdProFilesystem::isDir(const char *path) throw() {
//------------------------------------------------------------------------------
// checkClient
//------------------------------------------------------------------------------
int XrdProFilesystem::checkClient(XrdOucErrInfo &eInfo, const XrdSecEntity *client) {
int XrdProFilesystem::checkClient(const XrdSecEntity *client, XrdOucErrInfo &eInfo) {
/*
std::cout << "Calling FSctl with:\ncmd=" << cmd << "\narg=" << args.Arg1 << std::endl;
std::cout << "Client info:\n"
......@@ -86,30 +86,27 @@ int XrdProFilesystem::checkClient(XrdOucErrInfo &eInfo, const XrdSecEntity *clie
//------------------------------------------------------------------------------
// parseArchiveRequest
//------------------------------------------------------------------------------
int XrdProFilesystem::parseArchiveRequest(const XrdSfsFSctl &args, ParsedArchiveCmdLine &cmdLine) {
if(strncmp(args.Arg1, "/archive?", strlen("/archive?")) == 0)
{
std::stringstream ss(args.Arg1);
std::string s;
getline(ss, s, '?');
while (getline(ss, s, '+')) {
cmdLine.srcFiles.push_back(s);
}
cmdLine.srcFiles.pop_back();
cmdLine.dstPath = s;
return SFS_OK;
int XrdProFilesystem::parseArchiveRequest(const XrdSfsFSctl &args, ParsedArchiveCmdLine &cmdLine, XrdOucErrInfo &eInfo) {
std::stringstream ss(args.Arg1);
std::string s;
getline(ss, s, '?');
while (getline(ss, s, '+')) {
cmdLine.srcFiles.push_back(s);
}
else
{
std::cout << "[ERROR] Unknown plugin request string received" << std::endl;
cmdLine.srcFiles.pop_back();
cmdLine.dstPath = s;
if(cmdLine.srcFiles.empty() || cmdLine.dstPath.empty()) {
eInfo.setErrInfo(EINVAL, "[ERROR] Wrong arguments supplied");
return SFS_ERROR;
}
return SFS_OK;
}
//------------------------------------------------------------------------------
// executeArchiveCommand
//------------------------------------------------------------------------------
int XrdProFilesystem::executeArchiveCommand(ParsedArchiveCmdLine &cmdLine) {
int XrdProFilesystem::executeArchiveCommand(ParsedArchiveCmdLine &cmdLine, XrdOucErrInfo &eInfo) {
std::cout << "archive request received:\n";
for(std::list<std::string>::iterator it = cmdLine.srcFiles.begin(); it != cmdLine.srcFiles.end(); it++) {
std::cout << "SRC: " << *it << std::endl;
}
......@@ -117,28 +114,90 @@ int XrdProFilesystem::executeArchiveCommand(ParsedArchiveCmdLine &cmdLine) {
return SFS_OK;
}
//------------------------------------------------------------------------------
// parseCreateStorageClassRequest
//------------------------------------------------------------------------------
int XrdProFilesystem::parseCreateStorageClassRequest(const XrdSfsFSctl &args, ParsedCreateStorageClassCmdLine &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;
}
//------------------------------------------------------------------------------
// executeCreateStorageClassCommand
//------------------------------------------------------------------------------
int XrdProFilesystem::executeCreateStorageClassCommand(ParsedCreateStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo) {
std::cout << "create-storage-class request received:\n";
std::cout << "NAME: " << cmdLine.storageClassName << std::endl;
return SFS_OK;
}
//------------------------------------------------------------------------------
// dispatchRequest
//------------------------------------------------------------------------------
int XrdProFilesystem::dispatchRequest(XrdSfsFSctl &args, XrdOucErrInfo &eInfo) {
if(strncmp(args.Arg1, "/archive?", strlen("/archive?")) == 0)
{
ParsedArchiveCmdLine cmdLine;
int checkParse = parseArchiveRequest(args, cmdLine, eInfo);
if(SFS_OK!=checkParse) {
return checkParse;
}
int checkExecute = executeArchiveCommand(cmdLine, eInfo);
if(SFS_OK!=checkExecute) {
return checkExecute;
}
return SFS_OK;
}
else if(strncmp(args.Arg1, "/create-storage-class?", strlen("/create-storage-class?")) == 0)
{
ParsedCreateStorageClassCmdLine cmdLine;
int checkParse = parseCreateStorageClassRequest(args, cmdLine, eInfo);
if(SFS_OK!=checkParse) {
return checkParse;
}
int checkExecute = executeCreateStorageClassCommand(cmdLine, eInfo);
if(SFS_OK!=checkExecute) {
return checkExecute;
}
return SFS_OK;
}
else
{
eInfo.setErrInfo(EINVAL, "[ERROR] Unknown plugin request string received");
return SFS_ERROR;
}
}
//------------------------------------------------------------------------------
// FSctl
//------------------------------------------------------------------------------
int XrdProFilesystem::FSctl(const int cmd, XrdSfsFSctl &args, XrdOucErrInfo &eInfo, const XrdSecEntity *client)
{
int checkResult = checkClient(eInfo, client);
if(checkResult!=SFS_OK){
return SFS_ERROR;
int checkResult = checkClient(client, eInfo);
if(SFS_OK!=checkResult) {
return checkResult;
}
if(cmd == SFS_FSCTL_PLUGIO)
{
ParsedArchiveCmdLine cmdLine;
parseArchiveRequest(args, cmdLine);
executeArchiveCommand(cmdLine);
int checkDispatch = dispatchRequest(args, eInfo);
if(SFS_OK!=checkDispatch) {
return checkDispatch;
}
std::string response = "Request logged!";
eInfo.setErrInfo(response.length(), response.c_str());
return SFS_DATA;
}
else
{
std::cout << "[ERROR] Unknown query request received" << std::endl;
eInfo.setErrInfo(EINVAL, "[ERROR] Unknown query request received");
return SFS_ERROR;
}
}
......
......@@ -2,7 +2,8 @@
#include "XrdSfs/XrdSfsInterface.hh"
#include "xroot_utils/ParsedArchiveCmdLine.hpp"
#include "ParsedArchiveCmdLine.hpp"
#include "ParsedCreateStorageClassCmdLine.hpp"
class XrdProFilesystem : public XrdSfsFileSystem {
public:
......@@ -41,26 +42,56 @@ protected:
/**
* Checks whether client has correct permissions
*
* @param eInfo Error information
* @param client client information
* @param eInfo Error information
* @return SFS_OK in case check is passed, SFS_ERROR otherwise
*/
int checkClient(XrdOucErrInfo &eInfo, const XrdSecEntity *client);
int checkClient(const XrdSecEntity *client, XrdOucErrInfo &eInfo);
/**
* Parses the archive request into the command line structure
*
* @param args the archive request string
* @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 parseArchiveRequest(const XrdSfsFSctl &args, ParsedArchiveCmdLine &cmdLine);
int parseArchiveRequest(const XrdSfsFSctl &args, ParsedArchiveCmdLine &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 executeArchiveCommand(ParsedArchiveCmdLine &cmdLine);
int executeArchiveCommand(ParsedArchiveCmdLine &cmdLine, XrdOucErrInfo &eInfo);
/**
* Parses the create-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 parseCreateStorageClassRequest(const XrdSfsFSctl &args, ParsedCreateStorageClassCmdLine &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 executeCreateStorageClassCommand(ParsedCreateStorageClassCmdLine &cmdLine, XrdOucErrInfo &eInfo);
/**
* Dispatches the request based on the query
*
* @param args the archive request string
* @param eInfo Error information
* @return SFS_OK in case dispatching is done correctly, SFS_ERROR otherwise
*/
int dispatchRequest(XrdSfsFSctl &args, XrdOucErrInfo &eInfo);
};
\ No newline at end of file
make_minimum_required (VERSION 2.6)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment