Previous  |  Next  >  
Product: Cluster Server Guides   
Manual: Cluster Server 4.1 Agent Developer's Guide   

Using C++ or Script Entry Points

An entry point can be implemented as a C++ function or a script. The advantage to using C++ is that entry points are compiled and linked with the agent framework library. They run as part of the agent process, so there is no system overhead when they are called. The advantage to using scripts is that you can modify the entry points dynamically; however, a new process is created each time the entry points are called.

Note that you may use C++, Perl, and shell in any combination to implement multiple entry points for a single agent. This allows you to implement each entry point in the most advantageous manner. For example, you may use scripts to implement most entry points while using C++ to implement the monitor entry point, which is called often. If the monitor entry point is written in script, a new process must be created each time it is called.

C++ Agents

If you create an agent with all the agent's entry points in C++, or some entry points in C++ and some in script, you must create a C++ agent that contains the VCSAgStartup routine, the necessary C++ primitives, and the C++ entry points. A sample file containing templates for creating an agent using C++ entry points is located in $VCS_HOME/src/agent/Sample. Refer to Building a Custom VCS Agent for information about how to build an agent using C++ entry points or a combination of C++ and script entry points. See also Implementing Entry Points Using C++ or Implementing Entry Points Using Scripts.

Script Agents

If you create an agent using only script entry points, that is, no C++ code, you can base the agent on the ScriptAgent, $VCS_HOME/bin/ScriptAgent. Refer to Building a Custom VCS Agent for information about creating an agent using only script entry points. See also, Implementing Entry Points Using Scripts.

VCSAgStartup

When an agent starts, it uses the routine named VCSAgStartup to initialize the agent's data structures and connect the agent to the VCS engine. After the agent downloads the necessary information it needs for the configured resources from the engine, it can control the resources based on the entry points.

Implementing All or Some of the Entry Points in C++

If you implement all or some of the entry points in C++, you can use VCSAgStartup routine within the agent to assign the entry points to be used. You can do this by defining a variable of type VCSAGV40EntryPointStruct and setting its fields appropriately for each entry point. (See VCS Primitives.) If you implement some entry points using scripts, assign a NULL value to their fields in VCSAgV40EntryPointStruct, in which case, the agent looks for and executes the scripts.

Implementing Entry Points Using Scripts

If you implement all of the agent's entry points using scripts, you can base the agent on the ScriptAgent, which includes a built-in implementation of VCSAgStartup that looks for and executes the scripts.

Sample Structure

VCSAgStartup registers the agent entry points with the agent framework by calling the primitive VCSAgRegisterEPStruct, which includes the structure VCSAgV40EntryPointStruct.

VCSAgV40EntryPointStruct has the following definition:


 // Structure used to register the entry points.

 typedef struct {
   void (*open)(const char *res_name,void **attr_val);
   void (*close)(const char *res_name,void **attr_val);
   VCSAgResState (*monitor)(const char
     *res_name, void **attr_val, 
     int *conf_level);
   unsigned int (*online)(const char *res_name,
     void **attr_val);
   unsigned int (*offline) (const char *res_name,
     void **attr_val);
   unsigned int (*action) (const char *res_name, const char 
     *action_token, void **attr_val, char **action_args, 
     char *action_output);
   unsigned int (*info) (const char *res_name,
        VCSAgResInfoOp resinfo_op, void **attr_val, char
        **info_output, char ***opt_update_args, char
        ***opt_add_args);
   void (*attr_changed) (const char *res_name,
     const char *changed_res_name, const char
     *changed_attr_name, void **new_val);
   unsigned int (*clean) (const char *res_name,
     VCSAgWhyClean reason, void **attr_val);
   void (*shutdown) ();
 } VCSAgV40EntryPointStruct;

Example: Modifying VCSAgStartup for C++ and Script Entry Points

When using C++ to implement an entry point, assign the entry point's function to the corresponding field of VCSAgV40EntryPointStruct. In the following example, the function my_shutdown is assigned to the field shutdown.

Note that the monitor entry point, which is mandatory, is assigned a NULL value, indicating it is implemented using scripts. If you are using a script entry point, or if you are not implementing an optional entry point, set the corresponding field to NULL. For an entry point whose field is set to NULL, the agent automatically looks for the correct script to execute: $VCS_HOME/bin/resource_type/entry_point.


#include "VCSAgApi.h"
 void my_shutdown() {
   ...
 }

 void VCSAgStartup() {
   VCSAgV40EntryPointStruct ep;
   ep.open = NULL;
   ep.online = NULL;
   ep.offline = NULL;
   ep.monitor = NULL;
   ep.attr_changed = NULL;
   ep.clean = NULL;
   ep.close = NULL;
   ep.info = NULL;
   ep.action = NULL;
   ep.shutdown = my_shutdown;
   }

   VCSAgRegisterEPStruct(V40, &ep);
 ^ Return to Top Previous  |  Next  >  
Product: Cluster Server Guides  
Manual: Cluster Server 4.1 Agent Developer's Guide  
VERITAS Software Corporation
www.veritas.com