Commit cc47c480 authored by Michael Ott's avatar Michael Ott
Browse files

Expand SLURM-style nodelist to list of actual nodes

parent 80cae631
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "../../common/include/globalconfiguration.h" #include "../../common/include/globalconfiguration.h"
#include "timestamp.h" #include "timestamp.h"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <cstdlib> #include <cstdlib>
...@@ -34,6 +35,9 @@ ...@@ -34,6 +35,9 @@
#include <dcdb/jobdatastore.h> #include <dcdb/jobdatastore.h>
#include <iostream> #include <iostream>
#include <mosquitto.h> #include <mosquitto.h>
#include "dcdb/version.h"
#include "version.h"
#define SLURMJOBTIMEOUT 60000000000 #define SLURMJOBTIMEOUT 60000000000
...@@ -81,13 +85,37 @@ std::string getEnv(const char* var) { ...@@ -81,13 +85,37 @@ std::string getEnv(const char* var) {
} }
} }
void splitNodeList(const std::string& str, DCDB::NodeList& nl, char delim = ',') void splitNodeList(const std::string& str, DCDB::NodeList& nl)
{ {
nl.clear(); nl.clear();
std::stringstream ss(str); std::string s1 = str;
std::string token; boost::regex r1("([^,[]+)(\\[[0-9,-]+\\])?(,|$)", boost::regex::extended);
while (std::getline(ss, token, delim)) { boost::smatch m1;
nl.push_back(token); while (boost::regex_search(s1, m1, r1)) {
std::string hostBase = m1[1].str();
if (m1[2].str().size() == 0) {
nl.push_back(hostBase);
} else {
std::string s2 = m1[2].str();
boost::regex r2("([0-9]+)-?([0-9]+)?(,|\\])", boost::regex::extended);
boost::smatch m2;
while (boost::regex_search(s2, m2, r2)) {
if (m2[2] == "") {
nl.push_back(hostBase + m2[1].str());
} else {
int start = atoi(m2[1].str().c_str());
int stop = atoi(m2[2].str().c_str());
for (int i=start; i<=stop; i++) {
std::stringstream ss;
ss << std::setw(m2[2].str().length()) << std::setfill('0') << i;
nl.push_back(hostBase + ss.str());
}
}
s2 = m2.suffix().str();
}
}
s1 = m1.suffix().str();
} }
} }
...@@ -242,14 +270,19 @@ int main(int argc, char** argv) { ...@@ -242,14 +270,19 @@ int main(int argc, char** argv) {
} }
} }
std::cout << "JOBID = " << jobId << std::endl; DCDB::NodeList nl;
std::cout << "USER = " << userId << std::endl; splitNodeList(nodelist, nl);
std::cout << "START = " << ts << std::endl;
std::cout << "NODES = " << nodelist << std::endl; std::cout << "JOBID = " << jobId << std::endl;
std::cout << "USER = " << userId << std::endl;
DCDB::NodeList nl; std::cout << "START = " << ts << std::endl;
splitNodeList(nodelist, nl, ','); std::cout << "NODELIST = " << nodelist << std::endl;
std::cout << "NODES =";
for (auto &n: nl) {
std::cout << " " << n;
}
std::cout << std::endl;
try { try {
jd.jobId = jobId; jd.jobId = jobId;
jd.userId = userId; jd.userId = userId;
......
Markdown is supported
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