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

WIP: add stubs for C-API extension for inserting SLURM jobs via python script

parent 3e0cdea6
//================================================================================
// Name : c_api.h
// Author : Axel Auweter
// Author : Axel Auweter, Micha Mueller
// Copyright : Leibniz Supercomputing Centre
// Description : C Application Programming Interface for libdcdb
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2016 Leibniz Supercomputing Centre
// Copyright (C) 2011-2018 Leibniz Supercomputing Centre
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
......@@ -33,6 +33,9 @@
#include <stdint.h>
#include <time.h>
#include "dcdb/jobdatastore.h"
#include "dcdb/connection.h"
#ifndef DCDB_C_API_H
#define DCDB_C_API_H
......@@ -50,7 +53,8 @@ typedef enum {
DCDB_C_EMPTYSET, /**< The query into the database resulted in an empty set. */
DCDB_C_NOTINTEGRABLE, /**< One of the QuerySum() functions was called on a sensor that is not marked as integrable. */
DCDB_C_NOSENSOR, /**< The caller did not specify a sensor to be queried. */
DCDB_C_UNKNOWN /**< An unknown error occured. */
DCDB_C_BADPARAMS, /**< The provided function parameters are malformed or incomplete */
DCDB_C_UNKNOWN /**< An unknown error occurred. */
} DCDB_C_RESULT;
/**
......@@ -156,6 +160,101 @@ DCDB_C_RESULT dcdbQuerySumMultipleThreaded(
unsigned int numThreads
);
/*****************************************************************************/
/* Following are C-API functions to insert job information. */
/* Intended to be called from python-script. */
/* */
/* Expected order: */
/* 1. Create a database-connection via connectToDatabase(). */
/* 2. Create a JobDataStore object with the previous connection. */
/* 3. Insert all jobs via insertJobIntoDatabase and the previous JobDataStore*/
/* 4. If finished, destroy JobDataStore and Connection object with their */
/* corresponding destruct/disconnect methods. */
/*****************************************************************************/
/**
* @brief Construct a new DCDB::Connection object.
*
* @param hostname Hostname of database node
* @param port TCP port to use for connecting to the database node
* (for Cassandra, this is usually 9042).
* @return Pointer to the new Connection object, or NULL if an error occurred.
*
* @details
* Constructs a new Connection object via < b>new< \b>. Then tries to connect
* it to the database. If the connection attempt fails, the connection is
* destroyed and NULL is returned instead.
*/
DCDB::Connection* connectToDatabase(const char* hostname, uint16_t port);
/**
* @brief Disconnect and destroy a DCDB::Connection object.
*
* @param conn Pointer to the Connection, which shall be destroyed.
* @return Always returns DCDB_C_OK.
*
* @details
* First, if the Connection object pointed to by conn is still connected, it is
* disconnected from the database. Afterwards the object is deconstructed via
* < b>delete< \b>. This function is guaranteed to always succeed.
*
*/
DCDB_C_RESULT disconnectFromDatabase(DCDB::Connection* conn);
/**
* @brief Construct a new DCDB::JobDataStore object.
*
* @param conn Database connection, required to access the database.
*
* @return Pointer to the new JobDataStore object.
*
* @details
* Construct a new JobDataStore object via < b>new< \b>. Always succeeds. The
* given Connection object must already be connected to the database,
* otherwise later JobDataStore operations will fail.
*/
DCDB::JobDataStore* constructJobDataStore(DCDB::Connection* conn);
/**
* @brief Insert a job into the database.
*
* @param jds Pointer to JobDataStore object, which shall be used to
* insert the job.
* @param jid SLURM id of the job.
* @param uid SLURM user id of the job owner.
* @param startTs Start time of the job (in ms since Unix epoch).
* @param endTs End time of the job (in ms since Unix epoch).
* @param nodes String array of node names used by the job.
* @param nodeSize Size of the nodes array.
*
* @return DCDB_C_OK if the job was successfully inserted. DCDB_BAD_PARAMS if
* the given parameters were illogical. DCDB_C_UNKNOWN otherwise.
*
* @details
* Builds a JobData struct from (jid, uid, startTs, endTs, nodes, nodeSize) and
* then tries to insert it by calling the corresponding insert function of jds.
*/
DCDB_C_RESULT insertJobIntoDatabase(DCDB::JobDataStore* jds, DCDB::JobId jid,
DCDB::UserId uid, uint64_t startTs,
uint64_t endTs, const char ** nodes,
unsigned nodeSize);
/**
* @brief Destroy a DCDB::JobDataStore object.
*
* @param jds Pointer to the JobDataStore, which shall be destroyed.
* @return Always returns DCDB_C_OK.
*
* @details
* The object is deconstructed via < b>delete< \b>. This function is guaranteed
* to always succeed. NOTE: Does not delete the connection object, which was
* given to the JobDataStore at construction time. Use disconnectFromDatabase()
* to destroy the Connection object.
*
*/
DCDB_C_RESULT destructJobDataStore(DCDB::JobDataStore* jds);
#ifdef __cplusplus
}
#endif
......
//================================================================================
// Name : c_api.cpp
// Author : Axel Auweter, Daniele Tafani
// Author : Axel Auweter, Daniele Tafani, Micha Mueller
// Copyright : Leibniz Supercomputing Centre
// Description : C API Implementation for libdcdb
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2016 Leibniz Supercomputing Centre
// Copyright (C) 2011-2018 Leibniz Supercomputing Centre
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
......@@ -37,6 +37,7 @@
#include "dcdb/connection.h"
#include "dcdb/sensorconfig.h"
#include "dcdb/sensordatastore.h"
#include "dcdb/jobdatastore.h"
using namespace DCDB;
......@@ -433,3 +434,26 @@ DCDB_C_RESULT dcdbQuerySumMultipleThreaded(
delete connection;
return error;
}
Connection* connectToDatabase(const char* hostname, uint16_t port) {
return NULL;
}
DCDB_C_RESULT disconnectFromDatabase(Connection* conn) {
return DCDB_C_OK;
}
JobDataStore* constructJobDataStore(Connection* conn) {
return NULL;
}
DCDB_C_RESULT insertJobIntoDatabase(JobDataStore* jds, JobId jid,
UserId uid, uint64_t startTs,
uint64_t endTs, const char ** nodes,
unsigned nodeSize) {
return DCDB_C_UNKNOWN;
}
DCDB_C_RESULT destructJobDataStore(JobDataStore* jds) {
return DCDB_C_OK;
}
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