Você está na página 1de 38

Service Oriented

Architecture
Lecture 8: More BPEL
Notes selected from the paper Formal Semantics and Analysis
of control flow in WS-BPEL by Ouyang and others and the book
Business Process Execution Language for Web Services by
Matjaz Juric

95-843: Service Oriented Architecture


Master of Information System 1!
Management
Todays Topics
Basic BPEL constructs to Petri Nets
Generating and Handling Faults
Defining Scopes and Scope Rules
Correlation Sets
Compensation
Event Handling

95-843: Service Oriented Architecture


Master of Information System 2!
Management
Basic BPEL Constructs to
Petri Nets
For all of the BPEL constructs converted
to Petri nets see the paper by Ouyang
and others.
The notation:
rx ready for activity x
sx starting activity x
cx completed activity x
fx finished activity x

95-843: Service Oriented Architecture


Master of Information System 3!
Management
A Basic Activity
to_skipx
rx

X
sx

X
skip
cx

skippedx fx
95-843: Service Oriented Architecture
Master of Information System 4!
Management
Structured Activities (normal behavior)
(a) sequence
rx
X
<sequence name=X> sx
activity A
activity B
</sequence> rA
A
fA

rB
B
fB

95-843: Service Oriented Architecture


Master of Information System fx 5!
Management
Structured Activities (normal behavior)
(b) flow
<flow name=x>
activity A
activity B rx
</flow>
X

sx

rA rB
A B
fA fB

cx

95-843: Service Oriented Architecture fx


Master of Information System 6!
Management
Structured Activities (normal behavior)
(c) switch
<switch name=X> rx
<case>
<condition> X
Z1
</condition> sx ~Z1 Z2
activity A
Z1
</case>
<case>
rA rB
<condition>
Z2 A B
</condition>
activity B fA fB
</case>
</switch>

cx

95-843: Service Oriented Architecture fx


Master of Information System 7!
Management
Structured Activities (normal behavior)
(d) pick
rx
<pick name=X>
<onMessage e1> X
activity A
</onMessage>
sx
<onAlarm e2> e1 e2
activity B
<onAlarm> rA rB
</pick>
A B
fA fB

cx

95-843: Service Oriented Architecture


Master of Information System
fx 8!
Management
Structured Activities (normal behavior)
(e) while
<while name=X
<condition>
z X
</condition>
~z sx
activity A z
</while>

rA
A
fA

cx

95-843: Service Oriented Architecture


Master of Information System fx 9!
Management
Generating and Handling
Faults
Different types of fault behavior
when programming in the large.
What do we do if the network is
down?
What do we do if some other
process returns an error?
How do we signal errors to
synchronous and asynchronous
clients?
95-843: Service Oriented Architecture
Master of Information System 10!
Management
Fault Source (1)
(1) We perform a synchronous invoke and get
back a fault. The possibility of a fault being
returned is described in the WSDL of the
foreign service
<portType name="X">
<operation name="foo">
<input message="param1"/>
<output message="param2/>
<fault name="fault" message="someError"/>
</operation>
</portType>

95-843: Service Oriented Architecture


Master of Information System 11!
Management
Handling the Fault(1)
Suppose the synchronous invoke
generates a fault.
We can handle it inline:
<invoke .... >
<catch faultName = "SomeFaultName">
perform activities
</catch>
<catch faultName="SomeOtherFaultName">
perform activities
</catch>
<catchAll>
...
</catchAll>
</invoke>
95-843: Service Oriented Architecture
Master of Information System 12!
Management
Handling the Fault(2)
Suppose the synchronous invoke
generates a fault. This is another
approach.
We can use a fault handler.
<process...>
<partnerLinks>...</partnerLinks>
<variables>...</variables>
<faultHandlers>
<catch faultName or faultVariable> handle fault </catch>
<catch faultName or faultVariable> handle fault </catch>
<catchAll> handle fault </catchAll>
</faultHandlers>
<sequence>
invoke
</sequence>
</process>
95-843: Service Oriented Architecture
Master of Information System 13!
Management
Fault Source (2)
(2) We perform an asynchronous invoke and
later we get back a fault. The possibility of a
fault being returned is described in the
WSDL of the foreign service.

Normally, we would handle the return value


of an asynchronous request with a receive
activity. To prepare for the possibly of a
fault, we will use a pick activity.

95-843: Service Oriented Architecture


Master of Information System 14!
Management
Handling the Fault(3)
(2) Using pick after an asynchronous invoke to handle
a fault.

<pick>
<onMessage>... The onMessage can act as a
normal receive with almost
the same syntax.
</onMessage>
<onMessage>... The other onMessage can be used
</onMessage> to receive the fault notification.
<onAlarm>... The onAlarm element specifies an
end time or duration.
</onAlarm> It may contain a series of
activities or a throw.
</pick>

95-843: Service Oriented Architecture


Master of Information System 15!
Management
Fault Source (3)
The BPEL process itself may throw a
fault.
The BPEL run time may throw a fault.
If the fault is not handled the process
terminates.
There is no automatic passing of the
fault back to the client (the business
process has to do it).

95-843: Service Oriented Architecture


Master of Information System 16!
Management
Handling The Fault (4)
<process...>
<partnerLinks>...</partnerLinks>
<variables>...</variables>
<faultHandlers>
<catch faultName or faultVariable>
reply or invoke with fault message back to client
the invoke option requires the client to provide
a regular callback and a callback for the fault
</catch>
<catch faultName or faultVariable> handle fault
</catch>
<catchAll> handle fault </catchAll>
</faultHandlers>
<sequence>
:
<throw faultName="someFaultName"/>
</sequence>
</process>
95-843: Service Oriented Architecture
Master of Information System 17!
Management
Defining Scope
Why define scope?
We can define different fault
handling for different parts of a
process.
We can define variables that are
local to a scope.
We can define local correlation
sets, compensation handlers, and
event handlers in a scope.
95-843: Service Oriented Architecture
Master of Information System 18!
Management
Scope Syntax
<scope>
<variables>variables local to the scope</variables>
<correlationSets>...</correlationSets>
<faultHandlers>local handlers</faultHandlers>
<compensationHandler>...</compensationHandler>
<eventHandlers>...</eventHandlers>
BASIC OR STRUCTURED ACTIVITIES
</scope>

95-843: Service Oriented Architecture


Master of Information System 19!
Management
Scope Rules
Each scope has a primary activity.
This activity may be a basic activity or a structured
activity such as sequence or flow.
If a scope has a structured activity, it can have many
nested activities (all in the same scope).
A scope can also have nested scopes with arbitrary
depth.
Faults not caught in a scope are re-thrown to the
enclosing scope.
Scopes in which faults have occurred are considered to
have ended abnormally even if a fault handler has
caught the fault and not re-thrown it.

95-843: Service Oriented Architecture


Master of Information System 20!
Management
<process> Scope Example(1)
<partnerLinks>...
<variables>...
<faultHandlers>...
<sequence>
<receive>
<scope>
<variables>
<faultHandlers>
<sequence>
<flow>
invoke 1
invoke 2
</flow>
</sequence>
</scope>
<scope>
:
</scope>
</sequence>
</process>
95-843: Service Oriented Architecture
Master of Information System 21!
Management
Scope Example (2)
<scope>
<faultHandlers>
<catch> ... </catch>
<catch>... </catch>
</faultHandlers>
<invoke> This is equivalent
to the inline fault handling
: example.
</invoke>
Faults not caught in a scope
</scope> are re-thrown to the enclosing
95-843: Service Oriented Architecture
scope.
Master of Information System 22!
Management
Concurrency & Scope
If an event handler in a scope is executing at
the same time as the main process of a
scope there is the possibility of conflicting
use of shared variables.
Scopes that require concurrency control are
called serializable scopes. Concurrency is
prohibited in the following scope:

<scope variableAccessSerializable="yes">
...
</scope>
95-843: Service Oriented Architecture
Master of Information System 23!
Management
Correlation
Correlation is used to match
messages with business process
instances.
A set of properties shared by
messages and used for correlation
is called a correlation set.
Correlation sets are defined and
then used in invokes and receives.
95-843: Service Oriented Architecture
Master of Information System 24!
Management
Define The Correlation
Properties are defined
<process> with the WSDL extensibility
mechanism and are
<partnerLinks> associated with an
<variables> Xpath query into a
message.
<correlationSets>
<correlationSet name=TicketOrder
properties=aln:FlightNo/>
</correlationSets>
So, aln:FlightNo is a name
that points into a message
and TicketOrder is the name
of the correlationSet.

95-843: Service Oriented Architecture


Master of Information System 25!
Management
Use The Correlation(1)
<sequence>
<invoke> Make an asynchronous call
for a flight number.
<receive> Receive the response at a later time.
: Build a correlation set.
<correlations>
<correlation set=TicketOrder
initiate=yes/>
</correlations>
</receive>
:

95-843: Service Oriented Architecture


Master of Information System 26!
Management
Use The Correlation(2)
:
:
:
<invoke> Synchronously confirm with the
correlation
<correlations>
<correlation set=TicketOrder
pattern=out-in/>
</correlations>
</invoke>
:
:
95-843: Service Oriented Architecture
Master of Information System 27!
Management
Use The Correlation(3)
:
:
:
<invoke> Make a callback on the client with the
correlation
<correlations>
<correlation set=TicketOrder
pattern=out/>
</correlations>
</invoke>

:
:

95-843: Service Oriented Architecture


Master of Information System 28!
Management
Compensation(1)
Suppose we register for a really cool
SOA course but after one week of
classes we change our minds. We would
prefer to take a course in Latin
American History.
Lucky for us, the university provides us
with the ability to drop/add.
The drop is a compensating activity. It
undoes what we initially thought was a
good idea.

95-843: Service Oriented Architecture


Master of Information System 29!
Management
Compensation(2)
In business processes, the compensation
activity must be explicitly defined.
Business processes often last a long time and
traditional transaction processing methods are
often inappropriate.
Its not the case that a fault is thrown and an
error needs to be handled.
The operations completed successfully but now
need to be undone.

95-843: Service Oriented Architecture


Master of Information System 30!
Management
Compensation Handlers(1)
Compensation handlers may be
defined for the process, scope or
invoke activity. The process
compensation
<process> handler may only
be called after the
<partnerLinks> process has
<variables> completed
<faultHandlers> normally.
<compensationHandler> drop course activities
</compensationHandler> How it is invoked
<sequence> register for course is dependent on
the run-time
</sequence> environment.
</process>
95-843: Service Oriented Architecture
Master of Information System 31!
Management
Compensation Handlers(2)
Compensation handlers may be defined
for the process, scope or invoke
activity.
Call with
<scope> <compensate scope=XXX/>
<variables> Where XXX is the name of the
<correlationSets> scope.
<faultHandlers>
<compensationHandler> drop course
activities
<eventHandlers>
activities to register for a course
</scope>

95-843: Service Oriented Architecture


Master of Information System 32!
Management
Compensation Handlers(3)
Compensation handlers may be defined for the
process, scope or invoke activity.

<invoke>
The syntax used to call
register for SOA the handler is
<compensationHandler> <compensate
name=xxx />
activities to drop SOA where xxx is the name
</compensationHandler> of the invoke activity
that needs to be
</invoke>
compensated.

95-843: Service Oriented Architecture


Master of Information System 33!
Management
Calling Compensation
Handlers
The activity that is to be compensated
must have been completed normally.
Nothing happens if we try to
compensate an activity that has not
completed normally.
The values of variables will be the same
in the compensation handler as those
values after the activity took place.

95-843: Service Oriented Architecture


Master of Information System 34!
Management
Event Handlers(1)
Example (1): a claims handling process
supports the cancellation of a claim
while the process is currently running.
This may occur once or not at all. To do
this, the client of the process invokes
the cancellation operation that is
implemented using an event handler.
This is from IBM Developer Works

95-843: Service Oriented Architecture


Master of Information System 35!
Management
Event Handlers(2)
Example (2): Expiration of a timeout:
A manager wants to be informed when a
process takes longer than a week to be
finished.
Repeated expiration of timeout: a manager
wants to be informed when a process takes
longer than a week to be finished. After the
week is over, the manager wants to be
informed each day until the process is
finished.
From IBM Developer Works
95-843: Service Oriented Architecture
Master of Information System 36!
Management
Event Handlers in BPEL
WS-BPEL defines two types of
event handlers, as follows: An
onEvent event handler handles the
occurrence of an external message
event. This is the invocation of an
operation.
An onAlarm event handler handles
the expiration of a timeout.
From IBM Developer Works
95-843: Service Oriented Architecture
Master of Information System 37!
Management
Concurrency
Multiple onEvent and onAlarm events can
occur concurrently and they are treated as
concurrent activities. An event handler is
permitted to have several simultaneously
active instances. A private copy of all process
data and control behavior defined within an
event handler is provided to each instance of
an event handler.
From IBM Developer Works

95-843: Service Oriented Architecture


Master of Information System 38!
Management

Você também pode gostar