Commit a5b6bb4e authored by Alessio Netti's avatar Alessio Netti

dcdbconfig: commands to list and show job information

parent be1a21cb
......@@ -690,7 +690,7 @@ JDError JobDataStoreImpl::getJobsInIntervalIncl(std::list<JobData>& jobs,
CassStatement* statement = nullptr;
CassFuture* future = nullptr;
const char* query = "SELECT * FROM " JD_KEYSPACE_NAME "." CF_JOBDATA
" WHERE start_ts >= ? AND start_ts <= ? ;";
" WHERE start_ts >= ? AND start_ts <= ? ALLOW FILTERING;";
statement = cass_statement_new(query, 2);
cass_statement_set_paging_size(statement, PAGING_SIZE);
......
......@@ -37,11 +37,11 @@ _dcdbconfig_options()
fi
if [ "${num_args}" -le "$((${toplevel_command_at}+1))" ]; then
comrep+="help sensor db "
comrep+="help sensor db job"
else
if [ "${COMP_WORDS[${toplevel_command_at}]}" = "help" ]; then
if [ ! "${COMP_WORDS[$((${COMP_CWORD}-1))]}" = "sensor" ]; then
comrep="sensor db "
comrep="sensor db job"
fi
elif [ "${COMP_WORDS[${toplevel_command_at}]}" = "sensor" ]; then
if [ "${num_args}" -eq "$((${toplevel_command_at}+2))" ]; then
......@@ -81,6 +81,10 @@ _dcdbconfig_options()
if [ "${num_args}" -eq "$((${toplevel_command_at}+2))" ]; then
comrep="insert fuzzytrunc"
fi
elif [ "${COMP_WORDS[${toplevel_command_at}]}" = "job" ]; then
if [ "${num_args}" -eq "$((${toplevel_command_at}+2))" ]; then
comrep="show list running pending finished"
fi
fi
fi
......
include ../../config.mk
CXXFLAGS += -I../../common/include/ -I../../lib/include -I$(DCDBDEPLOYPATH)/include
OBJS = dcdbconfig.o sensoraction.o dbaction.o useraction.o
OBJS = dcdbconfig.o sensoraction.o dbaction.o jobaction.o useraction.o
LIBS = -L../../lib -L$(DCDBDEPLOYPATH)/lib -ldcdb -lcassandra -luv -lboost_random -lboost_system -lboost_date_time -lboost_regex -lssl -lcrypto -lpthread
# GCC 4.8 is broken
ifeq ($(findstring 4.8, $(shell $(CXX) --version)), 4.8)
......
......@@ -44,6 +44,7 @@ void usage(int argc, char* argv[])
std::cout << " HELP <command name> - print help for given command" << std::endl;
std::cout << " DB - perform low-level database functions" << std::endl;
std::cout << " SENSOR - list and configure sensors" << std::endl;
std::cout << " JOB - list and show job information" << std::endl;
}
int main(int argc, char* argv[])
......
//================================================================================
// Name : jobaction.cpp
// Author : Alessio Netti
// Contact : info@dcdb.it
// Copyright : Leibniz Supercomputing Centre
// Description : Implementation for performing actions on the DCDB Database
//================================================================================
//================================================================================
// 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 <iostream>
#include <string>
#include <boost/lexical_cast.hpp>
#include "jobaction.h"
/*
* Print the help for the SENSOR command
*/
void JobAction::printHelp(int argc, char* argv[])
{
/* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */
std::cout << "JOB command help" << std::endl << std::endl;
std::cout << "The JOB command has the following options:" << std::endl;
std::cout << " SHOW <jobid> - Shows information for a certain <jobid>" << std::endl;
std::cout << " LIST - Lists all job IDs stored in the database" << std::endl;
std::cout << " RUNNING - Lists all currently running jobs" << std::endl;
std::cout << " PENDING - Lists all jobs that have not yet started" << std::endl;
std::cout << " FINISHED - Lists all jobs that have already terminated" << std::endl;
}
/*
* Execute any of the Job commands
*/
int JobAction::executeCommand(int argc, char* argv[], int argvidx, const char* hostname)
{
/* Independent from the command, we need to connect to the server */
connection = new DCDB::Connection();
connection->setHostname(hostname);
if (!connection->connect()) {
std::cerr << "Cannot connect to Cassandra database." << std::endl;
return EXIT_FAILURE;
}
/* Check what we need to do (argv[argvidx] contains "JOB") */
argvidx++;
if (argvidx >= argc) {
std::cout << "The JOB command needs at least two parameters." << std::endl;
std::cout << "Run with 'HELP JOB' to see the list of possible JOB commands." << std::endl;
goto executeCommandError;
}
if (strcasecmp(argv[argvidx], "SHOW") == 0) {
/* SHOW needs two more parameters */
if (argvidx+1 >= argc) {
std::cout << "SHOW needs one more parameter!" << std::endl;
goto executeCommandError;
}
doShow(argv[argvidx+1]);
}
else if (strcasecmp(argv[argvidx], "LIST") == 0) {
doList();
}
else if (strcasecmp(argv[argvidx], "RUNNING") == 0) {
doRunning();
}
else if (strcasecmp(argv[argvidx], "PENDING") == 0) {
doPending();
}
else if (strcasecmp(argv[argvidx], "FINISHED") == 0) {
doFinished();
}
else {
std::cout << "Invalid JOB command: " << argv[argvidx] << std::endl;
goto executeCommandError;
}
/* Clean up */
connection->disconnect();
delete connection;
return EXIT_SUCCESS;
executeCommandError:
connection->disconnect();
delete connection;
return EXIT_FAILURE;
}
void JobAction::doShow(std::string jobId) {
DCDB::JobDataStore jobDataStore(connection);
DCDB::JobData jobData;
DCDB::JDError err = jobDataStore.getJobById(jobData, jobId);
std::list<std::string>::iterator nIt;
switch (err) {
case DCDB::JD_OK:
std::cout << "Job ID: " << jobId << std::endl;
std::cout << "User ID: " << jobData.userId << std::endl;
std::cout << "Start Time: " << jobData.startTime.getRaw() << std::endl;
std::cout << "End Time: " << jobData.endTime.getRaw() << std::endl;
std::cout << "Node List: ";
nIt = jobData.nodes.begin();
if(nIt != jobData.nodes.end()) {
std::cout << *nIt;
++nIt;
while(nIt != jobData.nodes.end()) {
std::cout << ", " << *nIt;
++nIt;
}
}
std::cout << std::endl;
break;
case DCDB::JD_JOBKEYNOTFOUND:
std::cout << "Job key not found: " << jobId << std::endl;
break;
case DCDB::JD_JOBIDNOTFOUND:
std::cout << "Job ID not found: " << jobId << std::endl;
break;
default:
std::cout << "Internal error." << std::endl;
}
}
void JobAction::doList() {
DCDB::JobDataStore jobDataStore(connection);
DCDB::TimeStamp tsEnd((uint64_t)LLONG_MAX);
DCDB::TimeStamp tsStart((uint64_t)0);
std::list<DCDB::JobData> jobList;
DCDB::JDError err = jobDataStore.getJobsInIntervalIncl(jobList, tsStart, tsEnd);
switch (err) {
case DCDB::JD_OK:
std::cout << "Job ID, User ID" << std::endl;
for(const auto &j : jobList) {
std::cout << j.jobId << "," << j.userId << std::endl;
}
std::cout << std::endl;
break;
default:
std::cout << "Internal error." << std::endl;
}
}
void JobAction::doRunning() {
DCDB::JobDataStore jobDataStore(connection);
DCDB::TimeStamp tsEnd;
DCDB::TimeStamp tsStart(tsEnd.getRaw() - JOB_ACTION_OFFSET);
std::list<DCDB::JobData> jobList;
DCDB::JDError err = jobDataStore.getJobsInIntervalRunning(jobList, tsStart, tsEnd);
switch (err) {
case DCDB::JD_OK:
std::cout << "Job ID, User ID" << std::endl;
for(const auto &j : jobList) {
std::cout << j.jobId << "," << j.userId << std::endl;
}
std::cout << std::endl;
break;
default:
std::cout << "Internal error." << std::endl;
}
}
void JobAction::doPending() {
DCDB::JobDataStore jobDataStore(connection);
DCDB::TimeStamp tsNow;
DCDB::TimeStamp tsEnd((uint64_t)LLONG_MAX);
DCDB::TimeStamp tsStart(tsNow.getRaw() + JOB_ACTION_OFFSET);
std::list<DCDB::JobData> jobList;
DCDB::JDError err = jobDataStore.getJobsInIntervalExcl(jobList, tsStart, tsEnd);
switch (err) {
case DCDB::JD_OK:
std::cout << "Job ID, User ID" << std::endl;
for(const auto &j : jobList) {
if(j.startTime.getRaw()>tsNow.getRaw())
std::cout << j.jobId << "," << j.userId << std::endl;
}
std::cout << std::endl;
break;
default:
std::cout << "Internal error." << std::endl;
}
}
void JobAction::doFinished() {
DCDB::JobDataStore jobDataStore(connection);
DCDB::TimeStamp tsNow;
DCDB::TimeStamp tsEnd(tsNow.getRaw() - JOB_ACTION_OFFSET);
DCDB::TimeStamp tsStart((uint64_t)0);
std::list<DCDB::JobData> jobList;
DCDB::JDError err = jobDataStore.getJobsInIntervalExcl(jobList, tsStart, tsEnd);
switch (err) {
case DCDB::JD_OK:
std::cout << "Job ID, User ID" << std::endl;
for(const auto &j : jobList) {
if(j.endTime.getRaw()!=0)
std::cout << j.jobId << "," << j.userId << std::endl;
}
std::cout << std::endl;
break;
default:
std::cout << "Internal error." << std::endl;
}
}
//================================================================================
// Name : jobaction.h
// Author : Alessio Netti
// Contact : info@dcdb.it
// Copyright : Leibniz Supercomputing Centre
// Description : Headers for performing actions on the DCDB Database
//================================================================================
//================================================================================
// 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 <dcdb/connection.h>
#include <dcdb/sensordatastore.h>
#include <dcdb/jobdatastore.h>
#include <dcdb/timestamp.h>
#include <string>
#include <limits.h>
#include "useraction.h"
#ifndef JOBACTION_H
#define JOBACTION_H
#define JOB_ACTION_OFFSET 10000000000
class JobAction : public UserAction
{
public:
void printHelp(int argc, char* argv[]);
int executeCommand(int argc, char* argv[], int argvidx, const char* hostname);
JobAction() {};
virtual ~JobAction() {};
protected:
DCDB::Connection* connection;
void doShow(std::string jobId);
void doList();
void doRunning();
void doFinished();
void doPending();
};
#endif
......@@ -28,6 +28,7 @@
#include "useraction.h"
#include "sensoraction.h"
#include "dbaction.h"
#include "jobaction.h"
#include <cstring>
#include <memory>
......@@ -47,6 +48,9 @@ std::shared_ptr<UserAction> UserActionFactory::getAction(const char *actionStr)
else if (strcasecmp(actionStr, "db") == 0) {
action = new DBAction();
}
else if (strcasecmp(actionStr, "job") == 0) {
action = new JobAction();
}
if (action != nullptr) {
return std::shared_ptr<UserAction>(action);
......
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