Commit f066148f authored by Micha Mueller's avatar Micha Mueller
Browse files

Add printJob function to C-API for debug reasons

parent 7b5a524a
......@@ -241,6 +241,22 @@ DCDB_C_RESULT insertJobIntoDatabase(DCDB::JobDataStore* jds, DCDB::JobId jid,
uint64_t endTs, const char ** nodes,
unsigned nodeSize);
/**
* @brief For Debugging. Print the jobdata or an appropriate error message.
*
* @param jds Pointer to JobDataStore object, which to query for the JobId.
* @param jid SLURM id of the job to be printed.
*
* @return DCDB_C_OK.
*
* @details
* For fast testing if a job was inserted correctly, this method allows to
* query the datastore for the job and print its data. If the job could not
* be found or another error was encountered, an appropriate error message is
* printed.
*/
DCDB_C_RESULT printJob(DCDB::JobDataStore* jds, DCDB::JobId jid);
/**
* @brief Destroy a DCDB::JobDataStore object.
*
......
......@@ -468,6 +468,8 @@ DCDB_C_RESULT insertJobIntoDatabase(JobDataStore* jds, JobId jid,
uint64_t endTs, const char ** nodes,
unsigned nodeSize) {
JobData jdata;
JDError ret;
jdata.jobId = jid;
jdata.userId = uid;
jdata.startTime = startTs;
......@@ -476,7 +478,7 @@ DCDB_C_RESULT insertJobIntoDatabase(JobDataStore* jds, JobId jid,
jdata.nodes.push_back(nodes[i]);
}
JDError ret = jds->insertJob(jdata);
ret = jds->insertJob(jdata);
if (ret == JD_OK) {
return DCDB_C_OK;
......@@ -486,6 +488,43 @@ DCDB_C_RESULT insertJobIntoDatabase(JobDataStore* jds, JobId jid,
return DCDB_C_UNKNOWN;
}
DCDB_C_RESULT printJob(JobDataStore* jds, JobId jid) {
JobData jdata;
JDError ret;
ret = jds->getJobById(jdata, jid);
switch (ret) {
case JD_OK:
std::cout << "Successfully retrieved job:" << std::endl;
std::cout << " JobId: " << jdata.jobId << std::endl;
std::cout << " UserId: " << jdata.userId << std::endl;
std::cout << " StartTime: " << jdata.startTime.getString() << std::endl;
std::cout << " EndTime: " << jdata.endTime.getString() << std::endl;
std::cout << " Nodes: " << std::endl;
for (const auto& n : jdata.nodes) {
std::cout << " " << n << std::endl;
}
break;
case JD_JOBIDNOTFOUND:
std::cout << "Could not retrieve job: JobId not found." << std::endl;
break;
case JD_PARSINGERROR:
std::cout << "Could not retrieve job: Error while parsing result." <<
std::endl;
break;
case JD_UNKNOWNERROR:
std::cout << "Could not retrieve job: Unknown error." << std::endl;
break;
default:
std::cout << "Fatal bug: this message should be unreachable!" <<
std::endl;
break;
}
return DCDB_C_OK;
}
DCDB_C_RESULT destructJobDataStore(JobDataStore* jds) {
if (jds) {
delete jds;
......
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