CS 290C: Formal Models for Web Software Lectures 14:

advertisement

CS 290C: Formal Models for Web Software

Lectures 14: Formal Modeling and Analysis of

Orchestration and Choreography Specifications

Instructor: Tevfik Bultan

Formal Modeling and Verification of Web services

• There has been a lot of work on formal modeling and verification of web services

• These efforts mostly focused on analyzing composite services specified using orchestration and choreography languages

• For example, there has been work on formally modeling

BPEL and WS-CDL specifications as state machines and then automatically verifying their properties using model checking

• I will give an overview of some work in this area

Formal Modeling and Analysis of Orchestration

• Basic Idea:

– Automatically convert BPEL specifications to state machine models

– Automatically analyze state machine models using a verification tool

• This approach has been implemented by developing tools that translate BPEL specifications to Promela

BPEL to State Machine Translation

Each atomic BPEL activities can be translated to a state machine

 single entry, single exit, and may have several exception exits

 Transitions have guards (extended state machine)

<assign … >

<copy>

<from = “yes” />

<to var = “aprvInfo” part = “accept”

</copy>

</assign>

<receive … operation = “approve” variable = “request”

/>

[apprvInfo/accept := ‘yes’]

[request := approve_In]

? approve_In

BPEL to State Machine Translation

<scope>

<invoke … operation="approve”, invar="request “ , outvar="aprvInfo ” />

<catch … faultname="loanfault “ >

< ... handler1 ... />

</catch>

</scope>

[approve_In := request]

! approve_In loanfault

? loanfault

? approve_Out handler1

[aprvInfo := approve_Out] 

BPEL to State Machine Translation

• Control flow constructs can be handled by composing state machines

<sequence …/>

<… act1…/>

<… act2…/>

</sequence

…/> fault1 act1

 fault2 act2

<flow …/>

< … act1 …>

< … act2 … >

</flow …/> act1 product act2

BPEL to State Machine Translation

• We can translate BPEL specifications to a state machine representation by recursively applying translation rules like we describe above

• However, BPEL specifications do not only have control flow constructs

– they can also contain branch conditions and assignment statements expressed using Xpath

– So we have to use an extended state machine representation which keeps the branch conditions, assignments, etc.

Extended State Machines

• Use an extended state machine model where the transitions can gave guards and updates

– Guards and updates are on XML messages and use

MSL and XPath

• MSL for declaring message types

– MSL (Model Schema Language) is a compact formal model language which captures core features of XML

Schema

• XPath expressions for guards

– XPath is a language for writing expressions (queries) that navigate through XML trees and return a set of answer nodes

Translating Extended State Machines to Promela

• Translate the extended state machine model to Promela and use the SPIN model checker to verify the properties of the orchestration

• SPIN is a finite state model checker

– Need to restrict XML message contents to finite domains

• Translating extended state machine models to Promela

– First, translate MSL type declarations to Promela type declarations

– Then, translate XPath expressions to Promela code

Mapping MSL types to Promela

• Basic types

– integer and boolean types are mapped to Promela basic types int and bool

– We only allow constant string values and strings are mapped to enumerated type ( mtype ) in Promela

• Other type constructors are handled using

– structured types (declared using typedef ) in Promela

– or arrays

Mapping MSL type constructors to Promela

• t [ g ] is translated to a typedef declaration

• g { m , n } is translated to an array declaration

• g

1

, g

2 is translated to a sequence of type declarations

• g

1

| g

2 is translated to a sequence of type declarations and an enumerated variable which is used to record which type is chosen

• g

1

& g

2 unordered type sequence can cause state-space explosion, so it is better to convert them to an ordered sequence after choosing a fixed ordering

Example

Register[ investorID[string] , requestList[ stockID[int]{1,3}

] , payment[ creditCardNum[int] | accountNum[int]

]

] typedef t1_investorID{ mtype stringvalue;} typedef t2_stockID{int intvalue;} typedef t3_requestList{ t2_stockID stockID [3]; int stockID_occ;

} typedef t4_accountNum{int intvalue;} typedef t5_creditCard{int intvalue;} mtype {m_accountNum, m_creditCard} typedef t6_payment{ t4_accountNum accountNum; t5_creditCard creditCard; mtype choice;

} typedef Register{ t1_investorID investorID; t3_requestList requestList; t6_payment payment;

}

XPath to Promela

• Generate code that evaluates the XPath expression

• Traverse the XPath expression from left to right

– Code generated in each step is inserted into the BLANK spaces left in the code from the previous step

– A tree representation of the MSL type is used to keep track of the context of the generated code

• Uses two data structures

– Type tree shows the structure of the corresponding MSL type

– Abstract statements which are mapped to Promela code

$request//stockID=$register//stockID[int()>5][position()=last()]

/* result of the XPath expression */ bool bResult = false;

/* results of the predicates 1, 2, and 1 resp. */ bool bRes1, bRes2, bRes3;

/* index, position(), last(), index, position() */ int i1, i2, i3, i4, i5; i2=1;

/* pre-calculate the value of last(), store in i3 */ i4=0; i5=1; i3=0; do

:: i4 < v_register.requestList.stockID_occ

->

/* compute first predicate */ bRes3 = false; if

:: v_register.requestList.stockID[i4].intvalue>5

-> bRes3 = true

:: else -> skip fi; if

:: bRes3 -> i5++; i3++;

:: else -> skip fi; i4++;

:: else -> break; od;

$request//stockID=$register//stockID[int()>5][position()=last()] i1=0; do

:: i1 < v_register.requestList.stockID_occ -> bRes1 = false; if

:: v_register.requestList.stockID[i1].intvalue>5 -> bRes1 = true

:: else -> skip fi; if

:: bRes1 -> bRes2 = false; if

:: (i2 == i3) -> bRes2 = true;

:: else -> skip fi; if

:: bRes2 -> if

:: (v_request.stockID.intvalue == v_register.requestList.stockID[i1].intvalue)

-> bResult = true;

:: else -> skip fi

:: else -> skip fi; i2++; i1++;

:: else -> break; od;

:: else -> skip fi;

Model Checking Using Promela

• Can analyze the SAS example from the previous lecture

– 3 peers: Investor, Broker, ResearchDept.

• An error was found in the specification using Spin

– Investor  Broker: a registerList of stockIDs

– Broker  ResearchDept.:

• relay request (1 stockID per request)

• find the stockID in the latest request, send its subsequent stockID in registerList

– Repeating stockID will cause error.

– Only discoverable by analysis of XPath expressions

Orchestration Verification

• What we have discussed was an automated verification approach for orchestrations written in BPEL

• The basic idea is to

– represent BPEL specifications as extended sate machines

– generate Promela specifications for these extended state machines (by bounding the data)

– and verify their properties using the Spin model checker

• The question is can we use a similar approach for services which involve interaction among multiple processes (for example an orchestrated service interacting with another orchestrated service)

• Let ’ s first recall the orchestration vs. choreography issue

Composing Services

Two dimensions:

1. Define an executable process that interacts with existing services and executes them in a particular order and combines the results to achieve a new goal

• Orchestration : From atomic services to stateful services

2. Specify how the individual services should interact with each other. Find or construct individual services that follow this interaction specification

• Choreography : Global specification of interactions among services

Orchestration vs. Choreography

• Orchestration : Central control of the behavior of a distributed system

• Like a conductor conducting an orchestra

• Conductor is in charge during the performance

• Orchestration specifies an executable process, identifying when and how that process should interact with other services

– Orchestration is used to specify the control flow of a composite web service (as opposed to an atomic web service that does not interact with any other service)

Orchestration vs. Choreography

• Choreography : Specification of the behavior of a distributed system without centralized control

• Choreographer specifies the behavior of the dancing team

• Choreographer is not present during the execution

• A choreography specifies how the services should interact

– It specifies the legal sequences of messages exchanged among individual services (peers)

– It is not necessarily executable

• A choreography can be realized by writing an orchestration for each peer involved in the choreography

– Choreography as global behavior specification

– Orchestration as local behavior specification that realizes the global specification

Choreography with WS-CDL

• Web Services Choreography Description Language (WS-

CDL)

• WS-CDL specifications describe `` peer-to-peer collaborations of Web Services participants by defining, from a global viewpoint, their common and complementary observable behavior; where ordered message exchanges result in accomplishing a common business goal .''

• A WS-CDL specification describes the interaction ordering among a set of peers using basic and structured activities

– Basic activities:

INTERACTION, PERFORM, ASSIGN, SILENT ACTION, NO ACTION

– Structured activities:

SEQUENCE, PARALLEL, CHOICE, PICK, FLOW, SCOPE, COMPENSATE

Choreography Specifications & State Machines

• Choreography specifications can also be translated to state machine models like the orchestration specifications

• As we did for BPEL specifications, given a WS-CDL specification

– map the basic actions of a choreography (such as an assignment or message exchange) to transitions of basic state machines

– map control flow constructs to various compositions of state machines

SAS Choreography Model

• State machine representation of the SAS choreography model register

1

3 reject

2 request accept

5

6 report cancel

7 ack

8 request report

9 terminate

4 12 terminate bill

11 cancel

10 ack

Another Issue: Asynchronous Messages

• Remember that one of the goals in web services is to achieve loose coupling among services that interact with each other

• One way to achieve this message-based interactions and asynchronous messaging

• Asynchronous messaging:

– Sender does not have to wait for the receiver

• Message is inserted to a message queue

• Messaging platform guarantees the delivery of the message

Asynchronous Messages

• Why support asynchronous messaging?

– Otherwise the sender has to block and wait for the receiver

– Sender may not need any data to be returned

– If the sender needs some data to be returned, it should wait when it needs to use that data

– Asynchronous messaging can alleviate the latency of message transmission through the Internet

– Asynchronous messaging can prevent sender from blocking if the receiver service is temporarily unavailable

• Rather then creating a thread to handle the send, use asynchronous messaging

Choreography Analysis

• So, we can assume the following formal model

– We have a choreography model which corresponds to a state machine and characterizes the ordering of interactions (message-exchanges) among different services

– We can also assume that each service participating in a choreography is also specified as a state machine model

(maybe extracted from an orchestration specification)

– We also assume that different services participating in the choreography are interacting with asynchronous messages

• Given this framework, some interesting analysis and verification problems arise

Choreography Analysis

• I will explain issues about choreography analysis using an example which describes how two professors and a grad student go to lunch at UCSB

Going to Lunch at UCSB

• Before Xiang graduated from UCSB, Xiang, Jianwen and I were using the following protocol for going to lunch:

– Sometime around noon one of us would call another one by phone and tell him where and when we would meet for lunch.

– The receiver of this first call would call the remaining peer and pass the information.

• Let ’ s call this protocol the First Caller Decides (FCD) protocol.

• At the time we did not have answering machines or voicemail!

FCD Protocol Scenarios

• Possible scenario

1. Tevfik calls Jianwen with the decision of where and when to eat

2. Jianwen calls Xiang and passes the information

• Another scenario

1. Jianwen calls Tevfik with the decision of where and when to eat

2. Tevfik calls Xiang and passes the information

FCD Protocol Scenarios

• Yet another scenario

1. Tevfik calls Xiang with the decision of where and when to eat

• Maybe Jianwen also calls Xiang at the same time with a different decision. But the phone is busy.

• Jianwen keeps calling. But Xiang is not going to answer because according to the protocol the next thing Xiang has to do is call Jianwen.

2. Xiang calls Jianwen and passes the information

FCD Protocol: Tevfik ’ s Behavior

Let ’ s look at all possible behaviors of Tevfik based on the FCD protocol

Tevfik calls Jianwen with the lunch decision

Tevfik is hungry

Tevfik calls Xiang with the lunch decision

Tevfik receives a call from Xiang telling him the lunch decision that

Tevfik has to pass to

Jianwen

Tevfik receives a call from

Jianwen passing him the lunch decision

Tevfik receives a call from

Xiang passing him the lunch decision

FCD Protocol: Tevfik ’ s Behavior

Message Labels:

!

send

?

receive

T->J(D)

Tevfik calls Jianwen with the lunch decision

J->X(P)

Jianwen calls Xiang to pass the decision

!T->J(D) ?J->T(P)

!T->X(D)

?J->T(D)

?X->T(P)

?X->T(D)

!T->X(P) !T->J(P)

State machines for the FCD Protocol

Tevfik

!T->J(D) ?J->T(P)

!T->J(D)

?J->T(D)

?X->T(P)

?X->T(D)

!T->X(P) !T->J(P)

Xiang

!X->J(D)

?J->X(P)

!X->T(D) ?T->X(P)

?J->X(D) ?T->X(D)

!X->T(P) !X->J(P)

Jianwen

!J->T(D) ?T->J(P)

!J->X(D)

?T->J(D)

?X->J(P)

?X->J(D)

!J->X(P) !J->T(P)

• Three state machines characterizing the behaviors of

Tevfik, Xiang and Jianwen according to the FCD protocol

FCD Protocol Has Voicemail Problems

• When the university installed a voicemail system FCD protocol started causing problems

– We were showing up at different restaurants at different times!

Example Problem Scenario

• Tevfik calls Xiang with the lunch decision

• Jianwen also calls Xiang with the lunch decision

– The phone is busy (Xiang is talking to Tevfik) so Jianwen leaves a message

• Xiang calls Jianwen passing the lunch decision

– Jianwen does not answer (he already left for lunch) so

Xiang leaves a message

• Jianwen shows up at a different restaurant!

• Message sequence is: T->X(D) J->X(D) X->J(P)

– The messages J->X(D) and X->J(P) are never consumed

• This scenario is not possible without voicemail!

A Different Lunch Protocol

• To fix this problem, Jianwen suggested that we change our lunch protocol as follows:

– As the most senior researcher among us Jianwen would make the first call to either Xiang or Tevfik and tell when and where we would meet for lunch.

– Then, the receiver of this call would pass the information to the other peer.

• Let ’ s call this protocol the Jianwen Decides (JD) protocol

State machines for the JD Protocol

Tevfik

?J->T(D)

?X->T(P)

!J->T(D)

!T->X(P)

Jianwen Xiang

?T->X(P)

!J->X(D)

?J->X(D)

!X->T(P)

• JD protocol works fine with voicemail!

Conversations

• The FCD and JD protocols specify a set of conversations

– A conversation is the sequence of messages generated during an execution of the protocol

• We can specify the set of conversations without showing how the peers implement them

– we call such a specification a conversation protocol

FCD and JD Conversation Protocols

FCD Protocol

T->X(D)

T->J(D)

J->X(P)

J->X(D)

X->T(D) X->J(D)

T->J(P)

J->T(P)

J->T(D)

X->T(P)

X->J(P) T->X(P)

Conversation set:

{ T->X(D) X->J(P) ,

T->J(D) J->X(P) ,

X->T(D) T->J(P) ,

X->J(D) J->T(P) ,

J->T(D) T->X(P) ,

J->X(D)X->T(P) }

JD Protocol

J->T(D)

T->X(P)

J->X(D)

X->T(P)

Conversation set:

{ J->T(D) T->X(P) ,

J->X(D) X->T(P) }

Observations & Questions

• The implementation of the FCD protocol behaves differently with synchronous and asynchronous communication whereas the implementation of the JD protocol behaves the same.

– Can we find a way to identify such implementations?

• The implementation of the FCD protocol does not obey the

FCD protocol if asynchronous communication is used whereas the implementation of the JD protocol obeys the

JD protocol even if asynchronous communication used.

– Given a conversation protocol can we figure out if there is an implementation which generates the same conversation set?

Conversations, Choreography, Orchestration

• A conversation protocol is a choreography specification

– A conversation set corresponds to a choreography

– A conversation set can be specified using a choreography language such as WS-CDL

– One can translate WS-CDL specifications to conversation protocols

• Peer state machines are orchestrations

– A peer state machine can be specified using an orchestration language such as WS-BPEL

– One can translate WS-BPEL specifications to peer state machines

A Model for Composite Web Services

• A composite web service consists of

– a finite set of peers

• Lunch example: T, X, J

– and a finite set of messages

• Lunch example (JD protocol) :

J->T(D) , T->X(P) , J->X(D) , X->T(P)

T->X(P)

Peer T Peer X

X->T(P)

J->T(D) J->X(D)

Peer J

Communication Model

• We assume that the messages among the peers are exchanged using reliable and asynchronous messaging

– FIFO and unbounded message queues

Peer J J->T(D) J->T(D) Peer T

• This model is similar to existing messaging platforms such as

– JMS (Java Message Service)

– Java API for XML messaging (JAXM)

– MSMQ (Microsoft Message Queuing Service)

Conversations

• Record the messages in the order they are sent

T->X(P)

Peer T Peer X

Generated conversation:

J->T(D) T->X(P)

Peer J

• A conversation is a sequence of messages generated during an execution

Properties of Conversations

• The notion of conversation enables us to reason about temporal properties of the composite web services

• LTL framework extends naturally to conversations

– LTL temporal operators

X (neXt), U (Until), G (Globally), F (Future)

– Atomic properties

Predicates on message classes (or contents)

Example: G ( payment 

F receipt )

• Model checking problem : Given an LTL property, does the conversation set satisfy the property?

Bottom-Up vs. Top-Down

Bottom-up approach

• Specify the behavior of each peer

– For example using an orchestration language such as

WS-BPEL

• The global communication behavior (conversation set) is implicitly defined based on the composed behavior of the peers

• Global communication behavior is hard to understand and analyze

Top-down approach

• Specify the global communication behavior (conversation set) explicitly as a protocol

– For example using a choreography language such as

WS-CDL

• Ensure that the conversations generated by the peers obey the protocol

Top-Down vs. Bottom-Up

Conversation

Protocol

J->T(D)

T->X(P)

J->X(D)

?

LTL property

GF( T->X(P)  X->T(P) )

X->T(P)

Peer T

?J->T(D)

?X->T(P)

!T->X(P)

!J->T(D)

Peer J

!J->X(D)

Peer X

?J->X(D)

?T->X(P)

Input

Queue

!X->T(P)

Virtual Watcher

...

?

GF( T->X(P)

X->T(P) )

LTL property

Conversation Protocols

• Conversation Protocol:

– An automaton that accepts the desired conversation set

• A conversation protocol is a contract agreed by all peers

– Each peer must act according to the protocol

• For reactive protocols with infinite message sequences use:

– Büchi automata which accept infinite strings

• For specifying message contents, use:

– Guarded automata

– Guards are constraints on the message contents

Synthesize Peer Implementations

• Conversation protocol specifies the global communication behavior

– How do we implement the peers?

• How do we obtain the contracts that peers have to obey from the global contract specified by the conversation protocol?

• Project the global protocol to each peer

– By dropping unrelated messages for each peer

Question

Conversations specified by the conversation protocol

?

Conversations generated by the projected services

If this equality holds the conversation protocol is realizable

• The JD protocol is realizable

• The FCD protocol is not realizable

Are there conditions which ensure the equivalence?

Realizability Problem

• Not all conversation protocols are realizable!

A

B: m1

!m1

?m1

!m2

?m2

C

D: m2

Conversation protocol

Peer A Peer B Peer C

Projection of the conversation protocol to the peers

Peer D

Conversation “ m2 m1 ” will also be generated by all peer implementations which follow the protocol

Another Unrealizable Protocol

A m3 m1 m2

C

B m2 A m1 B

B

B

A: m2

A, C

A

B: m1 m3

C

B

A: m2

A

B: m1

A

C: m3 m2 m1 m3

Watcher

Generated conversation: m2 m1 m3

Three Unrealizable Protocols

• Following conversation protocols are unrealizable

A

B: m1

C

D: m2

A

B: m1

C

A: m2

B

A: m2

A

B: m1

A

B: m1

B

A: m2

A

C: m3

Bottom-Up Approach

• We know that analyzing conversations of composite web services is difficult due to asynchronous communication

– Model checking for conversation properties is undecidable even for finite state peers

• The question is:

– Can we identify the composite web services where asynchronous communication does not create a problem?

• We call such compositions synchronizable

• The implementation of the JD protocol is synchronizable

• The implementation of the FCD protocol is not synchronizable

Three Examples, Example 1

!e

?a

1

!r

1

!r

2

?a

2 r

1

, r

2 e

!a

?r

1

1

!a

2

?r

2

?e

a

1

, a

2 requester server

• Conversation set is regular: ( r

1 a

1

| r

2 a

2

)* e

• During all executions the message queues are bounded

Example 2

?a

1

!r

1

!e

?a

2 r

1

, r

2 e

!a

?r

1

1

!a

2

?r

2

!r

2 a

1

, a

2

?e

server requester

• Conversation set is not regular

• Queues are not bounded

Example 3

!r

1

?a

!e

!r

2

!r

r

1

, r

2 e a

1

, a

2

?r

1

?r

!a

?e

?r

2 requester

• Conversation set is regular: ( r

1

• Queues are not bounded

| r

2

| ra )* e server

State Spaces of the Three Examples

1600

1400

1200

1000

800

600

400

200

0

1 3 5 7 9

11 13 queue length

Example 1

Example 2

Example 3

• Verification of Examples 2 and 3 are difficult even if we bound the queue length

• How can we distinguish Examples 1 and 3 (with regular conversation sets) from 2?

– Synchronizability Analysis

Synchronizability Analysis

• A composite web service is synchronizable if its conversation set does not change

– when asynchronous communication is replaced with synchronous communication

• If a composite web service is synchronizable we can check the properties about its conversations using synchronous communication semantics

– For finite state peers this is a finite state model checking problem

Realizability and Synchronizability Checking

• It turns out we can automatically check these conditions

• Synchronizability can be checked by comparing the behavior of synchronously communicating system with the system communicating with 1-bounded buffers

– If synchronous communication and 1-bounded communication give the same behaviors then the system is sycnrhonizable

• Realizability can be checked by using synchronizability

– A conversation protocol is realizable if its projection is synchronizable and all messages are eventually received

Implementation and Results

• Implemented using CADP toolbox

– Automatically generate a LOTOS specification for the conversation protocol

– Generate determinized projections (in LOTOS)

– Check equivalence of the 1-bounded asynchronous system and the conversation protocol

• Checked realizability of

– 9 web service choreography specifications

• 8 are realizable

– 9 collaboration diagrams

• 8 are realizable

– 86 Singularity channel contracts

• 84 are realizable

• Realizability check takes about 14 seconds on average

Download