This section includes the following topics:
Context Initialization and Persistence
To use the CLSCRS APIs, you must first initialize the clscrs
context. The calls to create and terminate this context are:
clscrs_init_crs
: Initializes the clscrs
context
clscrs_term_crs
: Terminates the clscrs
context
The caller is responsible for terminating the context when it is no longer needed.
Threading Support
If initialized with the CLSCRS_FLAG_USETHREADS
flag, then the CLSCRS API may spawn threads internally. Every API function executes in the context of the calling thread. The API context object may not be used concurrently by multiple threads. However, no thread-affinity on the part of the client is required. A process may create multiple API contexts and use those on different threads, subject to the one-thread-per-one-context-at-a-time rule.
CLSCRS API Data Structures
The following entities are passed into the API calls and contain return values from the API call:
clscrs_sp
: A stringpair (sp
) contains a name and a value string. The value can be NULL. It is created and destroyed, and its contents can be examined and the value replaced. A stringpair can be a member of exactly one stringpair list (splist
).
clscrs_splist
: A stringpair list (splist
) is a list of zero or more stringpairs used in various contexts. An API can add stringpairs to or remove them from a stringpair list, or the API can iterate stringpairs.
clscrs_entity_type
: The enumeration type you can use to identify the type of Oracle Clusterware entity.
The enumeration types are defined, as follows:
/* enum to specify the entity type */ typedef enum { clscrs_entity_res = 1, /* resource */ clscrs_entity_restype = 2, /* resource type */ clscrs_entity_serverpool = 3, /* server pool */ clscrs_entity_server = 4, /* server */ clscrs_entity_resinst = 5, /* resource instances */ clscrs_entity_config_policy = 6, /* configuration policy */ clscrs_entity_config_policyset = 7, /* configuration policy set */ clscrs_entity_server_category = 8 /* server category */ } clscrs_entity_type;
clscrs_crsentity
: This data structure (crsentity
) represents an Oracle Clusterware entity, which contains the name and additional data appropriate to the context in which the Oracle Clusterware entity is used. Sometimes an API contains Oracle Clusterware entity attribute data and other times it carries status and return messages about an operation. A single entity can be a member of exactly one clscrs_crsentitylist
.
clscrs_crsentitylist
: An entity list (crsentitylist
) is a data structure that contains zero or more instances of a clscrs_crsentity
. An API can add entities to or remove them from an entity list, or the API can iterate entities.
Memory Management
The CLSCRS APIs work on elements and lists. The elements are added to lists. The memory for both elements and lists is allocated and released through explicit API calls. It is the caller's responsibility to release the memory that they allocate. However, when elements are added to lists, only the list must be destroyed: the destruction of the list destroys its elements implicitly. The elements must be destroyed when they are not added to any list. For recursive lists, destroying the parent list also destroys any lists contained within it. The clscrs_sp
and clscrs_crsentity
elements must be destroyed by the caller. If they are part of a clscrs_splist
or clscrs_crsentitylist
, destroying the list destroys the respective clscrs_sp
and clscrs_crsentity
entities.
For example, when a resource is created and added to a resource list, only the resource list must be destroyed, but not the individual resource. Destroying the resource list releases the memory for the individual resource, too.
Memory is allocated by the API through the following calls:
clscrs_sp_create() clscrs_crsentity_create() clscrs_serverpool_create() clscrs_type_create() clscrs_splist_create() clscrs_crsentitylist_create() clscrs_entity_id_create()
Each of the calls in the preceding list has a corresponding clscrs_*_destroy()
call.
Error Handling and Tracing
Interactive and non-interactive CLSCRS APIs each use a different error-handling mechanism.
For non-interactive CLSCRS APIs, the error code is returned as the return value of the function call. For example:
clscrsret clscrs_sp_get_value(clscrs_sp *sp, oratext **value);
The error code is returned as a clscrsret
value.
For interactive CLSCRS APIs, the output result is represented, as follows:
The return value of the function call provides a high-level output of the request. Did the request reach the server? Was it completely successful, or completely or only partially unsuccessful? A successful return value means the request was received, processed, and the outcome was successful for all entities requested.
For each entity on which the request operated, there is a programmatic completion code stored in the op_status
list. If the value is not success
, it indicates the high-level type of the problem specific to processing the request for the particular object.
Optionally, the API might indicate that it wants to receive localized, human-readable error, warning, or status messages by using the callback mechanism. Each invocation of the callback provides the message, message type (severity), and the ID of the object to which the callback invocation pertains.
For example:
CLSCRS_STAT clscrs_register_resource2(clscrs_crsentitylist *in_crsentitylist, uword flags, clscrs_msgf2 msgf, void *msgarg, clscrs_crsentitylist *op_status);
The function returns an error code of value CLSCRS_STAT
.
The CRSD sends error messages, warning messages, and progress messages back to the client through the clscrs_msgf2
callback. The client must implement the callback to process these messages returned by the CRSD.
In previous Oracle Clusterware releases, the API also contained results of each operation on the Oracle Clusterware entities as part of the op_status
list. You can access that information using the following API:
clscrsret clscrs_entity_get_op_status(clscrs_entity *res, CLSCRS_STAT *status, oratext **msg);
The status
argument contains a status code about the CRSD operation on the Oracle Clusterware entity. Additionally, the msg
argument contains a message from the CRSD about the result of the operation. Though the op_status
list continues to contain the results of the CRSD operation for each Oracle Clusterware entity in the msg
argument, usage of the msg
argument to get the error codes and messages has now been deprecated and is not supported for any use of the API on a new entity. Only pre-existing use cases (for acting on resources, specifically) are supported. Use the callback function to process any messages returned by the CRSD.
Callback Mechanism
Interactive CLSCRS APIs provide a callback mechanism that the clients can use to process error messages, warning messages, and progress messages sent by the CRSD.
The signature of the callback mechanism is:
typedef void (*clscrs_msgf2)(void *usrp, const oratext *id, const oratext *msg, clscrs_msgtype msgtype);
In the preceding syntax:
usrp
: Is a user-supplied pointer that probably contains the context of the call
id
: Is the identifier of the entity to which the message corresponds
msg
: Is the output text
msgtype
: Is the type of the message; either error, warning, or progress
Example H-1 describes an example of the callback mechanism.
Example H-1 Callback Mechanism
void myCallback(void *arg, const oratext *pId, const oratext *pMsg, clscrs_msgtype msgType) { if (pMsg != NULL) { cout << pMsg << endl; } }
Example H-2 describes how to use the callback mechanism in an interactive API.
Example H-2 Using the Callback Mechanism In an Interactive API
clscrs_start_resource2(pResIdList, NULL, env, myCallback, NULL, 0, pOpStatus);
You can also print debug trace messages for the API, itself by passing the CLSCRS_FLAG_TRACE
flag when creating the context. The signature for context creation is:
CLSCRS_STAT clscrs_init_crs(clscrs_ctx **ctx, clscrs_msgf2 errf, void *errCtx, ub4 flags);
For the trace messages to work, you must specify both the CLSCRS_FLAG_TRACE
flag and a clscrs_msgf2
callback mechanism in the clscrs_init_crs
API.
The clscrs_msgf2
callback mechanism has the following signature:
typedef void (*clscrs_msgf)(void *usrp, const oratext *msg, sword msglen);
Filters
You can use filters to narrow down Oracle Clusterware entities upon which a CLSCRS API operates. Simple filters are attribute-value pairs with an operator. Operators must be surrounded by spaces, as shown in the examples. You can combine simple filters into expressions called expression filters using Boolean operators.
Supported filter operators are:
=
>
<
!=
co
: Containsst
: Starts withen
: Ends withSupported Boolean operators are AND
and OR
.
Examples of filters are:
TYPE = type1
((TYPE = type1) AND (CHECK_INTERVAL > 50))
(TYPE = type1) AND ((CHECK_INTERVAL > 30) OR (AUTO_START co never))
NAME en network.res
TYPE st ora.db
See Also:
Use the clscrs_comparator enum
and the clscrs_operator enum
located in the $ORA_CRS_HOME/crs/demo/clscrsx.h
file to get the correct type for the above comparators and operators, respectively, in the API calls
There are two types of filters and CLSCRS has a set of APIs to create these filters:
Comparison filter: A simple filter that compares two values. For example:
TYPE = ora.db.type
Use the clscrs_compfilter_create
API to create a comparison filter. For example, to create the (TYPE = ora.db.type)
comparison filter:
clscrs_compfilter_create(ctx, clscrs_TYPE, clscrs_comparator_eq, (const oratext *)"ora.db.type", &myCompFilter);
Expression filter: A filter that is created from either a set of comparison filters or expression filters, or both. For example:
((TYPE = ora.db.type) AND (CHECK_INTERVAL > 50))
Use the clscrs_expfilter_create
API to create a comparison filter. For example, to create an expression filter:
clscrs_exprfilter_create(myCompFilter1, clscrs_operator_or, myCompFilter2, &myExprFilter);
See Also:
The $ORA_CRS_HOME/crs/demo/clscrsx.h
file for usage information for the clscrs_compfilter_create
and clscrs_expfilter_create
APIs
Note:
Both the clscrs_compfilter_create
and clscrs_expfilter_create
APIs allocate memory that must be freed by calling clscrs_filter_destroy()
.
You can use filters in the following interactive CLSCRS APIs in place of an entity list:
clscrs_start_resource2
clscrs_stat2
clscrs_stop_resource2
clscrs_check_resource2
clscrs_relocate_resource2
Example H-3 describes using filters in an interactive CLSCRS API.
Example H-3 Filters In an Interactive CLSCRS API
clscrs_start_resource2(myCompFilter, NULL, env, msgf2, NULL, 0, pOpStatus);
Script Agent Usage
When you use CLSCRS APIs inside script agent entry points, keep the following in mind:
Some actions, such as start, stop, and clean, are executed under a lock on the resource instance. Thus, issuing a request to the server to act on the resource directly or by extension of a relation results in a dead-lock.
Issuing read-only (clscrs_stat2
) is generally safe unless it is an initial check, where the script agent must not call back on the server, because that results in a dead-lock, as well. Use the clsagfw
APIs to query the check entry point.
See Also:
Oracle Clusterware Resource Reference for examples of script agents
Help Interface
You can find the entire list of CLSCRS APIs, including usage information for each, in the $ORA_CRS_HOME/crs/demo/clscrsx.h
file, along with a demo called crsapp.c
.