Sun Microsystems
Products & Services
 
Support & Training
 
 

Previous Previous     Contents     Index     Next Next

The cmm_master_getinfo() Function

The code provided by Example A-2 gets information about master node by using the cmm_master_getinfo() function.

Example A-2 The cmm_master_getinfo.c Program

/**********************************************************
* Copyright (c) 2002 by Sun Microsystems, Inc.
* All rights reserved.
*
* 
* ident  "@(#)smpl_cmm_master_getinfo.c 1.2     02/06/05 SMI"
*
***************************************************************************/

#include <stdio.h>
#include <cmm.h>

int main(int argc , char **argv) {
  cmm_error_t  cmm_diag;
  cmm_member_t nodeInfo;
  
  
  
  cmm_diag = cmm_master_getinfo(&nodeInfo);

  if (cmm_diag != CMM_OK) {
    fprintf(stderr,"An error occured during 
    cmm_member_getinfo call, CR=%d\n",cmm_diag);
    fprintf(stderr,"Details: %s\n",cmm_strerror(cmm_diag));
    exit(1);
  }
  
  printf("Infornation on Master:\n");
  printf("\tName:               %s\n",nodeInfo.name);
  printf("\tAdress:             %s\n",nodeInfo.addr);
  printf("\tDomain Id:          %d\n",nodeInfo.domainid);
  printf("\tIncarnation number: %d\n",nodeInfo.incarnation_number);
  printf("\tSoftwareLoad id:    %s\n",nodeInfo.software_load_id);
  

  exit(0);
}

The cmm_member_getcount() Function

The code provided by Example A-3 gets information about all nodes in the cluster by using the cmm_member_getcount() function.

Example A-3 The smpl_cmm_member_getcount_all.c Program

/**********************************************************
* Copyright (c) 2002 by Sun Microsystems, Inc.
* All rights reserved.
*
* 
* ident  "@(#)smpl_cmm_member_getcount_all.c 1.3     02/09/25 SMI"
*
***************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <cmm.h>

int main(int argc , char ** argv) {
  cmm_error_t   L_Status;
  uint32_t      L_NodesNumber;
  cmm_member_t *L_Table = NULL;
  uint32_t      L_TableSize;
  int           i;

  /*Getting node count with cmm_member_getcount() */
  L_Status = cmm_member_getcount(&L_NodesNumber);
  if (L_Status != CMM_OK) {
    fprintf(stderr,"cmm_member_getcount() error: %s\n",
	cmm_strerror(L_Status));
    exit(1);
  }
  
  printf("Number of nodes in cluster: %d\n",L_NodesNumber);

  /*Getting information on all nodes in cluster*/
  L_TableSize = L_NodesNumber + 3; /* "+3" to be safer */

  L_Table = (cmm_member_t *) malloc(L_TableSize * sizeof(cmm_member_t));
  if (L_Table == NULL) {
    fprintf(stderr,"Memory allocation error\n");
    exit(1);
  }

 
  L_Status = cmm_member_getall(L_TableSize,L_Table,&L_NodesNumber);
 
  if (L_Status != CMM_OK) {
    fprintf(stderr,"cmm_member_getall() error %s\n",
	cmm_strerror(L_Status));
    free(L_Table);
    exit(1);
  }

  printf("Information on cluster:\n");
  for (i = 0 ; i < L_NodesNumber ; i++) {
    printf("Infornation on node:  %d\n",L_Table[i].nodeid);
    printf("\tName:               %s\n",L_Table[i].name);
    printf("\tAdress:             %s\n",L_Table[i].addr);
    printf("\tDomain Id:          %d\n",L_Table[i].domainid);
    printf("\tIncarnation number: %d\n",L_Table[i].incarnation_number);
    printf("\tSoftwareLoad id:    %s\n",L_Table[i].software_load_id);
    printf("\tRole:               ");
    if      (cmm_member_ismaster(&L_Table[i]))     printf("MASTER\n");
    else if (cmm_member_isvicemaster(&L_Table[i])) 
            printf("VICE-MASTER\n");
    else    printf("IN CLUSTER\n");
    
    printf("\tQualification:      ");
    if      (cmm_member_isqualified(&L_Table[i]))    printf("QUALIFIED\n");
    else if (cmm_member_isdisqualified(&L_Table[i])) 
            printf("DISQUALIFIED\n");
    
  }
  
  free(L_Table);

  exit(0);
}

Previous Previous     Contents     Index     Next Next