/**************************************************************************
 * FUNCTION:  Java_org_opensaf_ais_amf_CsiManagerImpl_getHaState
 * TYPE:      native method
 *  Class:     ais_amf_CsiManager
 *  Method:    getHaState
 *  Signature: (Ljava/lang/String;Ljava/lang/String;)Lorg/saforum/ais/amf/HaState;
 *************************************************************************/
JNIEXPORT jobject JNICALL
Java_org_opensaf_ais_amf_CsiManagerImpl_getHaState(JNIEnv *jniEnv,
						   jobject thisCsiManager,
						   jstring componentName,
						   jstring csiName)
{
	// VARIABLES
	SaNameT _saComponentName;
	SaNameT *_saComponentNamePtr = &_saComponentName;
	SaNameT _saCsiName;
	SaNameT *_saCsiNamePtr = &_saCsiName;
	SaAmfHandleT _saAmfHandle;
	SaAmfHAStateT _saHaState = SA_AMF_HA_QUIESCING + 1;	// this is an invalid value...
	SaAisErrorT _saStatus;
	// JNI
	jobject _amfLibraryHandle;
	jobject _haState;

	// BODY

	assert(thisCsiManager != NULL);
	_TRACE2
		("NATIVE: Executing Java_org_opensaf_ais_amf_CsiManagerImpl_getHaState()\n");

	// get Java library handle
	_amfLibraryHandle = (*jniEnv)->GetObjectField(jniEnv,
						      thisCsiManager,
						      FID_amfLibraryHandle);

	assert(_amfLibraryHandle != NULL);

	// get native library handle
	_saAmfHandle = (SaAmfHandleT)(*jniEnv)->GetLongField(jniEnv,
							     _amfLibraryHandle,
							     FID_saAmfHandle);
	// copy Java component name object
	if (JNU_copyFromStringToSaNameT(jniEnv,
					componentName,
					&_saComponentNamePtr) != JNI_TRUE) {
		return NULL;	// EXIT POINT! Exception pending...
	}

	U_printSaName("NATIVE: component name is ", _saComponentNamePtr);

	// copy Java CSI name object
	if (JNU_copyFromStringToSaNameT(jniEnv,
					csiName, &_saCsiNamePtr) != JNI_TRUE) {
		return NULL;	// EXIT POINT! Exception pending...
	}

	U_printSaName("NATIVE: CSI name is ", _saCsiNamePtr);
	_TRACE2
		("NATIVE: _saHaState before calling saAmfHAStateGet(...) is: %d\n",
		 _saHaState);

	// call saAmfHAStateGet
	_saStatus = saAmfHAStateGet(_saAmfHandle,
				    _saComponentNamePtr,
				    _saCsiNamePtr, &_saHaState);

	_TRACE2
		("NATIVE: _saHaState after saAmfHAStateGet(...) has returned is: %d\n",
		 _saHaState);
	_TRACE2("NATIVE: saAmfHAStateGet(...) has returned with %d...\n",
		_saStatus);

	// error handling
	if (_saStatus != SA_AIS_OK) {
		switch (_saStatus) {
		case SA_AIS_ERR_LIBRARY:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisLibraryException",
					   AIS_ERR_LIBRARY_MSG);
			break;
		case SA_AIS_ERR_TIMEOUT:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisTimeoutException",
					   AIS_ERR_TIMEOUT_MSG);
			break;
		case SA_AIS_ERR_TRY_AGAIN:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisTryAgainException",
					   AIS_ERR_TRY_AGAIN_MSG);
			break;
		case SA_AIS_ERR_BAD_HANDLE:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisBadHandleException",
					   AIS_ERR_BAD_HANDLE_MSG);
			break;
		case SA_AIS_ERR_INVALID_PARAM:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisInvalidParamException",
					   AIS_ERR_INVALID_PARAM_MSG);
			break;
		case SA_AIS_ERR_NO_MEMORY:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisNoMemoryException",
					   AIS_ERR_NO_MEMORY_MSG);
			break;
		case SA_AIS_ERR_NO_RESOURCES:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisNoResourcesException",
					   AIS_ERR_NO_RESOURCES_MSG);
			break;
		case SA_AIS_ERR_NOT_EXIST:
			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisNotExistException",
					   AIS_ERR_NOT_EXIST_MSG);
			break;
		default:
			// this should not happen here!

			assert(JNI_FALSE);

			JNU_throwNewByName(jniEnv,
					   "org/saforum/ais/AisLibraryException",
					   AIS_ERR_LIBRARY_MSG);
			break;
		}
		return NULL;	// EXIT POINT! Exception pending...
	}
	// return HA state
	_haState = JNU_HaState_getEnum(jniEnv, _saHaState);
	if (_haState == NULL) {
		// this should not happen here!

		_TRACE2("NATIVE ERROR: _haState is NULL\n");

		return NULL;	// AisLibraryException thrown already...
	}

	U_printSaAmfHAState
		("NATIVE: Java_org_opensaf_ais_amf_CsiManagerImpl_getHaState(...) returning normally with HA state: ",
		 _saHaState);

	return _haState;
}
예제 #2
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;
    }
}
예제 #3
0
/**
 * AMF invokes this callback to assign a new workload (ADD_ONE) or
 * to change state of an already assigned workload (TARGET_ALL).
 * The callback is used for the initial assignment, as a consequence
 * of admin operations and fail/switch-over
 * 
 * See example sequence diagrams in chapter 10.
 * 
 * @param invocation
 * @param comp_name
 * @param ha_state
 * @param csi_desc
 */
static void amf_csi_set_callback(SaInvocationT invocation,
								 const SaNameT *comp_name,
								 SaAmfHAStateT ha_state,
								 SaAmfCSIDescriptorT csi_desc)
{
	SaAisErrorT rc, error;
	SaAmfCSIAttributeT *attr;
	int i, status;

	if (csi_desc.csiFlags == SA_AMF_CSI_ADD_ONE) {

		syslog(LOG_INFO, "CSI Set - add '%s' HAState %s", 
			csi_desc.csiName.value, ha_state_name[ha_state]);

		/* For debug log the CSI attributes, they could
		** define the workload characteristics */
		for (i = 0; i < csi_desc.csiAttr.number; i++) {
			attr = &csi_desc.csiAttr.attr[i];
			syslog(LOG_DEBUG, "\tname: %s, value: %s",
				attr->attrName, attr->attrValue);
		}

	} else if (csi_desc.csiFlags == SA_AMF_CSI_TARGET_ALL) {
		syslog(LOG_INFO, "CSI Set - HAState %s for all assigned CSIs", 
			ha_state_name[ha_state]);
	} else {
		syslog(LOG_INFO, "CSI Set - HAState %s for '%s'", 
			ha_state_name[ha_state], csi_desc.csiName.value);
	}

	switch (ha_state) {
	case SA_AMF_HA_ACTIVE:
		status = foo_activate();
		break;
	case SA_AMF_HA_STANDBY:
		/* 
		 * Not much to do in this simple example code
		 * For real one could open a checkpoint for reads
		 * Open a communication channel for listening
		 * etc.
		 */
		status = 0;
		break;
	case SA_AMF_HA_QUIESCED:
		/* the effect of admin op lock on SU or node or ... */
		status = foo_deactivate();
		break;
	case SA_AMF_HA_QUIESCING:
		/* the effect of admin op lock on SU or node or ... */
		status = 0;
		break;
	default:
		syslog(LOG_ERR, "unmanaged HA state %u", ha_state);
		status = -1;
		break;
	}

	if (status == 0)
		error = SA_AIS_OK;
	else
		error = SA_AIS_ERR_FAILED_OPERATION;

	rc = saAmfResponse(my_amf_hdl, invocation, error);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfResponse FAILED - %u", rc);
		exit(1);
	}

	if (ha_state == SA_AMF_HA_QUIESCING) {
		/* "gracefully quiescing CSI work assignment" */
		sleep(1);
		rc = saAmfCSIQuiescingComplete(my_amf_hdl, invocation, SA_AIS_OK);
		if (rc != SA_AIS_OK) {
			syslog(LOG_ERR, "saAmfCSIQuiescingComplete FAILED - %u", rc);
			exit(1);
		}

		rc = saAmfHAStateGet(my_amf_hdl, comp_name, &csi_desc.csiName, &my_ha_state);
		if (rc != SA_AIS_OK) {
			syslog(LOG_ERR, "saAmfHAStateGet FAILED - %u", rc);
			exit(1);
		}

		syslog(LOG_INFO, "My HA state is %s", ha_state_name[my_ha_state]);
	}
}