Code Examples.
Code Examples.
COR Object Manipulation Functions
While the necessary blue-print is created during OpenClovis ASP initialization, COR object manipulation happens at run-time, and mainly through through three functions:
These three functions use transactions to perform the desired object related operation(s). After the MO class tree is created during COR initialization, you can create the MO/MSO, set an attribute of that MO/MSO or delete an MO/MSO using these Object manipulation functions.
The object creation, attribute-set and object deletion can be queued in one transaction. These operations when queued in the transaction are identified by a transaction ID. Each transaction ID can have multiple transaction jobs operating on an MO/MSO which can be identified by the object handle or moId and the attrPath (containment path). Once all COR object manipulations have been performed, the clCorTxnSessionCommit() function is called. The COR client packs the transaction jobs and makes an RMD to the server through the clCorTxnSessionCommit() function. The transaction jobs are packed in the network format.
At the server side, the information of the components (for which the transaction manager will initiate the transaction callbacks) is obtained from COR's route list. This is a list of stations that need to be visited. Also if the peer COR is up and running then it will also be a part of transaction. After adding all the transaction jobs for the transaction ID and its list of components, COR starts the transaction.
COR performs all the object-related operations in the commit phase of the transaction. For a given transaction ID, all the transaction jobs are walked and specific operations are performed. The clCorTxnJobWalk() function is called with a callback which performs the necessary operations based on the opType obtained from each transaction job.
Sample Code for the Object Create/Set/Delete using single as well as complex transaction.
ClRcT cor_test_object_manipulation ()
{
ClUint16T value16 = 0;
ClUint32T value32 = 0;
ClUint64T value64 = 0;
ClUint32T size16 = sizeof(ClUint16T);
ClUint32T size32 = sizeof(ClUint32T);
ClUint32T size64 = sizeof(ClUint64T);
value64 = 1;
0x301, -1, (void *)&value64, size64);
value64 = 1;
tid = 0;
(void *)&value64, size64);
value32 = 3;
(void *)&value32, size32);
return rc;
}
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
ClRcT clCorObjectHandleToMoIdGet(CL_IN ClCorObjectHandleT objHandle, CL_OUT ClCorMOIdPtrT moId, CL_OUT ClCorServiceIdT *srvcId)
Returns the MOID corresponding to compressed MO handle.
ClRcT clCorObjectDelete(CL_INOUT ClCorTxnSessionIdT *txnSessionId, CL_IN ClCorObjectHandleT handle)
Deletes a COR object.
ClRcT clCorMoIdInitialize(CL_INOUT ClCorMOIdPtrT pMoId)
Initializes a MOID or resets the content of an existing MOID.
ClRcT clCorMoIdFree(CL_INOUT ClCorMOIdPtrT pMoId)
Deletes the ClCorMOId handle.
ClPtrT ClCorObjectHandleT
The structure ClCorObjectHandle is the handle to MO.
Definition: clCorMetaData.h:608
ClRcT clCorObjectHandleGet(ClCorMOIdPtrT pMoId, ClCorObjectHandleT *objHandle)
Retrieves the compressed MO handle corresponding to MOID.
ClCorServiceIdT
The members of this enumeration type contains the service ID for all MSPs.
Definition: clCorServiceId.h:57
ClRcT clCorAttrPathFree(CL_INOUT ClCorAttrPathPtrT pAttrPath)
Deletes the COR attribute path handle.
#define CL_COR_SIMPLE_TXN
Simple transaction with only one job.
Definition: clCorMetaData.h:149
ClRcT clCorAttrPathAlloc(CL_INOUT ClCorAttrPathPtrT *pAttrPath)
Creates an attribute path.
ClPtrT ClCorTxnSessionIdT
The type of the handle of a COR transaction session.
Definition: clCorMetaData.h:637
ClRcT clCorMoIdAlloc(CL_INOUT ClCorMOIdPtrT *pMoId)
Creates an MoId.
ClRcT clCorObjectCreate(CL_INOUT ClCorTxnSessionIdT *txnSessionId, CL_IN ClCorMOIdPtrT moId, CL_OUT ClCorObjectHandleT *handle)
Creates a COR object.
ClRcT clCorObjectAttributeSet(CL_INOUT ClCorTxnSessionIdT *txnSessionId, CL_IN ClCorObjectHandleT pHandle, CL_IN ClCorAttrPathPtrT contAttrPath, CL_IN ClCorAttrIdT attrId, CL_IN ClUint32T index, CL_IN void *value, CL_IN ClUint32T size)
Sets the attribute of a COR object.
ClRcT clCorMoIdAppend(CL_INOUT ClCorMOIdPtrT pMoId, CL_IN ClCorClassTypeT type, CL_IN ClCorInstanceIdT instance)
Adds an entry to the MoId.
ClRcT clCorMoIdSet(CL_INOUT ClCorMOIdPtrT pMoId, CL_IN ClUint16T level, CL_IN ClCorClassTypeT type, CL_IN ClCorInstanceIdT instance)
Sets the class type and instanceId at a given node or level.
ClRcT clCorMoIdServiceSet(CL_INOUT ClCorMOIdPtrT pMoId, CL_IN ClCorMOServiceIdT svc)
Sets the service ID.
ClRcT clCorAttrPathAppend(CL_INOUT ClCorAttrPathPtrT pAttrPath, CL_IN ClCorClassTypeT attrId, CL_IN ClCorInstanceIdT index)
Adds an entry to the attribute path.
ClRcT clCorTxnSessionCommit(CL_IN ClCorTxnSessionIdT txnSessionId)
Commits an active transaction session.
@ CL_COR_SVC_ID_DUMMY_MANAGEMENT
OpenClovis Dummy MSP.
Definition: clCorServiceId.h:64
The structure ClCorMOId contains MoId of the object, which is the address of the COR object.
Definition: clCorMetaData.h:918
The structure ClCorAttrPath contains the path-list of the attribute.
Definition: clCorMetaData.h:997
COR Transaction APIs
COR Transaction APIs are used by components that participate in a transaction. A component participating in a transaction obtains a transaction handle ( txnHandle) through the callback functions for validate,commit and rollback which can be used in the COR transaction APIs to validate the transaction. A transaction can contain various COR operations related to one or more Managed Objects (MO). The operations related to an MO are considered as one transaction job. Within a transaction job there can be multiple COR operations which can be obtained by using the COR-Transaction APIs.
A transaction can consist of one or more object-create/set/delete operations or a combination of these operations as well. COR creates one COR-Transaction ID for a combination of MOID and attrpath. For a given COR-Transaction ID, COR creates one COR-Job ID for each attributeId. (that is being set for a particular MOID + attrPath). These jobs are linked together in the COR-job-list.
Following steps are performed to obtain COR-job-list and to perform a walk operation.
- When a transaction validate/commit/rollback is called, the COR-job-list ID can be obtained from the COR-transaction ID via the API clCorTxnJobHandleToCorTxnIdGet(). This function returns ClCorTxnIdT.
- clCorTxnJobWalk() function performs the walk operation corresponding to above COR-transaction ID. This function invokes a callback for every COR-job in the COR-job-list.
- The callback function takes in COR-Transaction ID and COR-job ID as parameters. COR provides a function to obtain information about the MOID if it is a create/delete operation. COR provides an API to obtain information about the attribute (MOID,attrpath.index, size, value) for a set operation, based on COR-Transaction ID and COR-job ID. For instance, the API clCorTxnJobSetParamsGet() returns attrId, index, value and size corresponding to a COR-Transaction ID and COR-job ID.
A sample validate function:
clTxnTestValidate(
CL_IN ClTxnTransactionHandleT txnHandle,
CL_IN ClTxnJobDefnHandleT jobDefn,
CL_IN ClUint32T jobDefnSize,
{
(void *)CL_PROV_VALIDATE_STATE );
return rc;
}
void *arg )
{
void* pValue = NULL;
ClUint32T valueSize = 0;
ClInt32T index = 0;
switch ( ( ClUint32T )corOp )
{
break ;
&pValue, &valueSize);
break ;
break ;
}
}
#define CL_INOUT
CL_INOUT macro assists in clearly defining arguments of an API, but has no actual meaning.
Definition: clCommon.h:108
#define CL_IN
CL_IN macro assists in clearly defining arguments of an API, but has no actual meaning.
Definition: clCommon.h:106
enum ClCorAttrType ClCorAttrTypeT
The values of this enumeration type refer to the COR attribute types.
ClRcT clCorTxnIdTxnFree(CL_IN ClCorTxnIdT corTxnId)
Frees the data for the transactionID .
ClRcT clCorTxnJobSetParamsGet(CL_IN ClCorTxnIdT txnId, CL_IN ClCorTxnJobIdT jobId, CL_OUT ClCorAttrIdT *pAttrId, CL_OUT ClInt32T *pIndex, CL_OUT void **pValue, CL_OUT ClUint32T *pSize)
Get all the information necessary for setting the attribute.
ClPtrT ClCorTxnIdT
The type of the COR transaction ID used to identify a transaction session.
Definition: clCorMetaData.h:642
ClCorOpsT
The values of the ClCorOpsT enumeration type contain the Operation IDs.
Definition: clCorMetaData.h:653
ClInt32T ClCorAttrIdT
The type of an identifier for a COR attribute.
Definition: clCorMetaData.h:206
ClRcT clCorTxnJobAttrPathGet(CL_IN ClCorTxnIdT txnId, CL_IN ClCorTxnJobIdT jobId, CL_OUT ClCorAttrPathT **pAttrPath)
Retrieves the attrpath from the transaction.
ClUint32T ClCorTxnJobIdT
The type of COR transaction Job Id, used to identify a job uniquely within a transaction.
Definition: clCorMetaData.h:647
ClRcT clCorTxnJobHandleToCorTxnIdGet(CL_IN ClTxnJobDefnHandleT jobDefn, CL_IN ClSizeT size, CL_OUT ClCorTxnIdT *pTxnId)
Get thetransactionID from thetransactionJob handle.
ClRcT clCorTxnJobMoIdGet(CL_IN ClCorTxnIdT txnId, CL_OUT ClCorMOIdT *pMOId)
Get the MoId From the transaction.
ClRcT clCorTxnJobWalk(CL_IN ClCorTxnIdT pThis, CL_IN ClCorTxnFuncT funcPtr, CL_IN void *cookie)
Walk through the transaction Jobs.
ClRcT clCorTxnJobOperationGet(CL_IN ClCorTxnIdT txnId, CL_IN ClCorTxnJobIdT jobId, CL_OUT ClCorOpsT *op)
Get the operation type.
@ CL_COR_OP_SET
Operation type is set.
Definition: clCorMetaData.h:664
@ CL_COR_OP_DELETE
Operation type is delete.
Definition: clCorMetaData.h:669
@ CL_COR_OP_CREATE
Operation type is create.
Definition: clCorMetaData.h:659
#define CL_FUNC_ENTER()
This macro is called while entering the function.
Definition: clDebugApi.h:195
#define CL_FUNC_EXIT()
This macro is called while exiting the function.
Definition: clDebugApi.h:201
COR Bundle Get
The COR bundle feature is used to perform get operation on multiple attributes in a single request to COR. The bundle-get can take list of attributes belonging to the same or different MO. These attributes can either be configuration or the runtime attributes. The user need to add all the get requests in the same bundle which will be send to COR server as a single request. There it will populate the value for configuration attributes and for the value of runtime attributes it will get it from the primary OI. After getting the response the OIs it will aggregates the information and send the response. Here is a sample code to demonstrate both the synchronous and asynchronous version of bundle get.
ClUint32T val_1 = 0, val_2 = 0, val_3 = 0, val_4 = 0;
jobStatus_3 = 0, jobStatus_4 = 0;
void clCorTestDataDisplay()
{
clOsalPrintf(
"The Value for the attribute 0x201 is [%d] \n", val_1);
else
clOsalPrintf(
"The get on attribute 0x201 failed with error [0x%x] \n",
jobStatus_1);
clOsalPrintf(
"The Value for the attribute 0x202 is [%d] \n", val_2);
else
clOsalPrintf(
"The get on attribute 0x201 failed with error [0x%x] \n",
jobStatus_2);
clOsalPrintf(
"The Value for the attribute 0x205 is [%d] \n", val_3);
else
clOsalPrintf(
"The get on attribute 0x203 failed with error [0x%x] \n",
jobStatus_3);
clOsalPrintf(
"The Value for the attribute 0x302 is [%d] \n", val_4);
else
clOsalPrintf(
"The get on attribute 0x301 failed with error [0x%x] \n",
jobStatus_4);
}
ClRcT clCorTestPrepareBundle(ClCorBundleHandlePtrT pBundleHandle)
{
return rc;
}
{
clLogError("COR", "GET",
"Failed to initialize the bundle. rc[0x%x]", rc);
return rc;
}
{
clLogError("COR", "GET",
"Failed to add the job in the bundle. rc[0x%x]",
rc);
goto handleError;
}
goto handleError;
}
attrInfo1.pAttrPath = NULL;
attrInfo1.attrId = 0x302;
attrInfo1.index = -1;
attrInfo1.bufferPtr = &val_4;
attrInfo1.bufferSize = sizeof(ClUint32T);
attrInfo1.pJobStatus = &jobStatus_4;
{
goto handleError;
}
{
jobStatus = rc;
clLogError("COR", "GET",
"Failed to add the job in the bundle. rc[0x%x]",
rc);
goto handleError;
}
handleError:
return rc;
}
ClPtrT cookie)
{
clCorTestDataDisplay();
{
clLogError("COR", "GET",
"Failed while finalizing the bundle. rc[0x%x]",
rc);
return rc;
}
return rc;
}
ClRcT _clCorTestBundleGetAsync()
{
rc = clCorTestPrepareBundle(&bundleHandle);
clLogError("COR", "GET",
"Failed while preparing the bundle for get. rc[0x%x]",
rc);
return rc;
}
{
clLogError("COR", "GET",
"Failed while applying the bundle. rc[0x%x]",
rc);
goto handleError;
}
_clCorTestDataDisplay()
handleError:
{
clLogError("COR", "GET",
"Failed while finalizing the bundle. rc[0x%x]",
rc);
return rc;
}
return rc;
}
ClRcT _clCorTestBundleGetSync()
{
rc = clCorTestPrepareBundle(&bundleHandle);
{
clLogError("COR", "GET",
"Failed while preparing the bundle for get. rc[0x%x]",
rc);
return rc;
}
{
clLogError("COR", "GET",
"Failed while applying the bundle. rc[0x%x]",
rc);
goto handleError;
}
_clCorTestDataDisplay()
handleError:
{
clLogError("COR", "GET",
"Failed while finalizing the bundle. rc[0x%x]",
rc);
return rc;
}
return rc;
}
ClUint32T ClCorJobStatusT
Status of each failed job.
Definition: clCorMetaData.h:221
ClRcT clCorBundleApplyAsync(CL_IN ClCorBundleHandleT bundleHandle, CL_IN ClCorBundleCallbackPtrT funcPtr, CL_IN ClPtrT userArg)
Function to apply the bundle asynchronously.
ClRcT clCorBundleInitialize(CL_OUT ClCorBundleHandlePtrT pBundleHandle, CL_IN ClCorBundleConfigPtrT pBundleConfig)
Creates a bundle and returns a unique handle identifying the bundle.
ClRcT clCorBundleObjectGet(CL_IN ClCorBundleHandleT bundleHandle, CL_IN const ClCorObjectHandleT *pObjectHandle, CL_INOUT ClCorAttrValueDescriptorListPtrT pAttrList)
Populates a bundle with read-jobs.
ClHandleT ClCorBundleHandleT
Type definition of the bundle handle.
Definition: clCorMetaData.h:226
ClRcT clCorBundleFinalize(ClCorBundleHandleT bundleHandle)
Finalizes the bundle.
ClRcT clCorBundleApply(CL_IN ClCorBundleHandleT bundleHandle)
Submits a bundle to the COR server for execution.
@ CL_COR_BUNDLE_NON_TRANSACTIONAL
Bundle type is non-transactional.
Definition: clCorMetaData.h:781
@ CL_COR_SVC_ID_PROVISIONING_MANAGEMENT
OpenClovis Provisioning Manager.
Definition: clCorServiceId.h:79
ClRcT clOsalPrintf(const ClCharT *fmt,...)
Prints to the standard output.
Structure to attribute job which will be added to the bundle.
Definition: clCorMetaData.h:1376
ClCorAttrPathPtrT pAttrPath
Pointer to the attribute path.
Definition: clCorMetaData.h:1380
ClInt32T bufferSize
Size of the buffer pointed by bufferPtr.
Definition: clCorMetaData.h:1396
ClInt32T index
Index of the array attribute.
Definition: clCorMetaData.h:1388
ClCorJobStatusT * pJobStatus
Status of the job.
Definition: clCorMetaData.h:1400
ClCorAttrIdT attrId
Attribute Identifier.
Definition: clCorMetaData.h:1384
ClPtrT bufferPtr
Pointer to the buffer which contain the data.
Definition: clCorMetaData.h:1392
Type for the attribute value list.
Definition: clCorMetaData.h:1418
ClUint32T numOfDescriptor
Number of Attribute Descriptor.
Definition: clCorMetaData.h:1422
ClCorAttrValueDescriptorPtrT pAttrDescriptor
Pointer to the list of attribute descriptors.
Definition: clCorMetaData.h:1427
Structure for storing the bundle configuration.
Definition: clCorMetaData.h:1479
Cor Create and Set
The clCorObjectCreateAndSet() is an additional function to the COR session capability. This API should be used to create the objects of the MO-Class which has intialized attributes modeled. The initialized attributes are key attribute which should be provided while creating an instance of the class. Inorder to create instance for this class, the API clCorObjectCreateAndSet() should be used which allows providing the attribute list and their values while creating the object. This API can be used to create an object without any key attributes as well. As this function is part of COR's session capability, so all the features of session are applicable to this API as well. Here is the sample code which shows the usage of this API.
ClRcT _clCorTestCreateAndSetUsage()
{
ClUint32T val_1 = 10, val_2 = 20;
&moId, NULL, &objH);
{
return rc;
}
attrList.numOfDescriptor = 2;
attrList.pAttrDescriptor = attrInfo;
&attrList, &objH);
return rc;
}
return rc;
}
ClRcT clCorTxnSessionFinalize(CL_IN ClCorTxnSessionIdT txnSessionId)
Finalizes a COR transaction session.
ClRcT clCorObjectCreateAndSet(CL_INOUT ClCorTxnSessionIdT *tid, CL_IN ClCorMOIdPtrT pMoId, CL_IN ClCorAttributeValueListPtrT attrList, CL_OUT ClCorObjectHandleT *pHandle)
Creates and sets a COR object.
ClRcT clCorMoIdInstanceSet(CL_INOUT ClCorMOIdPtrT pMoId, CL_IN ClUint16T ndepth, CL_IN ClCorInstanceIdT newInstance)
Sets the instance of the MoId.
Type to provide value for the initialized attributes.
Definition: clCorMetaData.h:1309
ClCorAttrPathPtrT pAttrPath
Attribute Path.
Definition: clCorMetaData.h:1313
ClInt32T index
Index of the attribute.
Definition: clCorMetaData.h:1323
ClInt32T bufferSize
Size of the buffer.
Definition: clCorMetaData.h:1333
ClCorAttrIdT attrId
Attribute Identifier.
Definition: clCorMetaData.h:1318
ClPtrT bufferPtr
Pointer to the buffer which contain the data.
Definition: clCorMetaData.h:1328
Type to provide the list of attribute values for initialized attributes.
Definition: clCorMetaData.h:1350