LinkedIn

Wednesday, August 3, 2011

Querying Composite Instance States in SOA-INFRA Dehydration Store forOracle SOA Suite 11g Processes

If you have a large number of composite instances present for a single or multiple composites the Enterprise Manager will not be a very ideal place to look at if we want to know the states of these instances.

We can however connect directly to the SOA_INFRA schema for our Oracle SOA Suite installation to execute a few scripts to view instance states of various composites.

Here are the database scripts available to find composite instances in various states in the CUBE_INSTANCE table.

The table below shows the various State Value for composite instances in the CUBE_INSTANCE table of the SOA_INFRA schema in the dehydration store.
STATE VALUE STATE STATE MEANING
0 INITIATED
State value for an instance that has just been created. The instance will only have this value as its state after it has been created by the process domain.

1 OPEN AND RUNNING
State value for an instance that has been created and has active activities executing. The instance is not in an exception or error condition.

2 OPEN AND SUSPENDED
State value for an instance that is unavailable. Performers of any of the activities that belong to this instance cannot take any action until the instance has returned to the running state.

3 OPEN AND FAULTED
State value for an instance that has an activity that has thrown an exception. When an activity throws an exception, the instance is flagged as being in an exception state until the exception is bubbled up, caught and handled.

4 CLOSED AND PENDING
State value for an instance that has started its cancellation procedure. Since cancelling an instance may involve a great deal of business logic, the amount of time the entire cancellation process may take may be anywhere from seconds to days. During this time, the instance is said to be pending cancellation; an instance may not be acted upon during this time.

5 CLOSED AND COMPLETED
State value for an instance that has been completed. All activities belonging to this instance have also been completed.

6 CLOSED AND FAULTED
State value for an instance that has an activity that has thrown an exception while the instance is being cancelled. This state is equivalent to <code>STATE_OPEN_FAULTED</code> except that when the exception is resolved, the state transitions back to <code>CLOSED_PENDING_CANCEL</code> rather than <code>STATE_OPEN_RUNNING</code>

7 CLOSED AND CANCELED
State value for an instance that has been cancelled. All activities belonging to this instance have also been cancelled.

8 CLOSED AND ABORTED
State value for an instance that has been aborted due to administrative control. All activities belonging to this instance are also moved to the aborted state.

9 CLOSED AND STALE
State value for an instance who's process has been changed since the process was last accessed. No actions may be performed on the instance. All activities that belong to this instance are also moved to the stale state.

10 NON RECOVERABLE
State value of instance that has failed and is marked as non recoverable.


The database query that can fetch and tabulate the number of instances in various states in the CUBE_INSTANCE table

SELECT (CASE WHEN STATE=1 THEN 'OPEN AND RUNNING'
WHEN STATE=2 THEN 'OPEN AND SUSPENDED'
WHEN STATE=3 THEN 'OPEN AND FAULTED'
WHEN STATE=4 THEN 'CLOSED AND PENDING'
WHEN STATE=5 THEN 'CLOSED AND COMPLETED'
WHEN STATE=6 THEN 'CLOSED AND FAUTED'
WHEN STATE=7 THEN 'CLOSED AND CANCELLED'
WHEN STATE=8 THEN 'CLOSED AND ABORTED'
WHEN STATE=9 THEN 'CLOSED AND STALE'
WHEN STATE=10 THEN 'NON-RECOVERABLE'
ELSE STATE || ''
END) AS STATE, COUNT(*) AS NUM_OF_CUBE_INST FROM CUBE_INSTANCE GROUP BY STATE;

In case you would like the same count of instances for a particular COMPOSITE application then extend the above sql script by adding additional filters to it.

You can add filters on CUBE_INSTANCE table based on COMPOSITE_NAME, COMPOSITE_REVISION, COMPONENTTYPE (BPEL/BPM/MEDIATOR) etc.

Schematron Validation in Oracle BPEL using Custom XPath Function

In one of my earlier post i had shown how we can use the Schematron feature to validate XML content in the Mediator component of Oracle SOA Suite 11g.

The article can be found at the link below


However the mechanism to validate an XML content inside a BPEL or BPMN component is not available as of now. In this blog entry I would like to show how we can achieve it in either a BPEL or a BPM process using a Custom Xpath Function.

I have found these blogs most informative and wonderful on how to create your own Custom XPath function in Oracle SOA Suite.



I would try to show how we can use the custom XPath (link to the Jar) function from within a BPEL process that invokes the behind the scene Java classes to provide a validation output. Preview the screenshot below as how the custom XPath will appear in JDeveloper.

image
  • Download the SchematronXpath.jar from the location in this link.
  • Open JDeveloper and Click on Tools->Preferences->SOA.
  • Add the SchematronXpath.jar and click OK. We will need to restart JDeveloper in order for this change to take effect.
  • Upon restarting we can see that the custom XPath function is available in the Functions pallette under User Defined Extension Functions

image

The validateSchematron function accepts the xml source and the corresponding Schematron file against which the xml content should be validated.

The output of the function contains a Static XML describing the validation status and validation messages (consisting of validation errors or warnings if any).

See a sample of the validation Output.

<ValidationOutput>
<ValidationFlag>false</ValidationFlag>
<ValidationMessage>(1).The value of the sum attribute should be the sum of all the values in the item child elements.</ValidationMessage>

The next thing to get this custom function executing at runtime in SOA Suite we need to add it to the SOA suite extension libraries.
  • Copy the SchematronXpath.jar jar file to the <MIDDLEWARE_HOME>/Oracle_SOA1/soa/modules/oracle.soa.ext_11.1.1 directory on the SOA Suite installation.
  • Run ant in that directory (setting JAVA_HOME if necessary) by executing <MIDDLEWARE_HOME>/modules/org.apache.ant_1.7.1/bin/ant.

Another option is to add the jar file in the BPEL runtime manually using the following steps.
  • Go to <Middleware Home>\Oracle_SOA1\soa\modules\oracle.soa.bpel_11.1.1 directory of your Oracle SOA Suite installation.
  • Copy the SchematronXpath.jar in the above directory
  • Unjar the oracle.soa.bpel.jar and edit the MANIFEST.MF to add an entry of the above jar in the classpath.
  • We then need to restart the SOA Suite to get it to recognize the jar in its classpath.
I then created a BPEL process that would invoke the custom XPath function to validate the content of its input. Also placed the schematron file inside a custom folder inside the BPEL project so that we can refer to it using the ora:doc('validationFiles/ValidateItemSum.sch') function using an Assign activity.

image

The val:validateSchematron(Element xmlSource, Element schemaSource) takes any xml input converted as Node/Element and the validation schema.

I then used a variable called validationResult of type xsd:anyType to get the validation response from the XPath

image

We can then get the validation status flag and validation messages by applying simple XPath expressions on the validaitonResult variable.

image

Once we deploy out BPEL process to a running SOA server we can also test it with a few input and see the results.

We first test the Happy test case where we pass two Items with values that add up to the sum attribute. As defined in the schematron file this should pass the validation and it does as is seen in the response.

image

Test the composite again but this time with Items values which doesn't add up to the value of the sum attribute.

This time the validation returns a false flag along with the Assert message defined in the schematron file.

image

If you have any questions and concerns for this particular approach please use the comment section below.

Also let me know in case if you are interested in the source code for the Custom XPath Java code that is demonstrated in this article.

The BPEL process used in this demo can be downloaded from this link.

Jar file for the CustomXpath function.