2006-02-23 14:00:51 +00:00
|
|
|
/*
|
|
|
|
* DC-API: Distributed Computing Platform for Master-Worker Applications
|
|
|
|
*
|
|
|
|
* Master side
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Norbert Podhorszki <pnorbert@sztaki.hu>
|
|
|
|
* Gabor Vida <vida@sztaki.hu>
|
|
|
|
* Gabor Gombas <gombasg@sztaki.hu>
|
|
|
|
*
|
|
|
|
* Copyright MTA SZTAKI, 2006
|
|
|
|
*/
|
2005-11-18 08:25:01 +00:00
|
|
|
#ifndef __DC_H_
|
|
|
|
#define __DC_H_
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2006-02-08 15:20:11 +00:00
|
|
|
#include <dc_common.h>
|
2005-12-06 15:36:31 +00:00
|
|
|
|
2006-02-23 14:00:51 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Constant definitions
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Possible states of a work unit */
|
|
|
|
typedef enum {
|
|
|
|
DC_WU_READY, /* Created, but not yet submitted */
|
|
|
|
DC_WU_RUNNING, /* Submitted and running */
|
|
|
|
DC_WU_FINISHED, /* The WU finished normally according to the grid
|
|
|
|
infrastructure. Note that the application client
|
|
|
|
returning an error code is considered a 'normal'
|
|
|
|
shutdown as far as the infrastructure is concerned,
|
|
|
|
so you should check the exit status and/or other
|
|
|
|
output. */
|
2006-03-09 15:17:30 +00:00
|
|
|
DC_WU_SUSPENDED,/* The work unit is suspended */
|
2006-02-23 14:00:51 +00:00
|
|
|
DC_WU_ABORTED, /* The WU was aborted for some reason (infrastructure
|
|
|
|
failure, no canonical result, or by calling
|
|
|
|
DC_cancel()) */
|
|
|
|
DC_WU_UNKNOWN /* The WU's state is not known. This may happen for
|
|
|
|
example when a WU is serialized, then it finishes,
|
|
|
|
and upon deserialization the underlying grid
|
|
|
|
infrastructure no longer knows about it */
|
|
|
|
} DC_WUState;
|
|
|
|
|
|
|
|
/* Possible event types */
|
2005-12-06 15:36:31 +00:00
|
|
|
typedef enum {
|
2006-02-23 14:00:51 +00:00
|
|
|
DC_EVENT_RESULT, /* A DC_Result is available */
|
|
|
|
DC_EVENT_SUBRESULT, /* A sub-result is available */
|
|
|
|
DC_EVENT_MESSAGE /* A message has arrived */
|
|
|
|
} DC_EventType;
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-02-23 14:00:51 +00:00
|
|
|
/* Special result files, used by DC_getResultOutput() */
|
|
|
|
#define DC_RESULT_STDOUT "__DC_STDOUT_" /* The client's standard
|
|
|
|
output */
|
|
|
|
#define DC_RESULT_STDERR "__DC_STDERR_" /* The client's standard
|
|
|
|
error */
|
|
|
|
#define DC_RESULT_LOG "__DC_LOG_" /* The system's log */
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* Data types
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Opaque type representing a workunit */
|
|
|
|
typedef struct _DC_Workunit DC_Workunit;
|
|
|
|
|
|
|
|
/* Opaque type representing a result */
|
|
|
|
typedef struct _DC_Result DC_Result;
|
|
|
|
|
2006-03-09 15:17:30 +00:00
|
|
|
/* Descriptor of a physical file */
|
|
|
|
typedef struct _DC_PhysicalFile DC_PhysicalFile;
|
|
|
|
struct _DC_PhysicalFile
|
|
|
|
{
|
|
|
|
char *label;
|
|
|
|
char *path;
|
2006-03-23 12:10:20 +00:00
|
|
|
DC_FileMode mode;
|
2006-03-09 15:17:30 +00:00
|
|
|
};
|
|
|
|
|
2006-02-23 14:00:51 +00:00
|
|
|
/* Description of a DC-API event */
|
|
|
|
typedef struct _DC_Event DC_Event;
|
|
|
|
struct _DC_Event
|
|
|
|
{
|
|
|
|
DC_EventType type;
|
2006-04-08 11:25:18 +00:00
|
|
|
DC_Workunit *wu;
|
2006-02-23 14:00:51 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
DC_Result *result;
|
2006-03-09 15:17:30 +00:00
|
|
|
DC_PhysicalFile *subresult;
|
2006-02-23 14:00:51 +00:00
|
|
|
char *message;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Prototype of the result handling callback function. */
|
2006-02-23 14:00:51 +00:00
|
|
|
typedef void (*DC_ResultCallback)(DC_Workunit *wu, DC_Result *result);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Prototype of the sub-result handling callback. */
|
2006-02-23 14:00:51 +00:00
|
|
|
typedef void (*DC_SubresultCallback)(DC_Workunit *wu,
|
|
|
|
const char *logicalFileName, const char *path);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Prototype of the message-handling callback. */
|
2006-02-23 14:00:51 +00:00
|
|
|
typedef void (*DC_MessageCallback)(DC_Workunit *wu, const char *message);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
|
|
|
|
2006-02-23 14:00:51 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Function prototypes: Library utilities
|
|
|
|
*/
|
2006-02-13 21:53:05 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Initializes the DC-API. */
|
2006-03-09 15:17:30 +00:00
|
|
|
int DC_init(const char *configFile);
|
2005-12-06 15:36:31 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Sets the callback functions that will be called when a particular event. */
|
2006-02-23 14:00:51 +00:00
|
|
|
void DC_setcb(DC_ResultCallback resultcb, DC_SubresultCallback subresultcb,
|
|
|
|
DC_MessageCallback msgcb);
|
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Waits for events and processes them. */
|
2006-03-23 12:10:20 +00:00
|
|
|
int DC_processEvents(int timeout);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Checks for events and return them. */
|
2006-02-23 14:00:51 +00:00
|
|
|
DC_Event *DC_waitEvent(const char *wuFilter, int timeout);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Checks for events for a particular WU. */
|
2006-02-23 14:00:51 +00:00
|
|
|
DC_Event *DC_waitWUEvent(DC_Workunit *wu, int timeout);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Destroys an event. */
|
2006-02-23 14:00:51 +00:00
|
|
|
void DC_destroyEvent(DC_Event *event);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Queries the number of WUs known to the API in the given state. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_getWUNumber(DC_WUState state);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-27 14:52:13 +00:00
|
|
|
/* Queries per-client configuration variables */
|
|
|
|
char *DC_getClientCfgStr(const char *clientName, const char *key,
|
|
|
|
int fallbackGlobal);
|
|
|
|
|
|
|
|
/* Queries per-client configuration variables */
|
|
|
|
int DC_getClientCfgInt(const char *clientName, const char *key,
|
|
|
|
int defaultValue, int fallbackGlobal);
|
|
|
|
|
2006-02-23 14:00:51 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Function prototypes: Work unit management
|
|
|
|
*/
|
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Creates one work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
DC_Workunit *DC_createWU(const char *clientName, const char *arguments[],
|
|
|
|
int subresults, const char *tag);
|
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Sets an input file for the work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_addWUInput(DC_Workunit *wu, const char *logicalFileName, const char *URL,
|
|
|
|
DC_FileMode fileMode);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Defines an output file for the work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_addWUOutput(DC_Workunit *wu, const char *logicalFileName);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Sets the priority for the work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_setWUPriority(DC_Workunit *wu, int priority);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Serializes a work unit description. */
|
2006-02-23 14:00:51 +00:00
|
|
|
char *DC_serializeWU(DC_Workunit *wu);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Restores a serialized work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
DC_Workunit *DC_deserializeWU(const char *buf);
|
2006-02-08 15:20:11 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Queries the state of a work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
DC_WUState DC_getWUState(DC_Workunit *wu);
|
2006-02-08 15:20:11 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Submits a work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_submitWU(DC_Workunit *wu);
|
2006-02-13 21:53:05 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Queries the low-level ID of the work unit. */
|
2006-05-03 11:02:02 +00:00
|
|
|
char *DC_getWUId(const DC_Workunit *wu);
|
2006-02-13 21:53:05 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Queries the tag of a work unit. */
|
2006-05-03 11:02:02 +00:00
|
|
|
char *DC_getWUTag(const DC_Workunit *wu);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Cancels all computations for a given work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_cancelWU(DC_Workunit *wu);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Temporarily suspends the execution of a work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_suspendWU(DC_Workunit *wu);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Resumes computation of a previously suspended work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_resumeWU(DC_Workunit *wu);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Releases internal resources allocated to a work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
void DC_destroyWU(DC_Workunit *wu);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Sends a message to a running work unit. */
|
2006-02-23 14:00:51 +00:00
|
|
|
int DC_sendWUMessage(DC_Workunit *wu, const char *message);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-02-23 14:00:51 +00:00
|
|
|
/********************************************************************
|
|
|
|
* Function prototypes: Result handling
|
|
|
|
*/
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Queries what optional fields are present in the result. */
|
2006-05-03 11:02:02 +00:00
|
|
|
unsigned DC_getResultCapabilities(const DC_Result *result);
|
2006-02-23 14:00:51 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Returns the WU that generated this result. */
|
2006-02-23 14:00:51 +00:00
|
|
|
DC_Workunit *DC_getResultWU(DC_Result *result);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Returns the exit code of the client application. */
|
2006-05-03 11:02:02 +00:00
|
|
|
int DC_getResultExit(const DC_Result *result);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
2006-04-08 11:25:18 +00:00
|
|
|
/* Returns the local name of an output file. */
|
2006-05-03 11:02:02 +00:00
|
|
|
char *DC_getResultOutput(const DC_Result *result, const char *logicalFileName);
|
2005-11-18 08:25:01 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __DC_H_ */
|