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

cta-xrootd_plugins-fakeeos now sends the contents of a binary file

parent 34ef9e8f
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@
#include "xroot_plugins/FakeEosCmdLineArgs.hpp"
#include "xroot_plugins/messages/notification.pb.h"
#include <fstream>
#include <iostream>
#include <stdint.h>
#include <string>
......@@ -53,6 +54,15 @@ int FakeEosCmd::exceptionThrowingMain(const int argc, char *const *const argv) {
return 0;
}
std::ifstream queryFileStream(cmdLineArgs.queryFilename, std::ios_base::binary);
if(!queryFileStream) {
m_err << "Failed to open " << cmdLineArgs.queryFilename << std::endl;
return 1;
}
std::vector<char> queryFileContents(
(std::istreambuf_iterator<char>(queryFileStream)),
(std::istreambuf_iterator<char>()));
const std::string protocol = "xroot";
const std::string fsUrl = protocol + ":" + "//" + cmdLineArgs.ctaHost + ":" + std::to_string(cmdLineArgs.ctaPort);
XrdCl::FileSystem fs(fsUrl, false);
......@@ -112,10 +122,10 @@ int FakeEosCmd::exceptionThrowingMain(const int argc, char *const *const argv) {
(*notification.mutable_directory()->mutable_xattr())["notification_directory_attr1"] = "directory_xattr1_value";
(*notification.mutable_directory()->mutable_xattr())["notification_directory_attr2"] = "directory_xattr2_value";
XrdCl::Buffer arg(cmdLineArgs.queryArg.size());
arg.FromString(cmdLineArgs.queryArg);
XrdCl::Buffer arg;
arg.Append(&queryFileContents[0], queryFileContents.size(), 0);
XrdCl::Buffer *response = nullptr;
const XrdCl::XRootDStatus status = fs.Query(XrdCl::QueryCode::OpaqueFile, arg, response);
const XrdCl::XRootDStatus status = fs.Query(XrdCl::QueryCode::Opaque, arg, response);
std::unique_ptr<XrdCl::Buffer> smartResponse(response);
std::cout << "status.ToStr()=" << status.ToStr() << std::endl;
......
......@@ -98,7 +98,7 @@ FakeEosCmdLineArgs::FakeEosCmdLineArgs(const int argc, char *const *const argv):
} catch(exception::Exception &ex) {
throw exception::Exception(std::string("Invalid CTA port number: " + ex.getMessage().str()));
}
queryArg = argv[optind+2];
queryFilename = argv[optind+2];
}
//------------------------------------------------------------------------------
......@@ -107,12 +107,20 @@ FakeEosCmdLineArgs::FakeEosCmdLineArgs(const int argc, char *const *const argv):
void FakeEosCmdLineArgs::printUsage(std::ostream &os) {
os <<
"Usage:" << std::endl <<
" cta-xroot_plugins-fakeeos [options] ctaHost ctaPort queryArg" << std::endl <<
" cta-xroot_plugins-fakeeos [options] ctaHost ctaPort queryFilename" << std::endl <<
"Where:" << std::endl <<
" ctaHost" << std::endl <<
" The network name of the host on which the CTA front end is running" << std::endl <<
" ctaPort" << std::endl <<
" The TCP/IP port on which the CTA front end is listening for connections" << std::endl <<
" queryFilename" << std::endl <<
" The name of file containing the query blob to be sent to the CTA front end" << std::endl <<
"Options:" << std::endl <<
" -h,--help" << std::endl <<
" Prints this usage message" << std::endl <<
"Example:" << std::endl <<
" cta-xrootd_plugins-fakeeos localhost 10955 /eos_cta_interface" << std::endl;
" echo -n -e 'Hello\\n\\x00World' > query.txt" << std::endl <<
" cta-xrootd_plugins-fakeeos localhost 10955 query.txt" << std::endl;
}
} // namespace xroot_plugins
......
......@@ -41,10 +41,14 @@ struct FakeEosCmdLineArgs {
uint16_t ctaPort;
/**
* The query argument to be sent to teh cTA front end using
* XrdCl::FileSystem::Query().
* The name of the file containing the query argument to be sent to the CTA
* front end using:
*
* XrdCl::FileSystem::Query(XrdCl::QueryCode::Opaque, arg, response)
*
* Where arg is the contents of the named file.
*/
std::string queryArg;
std::string queryFilename;
/**
* True if the usage message should be printed.
......
......@@ -80,8 +80,8 @@ int XrdCtaFilesystem::FSctl(const int cmd, XrdSfsFSctl &args, XrdOucErrInfo &eIn
{
(void)cmd; (void)args; (void)eInfo; (void)client;
if(SFS_FSCTL_PLUGIN != cmd) {
eInfo.setErrInfo(ENOTSUP, "Not supported: cmd != SFS_FSCTL_PLUGIN");
if(SFS_FSCTL_PLUGIO != cmd) {
eInfo.setErrInfo(ENOTSUP, "Not supported: cmd != SFS_FSCTL_PLUGIO");
return SFS_ERROR;
}
......@@ -94,19 +94,21 @@ int XrdCtaFilesystem::FSctl(const int cmd, XrdSfsFSctl &args, XrdOucErrInfo &eIn
arg2[args.Arg2Len] = '\0';
std::list<cta::log::Param> params;
params.push_back({"args.Arg1Len", args.Arg1Len});
params.push_back({"arg1", arg1.get()});
params.push_back({"args.Arg2Len", args.Arg2Len});
params.push_back({"arg2", arg2.get()});
params.push_back({"client->host", client->host});
params.push_back({"client->name", client->name});
(*m_log)(log::INFO, "FSctl called", params);
if(strcmp(arg1.get(), "/eos_cta_interface") && strcmp(arg1.get(), "/eos_cta_interface/")) {
std::ostringstream msg;
msg << arg1.get() << " does not exist";
eInfo.setErrInfo(ENOENT, msg.str().c_str());
return SFS_ERROR;
}
//if(strcmp(arg1.get(), "/eos_cta_interface") && strcmp(arg1.get(), "/eos_cta_interface/")) {
// std::ostringstream msg;
// msg << arg1.get() << " does not exist";
// eInfo.setErrInfo(ENOENT, msg.str().c_str());
// return SFS_ERROR;
//}
const size_t sizeOfMsg = 10*1024*1024;
char *const msg = static_cast<char *>(malloc(sizeOfMsg));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment