Service Oriented Architecture Lecture 7 BPEL Some notes
Service Oriented Architecture Lecture 7: BPEL Some notes selected from “Business Process Execution Language for Web Services” by Matjaz Juric 95 -843: Service Oriented Architecture Master of Information System Management 1
We Are Here From IBM’s High Level Reference Architecture 95 -843: Service Oriented Architecture Master of Information System Management 2
BPEL • Business Process Execution Language • Programming in the large • Processing logic to handle synchronous and asynchronous messages • Quite different from programming in the small - different issues to deal with • Structured programming language using while, if else, sequence, flow, … • XPATH used for addressing message 95 -843: Service Oriented Architecture parts 3 Master of Information System Management
Basics • Developing web services and exposing functionalities is not sufficient. • Need a way to compose these functionalities in the right order – a way to define business processes which will make use of the exposed functionalities. • BPEL allows composition of web services. • BPEL may be used for a long running process. • “Dehydration” is the term used to refer to the saving of a process state. • Successfully completed processes as well are saved in the dehydration store. 95 -843: Service Oriented Architecture Master of Information System Management 4
Web Service Composition Methods - Orchestration • A central process takes control over the involved web services and coordinates the execution of different operations on the web services involved in the operation. • This is done as per the requirements of the orchestration. • The involved web services do not know (and do not need to know) that they are involved into a composition and that they are a part of a higher business process. • Only the central coordinator of the orchestration knows this. • So orchestration is centralized with explicit definitions of operations and the order of invocation of web services. 95 -843: Service Oriented Architecture Master of Information System Management 5
Web Service Composition Methods - Choreography • Choreography does not rely on a central coordinator. • Each web service involved in the choreography knows exactly when to execute its operations and whom to interact with. • Choreography is a collaborative effort focused on exchange of messages. • All participants of the choreography need to be aware of the business process, operations to execute, messages to exchange, and the timing of message exchanges. • This is a peer-to-peer approach. 95 -843: Service Oriented Architecture Master of Information System Management 6
Composing web services to execute business processes • Orchestration is the more flexible approach compared to choreography: – We know exactly who is responsible for the execution of the whole business process. – We can incorporate web services, even those that are not aware that they are a part of a business process. – We can also provide alternative scenarios when faults occur. • BPEL follows the orchestration paradigm. • Choreography is covered by other standards, such as WSCI (Web Services choreography Interface) and WSCDL (Web Services Choreography Description Language). • Choreography has not gained support from the industry which would be comparable to BPEL. 95 -843: Service Oriented Architecture Master of Information System Management 7
Programming in the Large History • IBM WSFL (Web Service Flow Language) defined in May 2001. • Microsoft XLANG defined around the same time. • Joint submission to OASIS under the name BPEL 4 WS. • OASIS (September 2004) WS-BPEL-2. 0. • Has no standard graphical language. • The BPEL process itself is a web service. • BPEL business processes are portable. 95 -843: Service Oriented Architecture Master of Information System Management 8
BPEL • BPEL builds on top of XML and web services. • It is an XML-based language which supports the web services technology stack, including SOAP, WSDL, UDDI, WS-Reliable Messaging, WS-Addressing, WSCoordination and WS-Transaction. 95 -843: Service Oriented Architecture Master of Information System Management 9
A typical BPEL process • First, the BPEL business process receives a request. • To fulfill it, the process then invokes the involved web services and finally responds to the original caller. • Since the BPEL process communicates with other web services, it relies heavily on the WSDL description of the web services invoked by the composite web service. 95 -843: Service Oriented Architecture Master of Information System Management 10
Steps in a Process • Each step is called an activity. • BPEL supports primitive and structure activities. • Primitive activities represent basic constructs and are used for common tasks 95 -843: Service Oriented Architecture Master of Information System Management 11
Primitive Activities • Invoking other web services, using <invoke> • Waiting for the client to invoke the business process through sending a message, using <receive> (receiving a request) • Generating a response for synchronous operations, using <reply> • Manipulating data variables, using <assign> • Indicating faults and exceptions, using <throw> • Waiting for some time, using <wait> • Terminating the entire process, using <terminate> etc. 95 -843: Service Oriented Architecture Master of Information System Management 12
Defining Processes • Combine these and other primitive activities and define complex algorithms, which exactly specify the steps of business processes. • To combine primitive activities BPEL supports several structured activities 95 -843: Service Oriented Architecture Master of Information System Management 13
Structured Activities • Sequence ( <sequence>), which allows us to define a set of activities that will be invoked in an ordered sequence • Flow ( <flow>) for defining a set of activities that will be invoked in parallel • Case-switch construct ( <switch>) for implementing branches • While ( <while>) for defining loops • The ability to select one of a number of alternative paths, using <pick> 95 -843: Service Oriented Architecture Master of Information System Management 14
Definitions and Declarations • BPEL processes will typically declare variables using <variable> • BPEL processes will typically define partner links using <partner. Link> • A BPEL process can be synchronous or asynchronous. – A synchronous BPEL process blocks the client (the one which is using the process) until the process finishes and returns a result to the client. – An asynchronous process does not block the client. Rather it uses a callback to return the result (if any) 95 -843: Service Oriented Architecture Master of Information System Management 15
Example Process • For its clients a BPEL process looks like any other web service. • When we define a BPEL process, we actually define a new web service that is a composition of existing services. • The interface of the new BPEL composite web service uses a set of port types, through which it provides operations like any other web service. • To invoke a business process described in BPEL, we have to invoke the resulting composite web service. 95 -843: Service Oriented Architecture Master of Information System Management 16
95 -843: Service Oriented Architecture Master of Information System Management 17
Typical Structure (1) <process> <partner. Link> </partner. Links> <variable> </variable> <sequence> <receive> </receive> the initial client request 95 -843: Service Oriented Architecture Master of Information System Management 18
Partner Links • BPEL calls the links to all parties it interacts with as partner links • Partner links can be links to web services that are invoked by the BPEL process • Partner links can also be links to clients which invoke the BPEL process • Each BPEL process has at least one client partner link, because there has to be a client that invokes the BPEL process. 95 -843: Service Oriented Architecture Master of Information System Management 19
Typical Structure (2) <flow> <invoke> </flow> make calls in parallel a web service </invoke> another web service </invoke> 95 -843: Service Oriented Architecture Master of Information System Management 20
Typical Structure (3) <switch> make decisions <case condition =“…”> <assign> <copy> <from>…<to> </case> <otherwise> <assign> <copy> <from>…<to> </otherwise> </switch> <reply> reply to synchronous caller </sequence> </process> 95 -843: Service Oriented Architecture Master of Information System Management 21
Sequential Order of Activities <process> …. <sequence> Do activities in sequential order. <receive> <invoke> <assign> <invoke> <receive> <invoke> </sequence> </process> 95 -843: Service Oriented Architecture Master of Information System Management 22
Parallel Activities <process> …. <sequence> <receive> Wait to start process <flow> <invoke> </flow> </sequence> </process> 95 -843: Service Oriented Architecture Master of Information System Management The three invokes are carried out in parallel. 23
Parallel Sequences <process> …. <sequence> <receive> <flow> <sequence> <invoke> </sequence> </flow> </sequence> </process> Wait to start process. Both sequences may run in parallel. These two ‘invokes’ go in order 95 -843: Service Oriented Architecture Master of Information System Management 24
Synchronous Web Services The sender blocks and waits for a reply. The service should run fast. The <receive> and <reply> form a pair on B. <receive> <invoke>. . <invoke> No <receive> needed <reply> B A 95 -843: Service Oriented Architecture Master of Information System Management B is a synchronous web service and uses a BPEL reply. 25
Quiz on Synchronous Web Services What does A need to know about B? In other words, what is required in B’s WSDL? <receive> <invoke>. . <invoke> No <receive> needed. <reply> B A 95 -843: Service Oriented Architecture Master of Information System Management B is a synchronous web service and uses a BPEL reply. 26
Quiz on Synchronous Web Services What does A need to know about B? In other words, what is required in B’s WSDL? A needs to know the message types and the available operations as well as B’s location. <receive> <invoke>. . <invoke> No <receive> needed. <reply> B A 95 -843: Service Oriented Architecture Master of Information System Management B is a synchronous web service and uses a BPEL reply. 27
Asynchronous Web Services (1) Most real-world processes are long running and if callbacks are needed, message correlation may be used. If callbacks are not needed, B need not perform an <invoke>. <receive> <invoke>. . <invoke> Do other things… <receive> <invoke> B A 95 -843: Service Oriented Architecture Master of Information System Management B is an asynchronous web service and replies with an optional “invoke” not a “reply”. 28
Quiz on Asynchronous Web Services What does A need to know in order to use B? In other words, what information must be available in B’s WSDL? <receive> <invoke>. . <invoke> Do other things… <receive> <invoke> B A 95 -843: Service Oriented Architecture Master of Information System Management B is an asynchronous web service and replies with an optional “invoke” not a “reply”. 29
Quiz on Asynchronous Web Services What does A need to know in order to use B? In other words, what information must be available in B’s WSDL? A needs to know the message types and the available operations as well as B’s location. In order to use B, A must also know exactly what operations it needs to provide and what messages will be received. <receive> <invoke>. . <invoke> Do other things… <receive> <invoke> B A 95 -843: Service Oriented Architecture Master of Information System Management B is an asynchronous web service and replies with an optional “invoke” not a “reply”. 30
Example Business Process Collect employee information (name, id, travel plans, etc. ). Determine an employee’s flying status (first class or coach) and then determine the cheaper of two airlines. Return suggested flight to the employee. 95 -843: Service Oriented Architecture Master of Information System Management 31
Modified Example from Juric Text Employee Travel Status WS synchronous <receive> <invoke> Coach or first class <receive> <invoke> : <receive> American Airlines WS asynchronou price <invoke> Asynch Process for Business Travels price Delta Airlines WS asynchronou Asynchronous web service 95 -843: Service Oriented Architecture Master of Information System Management 32
Partner Links • Partner links describe links to partners. • Partners might be: (1) Services that invoke the BPEL process. (2) Services invoked by the BPEL process. (3) Services that play both roles - the BPEL process invokes the service and the service invokes a callback on the BPEL process. 95 -843: Service Oriented Architecture Master of Information System Management 33
Partner. Link. Types • Partner. Link. Types represent interactions between the parties. • We have three types of interactions in the airline example: (1) The client interacts with the BPEL process. (2) The BPEL process calls the employee status web service. (3) The BPEL process calls the two airline web services and expects callbacks from both. 95 -843: Service Oriented Architecture Master of Information System Management 34
Partner. Link. Types • Within the BPEL process WSDL, we have two roles defined for one of the links: <partner. Link. Type name="travel. LT"> <role name="travel. Service"> <port. Type name="tns: Travel. Approval. PT" /> </role> <role name="travel. Service. Customer"> <port. Type name="tns: Client. Callback. PT" /> </role> The interface of the BPEL service is implemented at the service. The interface of the client callback is implemented on the client. Client callback BPEL Process interface </partner. Link. Type> interface travel. LT 95 -843: Service Oriented Architecture Travel Link Type 35 Master of Information System Management
Partner. Link. Types • The employee status WS is synchronous so within the employee status WS WSDL we have one role defined: <partner. Link. Type name="employee. LT"> <role name="employee. Travel. Status. Service"> <port. Type name="tns: Employee. Travel. Status. PT" /> </role> </partner. Link. Type> employee. LT Employee Link Type 95 -843: Service Oriented Architecture Master of Information System Management Interface of employee status web service. 36
Partner. Link. Types • The airline web services are asynchronous and so within the airline WS WSDL’s we have two roles defined: <partner. Link. Type name="flight. LT"> <role name="airline. Service"> <port. Type name="tns: Flight. Availability. PT" /> </role> <role name="airline. Customer"> <port. Type name="tns: Flight. Callback. PT" /> </role> Callee’s </partner. Link. Type> 95 -843: Service Oriented Architecture Master of Information System Management callback interface flight. LT Flight Link Type Airline interface 37
Partner. Links Are in the BPEL (1) <partner. Links> <partner. Link name="client" partner. Link. Type="trv: travel. LT" my. Role="travel. Service" partner. Role="travel. Service. Customer"/> <partner. Link name="employee. Travel. Status" partner. Link. Type="emp: employee. LT" partner. Role="employee. Travel. Status. Service"/> <partner. Link name="American. Airlines" partner. Link. Type="aln: flight. LT" my. Role="airline. Customer" partner. Role="airline. Service"/> <partner. Link name="Delta. Airlines" partner. Link. Type="aln: flight. LT" my. Role="airline. Customer" partner. Role="airline. Service"/> </partner. Links> 95 -843: Service Oriented Architecture Master of Information System Management 38
Partner. Links Are in the BPEL(2) <partner. Links> <partner. Link name="client" partner. Link. Type="trv: travel. LT" my. Role="travel. Service" partner. Role="travel. Service. Customer"/> : : This partner link is of type travel. LT. So, two interfaces are involved. This process is the travel service part. The partner implements the client callback interface. These names are defined in the partner link type section. </partner. Links> 95 -843: Service Oriented Architecture Master of Information System Management 39
Partner. Links Are in the BPEL(3) <partner. Links> : : <partner. Link name="employee. Travel. Status" partner. Link. Type="emp: employee. LT" partner. Role="employee. Travel. Status. Service"/> : : This partner link is of type employee. LT. So, one interface is involved, that is, the interface of the employee status web service. </partner. Links> 95 -843: Service Oriented Architecture Master of Information System Management 40
Partner. Links Are in the BPEL(4) <partner. Links> : : <partner. Link name="American. Airlines" partner. Link. Type="aln: flight. LT" my. Role="airline. Customer" partner. Role="airline. Service"/> <partner. Link name="Delta. Airlines" partner. Link. Type="aln: flight. LT" my. Role="airline. Customer" partner. Role="airline. Service"/> Both of these partner links are of type flight. LT. As such, two interfaces are mentioned. The role of this process is to provide the callback (Flight. Callback. PT) and the role the partner is to provide the Flight. Availability. PT. </partner. Links> 95 -843: Service Oriented Architecture Master of Information System Management 41
Partner. Links Are in the BPEL(5) <partner. Links> <partner. Link name="client" partner. Link. Type="trv: travel. LT" my. Role="travel. Service" partner. Role="travel. Service. Customer"/> <partner. Link. Type name="travel. LT"> <role name="travel. Service"> <port. Type name="tns: Travel. Approval. PT" /> </role> <role name="travel. Service. Customer"> <port. Type name="tns: Client. Callback. PT" /> </role> The interface of the BPEL service is implemented at the service. The interface of the client callback is implemented on the client. </partner. Link. Type> 95 -843: Service Oriented Architecture Master of Information System Management 42
Partner. Links Are in the BPEL(6) <partner. Link name="employee. Travel. Status" partner. Link. Type="emp: employee. LT" partner. Role="employee. Travel. Status. Service"/> <partner. Link. Type name="employee. LT"> <role name="employee. Travel. Status. Service"> <port. Type name="tns: Employee. Travel. Status. PT" /> </role> 95 -843: Service Oriented Architecture Master of Information System Management 43
Partner. Links Are in the BPEL(7) <partner. Link name="American. Airlines" partner. Link. Type="aln: flight. LT" my. Role="airline. Customer" partner. Role="airline. Service"/> <partner. Link name="Delta. Airlines" partner. Link. Type="aln: flight. LT" my. Role="airline. Customer" partner. Role="airline. Service"/> <partner. Link. Type name="flight. LT"> <role name="airline. Service"> <port. Type name="tns: Flight. Availability. PT" /> </role> <role name="airline. Customer"> <port. Type name="tns: Flight. Callback. PT" /> </role> </partner. Link. Type> 95 -843: Service Oriented Architecture Master of Information System Management 44
Variables in BPEL <variables> <!-- input for this process --> <variable name="Travel. Request" message. Type="trv: Travel. Request. Message"/> <!-- input for the Employee Travel Status Web service --> <variable name="Employee. Travel. Status. Request" message. Type="emp: Employee. Travel. Status. Request. Message"/> <!-- output from the Employee Travel Status Web service --> <variable name="Employee. Travel. Status. Response" message. Type="emp: Employee. Travel. Status. Response. Message"/> 95 -843: Service Oriented Architecture Master of Information System Management 45
Variables (2) <!-- input for American and Delta Web services --> <variable name="Flight. Details" message. Type="aln: Flight. Ticket. Request. Message"/> <!-- output from American Airlines --> <variable name="Flight. Response. AA" message. Type="aln: Travel. Response. Message"/> <!-- output from Delta Airlines --> <variable name="Flight. Response. DA" message. Type="aln: Travel. Response. Message"/> <!-- output from BPEL process --> <variable name="Travel. Response" message. Type="aln: Travel. Response. Message"/> </variables> 95 -843: Service Oriented Architecture Master of Information System Management 46
BPEL Main Process (1) <sequence> <!-- Receive the initial request for business travel from client --> <receive partner. Link="client" port. Type="trv: Travel. Approval. PT" operation="Travel. Approval" variable="Travel. Request" create. Instance="yes" /> 95 -843: Service Oriented Architecture Master of Information System Management 47
BPEL Main Process (2) <!-- Prepare the input for the Employee Travel Status Web Service --> <assign> <copy> <from variable="Travel. Request" part="employee"/> <to variable="Employee. Travel. Status. Request" part="employee"/> </copy> </assign> 95 -843: Service Oriented Architecture Master of Information System Management 48
BPEL Main Process (3) <!-- Synchronously invoke the Employee Travel Status Web Service --> <invoke partner. Link="employee. Travel. Status" port. Type="emp: Employee. Travel. Status. PT" operation="Employee. Travel. Status" input. Variable="Employee. Travel. Status. Request" output. Variable="Employee. Travel. Status. Response" /> 95 -843: Service Oriented Architecture Master of Information System Management 49
BPEL Main Process (4) <!-- Prepare the input for the airlines. The input comes from two variables. --> <assign> <copy> <from variable="Travel. Request" part="flight. Data"/> <to variable="Flight. Details" part="flight. Data"/> </copy> <from variable="Employee. Travel. Status. Response" part="travel. Class"/> <to variable="Flight. Details" part="travel. Class"/> </copy> </assign> 95 -843: Service Oriented Architecture Master of Information System Management 50
BPEL Main Process (5) <!-- Make a concurrent invocation on both airlines. --> <flow> <sequence> <!-- Async invoke of the AA Web service and wait for the callback--> <invoke partner. Link="American. Airlines" port. Type="aln: Flight. Availability. PT" operation="Flight. Availability" input. Variable="Flight. Details" /> <receive partner. Link="American. Airlines" port. Type="aln: Flight. Callback. PT" operation="Flight. Ticket. Callback" variable="Flight. Response. AA" /> The receive operation must occur after the invoke. Hence, the sequence tag is used. </sequence> 95 -843: Service Oriented Architecture Master of Information System Management 51
BPEL Main Process (6) <sequence> <!-- Async invoke of the DA Web service and wait for the callback--> <invoke partner. Link="Delta. Airlines" port. Type="aln: Flight. Availability. PT" operation="Flight. Availability" input. Variable="Flight. Details" /> <receive partner. Link="Delta. Airlines" port. Type="aln: Flight. Callback. PT" operation="Flight. Ticket. Callback" variable="Flight. Response. DA" /> Only the flow is done in parallel. For the sequence to complete, the airline must respond. </sequence> </flow> 95 -843: Service Oriented Architecture Master of Information System Management 52
BPEL Main Process (7) <!-- The airlines have responded. Select the best offer and construct the Travel. Response --> <switch> <case condition="bpws: get. Variable. Data('Flight. Response. AA', 'confirmation. Data', '/confirmation. Data/Price') <= bpws: get. Variable. Data('Flight. Response. DA', 'confirmation. Data', '/confirmation. Data/Price')"> <!-- Select American Airlines --> <assign> <copy> <from variable="Flight. Response. AA" /> <to variable="Travel. Response" /> </copy> </assign> </case> 95 -843: Service Oriented Architecture Master of Information System Management 53
BPEL Main Process (8) <otherwise> <!-- Select Delta Airlines --> <assign> <copy> <from variable="Flight. Response. DA" /> <to variable="Travel. Response" /> </copy> </assign> </otherwise> </switch> 95 -843: Service Oriented Architecture Master of Information System Management 54
BPEL Main Process (9) <!-- Make a callback to the client --> <invoke partner. Link="client" port. Type="trv: Client. Callback. PT" operation="Client. Callback" input. Variable="Travel. Response" /> </sequence> </process> 95 -843: Service Oriented Architecture Master of Information System Management 55
Sketch of Working Process sequence receive assign invoke assign flow sequence invoke receive switch invoke information from employee assign to variable invoke service to determine flying status assign result to variable Do sequences in parallel call airline A get price for ticket call airline B get price for ticket select cheaper flight inform the employee 95 -843: Service Oriented Architecture Master of Information System Management 56
Would this work? sequence receive flow assign invoke receive switch invoke No. The previous slide had it right. Here, we have not expressed the synchronization dependencies between activities. However, BPEL provides for more complex concurrency scenarios using links. A single link is specified with a source and a target. 95 -843: Service Oriented Architecture Master of Information System Management 57
We Need To Add Links sequence receive flow assign invoke receive switch invoke assign before the invoke before the assign before the two invokes invoke before receive before the switch 95 -843: Service Oriented Architecture Master of Information System Management 58
Sources and Targets In BPEL <sequence> <receive> <flow> <assign>… <source link. Name = “A”/> </assign> <invoke>…. <target link. Name = “A” /> <source link. Name = “B” /> </invoke> <assign> <target link. Name = “B” /> <source link. Name = “C” /> <source link. Name = “D” /> </assign> 95 -843: Service Oriented Architecture Master of Information System Management Assign before invoke. Invoke before assign Assign before the two invokes. Link names are user defined and should be well chosen. 59
Sources and Targets <invoke> <target link. Name = “C”/> <source link. Name = “E”/> </invoke> <receive> <target link. Name = “E”/> <source link. Name = “G”/> </receive> <invoke> <target link. Name = “D”/> <source link. Name =“F” /> </invoke> 95 -843: Service Oriented Architecture Master of Information System Management 60
Sources and Targets <receive> <target link. Name = “F”/> <source link. Name = “H”/> </receive> <switch> <target link. Name = “G”/> <target link. Name = “H”/> </switch> </flow> <invoke> 95 -843: Service Oriented Architecture Master of Information System Management 61
Concurrency and Links • The flow tag provides the ability to express synchronization dependencies between activities. • In other words, we can specify what happens and when. • Link definitions are placed within the flow activity. For example, <flow> <links> <link name = “A”/> <link name = “B” /> </links> : • Every link must be associated with exactly one source and target. • A link’s target activity may only be performed after the source activity has completed. • Transition conditions may be added for additional confusion. 95 -843: Service Oriented Architecture Master of Information System Management 62
- Slides: 62