CTBCAFServiceAlmMgmt

From TBwiki
(Difference between revisions)
Jump to: navigation, search
(Adding an application to the Toolpack Web Portal list of applications)
(Example usage)
Line 33: Line 33:
  
 
== Example usage ==
 
== Example usage ==
 +
 +
class MyApplication : public ITBCAFServiceAlmMgmtClient
 +
{
 +
// your class definition
 +
 +
// Functions inherited from ITBCAFServiceAlmMgmtClient
 +
virtual TBX_VOID OnMgmtReady();
 +
virtual TBX_VOID OnMgmtShutdown( TBX_BOOL in_fGracefulShutdown = TBX_FALSE );
 +
virtual TBX_RESULT OnMgmtHeartBeat();
 +
};
 +
 +
TBX_RESULT MyApplication::Init()
 +
{
 +
TBX_RESULT Result = TBX_RESULT_OK;
 +
 +
// Answer to management message
 +
Result = CTBCAFServiceAlmMgmt::Init(TBX_FALSE);
 +
if( TBX_RESULT_SUCCESS( Result ) )
 +
{
 +
// Register ourself to launch service
 +
CTBCAFServiceAlmMgmt::GetInstance()->Register(this);
 +
}
 +
 +
return Result;
 +
}
 +
 +
TBX_RESULT MyApplication::UnInit()
 +
{
 +
TBX_RESULT Result = TBX_RESULT_OK;
 +
 +
/* Unregister from ALM client */
 +
Result = CTBCAFServiceAlmMgmt::Uninit();
 +
 +
return Result;
 +
}
 +
 +
TBX_VOID MyApplication::OnMgmtReady()
 +
{
 +
// Do whatever you want when successfully connected to Toolpack OAM
 +
LogTrace
 +
(
 +
TBCAF_TRACE_LEVEL_ALWAYS,
 +
"OnMgmtReady: Now connected to Toolpack OAM ALM"
 +
);
 +
}
 +
 +
TBX_VOID MyApplication::OnMgmtShutdown( TBX_BOOL in_fGracefulShutdown )
 +
{
 +
// Indicate to current application that it must shutdown itself
 +
mfQuit = TBX_TRUE;
 +
 +
if( in_fGracefulShutdown )
 +
{
 +
// No hurry. We can start actively refusing new incoming calls,
 +
// but leave active calls terminate gracefully as users hangup, for example.
 +
// Or we can just quit immediately if we don't care implementing a "graceful" shutdown!
 +
}
 +
else
 +
{
 +
// Hurry a bit more, no time to wait for calls to terminate gracefully,
 +
// we'll get killed in 20 seconds if we don't quit!
 +
}
 +
}
 +
 +
TBX_RESULT CTBS2GWSimpleCall::OnMgmtHeartBeat()
 +
{
 +
  TBX_RESULT Result = TBX_RESULT_OK;
 +
 +
// Poll the CAF framework to detect problems with it
 +
Result = TBCAF::GlobalPoll();
 +
 +
// Poll any modules of current application to see if they are in good health.
 +
// A good idea is to at least enter each module, as if there is an infinite loop
 +
// or dead-lock within one of them, for example, we'll block on the module's mutex
 +
// and not return from OnMgmtHeartBeat(), causing Toolpack OAM to kill ourself after
 +
// 20 seconds (which is probably what we want if we have a dead-lock somewhere!)
 +
 +
return Result;
 +
}

Revision as of 09:28, 30 May 2011

The class CTBCAFServiceAlmMgmt is used by an application that wants to be launched automatically by the Toolpack system.

An application that initializes this class has to provide a callback to interface ITBCAFServiceAlmMgmtClient. This interface provides 3 functions that the application must implement:

  • OnMgmtReady: Tells the application that it's properly being detected by Toolpack OAM.
  • OnMgmtShutdown: Tells the application that it must shutdown itself. If the application takes too long (default timeout 20 seconds) it will get killed by Toolpack OAM.
  • OnMgmtHeartBeat: This function is called periodically by Toolpack OAM to test that the application is still alive. The application, within this function, should perform a sanity check on it's various internal modules. If this function call does not return, Toolpack OAM will kill the application after a timeout (default 20 seconds).


Adding an application to the Toolpack Web Portal list of applications

Once an application has create an object of class CTBCAFServiceAlmMgmt, and properly implemented the interface ITBCAFServiceAlmMgmtClient, it's ready to be automatically launched and shutdown by Toolpack OAM. The list of applications that are launched by Toolpack OAM is found in the Toolpack Web Portal, under sections:

  • Applications -> Configurations
  • Applications -> Instances

Steps to add an new applications are:

  • Create a new Application Configuration
    • Go to Applications -> Configurations
    • Click "Create New Application Config"
    • Fill appropriate information
      • Name of this application's configuration
      • Path of the binary file to launch (some variables can be used here for convenience)
      • Working directory
      • Command-line arguments
  • Create a new Application Instance
    • Go to Applications -> Instances
    • Click "Create New Application Instance"
    • Fill appropriate information
      • Name for this application instance
      • Host the application should be running on
      • Configuration just created above
      • Target state (run, don't run)
  • Apply the modified configuration

Example usage

class MyApplication : public ITBCAFServiceAlmMgmtClient
{
	// your class definition

	// Functions inherited from ITBCAFServiceAlmMgmtClient
	virtual TBX_VOID OnMgmtReady();
	virtual TBX_VOID OnMgmtShutdown( TBX_BOOL in_fGracefulShutdown = TBX_FALSE );
	virtual TBX_RESULT OnMgmtHeartBeat();
};

TBX_RESULT MyApplication::Init()
{
	TBX_RESULT			Result = TBX_RESULT_OK;

	// Answer to management message
	Result = CTBCAFServiceAlmMgmt::Init(TBX_FALSE);
	if( TBX_RESULT_SUCCESS( Result ) )
	{
		// Register ourself to launch service
		CTBCAFServiceAlmMgmt::GetInstance()->Register(this);
	}

	return Result;
}

TBX_RESULT MyApplication::UnInit()
{
	TBX_RESULT			Result = TBX_RESULT_OK;

	/* Unregister from ALM client */
	Result = CTBCAFServiceAlmMgmt::Uninit();

	return Result;
}

TBX_VOID MyApplication::OnMgmtReady()
{
	// Do whatever you want when successfully connected to Toolpack OAM
	LogTrace
	(
		TBCAF_TRACE_LEVEL_ALWAYS,
		"OnMgmtReady: Now connected to Toolpack OAM ALM"
	);
}

TBX_VOID MyApplication::OnMgmtShutdown( TBX_BOOL in_fGracefulShutdown )
{
	// Indicate to current application that it must shutdown itself
	mfQuit = TBX_TRUE;

	if( in_fGracefulShutdown )
	{
		// No hurry. We can start actively refusing new incoming calls,
		// but leave active calls terminate gracefully as users hangup, for example.
		// Or we can just quit immediately if we don't care implementing a "graceful" shutdown!
	}
	else
	{
		// Hurry a bit more, no time to wait for calls to terminate gracefully,
		// we'll get killed in 20 seconds if we don't quit!
	}
}

TBX_RESULT CTBS2GWSimpleCall::OnMgmtHeartBeat()
{
 	TBX_RESULT			Result = TBX_RESULT_OK;

	// Poll the CAF framework to detect problems with it
	Result = TBCAF::GlobalPoll();

	// Poll any modules of current application to see if they are in good health.
	// A good idea is to at least enter each module, as if there is an infinite loop
	// or dead-lock within one of them, for example, we'll block on the module's mutex
	// and not return from OnMgmtHeartBeat(), causing Toolpack OAM to kill ourself after
	// 20 seconds (which is probably what we want if we have a dead-lock somewhere!)

	return Result;
}
Personal tools