Commit 900f82c5 authored by Michael Ott's avatar Michael Ott
Browse files

Add -s paramter for specifiying sed-style substition pattern for nodelists

parent 211a0a7e
......@@ -57,19 +57,20 @@ void publishCallback(struct mosquitto *mosq, void *obj, int mid) {
void usage() {
std::cout << "Usage:" << std::endl;
std::cout << " dcdbslurmjob [-b<host>] [-t<timestamp>] [-n<nodelist>] [-j<jobid>] [-i<userid>] start|stop" << std::endl;
std::cout << " dcdbslurmjob [-c<host>] [-u<username>] [-p<password>] [-t<timestamp>] [-n<nodelist>] [-j<jobid>] [-i<userid>] start|stop" << std::endl;
std::cout << " dcdbslurmjob [-c<host>] [-u<username>] [-p<password>] [-t<timestamp>] [-n<nodelist>] [-j<jobid>] [-i<userid>] [-s<pattern>] start|stop" << std::endl;
std::cout << " dcdbslurmjob -h" << std::endl;
std::cout << std::endl;
std::cout << "Options:" << std::endl;
std::cout << " -b<host> MQTT broker [default: 127.0.0.1:1883]" << std::endl;
std::cout << " -c<host> Cassandra host [default: 127.0.0.1:9042]" << std::endl;
std::cout << " -u<username> Cassandra username [default: none]" << std::endl;
std::cout << " -p<password> Cassandra password [default: none]" << std::endl;
std::cout << " -t<timestamp> Timestamp value [default: now]" << std::endl;
std::cout << " -n<nodelist> Comma-separated nodelist [default: SLURM_JOB_NODELIST]" << std::endl;
std::cout << " -j<jobid> Numerical job id [default: SLURM_JOB_ID var]" << std::endl;
std::cout << " -i<userid> Numerical user id [default: SLURM_JOB_USER var]" << std::endl;
std::cout << " -b<host> MQTT broker [default: 127.0.0.1:1883]" << std::endl;
std::cout << " -c<host> Cassandra host [default: 127.0.0.1:9042]" << std::endl;
std::cout << " -u<username> Cassandra username [default: none]" << std::endl;
std::cout << " -p<password> Cassandra password [default: none]" << std::endl;
std::cout << " -t<timestamp> Timestamp value [default: now]" << std::endl;
std::cout << " -n<nodelist> Comma-separated nodelist [default: SLURM_JOB_NODELIST]" << std::endl;
std::cout << " -j<jobid> Numerical job id [default: SLURM_JOB_ID var]" << std::endl;
std::cout << " -i<userid> Numerical user id [default: SLURM_JOB_USER var]" << std::endl;
std::cout << " -s<pattern> Nodelist substitution pattern [default: none]" << std::endl;
std::cout << std::endl;
std::cout << " -h This help page" << std::endl;
std::cout << std::endl;
......@@ -119,6 +120,22 @@ void splitNodeList(const std::string& str, DCDB::NodeList& nl)
}
}
void convertNodeList(DCDB::NodeList& nl, std::string substitution) {
//check if input has sed format of "s/.../.../" for substitution
boost::regex checkSubstitute("s([^\\\\]{1})([\\S|\\s]*)\\1([\\S|\\s]*)\\1");
boost::smatch matchResults;
if (regex_match(substitution, matchResults, checkSubstitute)) {
//input has substitute format
boost::regex re = (boost::regex(matchResults[2].str(), boost::regex_constants::extended));
std::string fmt = matchResults[3].str();
for (auto &n: nl) {
n = boost::regex_replace(n, re, fmt);
//std::cout << n <<" => " << mqtt << std::endl;
}
}
}
/**
* Retrieves Slurm job data from environment variables and sends it to either a
* CollectAgent or a Cassandra database. Job data can also be passed as command
......@@ -135,10 +152,11 @@ int main(int argc, char** argv) {
std::string host = "127.0.0.1", cassandraPort = "9042", cassandraUser = "", cassandraPassword = "";
int brokerPort = 1883;
std::string nodelist="", jobId="", userId="";
std::string substition="";
uint64_t ts=0;
// Defining options
const char *opts = "b:c:u:p:n:t:j:i:h";
const char *opts = "b:c:u:p:n:t:j:i:s:h";
char ret;
while ((ret = getopt(argc, argv, opts))!=-1) {
......@@ -208,6 +226,9 @@ int main(int argc, char** argv) {
case 'i':
userId = optarg;
break;
case 's':
substition = optarg;
break;
case 'h':
default:
usage();
......@@ -272,6 +293,7 @@ int main(int argc, char** argv) {
DCDB::NodeList nl;
splitNodeList(nodelist, nl);
convertNodeList(nl, substition);
std::cout << "JOBID = " << jobId << std::endl;
std::cout << "USER = " << userId << std::endl;
......@@ -283,6 +305,8 @@ int main(int argc, char** argv) {
}
std::cout << std::endl;
try {
jd.jobId = jobId;
jd.userId = userId;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment