sun.com | docs.sun.com | How To Buy | My Sun | Worldwide Sites |  |

| Previous Contents Index Next
Chapter 5 # Retrieving Node Information Using the CMM API This chapter describes how to use the functions of the CMM API to retrieve information about nodes. For more information, see the following topics: Identifying the Current Node Retrieving Information About the Master Node or Vice-Master Node Retrieving Information About Any Node Retrieving Information About All Nodes in the Cluster Identifying the Role of a Node Identifying the Properties of a Node Using the `cmm_member_t` Structure for Information About Member Nodes ## Identifying the Current Node The `cmm_node_getid()` function, described in the `cmm_node_getid`(3CMM) man page, retrieves the nodeid of the current node, that is, the node on which your application is currently running. The nodeid is used in other CMM calls as a parameter. If the current node is a nonpeer node, the `cmm_node_getid()` function returns the `CMM_ECONN` message. For further details on return values, see Table 8-1. The following example demonstrates how to use the `cmm_node_getid()` function: Example 5-1 Retrieving the nodeid of the Current Node
    #include <cmm.h>
    #include <stdio.h>
    #include <stdlib.h>         /* for exit() */

    /*******************************************************************/
    void main(void)
    {
        cmm_error_t  res;
        cmm_nodeid_t currnode;

        /* get the current node id */
        if ((res = cmm_node_getid(&currnode))==CMM_OK)
            printf("Current node id is: %d\n", currnode);
        else
            printf("Error getting info on local node: %s\n",
                cmm_strerror(res));
    }
## Retrieving Information About the Master Node or Vice-Master Node The `cmm_master_getinfo()` function retrieves all of the available information about the master node in the cluster. This is similar to the `cmm_member_getinfo()` function, but you do not need the nodeid. If there is no master node, the cluster is not in a valid state and the call returns the `CMM_ENOCLUSTER` error. During a failover triggered by the disqualification of the master node, there is a time during which no master exists. During this period, the `CMM_ENOCLUSTER` error is returned. For more information about return values, see Return Values of the CMM API. The following example tests for the success of a call to the `cmm_master_getinfo()` function: Example 5-2 Testing the Success of the `cmm_master_getinfo()` Function
    #include <cmm.h>
    ...
    cmm_error_t res;
    cmm_member_t member;
    ...
    res = cmm_master_getinfo(&member);
    if (res != CMM_OK) {
        /* Handle error. */
        ...
    }
    ...
For further information, see the `cmm_master_getinfo`(3CMM) man page. The `cmm_vicemaster_getinfo()` function retrieves all of the available information about the vice-master node in the cluster. If there is no vice-master node, the function returns the `CMM_ESRCH` error. For information, see the `cmm_vicemaster_getinfo`(3CMM) man page. These functions return the `cmm_member_t` structure. For information about the `cmm_member_t` structure, see Using the `cmm_member_t` Structure for Information About Member Nodes. The following example demonstrates how to test for the presence of a vice-master node by using the `cmm_vicemaster_getinfo()` function. Example 5-3 Determining Which Node is the Vice-Master
    #include <cmm.h>
    #include <stdio.h>
    #include <stdlib.h>        /* for exit() */
    #include <strings.h>        /* for strcpy */
    #include "common.h"

    /******************************************************************/
    void main(void)
    {
        cmm_error_t  res;
        cmm_member_t vicemaster_info;
        timespec_t   time_out = { 0, 500000 /* musec */};

        }

        /* get info on vicemaster */
        res = cmm_vicemaster_getinfo(&vicemaster_info);
        switch(res) {
        case CMM_ESRCH:
            puts("No Vice master in current cluster");
            break ;
        case CMM_OK:
            puts("Vice master in current cluster is");
            print_member(&vicemaster_info);
            break ;
        default:
            printf("Error getting info on vicemaster: %s\n",
                cmm_strerror(res));
            exit(1);
        }
    }
Previous Contents Index Next

Copyright 1994-2004 Sun Microsystems