Ana səhifə

Web Services Business Process Execution Language Version 0 Public Review Draft 02, 20 November, 2006


Yüklə 2.65 Mb.
səhifə13/23
tarix27.06.2016
ölçüsü2.65 Mb.
1   ...   9   10   11   12   13   14   15   16   ...   23

12.3. Error Handling in Business Processes


Business processes are often of long duration. They can manipulate business data in back-end databases and line-of-business applications. Error handling in this environment is both difficult and business critical. The use of ACID transactions is usually limited to local updates because of trust issues and because locks and isolation cannot be maintained for the long periods during which fault conditions and technical and business errors can occur in a business process instance. As a result, the overall business transaction can fail or be cancelled after many ACID transactions have been committed. The partial work done must be undone as best as possible. Error handling in WS-BPEL processes therefore leverages the concept of compensation, that is, application-specific activities that attempt to reverse the effects of a previous activity that was carried out as part of a larger unit of work that is being abandoned. There is a history of work in this area regarding the use of Sagas [Sagas] and open nested transactions [Trends]. WS-BPEL provides a variant of such a compensation mechanism by providing the ability for flexible control of the reversal. WS-BPEL achieves this by providing the ability to define fault handling and compensation in an application-specific manner, in support of Long-Running Transactions (LRT’s).

The notion of LRT described here is purely local and occurs within a single business process instance. There is no distributed coordination necessary regarding an agreed-upon outcome among multiple-participant services. The achievement of distributed agreement is an orthogonal problem outside the scope of this specification.

As an example, consider the planning and fulfillment of a travel itinerary. This can be viewed as an LRT in which individual service reservations can use nested transactions within the scope of the overall LRT. If the itinerary is cancelled, the reservation transactions must be compensated for by cancellation transactions, and the corresponding payment transactions must be compensated accordingly. For ACID transactions in databases the transaction coordinator(s) and the resources that they control know all of the uncommitted updates and the order in which they must be reversed, and they are in full control of such reversal. In business transactions, the compensation behavior is itself a part of the business logic and protocol, and must be explicitly specified. In this example, there might be penalties or fees applied for cancellation of an airline reservation depending on the class of ticket and the timing of the cancellation. If a payroll advance has been given to pay for the travel, the reservation must be successfully cancelled before the payroll advance for it can be reversed in the form of a payroll deduction. This means the compensation actions might need to run in the same order as the original transactions, which is not the standard or default in most ACID transaction systems. Using activities as the definition of logical units of work, WS-BPEL addresses these requirements of LRT.

12.4. Compensation Handlers


The ability to declare compensation logic alongside forward-working logic is the underpinning of the application-controlled error-handling framework of WS-BPEL. WS-BPEL allows scopes to delineate that part of the behavior that is meant to be reversible in an application-defined way by specifying a compensation handler. Scopes with compensation and fault handlers can be nested without constraint to arbitrary depth.

12.4.1. Defining a Compensation Handler


Syntactically, a is simply a wrapper for an activity that performs compensation as shown below.

activity


As explained in section 10.3. Invoking Web Service Operations – Invoke, there is a special shortcut for the activity to inline a rather than explicitly using an immediately enclosing . For example:



portType="SP:Purchasing"

operation="Purchase"

inputVariable="sendPO"

outputVariable="getResponse">



pattern="request" />







portType="SP:Purchasing"

operation="CancelPurchase"

inputVariable="getResponse"

outputVariable="getConfirmation">











In this example, the original activity makes a purchase and in case that purchase needs to be compensated, the invokes a cancellation operation on the same port of the same partner link, using the response to the purchase request as the input.

Without the shortcut this example would be expressed as follows:





portType="SP:Purchasing"

operation="CancelPurchase"

inputVariable="getResponse"

outputVariable="getConfirmation">











portType="SP:Purchasing"

operation="Purchase"

inputVariable="sendPO"

outputVariable="getResponse">



pattern="request" />







Note that the variable getResponse is not local to the to which the is attached and can be reused later for other purposes before compensation for this is invoked. The current state of non-local variables is available in compensation handlers as explained more fully below. Assuming the compensation handler needs the specific response to the operation that is being reversed, that response would most conveniently be stored in a variable that is local to the , i.e., by making getResponse local to the . In this case, an explicit is needed for the variable declaration.

If the for a scope is not specified, default compensation handling for the scope is provided (see section 12.5.2. Default Compensation Order for more details).

12.4.2. Process State Usage in Compensation Handlers


A compensation handler always uses the current state of the process at the time the compensation handler is executed. This state comes from its associated scope and all enclosing scopes, and includes the state of variables, partner links and correlation sets. Compensation handlers are able to both read and write the values of all such data. Other parts of the process will see the changes made to shared data by compensation handlers, and conversely, compensation handlers will see changes made to shared data by other parts of the process. In cases where a compensation handler runs concurrently with other parts of the process, compensation handlers may need to use isolated scopes when they touch state in enclosing 's to avoid interference (see section 12.8. Isolated Scopes).

The process state consists of the current state of all scopes that have been started. This includes scopes that have completed successfully but for which the associated compensation handler has not been invoked. For successfully completed (but uncompensated) scopes, their state is kept at the time of completion. Such scopes are not running, yet they are still reachable. This is because their compensation handlers are still available, and therefore the execution of such scopes may continue during the execution of their compensation handlers, which can be thought of as an optional continuation of the behavior of the associated scope. A scope may have been executed several times (e.g. in a or in a ), so the state of the process includes the state of all successfully completed (and uncompensated) iteration instances of the scope. We refer to the preserved state of a successfully completed uncompensated scope as a scope snapshot.

The behavior of a compensation handler can use the state of the associated scope as it has been left. This includes variables, partner links, message exchanges, and correlation sets in both the associated scope and all scopes that enclose it. For the variables in the associated scope, the compensation handler starts executing with the scope snapshot. The compensation handler also has access to the current state of each enclosing scope. This state is shared with any concurrent units of logic. The compensation handler may itself have been called from the compensation handler of the parent scope. It will then share the continuation of the state of the enclosing scope that its caller is using. 

The picture below shows three nested scopes P, S2 and S3, a fault handler FH(P) of the process and compensation handlers CH(S2) and CH(S3).

The picture is based on the XML below. When executing the process, the first scope P (the process itself) declares a variable V1 and initializes it to the value of 0. Scopes S2 and S3 are executed. At successful completion of S2 and S3, all variable values are set to 1 and are frozen into snapshots (in the timeline shown by dotted lines). Subsequently, a fault occurs within the process P (indicated by event “1” in the picture), which gets caught by the fault handler FH(P) of the process P. When the fault handler of the process calls the compensation handler CH(S2) of scope S2 (indicated by event “2” in the picture), the snapshot of S2’s state is retrieved and used while compensating. The same applies when compensating scope S3 (indicated by event “3” in the picture).



Figure 3: Variable Access in Compensation Handlers





0





















0





...









0





...


when this logic is reached -->

...








1













1







1













12.4.3. Invoking a Compensation Handler


A compensation handler can be invoked by using the or (together referred to as the "compensation activities"). A compensation handler for a scope MUST be made available for invocation only when the scope completes successfully. Any attempt to compensate a scope, for which the compensation handler either has not been installed or has been installed and executed, MUST be treated as executing an activity. Therefore, handlers do not rely on state to determine which nested scopes have completed successfully.

standard-elements




standard-elements



The and activities MUST only be used within , , , and .

Fault handlers, compensation handlers, and termination handlers are referred to as FCT-handlers. For the purpose of specifying the semantics of and , a scope A is considered to immediately enclose another scope B, if B is enclosed in A and B is not enclosed in any other scope or FCT-handler that is itself enclosed in the outer scope A. Other structured activities (e.g. or ) and event handlers enclosed in A do not affect the concept of immediate enclosure. This definition includes scopes that result from the shorthand notation for fault handlers and compensation handlers.

[SA00092]Within a scope, the name of all named immediately enclosed scopes MUST be unique. This requirement MUST be statically enforced.

A or activity in an FCT-handler is used to compensate the behavior of a successfully completed scope immediately enclosed inside the scope associated with the FCT-handler. [SA00077] The value of the target attribute on a activity MUST refer to the name of an immediately enclosed scope. This includes immediately enclosed scopes of an event handler ( or ) associated with the same scope (see section 12.7. Event Handlers). This rule MUST be statically enforced.

FCT-handlers may themselves contain scopes. The invocation of a compensation activity is interpreted based on the immediately enclosing FCT-handler and is used to compensate the behavior of a successfully completed scope immediately enclosed inside the scope associated with that FCT-handler. There is therefore no way to use a compensation activity to compensate the scopes immediately enclosed inside an FCT-handler. An


12.4.3.1. Compensation of a Specific Scope

The activity causes one specified child scope to be compensated. For example:

The names of all named activities immediately enclosed in a scope must be unique (see section 10.1. Standard Attributes for All Activities). [SA00078] The target attribute of a activity MUST refer to a scope or an invoke activity with a fault handler or compensation handler. The referenced activity MUST be immediately enclosed by the scope containing the FCT-handler with the activity. If these requirements are not met then the WS-BPEL process MUST be rejected. These requirements MUST be statically enforced.


12.4.3.2. Invoking Default Compensation Behavior

The activity causes all immediately enclosed scopes to be compensated in default order (see section 12.5.2. Default Compensation Order).

This activity is used when an FCT-handler needs to perform additional work, such as updating variables, in addition to performing default compensation for the targeted immediately enclosed scopes.

User-defined FCT-handlers may use activities to compensate specific immediately enclosed scopes and/or to compensate all immediately enclosed scopes in default order. Any repeated attempt to compensate immediately enclosed scopes is treated as executing an activity (see section 12.4.3. Invoking a Compensation Handler).

When user-defined FCT-handlers are executed, a WS-BPEL processor MUST NOT compensate immediately enclosed scopes unless the or activities are used.


12.4.4. Compensation within Repeatable Constructs or Handlers

12.4.4.1. Compensation Handler Instance Groups

Placing a scope inside a repeatable construct, such as loop or an event handler usually results in multiple instances of that scope. One scope instance is created for each repetition or event handler instantiation, respectively.

When a or activity is used to invoke the compensation handler of a scope contained in a repeatable construct, the compensation activity runs a set of installed compensation handler instances and causes the corresponding set of child scope instances to be compensated. The set of all such installed compensation handler instantiations is called a Compensation Handler Instance Group.

In the case of scope specific compensation (), the Compensation Handler Instance Group contains the installed compensation handler instances of a particular target scope that is executed within a repeatable construct. For the case of default compensation (), the Compensation Handler Instance Group contains the compensation handler instances of all immediately enclosed scopes that completed successfully. The compensation handler instances of immediately enclosed scopes, are treated as a single group.

If an uncaught fault occurs while executing any compensation handler instance of the group, or if compensation activities are terminated, then all running instances MUST be terminated following standard WS-BPEL activity termination semantics. All compensation handler instances of the group and compensation handler instance groups of immediately enclosed scopes are uninstalled. Completed compensation handler instances within a Compensation Handler Instance Group are not subject to further compensation.


12.4.4.2. Compensation within Repeatable Constructs

If a scope being compensated by name is nested in a , , or non-parallel loop, the invocation of the installed instances of the compensation handlers in the successive iterations MUST be in reverse order.

In the case of parallel and event handlers, no ordering requirement is imposed on the compensation of the associated scope.


12.4.4.3. Compensation within FCT-Handlers

If a scope is enclosed inside an FCT-handler, then the enclosed scope’s compensation handler is available only for the lifetime of the enclosing handler. Once the handler completes, any installed compensation handlers within it are uninstalled. [SA00079] A root scope enclosed inside a handler of the above three kinds cannot have a compensation handler associated because it is not reachable at all from anywhere within the process. Therefore, the root scope inside a handler of the above three kinds MUST NOT have a compensation handler. This rule MUST be statically enforced. Note that the root scope of an event handler ( or ) can have a compensation handler.

Figure 4: Compensation within Fault Handlers shows a fault handler FH(S1) that contains a scope S2. Scope S2 cannot have a compensation handler CH(S2) as this compensation handler would be unreachable, but it may have a fault handler FH(S2) that is allowed to compensate an inner scope S3.



Figure 4: Compensation within Fault Handlers
Compensation within Fault Handlers

A fault in a fault handler MUST cause all running contained activities to be terminated (see section 12.6 Termination Handlers). All compensation handlers contained in the fault handler MUST be uninstalled. The fault is propagated to the enclosing scope.

Compensation within Compensation Handlers

A root scope enclosed by a compensation handler can be used to ensure “all or nothing” semantics, but not for reversing the work of a successfully completed compensation handler. If the compensation handler completes successfully then any installed compensation handlers for scopes nested within it are uninstalled. The successfully completed compensation cannot be reversed, because the root scope inside a compensation handler cannot have a its own compensation handler associated because it is not reachable at all from anywhere within the process.

A compensation handler that faults (“internal fault”) will undo its partial work by compensating all scopes immediately enclosed by the root scope according to the fault handler of the root scope. If such a fault handler is not specified explicitly, partial work will be compensated in the default order (see section 12.5.2. Default Compensation Order). This approach can be used to provide all or nothing semantics for compensation handlers. After the partial work is undone, the compensation handler MUST be uninstalled. The fault MUST be propagated to the caller of the compensation handler. This caller is a default FCT-handler of the enclosing scope or a compensation activity contained within a user-defined handler.

Figure 5: Compensation within Compensation Handlers shows a compensation handler CH(S1) that contains a scope S2. As in the preceding figure, S2 cannot have a compensation handler CH(S2) itself but may have a fault handler FH(S2) that is allowed to compensate an inner scope S3.




Figure 5: Compensation within Compensation Handlers
Compensation within Termination Handlers

A fault inside a termination handler MUST NOT be not propagated to the enclosing scope (see section 12.6 Termination Handlers). Other than that, all of the statements about fault handlers apply to termination handlers as well.


1   ...   9   10   11   12   13   14   15   16   ...   23


Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©atelim.com 2016
rəhbərliyinə müraciət