dnxAgent.c File Reference

Implements the server management agent. More...

#include "dnxAgent.h"
#include "dnxNebMain.h"
#include "dnxTransport.h"
#include "dnxProtocol.h"
#include "dnxCfgParser.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxLogging.h"
#include "dnxStats.h"
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

Go to the source code of this file.

Data Structures

struct  MgmtNodeStatsData

Defines

#define elemcount(x)   (sizeof(x)/sizeof(*(x)))

Functions

static char * buildHelpReply (void)
 Build an allocated response buffer for the HELP request.
static int appendString (char **spp, char *fmt,...)
 Append text to a string by reallocating the string buffer.
static int dnxCountNodes (DnxNodeData *node, void *data)
 Count the number of active nodes in the node table.
static char * buildMgmtStatsReply (char *req)
 Build an allocated response buffer for requested stats values.
static int dnxBuildNodeStatsReply (DnxNodeData *node, void *data)
 Return an allocated stats buffer for a given active node.
static char * buildMgmtNodeStatsReply (char *req)
 Build an allocated response buffer for requested stats values.
static int dnxResetNodeStats (DnxNodeData *node, void *data)
 Reset (zero) the stats of this node.
static int dnxNodeListBuilder (DnxNodeData *node, void *data)
 Append the active node address string to a list of node address strings.
static char * buildMgmtNodeListReply (void)
 Build and return a response for a list of nodes.
static char * buildMgmtCfgReply (void)
 Build an allocated response buffer for the current configuration.
static void * dnxAgentServer (void *data)
 The agent thread control procedure.
int dnxInitAgent (char *agentUrl, DnxCfgParser *parser)
 Initializes the server management agent.
void dnxReleaseAgent (void)
 Cleans up server management agent.

Variables

static char * s_agentName = "Agent"
 The agent channel name.
static DnxChannels_agent
 The agent comm channel.
static pthread_t s_agentTid
 The agent thread id.
static DnxCfgParsers_parser
 The system configuration parser.
static int s_shutdown
 The agent shutdown flag.


Detailed Description

Implements the server management agent.

Author:
John Calcote (dnx-devel@lists.sourceforge.net)
Attention:
Please submit patches to http://dnx.sourceforge.net

Definition in file dnxAgent.c.


Define Documentation

#define elemcount (  )     (sizeof(x)/sizeof(*(x)))

Definition at line 48 of file dnxAgent.c.


Function Documentation

static int appendString ( char **  spp,
char *  fmt,
  ... 
) [static]

Append text to a string by reallocating the string buffer.

This is a var-args function. Additional parameters following the fmt parameter are based on the content of the fmt string.

Parameters:
[in] spp - the address of a dynamically allocated buffer pointer.
[in] fmt - a printf-like format specifier string.
Returns:
Zero on success, or DNX_ERR_MEMORY on out-of-memory condition.

Definition at line 110 of file dnxAgent.c.

References DNX_ERR_MEMORY, and xrealloc.

static char* buildHelpReply ( void   )  [static]

Build an allocated response buffer for the HELP request.

Returns:
A pointer to an allocated response buffer, or 0 if out of memory.

Definition at line 65 of file dnxAgent.c.

References xstrdup.

static char* buildMgmtCfgReply ( void   )  [static]

Build an allocated response buffer for the current configuration.

Returns:
A pointer to an allocated response buffer, or 0 if out of memory.

Definition at line 412 of file dnxAgent.c.

References dnxCfgParserGetCfg(), xfree, and xmalloc.

static char* buildMgmtNodeListReply ( void   )  [static]

Build and return a response for a list of nodes.

Returns:
an allocated buffer containing a node list.

Definition at line 391 of file dnxAgent.c.

References dnxNodeListBuilder(), dnxStatsForEachNode(), and xstrdup.

static char* buildMgmtNodeStatsReply ( char *  req  )  [static]

Build an allocated response buffer for requested stats values.

Parameters:
[in] req - The ip address followed by the requested stats in a comma-separated string format.
Returns:
A pointer to an allocated response buffer, or 0 if out of memory.

Definition at line 330 of file dnxAgent.c.

References dnxBuildNodeStatsReply(), dnxStatsForNodeByAddrStr(), MgmtNodeStatsData::rsp, MgmtNodeStatsData::stats, and xstrdup.

static char* buildMgmtStatsReply ( char *  req  )  [static]

Build an allocated response buffer for requested stats values.

Parameters:
[in] req - The requested stats in comma-separated string format.
Returns:
A pointer to an allocated response buffer, or 0 if out of memory.

Definition at line 161 of file dnxAgent.c.

References appendString(), DISPATCHES_FAILED, DISPATCHES_OK, dnxCountNodes(), dnxStatsForEachNode(), dnxStatsGetServerStats(), elemcount, JOBS_HANDLED, JOBS_REJECTED_NO_NODES, JOBS_REJECTED_NO_SLOTS, POST_RESULTS_FAILED, POST_RESULTS_OK, REQUESTS_EXPIRED, REQUESTS_RECEIVED, RESULTS_FAILED, RESULTS_OK, RESULTS_TIMED_OUT, STATS_COUNT, and xfree.

static void* dnxAgentServer ( void *  data  )  [static]

static int dnxBuildNodeStatsReply ( DnxNodeData node,
void *  data 
) [static]

Return an allocated stats buffer for a given active node.

The results are built in data->rsp;

Parameters:
[in] node - the node in this iteration.
[in] data - the MgmtNodeStatsData structure.
Returns:
zero on success, non-zero on error.

Definition at line 254 of file dnxAgent.c.

References appendString(), DISPATCHES_FAILED, DISPATCHES_OK, DNX_ERR_MEMORY, DNX_OK, elemcount, REQUESTS_EXPIRED, REQUESTS_RECEIVED, RESULTS_FAILED, RESULTS_OK, RESULTS_TIMED_OUT, MgmtNodeStatsData::rsp, DnxNodeData::stats, MgmtNodeStatsData::stats, and xfree.

static int dnxCountNodes ( DnxNodeData node,
void *  data 
) [static]

Count the number of active nodes in the node table.

Parameters:
[in] node - the node in this iteration.
[in] data - the address of an integer counter.
Returns:
zero on success, non-zero on error. A non-zero error code stops the list iteration.

Definition at line 145 of file dnxAgent.c.

References REQUESTS_RECEIVED, and DnxNodeData::stats.

int dnxInitAgent ( char *  agentUrl,
DnxCfgParser parser 
)

Initializes the server management agent.

Parameters:
[in] agentUrl - the listen url of the agent.
[in] parser - the global configuration parser.
Returns:
Zero on success, or a non-zero error code.

Definition at line 522 of file dnxAgent.c.

References DNX_ERR_THREAD, DNX_MODE_PASSIVE, DNX_OK, dnxAgentServer(), dnxChanMapAdd(), dnxChanMapDelete(), dnxConnect(), dnxDisconnect(), dnxErrorString(), dnxLog(), s_agentName, s_agentTid, and s_shutdown.

static int dnxNodeListBuilder ( DnxNodeData node,
void *  data 
) [static]

Append the active node address string to a list of node address strings.

Parameters:
[in] node - the node in this iteration.
[in] data - the address of a character pointer containing the list.
Returns:
zero on success, non-zero on error. A non-zero error code stops the list iteration.

Definition at line 378 of file dnxAgent.c.

References DnxNodeData::addrstr, appendString(), REQUESTS_RECEIVED, and DnxNodeData::stats.

void dnxReleaseAgent ( void   ) 

Cleans up server management agent.

Definition at line 549 of file dnxAgent.c.

References dnxChanMapDelete(), dnxDisconnect(), s_agentName, s_agentTid, and s_shutdown.

static int dnxResetNodeStats ( DnxNodeData node,
void *  data 
) [static]

Reset (zero) the stats of this node.

Parameters:
[in] node - the node in this iteration.
[in] data - the address of a character pointer containing the list.
Returns:
zero on success, non-zero on error. A non-zero error code stops the list iteration.

Definition at line 362 of file dnxAgent.c.

References DnxNodeData::stats.


Variable Documentation

DnxChannel* s_agent [static]

The agent comm channel.

Definition at line 52 of file dnxAgent.c.

char* s_agentName = "Agent" [static]

The agent channel name.

Definition at line 51 of file dnxAgent.c.

pthread_t s_agentTid [static]

The agent thread id.

Definition at line 53 of file dnxAgent.c.

The system configuration parser.

Definition at line 54 of file dnxAgent.c.

int s_shutdown [static]

The agent shutdown flag.

Definition at line 55 of file dnxAgent.c.


Generated on Tue Apr 13 15:48:08 2010 for DNX by  doxygen 1.5.6