Building and Deploying C and C++ Agents

Example C and C++ agents are included with Oracle Clusterware that demonstrate using the agent framework to implement high availability agents for applications. Appendix F describes an example of an agent called demoagent1.cpp. This agent manages a simple resource that represents a file on disk and performs the following tasks:

  • On start: Creates the file

  • On stop: Gracefully deletes the file

  • On check: Detects whether the file is present

  • On clean: Forcefully deletes the file

To describe this particular resource to Oracle Clusterware, you must first create a resource type that contains all the characteristic attributes for this resource class. In this case, the only attribute to be described is the name of the file to be managed. The following steps demonstrate how to set up the resource and its agent and test the functionality of the resource:

  1. Compile the C++ agent using the demoagent1.cpp source file provided and a makefile. Modify the makefile based on the local compiler and linker paths and installation locations. The output is an executable named demoagent1. This example assumes that the executable is located in a directory named /path/to/ on every node of the cluster.
  2. Use CRSCTL to add a new resource type, as follows:
    crsctl add type hotfile_type -basetype cluster_resource -attr
       "ATTRIBUTE=PATH_NAME,TYPE=string,DEFAULT_VALUE=default.txt,
       ATTRIBUTE=AGENT_FILENAME,TYPE=string,DEFAULT_VALUE=/path/to/demoagent1"
    

    In the preceding command example, PATH_NAME is the directory path for every resource of this type. Modify the value of PATH_NAME to the appropriate directory ___location on the disk.

    The AGENT_FILENAME attribute specifies the ___location of the agent binary that implements the resource management commands for this resource type. This step adds a new resource type to Oracle Clusterware.

  3. Create a new resource based on the type that is defined in the previous step, as follows:
    $ crsctl add res file1 -type hotfile_type -attr "PATH_NAME=/var/log/file1.txt"
    $ crsctl add res file2 -type hotfile_type -attr "PATH_NAME=/var/log/file2.txt"
    

    The preceding commands add resources named file1 and file2 to be managed and monitored by Oracle Clusterware.

  4. Start and stop the resources using CRSCTL, as follows:
    $ crsctl start res file1
    $ crsctl start res file2
    $ crsctl relocate res file1
    $ crsctl stop res file2
    

    Oracle Clusterware creates and deletes the disk files as the resources are started and stopped.

See Also:

Oracle Clusterware Agent Framework C Application Program Interfaces for details of the agent framework, agent framework API reference, and supplied example agents