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

Added workflow event argument to cta-xrootd_plugins-write-notification-msg

parent 7b7bac5e
Branches
Tags
No related merge requests found
......@@ -18,7 +18,7 @@
#include "common/exception/Exception.hpp"
#include "common/make_unique.hpp"
#include "eos/messages/eos_messages.pb.h"
#include "xroot_plugins/WriteNotificationMsgCmd.hpp"
#include "xroot_plugins/WriteNotificationMsgCmdLineArgs.hpp"
......@@ -59,7 +59,7 @@ int WriteNotificationMsgCmd::exceptionThrowingMain(const int argc, char *const *
eos::wfe::Wrapper wrapper;
wrapper.set_type(eos::wfe::Wrapper::NOTIFICATION);
wrapper.mutable_notification()->mutable_wf()->set_event(eos::wfe::Workflow::CLOSEW);
wrapper.mutable_notification()->mutable_wf()->set_event(cmdLineArgs.wfEvent);
wrapper.mutable_notification()->mutable_wf()->set_queue("notification_workflow_queue");
wrapper.mutable_notification()->mutable_wf()->set_wfname("default");
wrapper.mutable_notification()->mutable_wf()->set_vpath("notification_workflow_vpath");
......
......@@ -20,6 +20,7 @@
#include "common/utils/utils.hpp"
#include "xroot_plugins/WriteNotificationMsgCmdLineArgs.hpp"
#include <algorithm>
#include <getopt.h>
#include <ostream>
......@@ -30,6 +31,7 @@ namespace xroot_plugins {
// constructor
//------------------------------------------------------------------------------
WriteNotificationMsgCmdLineArgs::WriteNotificationMsgCmdLineArgs(const int argc, char *const *const argv):
wfEvent(eos::wfe::Workflow::NONE),
writeJsonToStdOut(false),
help(false) {
......@@ -100,22 +102,50 @@ WriteNotificationMsgCmdLineArgs::WriteNotificationMsgCmdLineArgs(const int argc,
throw ex;
}
// There is no need to continue parsing if either the help or json option is
// set
if(help || writeJsonToStdOut) {
// There is no need to continue parsing if the help option is set
if(help) {
return;
}
// Check the number of arguments
const int expectedNbArgs = 1;
if(actualNbArgs != expectedNbArgs) {
exception::CommandLineNotParsed ex;
ex.getMessage() << "Wrong number of command-line arguments: excepted=" << expectedNbArgs << " actual=" <<
if(writeJsonToStdOut) {
// Check the number of arguments
const int expectedNbArgs = 1;
if(actualNbArgs != expectedNbArgs) {
exception::CommandLineNotParsed ex;
ex.getMessage() << "Wrong number of command-line arguments with the -j|--json argument: excepted=" <<
expectedNbArgs << " actual=" << actualNbArgs;
throw ex;
}
wfEvent = parseWfEvent(argv[optind]);
} else {
// Check the number of arguments
const int expectedNbArgs = 2;
if (actualNbArgs != expectedNbArgs) {
exception::CommandLineNotParsed ex;
ex.getMessage() << "Wrong number of command-line arguments: excepted=" << expectedNbArgs << " actual=" <<
actualNbArgs;
throw ex;
throw ex;
}
wfEvent = parseWfEvent(argv[optind]);
filename = argv[optind + 1];
}
}
filename = argv[optind];
//------------------------------------------------------------------------------
// parseWfEvent
//------------------------------------------------------------------------------
eos::wfe::Workflow::EventType WriteNotificationMsgCmdLineArgs::parseWfEvent(std::string str) {
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
if(str == "CLOSEW") {
return eos::wfe::Workflow::CLOSEW;
} else if(str == "PREPARE") {
return eos::wfe::Workflow::PREPARE;
} else {
throw cta::exception::Exception(std::string("Unknown workflow event: event=") + str);
}
}
//------------------------------------------------------------------------------
......@@ -126,10 +156,13 @@ void WriteNotificationMsgCmdLineArgs::printUsage(std::ostream &os) {
"Description:" << std::endl <<
" Writes a \"notification\" message to the specified file" << std::endl <<
"Usage:" << std::endl <<
" cta-xroot_plugins-write-notification-msg filename" << std::endl <<
" cta-xroot_plugins-write-notification-msg event filename" << std::endl <<
" cta-xroot_plugins-write-notification-msg event -j|--json" << std::endl <<
" cta-xroot_plugins-write-notification-msg -h|--help" << std::endl <<
" cta-xroot_plugins-write-notification-msg -j|--json" << std::endl <<
"Where:" << std::endl <<
" event" << std::endl <<
" The type of the workflow event which is case insensitive and can" << std::endl <<
" either be CLOSEW or PREPARE" << std::endl <<
" filename" << std::endl <<
" The name of file to which the notification message will be written." << std::endl <<
" Please note that this file will be overwritten if it already exists." << std::endl <<
......@@ -139,7 +172,7 @@ void WriteNotificationMsgCmdLineArgs::printUsage(std::ostream &os) {
" -j, --json" << std::endl <<
" Prints the JSON representation of the notification message to standard out" << std::endl <<
"Example:" << std::endl <<
" cta-xrootd_plugins-write-notification-msg notification.msg" << std::endl <<
" cta-xrootd_plugins-write-notification-msg CLOSEW notification.msg" << std::endl <<
" cat notification.msg | protoc --decode_raw" << std::endl;
}
......
......@@ -18,6 +18,8 @@
#pragma once
#include "eos/messages/eos_messages.pb.h"
#include <ostream>
#include <stdint.h>
#include <string>
......@@ -30,6 +32,11 @@ namespace xroot_plugins {
* named cta-write-notification-msg.
*/
struct WriteNotificationMsgCmdLineArgs {
/**
* The workflow event type of the notification message.
*/
eos::wfe::Workflow::EventType wfEvent;
/**
* The name of the file to which the notification message should be written.
*/
......@@ -55,6 +62,16 @@ struct WriteNotificationMsgCmdLineArgs {
*/
WriteNotificationMsgCmdLineArgs(const int argc, char *const *const argv);
/**
* Parses the specified event string.
*
* Parsing is case insensitive.
*
* @param str The string to be parsed.
* @return The numeric equivalent of the string.
*/
static eos::wfe::Workflow::EventType parseWfEvent(std::string str);
/**
* Prints the usage message of the command-line tool.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment