ClInt32T main(ClInt32T argc, ClCharT *argv[])
{
    SaAisErrorT rc = SA_AIS_OK;

    /* Connect to the SAF cluster */
    rc = initializeAmf();
    
    if( rc != SA_AIS_OK)
    {
      CL_DEBUG_PRINT(CL_DEBUG_CRITICAL,
                       ("CKPT: ckptInitialize failed [0x%X]\n\r", rc));
        return rc;
    }       
	
   
    /* Do the application specific initialization here. */
    
    /* Block on AMF dispatch file descriptor for callbacks.
       When this function returns its time to quit. */
    dispatchLoop();
    
    
    /* Now finalize my connection with the SAF cluster */
    rc = saAmfFinalize(amfHandle);
      

    return 0;
}
int main(int argc, char *argv[])
{
    SaAisErrorT rc = SA_AIS_OK;

    /* Connect to the SAF cluster */
    initializeAmf();

    /* Do the application specific initialization here. */
    
    /* Block on AMF dispatch file descriptor for callbacks.
       When this function returns its time to quit. */
    dispatchLoop();

    checkpoint_finalize();
    
    /* Do the application specific finalization here. */

    /* Now finalize my connection with the SAF cluster */
    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
      clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
    else
      clprintf (CL_LOG_SEV_INFO, "AMF Finalized");   

    return 0;
}
int main(int argc, char *argv[])
{
    SaAisErrorT rc = SA_AIS_OK;

    /* Connect to the SAF cluster */
    initializeAmf();

    /* Do the application specific initialization here. */
    /* Set up console redirection for demo purposes */
    (void)ev_init(argc, argv, (ClCharT*)appName.value);

    /* Block on AMF dispatch file descriptor for callbacks.
       When this function returns its time to quit. */
    dispatchLoop();
    
    /* Do the application specific finalization here. */

    /* Now finalize my connection with the SAF cluster */
    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
      clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
    else
      clprintf (CL_LOG_SEV_INFO, "AMF Finalized");   

    return 0;
}
int main(int argc, char *argv[])
{
    SaAisErrorT rc = SA_AIS_OK;
    SaSelectionObjectT dispatch_fd;
    fd_set read_fds;
    ClRcT ret = CL_OK;

    /* Connect to the SAF cluster */
    initializeAmf();

    /* Do the application specific initialization here. */
    FD_ZERO(&read_fds);

    if ( (rc = saAmfSelectionObjectGet(amfHandle, &dispatch_fd)) != SA_AIS_OK)
        errorExit(rc);
    
    FD_SET(dispatch_fd, &read_fds);
    
    /* Handle the AMF dispatch loop by spawning a thread that does it */
    ret = clOsalTaskCreateDetached("DISPATCH-THREAD", CL_OSAL_SCHED_OTHER, 0, 0, saAmfDispatchThread, NULL);
    if(ret != CL_OK)
    {
        clprintf(CL_LOG_SEV_ERROR, "Dispatch task create failed with rc 0x%x",rc);
        return ret;
    } 
    while (!unblockNow)
    {
        /* csa112: If I am active then I'll publish an event.
           Note, any application can publish and event regardless of
           HA state.  This tutorial simply uses HA state so only
           one of the two processes are publishing.
        */
        
        if (running && ha_state == SA_AMF_HA_ACTIVE)
        {
            csa113Comp_PublishEvent();
        }
    
        sleep(1);  /* Keep the event publish rate reasonable for this tutorial*/
    }
    
    /* Do the application specific finalization here. */
    if ((rc = saEvtChannelClose(evtChannelHandle)) != SA_AIS_OK)
    {
        clprintf(CL_LOG_SEV_ERROR, "Failed [0x%x] to close event channel", rc);
    }

    if ((rc = saEvtFinalize(evtLibHandle)) != SA_AIS_OK)
    {
        clprintf(CL_LOG_SEV_ERROR, "Failed [0x%x] to finalize event library", rc);
    }

    /* Now finalize my connection with the SAF cluster */
    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
      clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
    else
      clprintf (CL_LOG_SEV_INFO, "AMF Finalized");   

    return 0;
}
int main(int argc, char *argv[])
{
    ClRcT   rc = CL_OK;
    if (argc < 2){
        clLog (EMER,GEN,NA, "usage : %s", GMS_USAGE);
        exit(0);
    }

    /* Connect to the SAF cluster */
    rc = initializeAmf();
    if( rc != CL_OK)
    {
        clLogCritical(GEN,NA,
                      "GMS: gmsInitialize failed [0x%X]\n\r", rc);
        return rc;
    }
    _clGmsServiceInitialize ( argc , argv );

    
    /* Block on AMF dispatch file descriptor for callbacks.
       When this function returns its time to quit. */
    dispatchLoop();
    
    saAmfFinalize(amfHandle); 

    return 0;
}
/****************************************************************************
  Name          : proxy_healthcheck_callback
 
  Description   : This routine is a callback to perform the healthcheck and 
                  report any healthcheck failure to AMF. It is specified as 
                  a part of AMF initialization. It demonstrates the use of 
                  following AMF APIs:
                  a) saAmfHealthcheckStop()
                  b) saAmfComponentErrorReport()
 
  Arguments     : inv              - particular invocation of this callback 
                                     function
                  comp_name        - ptr to the component name
                  health_check_key - ptr to the healthcheck key for which the
                                     healthcheck is to be performed.
 
  Return Values : None.
 
  Notes         : This routine responds to the healhcheck callbacks for 
                  AVSV_HEALTHCHECK_CALLBACK_MAX_COUNT times after which it sends 
                  an error report.
******************************************************************************/
void proxy_healthcheck_callback(SaInvocationT        inv, 
                                   const SaNameT        *comp_name,
                                   SaAmfHealthcheckKeyT *health_check_key)
{
   SaAisErrorT rc;
   static int healthcheck_count = 0;

   printf("\n Dispatched 'HealthCheck' Callback \n Component: %s \n HealthCheckKey: %s \n", 
                      comp_name->value, health_check_key->key);

   /* Respond immediately */
   rc = saAmfResponse(pxy_pxd_cb.pxy_info.amfHandle, inv, SA_AIS_OK);
   if ( SA_AIS_OK != rc )
   {
      saAmfComponentUnregister(pxy_pxd_cb.pxy_info.amfHandle, &pxy_pxd_cb.pxy_info.compName, 0);
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      printf("\nsaAmfResponse returned failure for Health Check. Result %d\n",rc);
      return;
   }

   /* Increment healthcheck count */
   healthcheck_count++;

   return;
}
Example #7
0
/****************************************************************************
 * Name          : eds_se_lib_destroy
 *
 * Description   : Invoked to destroy the EDS
 *                 
 *
 * Arguments     : 
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE..
 *
 * Notes         : None.
 *****************************************************************************/
static uint32_t eds_se_lib_destroy(NCS_LIB_REQ_INFO *req_info)
{
    /** Code to destroy the EDS **/
	EDS_CB *eds_cb;
	m_INIT_CRITICAL;
	TRACE_ENTER();

	if (NULL == (eds_cb = (NCSCONTEXT)ncshm_take_hdl(NCS_SERVICE_ID_EDS, gl_eds_hdl))) {
		LOG_ER("Handle take failed for global handle");
		TRACE_LEAVE();
		return (NCSCC_RC_FAILURE);
	} else {
		m_START_CRITICAL;
      /** Lock EDA_CB
       **/
		m_NCS_LOCK(&eds_cb->cb_lock, NCS_LOCK_WRITE);

		/* deregister from AMF */
		saAmfComponentUnregister(eds_cb->amf_hdl, &eds_cb->comp_name, NULL);

		/* End association from the AMF lib */
		saAmfFinalize(eds_cb->amf_hdl);

		/* Finalize with CLM */
		saClmFinalize(eds_cb->clm_hdl);

		/* Clean up all internal structures */
		eds_remove_reglist_entry(eds_cb, 0, true);

		/* Destroy the cb */
		eds_cb_destroy(eds_cb);

		/* Give back the handle */
		ncshm_give_hdl(gl_eds_hdl);
		ncshm_destroy_hdl(NCS_SERVICE_ID_GLD, gl_eds_hdl);

		/* Detach from IPC */
		m_NCS_IPC_DETACH(&eds_cb->mbx, eds_clear_mbx, eds_cb);

		/* Disconnect from MDS */
		eds_mds_finalize(eds_cb);

		/* Release the IPC */
		m_NCS_IPC_RELEASE(&eds_cb->mbx, NULL);

      /** UnLock EDA_CB
       **/
		m_NCS_UNLOCK(&eds_cb->cb_lock, NCS_LOCK_WRITE);
		m_NCS_LOCK_DESTROY(&eds_cb->cb_lock);
		m_MMGR_FREE_EDS_CB(eds_cb);

		gl_eds_hdl = 0;
		m_END_CRITICAL;
		TRACE("eds-cb-lib destroy done .");
	}

	TRACE_LEAVE();
	return (NCSCC_RC_SUCCESS);
}
/****************************************************************************
  Name          : proxy_csi_set_callback
 
  Description   : This routine is a callback to set (add/modify) the HA state
                  of a CSI (or all the CSIs) that is newly/already assigned 
                  to the component. It is specified as a part of AMF 
                  initialization.
 
  Arguments     : inv       - particular invocation of this callback function
                  comp_name - ptr to the component name
                  ha_state  - ha state to be assumed by the CSI (or all the 
                              CSIs)
                  csi_desc  - CSI descriptor

  Return Values : None.
 
  Notes         : None. 
******************************************************************************/
void proxy_csi_set_callback(SaInvocationT       inv, 
                               const SaNameT       *comp_name,
                               SaAmfHAStateT       ha_state,
                               SaAmfCSIDescriptorT csi_desc)
{
   SaAmfHAStateT ha_st;
   SaAisErrorT      rc = SA_AIS_OK;
   SaNameT *csi_name;
   uns8    trk_flags;
   uns32   index = 0;

   printf("\n'Proxy CSI Set' Callback \n Component: %s \n CSIName: %s \n HAState: %s \n CSIFlags: %s \n", 
                      comp_name->value, csi_desc.csiName.value, 
                      ha_state_str[ha_state], csi_flag_str[csi_desc.csiFlags]);

   switch(ha_state)
   {
   case SA_AMF_HA_ACTIVE:
      /* We need to register all the proxied component when becoming ACT */
      pxy_pxd_cb.pxy_info.haState = ha_state;
      for(index=0; index<PXY_PXD_NUM_OF_PROXIED_COMP; index++)
        pxy_pxd_cb.pxd_info[index].reg_pxied_comp = TRUE;
      break;

   case SA_AMF_HA_QUIESCED: 
      /* We need to unregister to all proxied components, if going to STDBY 
         from ACT.*/
      if(SA_AMF_HA_ACTIVE == pxy_pxd_cb.pxy_info.haState)
      {
         /* If previous HA state is ACT, then unregister all proxied comp. */
         pxy_pxd_cb.unreg_pxied_comp = TRUE;
      }
      pxy_pxd_cb.pxy_info.haState = ha_state;
      break;
   case SA_AMF_HA_STANDBY:
      pxy_pxd_cb.pxy_info.haState = ha_state;
      break;
   default:
      rc=SA_AIS_ERR_FAILED_OPERATION;
      break;
   };

   rc = saAmfResponse(pxy_pxd_cb.pxy_info.amfHandle, inv, rc);
   if ( SA_AIS_OK != rc )
   {
      printf("\nsaAmfResponse returned failure for CSI Set. Result %d\n",rc);
      saAmfComponentUnregister(pxy_pxd_cb.pxy_info.amfHandle, 
                               &pxy_pxd_cb.pxy_info.compName, 0);
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }

   return;
}
ClInt32T main(ClInt32T argc, ClCharT *argv[])
{
   ClRcT  rc = CL_OK;
   rc = clLogSvrInitialize(argc,argv);
   if(rc != CL_OK)
   {
        CL_LOG_DEBUG_ERROR(("clLogSvrInitialize() failed with : rc[0x %x]", rc));
        return rc;
   }
   dispatchLoop();
   saAmfFinalize(amfHandle);   
   return 0;
}
static PyObject* finalizeAmf(PyObject *self, PyObject *args)
{    
    ClRcT rc;
    
    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
	{
        clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
        PyObject* errData = Py_BuildValue("is",rc,"AMF finalization error");
        PyErr_SetObject(PyExc_SystemError,errData);
        return NULL;
	}

    clprintf (CL_LOG_SEV_INFO, "AMF Finalized");

    Py_RETURN_NONE;    
}
Example #11
0
/****************************************************************************
  Name          : avsv_amf_comp_terminate_callback

  Description   : This routine is a callback to terminate the component. It
		  is specified as a part of AMF initialization.

  Arguments     : inv             - particular invocation of this callback
				    function
		  comp_name       - ptr to the component name

  Return Values : None.

  Notes         : None
******************************************************************************/
void avsv_amf_comp_terminate_callback(SaInvocationT inv,
                                      const SaNameT *comp_name)
{
    SaAisErrorT rc;

    syslog(LOG_INFO, "\n Dispatched 'Component Terminate' Callback \n Component: %s ",
           comp_name->value);

    /* Respond immediately */
    rc = saAmfResponse(gl_amf_hdl, inv, SA_AIS_OK);
    if ( SA_AIS_OK != rc ) {
        syslog(LOG_ERR, "saAmfResponse FAILED - %u", rc);
        saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
        saAmfFinalize(gl_amf_hdl);
    }
}
Example #12
0
/****************************************************************************
  Name          : proxy_comp_terminate_callback
 
  Description   : This routine is a callback to terminate the component. It 
                  is specified as a part of AMF initialization.
 
  Arguments     : inv             - particular invocation of this callback 
                                    function
                  comp_name       - ptr to the component name
 
  Return Values : None.
 
  Notes         : None
******************************************************************************/
void proxy_comp_terminate_callback(SaInvocationT inv, 
                                      const SaNameT *comp_name)
{
   SaAisErrorT rc;

   printf("\n Proxy 'Component Terminate' Callback \n Component: %s \n", 
                      comp_name->value);

   rc = saAmfResponse(pxy_pxd_cb.pxy_info.amfHandle, inv, SA_AIS_OK);
   if ( SA_AIS_OK != rc )
   {
      saAmfComponentUnregister(pxy_pxd_cb.pxy_info.amfHandle, 
                               &pxy_pxd_cb.pxy_info.compName, 0);
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      printf("\nsaAmfResponse returned failure for Comp Terminate. Result %d\n",rc);
   }

   return;
}
int main (void) {
	SaAmfHandleT handle;
	int result;
	SaNameT compName;
	pthread_t dispatch_thread;
	pthread_attr_t dispatch_thread_attribute;

	result = saAmfInitialize (&handle, &amfCallbacks, &version);
	if (result != SA_OK) {
		printf ("initialize result is %d\n", result);
		exit (1);
	}

	setSanameT (&compName, "comp_b_in_su_y");

	result = saAmfComponentRegister (&handle, &compName, NULL);
	printf ("register result is %d (should be 1)\n", result);

	pthread_attr_init (&dispatch_thread_attribute);
	pthread_attr_setschedpolicy (&dispatch_thread_attribute, SCHED_FIFO);
//	pthread_attr_setschedparam (&dispatch_thread_attribute, 99);
	pthread_create (&dispatch_thread, NULL, th_dispatch, &handle);

	sleep (5);

printf ("Finalizing handle\n");

	saAmfComponentUnregister (&handle, &compName, NULL);

	saAmfFinalize (&handle);

printf ("Handle Finalized\n");
	sleep (1); /* this sleep isn't really necessary */
	result = saAmfInitialize (&handle, &amfCallbacks, &version);
	result = saAmfComponentRegister (&handle, &compName, NULL);
	pthread_create (&dispatch_thread, NULL, th_dispatch, &handle);
	sleep (10);
//	saAmfFinalize (&handle);

	exit (0);
}
Example #14
0
/****************************************************************************
  Name          : avsv_amf_csi_remove_callback

  Description   : This routine is a callback to remove the CSI (or all the
		  CSIs) that is/are assigned to the component. It is specified
		  as a part of AMF initialization.

  Arguments     : inv       - particular invocation of this callback function
		  comp_name - ptr to the component name
		  csi_name  - ptr to the CSI name that is being removed
		  csi_flags - specifies if one or more CSIs are affected

  Return Values : None.

  Notes         : None
******************************************************************************/
void avsv_amf_csi_remove_callback(SaInvocationT  inv,
                                  const SaNameT  *comp_name,
                                  const SaNameT  *csi_name,
                                  SaAmfCSIFlagsT csi_flags)
{
    SaAisErrorT rc;

    syslog(LOG_INFO, "\n Dispatched 'CSI Remove' Callback \n Component: %s \n CSI: %s \n CSIFlags: %s ",
           comp_name->value, csi_name->value, csi_flag_str[csi_flags]);

    /* Reset the ha state */
    gl_ha_state = 0;

    /* Respond immediately */
    rc = saAmfResponse(gl_amf_hdl, inv, SA_AIS_OK);
    if ( SA_AIS_OK != rc ) {
        syslog(LOG_ERR, "saAmfResponse FAILED - %u", rc);
        saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
        saAmfFinalize(gl_amf_hdl);
    }
}
ClInt32T main(ClInt32T argc, ClCharT *argv[])
{
    SaAisErrorT rc = SA_AIS_OK;

    /* Connect to the SAF cluster */
    rc = initializeAmf();
    if( rc != SA_AIS_OK)
    {
       clLogCritical(CL_LOG_AREA_UNSPECIFIED, CL_LOG_CONTEXT_UNSPECIFIED,
                     "CKPT: ckptInitialize failed [0x%X]\n\r", rc);
        return rc;
    }       
        
    /* Block on AMF dispatch file descriptor for callbacks.
       When this function returns its time to quit. */
    dispatchLoop();
        
    /* Now finalize my connection with the SAF cluster */
    rc = saAmfFinalize(amfHandle);
   
    return 0;
}
ClInt32T main(ClInt32T argc, ClCharT *argv[])
{
    ClRcT rc = CL_OK;

    /* Connect to the SAF cluster */

    rc = initializeAmf();
    if(rc != CL_OK)
    {
       CL_DEBUG_PRINT(CL_DEBUG_CRITICAL,
                       ("MSG: msgInitialize failed [0x%X]\n\r", rc));
       return rc;
    }

    /* Block on AMF dispatch file descriptor for callbacks.
       When this function returns its time to quit. */
    dispatchLoop();

    /* Now finalize my connection with the SAF cluster */

   saAmfFinalize(amfHandle);

   return 0;
}
Example #17
0
/* Unregistration and Finalization with AMF Library */
uns32 dts_amf_finalize(DTS_CB *dts_cb_inst)
{
	SaAisErrorT status = SA_AIS_OK;

	/* delete the fd from the select list */
	memset(&dts_cb_inst->dts_amf_sel_obj, 0, sizeof(SaSelectionObjectT));

	/* Disable the health monitoring */
	status = saAmfHealthcheckStop(dts_cb_inst->amf_hdl, &dts_cb_inst->comp_name, &dts_cb_inst->health_chk_key);

	if (status != SA_AIS_OK) {
		/* log the error */
		m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_finalize: Helath Check stop failed");
		/* continue finalization */
	}

	/* Unregister with AMF */
	status = saAmfComponentUnregister(dts_cb_inst->amf_hdl, &dts_cb_inst->comp_name, NULL);
	if (status != SA_AIS_OK) {
		/* log the error */
		m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_finalize: Component unregistered failed!!");
		/* continue finalization */
	}

	/* Finalize */
	status = saAmfFinalize(dts_cb_inst->amf_hdl);
	if (status != SA_AIS_OK) {
		/* log the error */
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_amf_finalize: Component Finalized failed!!");
	}

	dts_cb_inst->amf_init = FALSE;
	m_LOG_DTS_API(DTS_AMF_FINALIZE);

	return NCSCC_RC_SUCCESS;
}
Example #18
0
/****************************************************************************
 * Name          : gld_se_lib_destroy
 *
 * Description   : Invoked to destroy the GLD
 *                 
 *
 * Arguments     : 
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE..
 *
 * Notes         : None.
 *****************************************************************************/
uns32 gld_se_lib_destroy(NCS_LIB_REQ_INFO *req_info)
{
	GLSV_GLD_CB *gld_cb;

	if ((gld_cb = (NCSCONTEXT)ncshm_take_hdl(NCS_SERVICE_ID_GLD, gl_gld_hdl))
	    == NULL) {
		m_LOG_GLD_HEADLINE(GLD_TAKE_HANDLE_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
		return (NCSCC_RC_FAILURE);
	} else {
		/* Disconnect from MDS */
		gld_mds_shut(gld_cb);

		saAmfComponentUnregister(gld_cb->amf_hdl, &gld_cb->comp_name, (SaNameT *)NULL);
		saAmfFinalize(gld_cb->amf_hdl);

		ncshm_give_hdl(gl_gld_hdl);
		ncshm_destroy_hdl(NCS_SERVICE_ID_GLD, gl_gld_hdl);
		m_NCS_IPC_DETACH(&gld_cb->mbx, gld_clear_mbx, gld_cb);

		gld_cb_destroy(gld_cb);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
	}
	return (NCSCC_RC_SUCCESS);
}
Example #19
0
/****************************************************************************
  Name          : proxy_csi_remove_callback
 
  Description   : This routine is a callback to remove the CSI (or all the 
                  CSIs) that is/are assigned to the component. It is specified
                  as a part of AMF initialization.
 
  Arguments     : inv       - particular invocation of this callback function
                  comp_name - ptr to the component name
                  csi_name  - ptr to the CSI name that is being removed
                  csi_flags - specifies if one or more CSIs are affected

  Return Values : None.
 
  Notes         : None
******************************************************************************/
void proxy_csi_remove_callback(SaInvocationT  inv, 
                                  const SaNameT  *comp_name,
                                  const SaNameT  *csi_name,
                                  SaAmfCSIFlagsT csi_flags)
{
   SaAisErrorT rc;

   printf("\n Proxy 'CSI Remove' Callback \n Component: %s \n CSI: %s \n CSIFlags: %s \n", 
                      comp_name->value, csi_name->value, csi_flag_str[csi_flags]);

   /* Reset the ha state */
   pxy_pxd_cb.pxy_info.haState = 0;

   /* Respond immediately */
   rc = saAmfResponse(pxy_pxd_cb.pxy_info.amfHandle, inv, SA_AIS_OK);
   if ( SA_AIS_OK != rc )
   {
      saAmfComponentUnregister(pxy_pxd_cb.pxy_info.amfHandle, &pxy_pxd_cb.pxy_info.compName, 0);
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      printf("\nsaAmfResponse returned failure for CSI Remove. Result %d\n",rc);
   }

   return;
}
ClInt32T main(ClInt32T argc, ClCharT *argv[])
{
    ClRcT rc = CL_OK;

    clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs);
    
    rc = clEvtInitialize(argc,argv);
    if( rc != CL_OK )
    {
        CL_DEBUG_PRINT(CL_DEBUG_CRITICAL,
                       ("Event: clEvtInitialize failed [0x%X]\n\r", rc));
        return rc;
    }
            
    /* Block on AMF dispatch file descriptor for callbacks.
       When this function returns its time to quit. */
    dispatchLoop();
    
    /* Do the Event Service finalization here. */
    
   saAmfFinalize(gClEvtAmfHandle);
     
   return 0;
}
Example #21
0
/****************************************************************************
  Name          : pxy_pxd_amf_process
 
  Description   : This routine is an entry point for the AMF interface task.
                  It demonstrates the use of following AMF APIs
                  a) saAmfInitialize
                  b) saAmfSelectionObjectGet
                  c) saAmfCompNameGet
                  d) saAmfComponentRegister
                  e) saAmfDispatch
 
  Arguments     : None.
 
  Return Values : None.
 
  Notes         : None
******************************************************************************/
void pxy_pxd_amf_process (void)
{
   SaAisErrorT        rc;
   NCS_SEL_OBJ_SET    wait_sel_objs, all_sel_objs;
   SaSelectionObjectT pxy_amf_sel_obj,pxd_amf_sel_obj[PXY_PXD_NUM_OF_PROXIED_COMP];
   NCS_SEL_OBJ        pxy_amf_ncs_sel_obj,pxd_amf_ncs_sel_obj[PXY_PXD_NUM_OF_PROXIED_COMP];
   NCS_SEL_OBJ        highest_sel_obj,wait_sel_fd;
   int ret = 0;
   uns32 comp_inv_hc_time_out = 500;
   uns32 index = 0;

   /* this is to allow to establish MDS session with AvSv */
   m_NCS_TASK_SLEEP(3000);

   pxy_pxd_proxy_initialize();   

   rc = pxy_pxd_proxy_amf_init();

   if (SA_AIS_OK != rc)
      return;
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
     rc = pxy_pxd_proxied_amf_init(index);

   if (SA_AIS_OK != rc)
      return;

   /* Get the selection object corresponding to this AMF handle */
   rc = saAmfSelectionObjectGet(pxy_pxd_cb.pxy_info.amfHandle, &pxy_amf_sel_obj);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }
   
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
     /* Get the selection object corresponding to this AMF handle */
     rc = saAmfSelectionObjectGet(pxy_pxd_cb.pxd_info[index].amfHandle, 
                                  &pxd_amf_sel_obj[index]);
     if (SA_AIS_OK != rc)
     {
       saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
       printf("\n AMF Selection Object Get Failed for index %d !!!\n",index);
       return;
     }
   }

   printf("\n AMF Selection Object Get Successful !!! \n");

   rc = saAmfComponentNameGet(pxy_pxd_cb.pxy_info.amfHandle, 
                                 &pxy_pxd_cb.pxy_info.compName);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }

   printf("\n Component Name Get Successful !!! \n CompName: %s \n",
                      pxy_pxd_cb.pxy_info.compName.value);


   rc = saAmfComponentRegister(pxy_pxd_cb.pxy_info.amfHandle, 
                               &pxy_pxd_cb.pxy_info.compName, 0);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }

   printf("\n Proxy Component Registered !!! \n");

   /* Reset the wait select objects */
   m_NCS_SEL_OBJ_ZERO(&all_sel_objs);

   m_SET_FD_IN_SEL_OBJ((uns32)pxy_amf_sel_obj, pxy_amf_ncs_sel_obj);
   m_NCS_SEL_OBJ_SET(pxy_amf_ncs_sel_obj, &all_sel_objs);
   highest_sel_obj = pxy_amf_ncs_sel_obj;

   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    m_SET_FD_IN_SEL_OBJ((uns32)pxd_amf_sel_obj[index], pxd_amf_ncs_sel_obj[index]);
    m_NCS_SEL_OBJ_SET(pxd_amf_ncs_sel_obj[index], &all_sel_objs);
    highest_sel_obj = m_GET_HIGHER_SEL_OBJ(highest_sel_obj, pxd_amf_ncs_sel_obj[index]);
   }

   wait_sel_objs = all_sel_objs;
   wait_sel_fd  = highest_sel_obj;

   /* Now wait forever */
   while ((ret = m_NCS_SEL_OBJ_SELECT(wait_sel_fd, &wait_sel_objs, NULL, NULL,
           &comp_inv_hc_time_out)) != -1)
   {
    comp_inv_hc_time_out = 500;
    /* Check if it's an event from AMF */
    if(m_NCS_SEL_OBJ_ISSET(pxy_amf_ncs_sel_obj, &wait_sel_objs))
    {
      printf("\n Got Proxy AMF event!!! \n");
      /* There is an AMF callback waiting to be be processed. Process it */
      rc = saAmfDispatch(pxy_pxd_cb.pxy_info.amfHandle, SA_DISPATCH_ALL);
      if (SA_AIS_OK != rc)
      {
         printf("\n Proxy saAmfDispatch failed !!! \n");
         break;
      }
    }
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    if(TRUE == pxy_pxd_cb.pxd_info[index].reg_pxied_comp)
    {
      printf("\n Before registering pxd[%d]!!!\n",index);
      /* Need to register proxied component */
      rc = saAmfComponentRegister(pxy_pxd_cb.pxd_info[index].amfHandle,
                                   &pxy_pxd_cb.pxd_info[index].compName,
                                   &pxy_pxd_cb.pxy_info.compName);
      if (SA_AIS_OK == rc)
      {
        printf("\n Proxied[%d] Component Registeration Successful. "
                              "Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
        pxy_pxd_cb.pxd_info[index].health_start = TRUE;
        pxy_pxd_cb.pxd_info[index].reg_pxied_comp = FALSE;
      }
      else if (SA_AIS_ERR_TRY_AGAIN == rc)
      {
        printf("\n Proxied[%d] Component Registeration failed. TRY_AGAIN"
                              " Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
      }
      else
      {
        printf("\n Proxied[%d] Component Registeration failed."
                              " Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
        pxy_pxd_cb.pxd_info[index].reg_pxied_comp = FALSE;
      }
     }
    } /* if(TRUE == pxy_pxd_cb.reg_pxied_comp) */

   /* Section 1 Starts : Health Check : SA_AMF_HEALTHCHECK_AMF_INVOKED */
   {
    SaAmfHealthcheckInvocationT    hc_inv;
    SaAmfRecommendedRecoveryT      rec_rcvr;

     for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
     {
       if(TRUE == pxy_pxd_cb.pxd_info[index].health_start)
       { 
        printf("\n Before registering hc [%d]!!!\n",index);
        hc_inv = SA_AMF_HEALTHCHECK_AMF_INVOKED;
        rec_rcvr = SA_AMF_COMPONENT_FAILOVER;

        rc = saAmfHealthcheckStart(pxy_pxd_cb.pxd_info[index].amfHandle, 
                                   &pxy_pxd_cb.pxd_info[index].compName, 
                                   &pxy_pxd_cb.pxd_info[index].healthcheck_key,
                                   hc_inv, rec_rcvr);
        if (SA_AIS_OK == rc )
        {
          printf("Started AMF-Initiated HealthCheck (with Component "
                          "Failover Recommended Recovery) \n Comp: %s \n" 
                          "HealthCheckKey: %s \n",
                          pxy_pxd_cb.pxd_info[index].compName.value, 
                          pxy_pxd_cb.pxd_info[index].healthcheck_key.key);
          pxy_pxd_cb.pxd_info[index].health_start = FALSE;   
          pxy_pxd_cb.pxd_info[index].health_start_comp_inv = TRUE;   
        }
        else if(SA_AIS_ERR_TRY_AGAIN == rc)
        {
          printf(" AMF-Initiated HealthCheck TRY_AGAIN (with Component"
                            " Failover Recommended Recovery) \n Comp: %s \n" 
                            "HealthCheckKey: %s. Res %d \n",
                            pxy_pxd_cb.pxd_info[index].compName.value, 
                            pxy_pxd_cb.pxd_info[index].healthcheck_key.key, rc);
        }
        else
        {
          printf(" AMF-Initiated HealthCheck failed (with Component "
                            "Failover Recommended Recovery) \n Comp: %s \n" 
                            "HealthCheckKey: %s. Res %d \n",
                            pxy_pxd_cb.pxd_info[index].compName.value, 
                            pxy_pxd_cb.pxd_info[index].healthcheck_key.key, rc);
          pxy_pxd_cb.pxd_info[index].health_start = FALSE;   
        }
       } /* if(TRUE == pxy_pxd_cb.pxd_info[index].health_start)*/ 
     }
   }
   /* Section 1 Ends : Health Check : SA_AMF_HEALTHCHECK_AMF_INVOKED */

  if(TRUE == pxy_pxd_cb.unreg_pxied_comp)
  {
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
      printf("\n Before unregistering PXD[%d]!!! \n",index);
      /* Need to unregister proxied component */
       rc = saAmfComponentUnregister(pxy_pxd_cb.pxd_info[index].amfHandle,
                                     &pxy_pxd_cb.pxd_info[index].compName,
                                     &pxy_pxd_cb.pxy_info.compName);
       if (SA_AIS_OK != rc)
       {
          printf("\n Proxied Component unreg failed. Comp %s, Pxy Comp %s, Res %d\n",
                                pxy_pxd_cb.pxd_info[index].compName.value,
                                pxy_pxd_cb.pxy_info.compName.value,rc);
       }
       else
          printf("\n Proxied Component unreg Succ. Comp %s, Pxy Comp %s\n",
                                pxy_pxd_cb.pxd_info[index].compName.value,
                                pxy_pxd_cb.pxy_info.compName.value);
       pxy_pxd_cb.unreg_pxied_comp = FALSE;
       pxy_pxd_cb.pxd_info[index].health_start_comp_inv = FALSE;
   }
  }

   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    /* Check if it's an event from AMF */
    if(m_NCS_SEL_OBJ_ISSET(pxd_amf_ncs_sel_obj[index], &wait_sel_objs))
    {
      printf("\n Before Pxd dispatch PXD[%d] !!!\n",index);
      /* There is an AMF callback waiting to be be processed. Process it */
      rc = saAmfDispatch(pxy_pxd_cb.pxd_info[index].amfHandle, SA_DISPATCH_ONE);
      if (SA_AIS_OK != rc)
      {
         printf("\n PXD[%d] saAmfDispatch failed !!! \n",index);
         break;
      }
    }
   }
      /* Again set AMF select object to wait for another callback */
      wait_sel_objs = all_sel_objs;
      wait_sel_fd  = highest_sel_obj;
   }/* While loop */

   printf("\n\n Proxy Exited, ret %d!!!\n\n",ret);

   return;
}
void clGmsServerTerminate(SaInvocationT invocation, const SaNameT *compName)
{

    ClRcT   rc = CL_OK;

    gmsGlobalInfo.opState = CL_GMS_STATE_SHUTING_DOWN;

    clLog(CRITICAL,GEN,NA, "Got termination request for component [%.*s]. Started Shutting Down...", compName->length,compName->value);
    
    rc = clEoClientUninstallTables (gmsGlobalInfo.gmsEoObject, CL_EO_SERVER_SYM_MOD(gAspFuncTable, GMS));
    if (rc != CL_OK)
    {
        clLog(ERROR,GEN,NA, "clEoClientUninstall failed with rc = 0x%x", rc);
    }
    /*
     * Unregister with AMF and respond to AMF saying whether the
     * termination was successful or not.
     */
    

    rc = clDebugDeregister(gGmsDebugReg);
    if (rc != CL_OK)
    {
        clLog(ERROR,GEN,NA, "clDebugDeregister failed with rc = 0x%x", rc);
    }

    /* Close the leader election algorithm dl if open */
#ifndef VXWORKS_BUILD 
    if (pluginHandle != NULL)
    {
        dlclose(pluginHandle);
    }
#endif

    if(gClTotemRunning)
    {
        /* We need to invoke openais finalize function instead of signal
         * handler here */
        totempg_finalize();

        /* Waiting for 10ms before invoking exit() */
        usleep(10000);
    }
    clLog(CRITICAL,GEN,NA,
          "GMS server exiting");

    rc = clHandleDatabaseDestroy(contextHandleDatabase);
    if (rc != CL_OK)
    {
        clLog(ERROR,GEN,NA,
                "contextHandleDatabase destroy failed with Rc = 0x%x",rc);
    }
    rc = saAmfComponentUnregister(amfHandle, compName, NULL);
    
    if(rc != SA_AIS_OK) 
    {
        clLog(ERROR,GEN,NA,
              "saAmfComponentUnregister failed with rc = 0x%x", rc);     
    }

    rc = saAmfFinalize(amfHandle);

    if (rc != SA_AIS_OK)
    {
        clLog(ERROR,GEN,NA,
              "saAmfFinalize failed with rc = 0x%x", rc);
    }
    /* Ok tell SAFplus that we handled it properly */
    rc = saAmfResponse(amfHandle, invocation, SA_AIS_OK);
    
    if (rc != SA_AIS_OK)
    {
        clLog(ERROR,GEN,NA,
              "clCpmResponse failed with rc = 0x%x", rc);
    }
    unblockNow = CL_TRUE;
}
Example #23
0
/****************************************************************************
 * Name          : gld_se_lib_init
 *
 * Description   : Invoked to Initialize the GLD
 *                 
 *
 * Arguments     : 
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE..
 *
 * Notes         : None.
 *****************************************************************************/
uns32 gld_se_lib_init(NCS_LIB_REQ_INFO *req_info)
{
	GLSV_GLD_CB *gld_cb;
	SaAisErrorT amf_error;
	uns32 res = NCSCC_RC_SUCCESS;
	SaAmfHealthcheckKeyT Healthy;
	int8 *health_key;

	/* Register with Logging subsystem */
	if (NCS_GLSV_LOG == 1)
		gld_flx_log_reg();

	/* Allocate and initialize the control block */
	gld_cb = m_MMGR_ALLOC_GLSV_GLD_CB;

	if (gld_cb == NULL) {
		m_LOG_GLD_MEMFAIL(GLD_CB_ALLOC_FAILED, __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	}
	memset(gld_cb, 0, sizeof(GLSV_GLD_CB));

	/* TBD- Pool id is to be set */
	gl_gld_hdl = gld_cb->my_hdl = ncshm_create_hdl(gld_cb->hm_poolid, NCS_SERVICE_ID_GLD, (NCSCONTEXT)gld_cb);
	if (0 == gld_cb->my_hdl) {
		m_LOG_GLD_HEADLINE(GLD_CREATE_HANDLE_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}

	/* Initialize the cb parameters */
	if (gld_cb_init(gld_cb) != NCSCC_RC_SUCCESS) {
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}

	/* Initialize amf framework */
	if (gld_amf_init(gld_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_INIT_ERROR, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}
	m_LOG_GLD_SVC_PRVDR(GLD_AMF_INIT_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	/* Bind to MDS */
	if (gld_mds_init(gld_cb) != NCSCC_RC_SUCCESS) {
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		m_LOG_GLD_SVC_PRVDR(GLD_MDS_INSTALL_FAIL, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_MDS_INSTALL_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	/*   Initialise with the MBCSV service  */
	if (glsv_gld_mbcsv_register(gld_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLD_MBCSV(GLD_MBCSV_INIT_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;

	} else {
		m_LOG_GLD_MBCSV(GLD_MBCSV_INIT_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	}

	/* register glsv with imm */
	amf_error = gld_imm_init(gld_cb);
	if (amf_error != SA_AIS_OK) {
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		gld_log(NCSFL_SEV_ERROR, "Imm Init Failed %u\n", amf_error);
		return NCSCC_RC_FAILURE;
	}

	/* TASK CREATION AND INITIALIZING THE MAILBOX */
	if ((m_NCS_IPC_CREATE(&gld_cb->mbx) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_IPC_ATTACH(&gld_cb->mbx) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_TASK_CREATE((NCS_OS_CB)gld_main_process,
			       &gld_cb->mbx, "GLD", m_GLD_TASK_PRIORITY,
			       m_GLD_STACKSIZE,
			       &gld_cb->task_hdl) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_TASK_START(gld_cb->task_hdl) != NCSCC_RC_SUCCESS)) {
		m_LOG_GLD_HEADLINE(GLD_IPC_TASK_INIT, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return (NCSCC_RC_FAILURE);
	}

	m_NCS_EDU_HDL_INIT(&gld_cb->edu_hdl);

	/* register GLD component with AvSv */
	amf_error = saAmfComponentRegister(gld_cb->amf_hdl, &gld_cb->comp_name, (SaNameT *)NULL);
	if (amf_error != SA_AIS_OK) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_REG_ERROR, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		m_NCS_EDU_HDL_FLUSH(&gld_cb->edu_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_REG_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

   /** start the AMF health check **/
	memset(&Healthy, 0, sizeof(Healthy));
	health_key = (int8 *)getenv("GLSV_ENV_HEALTHCHECK_KEY");
	if (health_key == NULL) {
		if (strlen("A1B2") < sizeof(Healthy.key))
			strncpy((char *)Healthy.key, "A1B2", sizeof(Healthy.key));
		m_LOG_GLD_HEADLINE(GLD_HEALTH_KEY_DEFAULT_SET, NCSFL_SEV_INFO, __FILE__, __LINE__, 0);
	} else {
		if (strlen((char *)health_key) < sizeof(Healthy.key))
			strncpy((char *)Healthy.key, (char *)health_key, SA_AMF_HEALTHCHECK_KEY_MAX - 1);
	}
	Healthy.keyLen = strlen((char *)Healthy.key);

	amf_error = saAmfHealthcheckStart(gld_cb->amf_hdl, &gld_cb->comp_name, &Healthy,
					  SA_AMF_HEALTHCHECK_AMF_INVOKED, SA_AMF_COMPONENT_FAILOVER);
	if (amf_error != SA_AIS_OK) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_HLTH_CHK_START_FAIL, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		saAmfComponentUnregister(gld_cb->amf_hdl, &gld_cb->comp_name, (SaNameT *)NULL);
		m_NCS_EDU_HDL_FLUSH(&gld_cb->edu_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_HLTH_CHK_START_DONE, NCSFL_SEV_INFO, __FILE__, __LINE__);

	return (res);
}
int main(int argc, char *argv[])
{
    SaNameT             appName = {0};
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    SaSelectionObjectT dispatch_fd;
    fd_set read_fds;
    
    /*
     * Declare other local variables here.
     */

    /*
     * Get the pid for the process and store it in global variable.
     */

    mypid = getpid();

    /*
     * Initialize and register with CPM. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */

    version.releaseCode  = 'B';
    version.majorVersion = 01;
    version.minorVersion = 01;
    
    callbacks.saAmfHealthcheckCallback          = NULL;
    callbacks.saAmfComponentTerminateCallback   = clCompAppTerminate;
    callbacks.saAmfCSISetCallback               = clCompAppAMFCSISet;
    callbacks.saAmfCSIRemoveCallback            = clCompAppAMFCSIRemove;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
        
    /*
     * Initialize AMF client library.
     */

    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK) 
        goto errorexit;

    FD_ZERO(&read_fds);

    /*
     * Get the AMF dispatch FD for the callbacks
     */
    if ( (rc = saAmfSelectionObjectGet(amfHandle, &dispatch_fd)) != SA_AIS_OK)
        goto errorexit;
    
    FD_SET(dispatch_fd, &read_fds);


    /*
     * Do the application specific initialization here.
     */


    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        goto errorexit;
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK) 
        goto errorexit;

    /* Open the log stream as soon as I've registered with AMF */
    clEvalAppLogStreamOpen((ClCharT *)appName.value, &gEvalLogStream);

    /* Handle the AMF dispatch loop by spawning a thread that does it */
    rc = clOsalTaskCreateDetached("DISPATCH-THREAD", CL_OSAL_SCHED_OTHER, 0, 0, saAmfDispatchThread, NULL);
    if(rc != CL_OK)
    {
        clprintf(CL_LOG_SEV_ERROR, "Dispatch task create failed with rc 0x%x",rc);
        return rc;
    }
    
    /*
     * Print out standard information for this component.
     */

    clEoMyEoIocPortGet(&iocPort);
    
    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);

    /* csa112: initialize the event client library, open the event channel and subscribe to events */
    if (1)
    {
        const SaEvtCallbacksT evtCallbacks =
        {
            NULL,  /* Event open callback */
            csa112Comp_appEventCallback  /* Event delivery callback */
        };
        SaVersionT  evtVersion = {(ClUint8T)'B', 0x1, 0x1};
        
        rc = saEvtInitialize(&evtLibHandle, &evtCallbacks, &evtVersion);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_ERROR, "Failed to init event mechanism [0x%x]\n", rc);
            return rc;
        }
            // Open an event chanel so that we can subscribe to events on that channel
        rc = saEvtChannelOpen(evtLibHandle, &evtChannelName, (SA_EVT_CHANNEL_PUBLISHER | SA_EVT_CHANNEL_SUBSCRIBER | SA_EVT_CHANNEL_CREATE), (SaTimeT)SA_TIME_END, &evtChannelHandle);
        if (rc != SA_AIS_OK)
          {
          clprintf(CL_LOG_SEV_ERROR, "Failure opening event channel [0x%x] at %ld", rc, time(0L));
          goto errorexit;
          }
        
      rc = saEvtEventSubscribe(evtChannelHandle, NULL, 1);
      if (rc != SA_AIS_OK)
      {
        clprintf(CL_LOG_SEV_ERROR, "Failed to subscribe to event channel [0x%x]",rc);
        goto errorexit;
      }
    }

    /*csa113: create an event definition to be published */
    if (1)
    {
        SaNameT publisherName;
        clNameSet((ClNameT*) &publisherName,PUBLISHER_NAME);
        
        rc = saEvtEventAllocate(evtChannelHandle, &eventHandle);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_SEV_ERROR, "Failed to allocate event [0x%x]\n", rc);
            assert(0);
        }

        rc = saEvtEventAttributesSet(eventHandle, NULL, 1, 0, &publisherName);
        if (rc != SA_AIS_OK)
        {
            clprintf(CL_LOG_ERROR, "Failed to set event attributes [0x%x]\n",rc);
            assert(0);            
        }
    }
    
    
    while (!exiting)
    {
        /* csa112: If I am active then I'll publish an event.
           Note, any application can publish and event regardless of
           HA state.  This tutorial simply uses HA state so only
           one of the two processes are publishing.
        */
        
    if (running && ha_state == SA_AMF_HA_ACTIVE)
    {
        csa113Comp_PublishEvent();
    }
    
    sleep(1);  /* Keep the event publish rate reasonable for this tutorial*/
    }
    
    /*
     * Do the application specific finalization here.
     */

    /* csa112: close the event channel, finalize the event client library */
    if ((rc = saEvtChannelClose(evtChannelHandle)) != SA_AIS_OK)
    {
        clprintf(CL_LOG_ERROR, "Failed [0x%x] to close event channel", rc);
    }

    if ((rc = saEvtFinalize(evtLibHandle)) != SA_AIS_OK)
    {
        clprintf(CL_LOG_ERROR, "Failed [0x%x] to finalize event library", rc);
    }

    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
	{
        clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
	}

    clprintf (CL_LOG_SEV_INFO, "AMF Finalized");
    
    return 0;

errorexit:

    clprintf (CL_LOG_SEV_ERROR, "Component [%.*s] : PID [%d]. Initialization error [0x%x]\n",
              appName.length, appName.value, mypid, rc);

    return -1;
}
Example #25
0
/****************************************************************************
  Name          : avsv_amf_process

  Description   : This routine is an entry point for the AMF interface task.
		  It demonstrates the use of following AMF APIs
		  a) saAmfInitialize
		  b) saAmfSelectionObjectGet
		  c) saAmfCompNameGet
		  d) saAmfComponentRegister
		  e) saAmfDispatch

  Arguments     : None.

  Return Values : None.

  Notes         : None
******************************************************************************/
void *avsv_amf_process (void* dummy)
{
    SaAmfCallbacksT    reg_callback_set;
    SaVersionT         ver;
    SaAisErrorT        rc;
    SaSelectionObjectT amf_sel_obj;
    struct pollfd fds[1];

    syslog(LOG_INFO, " AMF thread entered");

    /*#########################################################################
    		  Demonstrating the use of saAmfInitialize()
    #########################################################################*/

    /* Fill the callbacks that are to be registered with AMF */
    memset(&reg_callback_set, 0, sizeof(SaAmfCallbacksT));
    reg_callback_set.saAmfCSISetCallback = avsv_amf_csi_set_callback;
    reg_callback_set.saAmfCSIRemoveCallback = avsv_amf_csi_remove_callback;
    reg_callback_set.saAmfHealthcheckCallback = avsv_amf_healthcheck_callback;
    reg_callback_set.saAmfComponentTerminateCallback = avsv_amf_comp_terminate_callback;
    reg_callback_set.saAmfProtectionGroupTrackCallback = avsv_amf_protection_group_callback;

    /* Fill the AMF version */
    m_AMF_VER_GET(ver);

    /* Initialize AMF */
    rc = saAmfInitialize(&gl_amf_hdl, &reg_callback_set, &ver);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, " saAmfInitialize FAILED %u", rc);
        goto done;
    }

    syslog(LOG_INFO, "AMF Initialization Done !!!");
    syslog(LOG_INFO, "\tAmfHandle: %llx ", gl_amf_hdl);

    /*#########################################################################
    	       Demonstrating the use of saAmfSelectionObjectGet()
    #########################################################################*/

    /* Get the selection object corresponding to this AMF handle */
    rc = saAmfSelectionObjectGet(gl_amf_hdl, &amf_sel_obj);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfSelectionObjectGet FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "AMF Selection Object Get Successful !!!");

    /*#########################################################################
    		Demonstrating the use of saAmfCompNameGet()
    #########################################################################*/

    rc = saAmfComponentNameGet(gl_amf_hdl, &gl_comp_name);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfComponentNameGet FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "Component Name Get Successful !!!");
    syslog(LOG_INFO, "\tCompName: %s", gl_comp_name.value);

    /*#########################################################################
    	      Demonstrating the use of saAmfComponentRegister()
    #########################################################################*/

    rc = saAmfComponentRegister(gl_amf_hdl, &gl_comp_name, 0);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfComponentRegister FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "Component Registered !!!");

    fds[0].fd = amf_sel_obj;
    fds[0].events = POLLIN;

    /***** Now wait on the AMF selection object *****/
    while (1) {
        int res = poll(fds, 1, -1);

        if (res == -1) {
            if (errno == EINTR)
                continue;
            else {
                syslog(LOG_ERR, "poll FAILED - %s", strerror(errno));
                exit(1);
            }
        }

        /*######################################################################
        		Demonstrating the use of saAmfDispatch()
        ######################################################################*/

        if (fds[0].revents & POLLIN) {
            /* There is an AMF callback waiting to be be processed. Process it */
            rc = saAmfDispatch(gl_amf_hdl, SA_DISPATCH_ONE);
            if (SA_AIS_OK != rc) {
                syslog(LOG_ERR, "saAmfDispatch FAILED %u", rc);
                saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
                saAmfFinalize(gl_amf_hdl);
                break;
            }
        }
    }

    syslog(LOG_INFO, "DEMO OVER !!!");
done:
    return NULL;
}
Example #26
0
/****************************************************************************
  Name          : avsv_amf_healthcheck_callback

  Description   : This routine is a callback to perform the healthcheck and
		  report any healthcheck failure to AMF. It is specified as
		  a part of AMF initialization. It demonstrates the use of
		  following AMF APIs:
		  a) saAmfHealthcheckStop()
		  b) saAmfComponentErrorReport()

  Arguments     : inv              - particular invocation of this callback
				     function
		  comp_name        - ptr to the component name
		  health_check_key - ptr to the healthcheck key for which the
				     healthcheck is to be performed.

  Return Values : None.

  Notes         : This routine responds to the healhcheck callbacks for
		  AVSV_HEALTHCHECK_CALLBACK_MAX_COUNT times after which it sends
		  an error report.
******************************************************************************/
void avsv_amf_healthcheck_callback(SaInvocationT        inv,
                                   const SaNameT        *comp_name,
                                   SaAmfHealthcheckKeyT *health_check_key)
{
    SaAisErrorT rc;
    static int healthcheck_count = 0;

    syslog(LOG_INFO, "\n Dispatched 'HealthCheck' Callback \n Component: %s \n HealthCheckKey: %s ",
           comp_name->value, health_check_key->key);

    /* Respond immediately */
    rc = saAmfResponse(gl_amf_hdl, inv, SA_AIS_OK);
    if ( SA_AIS_OK != rc ) {
        syslog(LOG_ERR, "saAmfResponse FAILED - %u", rc);
        saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
        saAmfFinalize(gl_amf_hdl);
        return;
    }

    /* Increment healthcheck count */
    healthcheck_count++;

    /* Send the Error Report */
    if (AMF_HEALTHCHECK_CALLBACK_MAX_COUNT == healthcheck_count) {
        /*######################################################################
        	    Demonstrating the use of saAmfHealthcheckStop()
        ######################################################################*/

        rc = saAmfHealthcheckStop(gl_amf_hdl, &gl_comp_name, &gl_healthcheck_key);
        if ( SA_AIS_OK != rc ) {
            syslog(LOG_ERR, "saAmfHealthcheckStop FAILED - %u", rc);
            saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
            saAmfFinalize(gl_amf_hdl);
            return;
        }

        syslog(LOG_INFO, "\n Stopped HealthCheck for Comp: %s with HealthCheckKey: %s ",
               gl_comp_name.value, gl_healthcheck_key.key);

        /*######################################################################
        	  Demonstrating the use of saAmfComponentErrorReport()
        ######################################################################*/

        syslog(LOG_INFO, "\n\n DEMONSTRATING COMPONENT FAILOVER THROUGH ERROR REPORT !!! ");
        sleep(2);

        rc = saAmfComponentErrorReport(gl_amf_hdl, &gl_comp_name, 0, SA_AMF_COMPONENT_FAILOVER, 0);
        if ( SA_AIS_OK != rc ) {
            syslog(LOG_ERR, "saAmfComponentErrorReport FAILED - %u", rc);
            saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
            saAmfFinalize(gl_amf_hdl);
            return;
        }

        syslog(LOG_INFO, "\n Sent Error Report for Comp: %s with CompFailover as the recommended recovery ",
               gl_comp_name.value);

        /* Reset the ha state */
        gl_ha_state = 0;
    }
}
int main (int argc, char **argv) {
	int result;
	SaSelectionObjectT select_fd;
	fd_set read_fds;
	extern char *optarg;
	extern int optind;
	int c;

	memset (&compNameGlobal, 0, sizeof (SaNameT));
	signal (SIGINT, sigintr_handler);
#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
	result = sched_setscheduler (0, SCHED_RR, &sched_param);
	if (result == -1) {
		printf ("couldn't set sched priority\n");
 	}
#endif

	for (;;){
		c = getopt(argc,argv,"h:n:");
		if (c==-1) {
			break;
		}
		switch (c) {
		case 0 :
			break;
		case 'h':
			health_flag = 0;
			sscanf (optarg,"%ud" ,&healthcheck_count);
			break;
		case 'n':
	  		setSanameT (&compNameGlobal, optarg);
			break;
                default :
			break;
                }
	}

	result = saAmfInitialize (&handle, &amfCallbacks, &version);
	if (result != SA_OK) {
		printf ("initialize result is %d\n", result);
		exit (1);
	}

	FD_ZERO (&read_fds);
	saAmfSelectionObjectGet (handle, &select_fd);
	FD_SET (select_fd, &read_fds);
	if (compNameGlobal.length <= 0) {
		setSanameT (&compNameGlobal, "comp_b_in_su_2");
	}

	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);
	printf ("start %d\n", result);

	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);
	printf ("start %d\n", result);
	result = saAmfComponentRegister (handle, &compNameGlobal, NULL);
	printf ("register result is %d (should be 1)\n", result);

	do {
		select (select_fd + 1, &read_fds, 0, 0, 0);
		saAmfDispatch (handle, SA_DISPATCH_ALL);
	} while (result && stop == 0);

	sleep (5);
	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);

	do {
		select (select_fd + 1, &read_fds, 0, 0, 0);
		saAmfDispatch (handle, SA_DISPATCH_ALL);
	} while (result);

	saAmfFinalize (handle);

	exit (0);
}
Example #28
0
/****************************************************************************
  Name          : avsv_amf_csi_set_callback

  Description   : This routine is a callback to set (add/modify) the HA state
		  of a CSI (or all the CSIs) that is newly/already assigned
		  to the component. It is specified as a part of AMF
		  initialization. It demonstrates the use of following
		  AMF APIs:
		  a) saAmfHAStateGet()
		  b) saAmfHealthcheckStart()
		  c) saAmfProtectionGroupTrack()
		  d) saAmfComponentUnregister()
		  e) saAmfFinalize()


  Arguments     : inv       - particular invocation of this callback function
		  comp_name - ptr to the component name
		  ha_state  - ha state to be assumed by the CSI (or all the
			      CSIs)
		  csi_desc  - CSI descriptor

  Return Values : None.

  Notes         : This routine starts health check on the active entity. If
		  the CSI transitions from standby to active, the demo is
		  considered over & then the usage of 'Component Unregister' &
		  'AMF Finalize' is illustrated.
******************************************************************************/
void avsv_amf_csi_set_callback(SaInvocationT       inv,
                               const SaNameT       *comp_name,
                               SaAmfHAStateT       ha_state,
                               SaAmfCSIDescriptorT csi_desc)
{
    SaAmfHAStateT ha_st;
    SaAisErrorT      rc;
    SaAmfHealthcheckInvocationT    hc_inv;
    SaAmfRecommendedRecoveryT      rec_rcvr;
    SaNameT *csi_name;
    SaUint8T    trk_flags;
    SaAmfProtectionGroupNotificationBufferT *not_buf;

    syslog(LOG_INFO, "Dispatched 'CSI Set' Callback for Component: '%s'", comp_name->value);
    syslog(LOG_INFO, "\tCSIName: %s \n HAState: %s \n CSIFlags: %s ",
           csi_desc.csiName.value, ha_state_str[ha_state], csi_flag_str[csi_desc.csiFlags]);

    /* Store the ha state */
    gl_ha_state = ha_state;

    /* Respond immediately */
    rc = saAmfResponse(gl_amf_hdl, inv, SA_AIS_OK);
    if ( SA_AIS_OK != rc ) {
        syslog(LOG_ERR, "saAmfResponse FAILED - %u", rc);
        saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
        saAmfFinalize(gl_amf_hdl);
        return;
    }

    /*
     * If ha-state is active & it's a new assignment, demonstrate the usage
     * of ha-state-get & start healthcheck
     */
    if ( (SA_AMF_HA_ACTIVE == ha_state) &&
            (SA_AMF_CSI_NEW_ASSIGN ==
             csi_desc.csiStateDescriptor.activeDescriptor.transitionDescriptor) ) {
        /*######################################################################
        	   Demonstrating the use of saAmfHAStateGet()
        ######################################################################*/

        syslog(LOG_INFO, "INVOKING saAmfHAStateGet() API !!!");
        sleep(2);

        rc = saAmfHAStateGet(gl_amf_hdl, &gl_comp_name, &csi_desc.csiName, &ha_st);
        if ( SA_AIS_OK != rc ) {
            syslog(LOG_ERR, "saAmfHAStateGet FAILED - %u", rc);
            saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
            saAmfFinalize(gl_amf_hdl);
            return;
        }

        syslog(LOG_INFO, "CompName: %s \n CSIName: %s \n HAState: %s ",
               gl_comp_name.value, csi_desc.csiName.value,
               ha_state_str[ha_st]);

        /*######################################################################
        	    Demonstrating the use of saAmfHealthcheckStart()
        ######################################################################*/

        syslog(LOG_INFO, "DEMONSTRATING AMF-INITIATED HEALTHCHECK !!!");
        sleep(2);

        /* Fill the healthcheck parameters */
        hc_inv = SA_AMF_HEALTHCHECK_AMF_INVOKED;
        rec_rcvr = SA_AMF_COMPONENT_FAILOVER;

        /* Start the Healthcheck */
        rc = saAmfHealthcheckStart(gl_amf_hdl, &gl_comp_name, &gl_healthcheck_key,
                                   hc_inv, rec_rcvr);
        if ( SA_AIS_OK != rc ) {
            syslog(LOG_ERR, "saAmfHealthcheckStart FAILED - %u", rc);
            saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
            saAmfFinalize(gl_amf_hdl);
            return;
        }

        syslog(LOG_INFO, "Started AMF-Initiated HealthCheck (with Component Failover Recommended Recovery) \n Comp: %s \n HealthCheckKey: %s ",
               gl_comp_name.value, gl_healthcheck_key.key);
    }

    /*
     * If ha-state is standby, start tracking the protection group
     * associated with this CSI & initiate counter reading from the active
     */
    if ( SA_AMF_HA_STANDBY == ha_state ) {
        /*######################################################################
        	    Demonstrating the use of saAmfProtectionGroupTrack()
        ######################################################################*/

        /* Fill the protection group track parameters */
        csi_name = &csi_desc.csiName;
        trk_flags = SA_TRACK_CHANGES_ONLY;
        not_buf = NULL;

        /* Start Tracking the Protection Group */
        rc = saAmfProtectionGroupTrack(gl_amf_hdl, csi_name, trk_flags, not_buf);
        if ( SA_AIS_OK != rc ) {
            syslog(LOG_ERR, "saAmfProtectionGroupTrack FAILED - %u", rc);
            saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
            saAmfFinalize(gl_amf_hdl);
            return;
        }

        syslog(LOG_INFO, "\n Started Protection Group Tracking \n CSI: %s \n Track Flags: Changes Only ",
               csi_name->value);
    }

    /* If ha-state is active & it is a result of failover, stop the demo */
    if ( (SA_AMF_HA_ACTIVE == ha_state) &&
            (SA_AMF_CSI_NEW_ASSIGN !=
             csi_desc.csiStateDescriptor.activeDescriptor.transitionDescriptor) ) {
        syslog(LOG_INFO, "\n\n DEMO OVER (UNREGISTER & FINALIZE THE COMPONENT) !!! ");

        /*######################################################################
        	   Demonstrating the use of saAmfComponentUnregister()
        ######################################################################*/

        sleep(15);

        rc = saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
        if ( SA_AIS_OK != rc ) {
            syslog(LOG_ERR, "saAmfComponentUnregister FAILED - %u", rc);
            return;
        }

        syslog(LOG_INFO, " Component UnRegistered !!! ");

        /*######################################################################
        	       Demonstrating the use of saAmfFinalize()
        ######################################################################*/

        sleep(2);

        rc = saAmfFinalize(gl_amf_hdl);
        if ( SA_AIS_OK != rc ) {
            syslog(LOG_ERR, "saAmfFinalize FAILED - %u", rc);
            return;
        }

        syslog(LOG_INFO, " AMF Finalize Done !!! ");

        /* Reset the ha state */
        gl_ha_state = 0;
    }
}
int main(int argc, char *argv[])
{
    SaNameT             appName = {0};
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    SaSelectionObjectT dispatch_fd;
    fd_set read_fds;

    /*
     * Declare other local variables here.
     */


    /*
     * Get the pid for the process and store it in global variable.
     */

    mypid = getpid();

    /*
     * Initialize and register with CPM. 'version' specifies the version of
     * AMF with which this application would like to interface. 'callbacks'
     * is used to register the callbacks this component expects to receive.
     */

    version.releaseCode                         = 'B';
    version.majorVersion                        = 01;
    version.minorVersion                        = 01;

    callbacks.saAmfHealthcheckCallback                    = NULL;
    callbacks.saAmfComponentTerminateCallback             = clCompAppTerminate;
    callbacks.saAmfCSISetCallback                         = clCompAppAMFCSISet;
    callbacks.saAmfCSIRemoveCallback                      = clCompAppAMFCSIRemove;
    callbacks.saAmfProtectionGroupTrackCallback           = NULL;
    callbacks.saAmfProxiedComponentInstantiateCallback    = clProxiedCompInstantiate;
    callbacks.saAmfProxiedComponentCleanupCallback        = clProxiedCompCleanup;

    /*
     * Get IOC Address, Port and Name. Register with AMF.
     */

    clEoMyEoIocPortGet(&iocPort);

    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK)
        goto errorexit;

    FD_ZERO(&read_fds);

    /*
     * Get the AMF dispatch FD for the callbacks
     */
    if ( (rc = saAmfSelectionObjectGet(amfHandle, &dispatch_fd)) != SA_AIS_OK)
        goto errorexit;

    FD_SET(dispatch_fd, &read_fds);

    /*
     * Do the application specific initialization here.
     */


    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK)
        goto errorexit;
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK)
        goto errorexit;

    /*
     * Print out standard information for this component.
     */

    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);

    /*
     * Block on AMF dispatch file descriptor for callbacks
     */
    do
    {
        if( select(dispatch_fd + 1, &read_fds, NULL, NULL, NULL) < 0)
        {
            clprintf (CL_LOG_SEV_ERROR, "Error in select()");
            perror("");
            break;
        }
        saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
    } while(!unblockNow);

    /*
     * Do the application specific finalization here.
     */


    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
    {
        clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
    }

    clprintf (CL_LOG_SEV_INFO, "AMF Finalized");

    return 0;

errorexit:

    clprintf (CL_LOG_SEV_ERROR, "Component [%.*s] : PID [%d]. Initialization error [0x%x]\n",
              appName.length, appName.value, mypid, rc);

    return -1;
}
Example #30
0
/****************************************************************************
  Name          : avsv_amf_protection_group_callback

  Description   : This routine is a callback to notify the application of any
		  changes in the protection group. It demonstrates the use of
		  following AMF APIs:
		  a) saAmfProtectionGroupTrackStop()
		  b) saAmfPmStart()
		  c) saAmfPmStop()

  Arguments     : csi_name - ptr to the csi-name
		  not_buf  - ptr to the notification buffer
		  mem_num  - number of components that belong to this
			     protection group
		  err      - error code

  Return Values : None.

  Notes         : None.
******************************************************************************/
void avsv_amf_protection_group_callback(const SaNameT *csi_name,
                                        SaAmfProtectionGroupNotificationBufferT *not_buf,
                                        SaUint32T mem_num,
                                        SaAisErrorT err)
{
    unsigned int  item_count;
    pid_t  pid;
    SaAmfPmErrorsT   pm_err;
    SaAmfRecommendedRecoveryT rec_rcvr;
    SaAmfPmStopQualifierT     stop_qual;
    SaAisErrorT  rc;

    syslog(LOG_INFO, "\n Dispatched 'Protection Group' Callback \n CSI: %s \n No. of Members: %d ",
           csi_name->value, mem_num);

    if ( SA_AIS_OK != err )
        return;

    /* Print the Protection Group members */
    for (item_count= 0; item_count < not_buf->numberOfItems; item_count++) {
        syslog(LOG_INFO, " CompName[%d]: %s ",
               item_count, not_buf->notification[item_count].member.compName.value);
        syslog(LOG_INFO, " Rank[%d]    : %d ",
               item_count, not_buf->notification[item_count].member.rank);
        syslog(LOG_INFO, " HAState[%d] : %s ",
               item_count, ha_state_str[not_buf->notification[item_count].member.haState]);
        syslog(LOG_INFO, " Change[%d]  : %s ",
               item_count, pg_change_str[not_buf->notification[item_count].change]);
    }


    /*######################################################################
    	Demonstrating the use of saAmfProtectionGroupTrackStop()
    ######################################################################*/

    rc = saAmfProtectionGroupTrackStop(gl_amf_hdl, csi_name);
    if ( SA_AIS_OK != rc ) {
        syslog(LOG_ERR, "saAmfProtectionGroupTrackStop FAILED - %u", rc);
        saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
        saAmfFinalize(gl_amf_hdl);
        return;
    }

    syslog(LOG_INFO, "\n Stopped Protection Group Tracking for CSI: %s ",
           csi_name->value);


    /*######################################################################
    	       Demonstrating the use of saAmfPmStart()
    ######################################################################*/

    /* Fill the `Passive Monitoring Start' parameters */
    pid = getpid();
    pm_err = SA_AMF_PM_NON_ZERO_EXIT;
    rec_rcvr = SA_AMF_COMPONENT_RESTART;

    /* Start Passive Monitoring */
    rc = saAmfPmStart(gl_amf_hdl, &gl_comp_name, pid, 0, pm_err, rec_rcvr);
    if ( SA_AIS_OK != rc ) {
        syslog(LOG_ERR, "saAmfPmStart FAILED - %u", rc);
        saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
        saAmfFinalize(gl_amf_hdl);
        return;
    }

    syslog(LOG_INFO, "\n Started Passive Monitoring for Comp: %s ",
           gl_comp_name.value);


    /*######################################################################
    	       Demonstrating the use of saAmfPmStop()
    ######################################################################*/

    /* Fill the `Passive Monitoring Stop' parameters */
    pid = getpid();
    pm_err = SA_AMF_PM_NON_ZERO_EXIT;
    stop_qual = SA_AMF_PM_PROC;

    /* Start Passive Monitoring */
    rc = saAmfPmStop(gl_amf_hdl, &gl_comp_name, stop_qual, pid, pm_err);
    if ( SA_AIS_OK != rc ) {
        syslog(LOG_ERR, "saAmfPmStop FAILED - %u", rc);
        saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
        saAmfFinalize(gl_amf_hdl);
        return;
    }

    syslog(LOG_INFO, "\n Stopped Passive Monitoring for Comp: %s ",
           gl_comp_name.value);
}