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

Add initial dcdbslurmjob tool to read Slurm job data from environment

parent ab3b17e3
include ../config.mk
PROJECTS = dcdbconfig dcdbquery dcdbunitconv dcdbquerysum dcdbcsvimport
PROJECTS = dcdbconfig dcdbquery dcdbunitconv dcdbquerysum dcdbcsvimport dcdbslurmjob
.PHONY : clean install $(PROJECTS)
......
include ../../config.mk
CXXFLAGS += -I../../common/include/ -I../../lib/include -I$(DCDBDEPLOYPATH)/include
OBJS = dcdbslurmjob.o
TARGET = dcdbslurmjob
.PHONY : clean install
$(TARGET): $(OBJS)
$(CXX) -o $(TARGET) $(OBJS) $(LIBS)
all: $(TARGET)
clean:
rm -f $(TARGET)
rm -f $(OBJS)
install: $(TARGET)
install $(TARGET) $(DCDBDEPLOYPATH)/bin/
//================================================================================
// Name : dcdbslurmjob.cpp
// Author : Michael Ott
// Copyright : Leibniz Supercomputing Centre
// Description : Main file of the dcdbslurmjob command line utility
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//================================================================================
#include <cstdlib>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include "timestamp.h"
std::string getEnv(const char* var) {
char* str = std::getenv(var);
if (str != NULL) {
return std::string(str);
} else {
return std::string("");
}
}
int main(int argc, char** argv) {
std::cout << "dcdbslurmjob " << VERSION << std::endl << std::endl;
if (argc != 2) {
std::cerr << "One argument is required: start or stop" << std::endl;
return 1;
}
uint64_t ts = getTimestamp();
std::string jobId = getEnv("SLURM_JOB_ID");
if (boost::iequals(argv[1], "start")) {
std::string user = getEnv("SLURM_JOB_USER");
std::string nodeList = getEnv("SLURM_JOB_NODELIST");
std::cout << "START: ts=" << ts << " jobId=" << jobId << " user=" << user << " nodelist=" << nodeList << std::endl;
} else if (boost::iequals(argv[1], "stop")) {
std::cout << "STOP: ts=" << ts << " jobId=" << jobId << std::endl;
} else {
std::cerr << "Unknown argument: " << argv[1] << std::endl;
}
return 0;
}
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