contract-based discovery and adaptation of web services

65
Contract-based Discovery and Adaptation of Web Services Luca Padovani Jointly with Samuele Carpineti, Giuseppe Castagna, Nils Gesbert, Cosimo Laneve 9th International School on Formal Methods for the Design of Computer, Communication and Software Systems: Web Services Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 1 / 65

Upload: others

Post on 03-Feb-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Contract-based Discovery and Adaptation of Web Services

Contract-based Discovery and Adaptationof Web Services

Luca Padovani

Jointly withSamuele Carpineti, Giuseppe Castagna, Nils Gesbert,

Cosimo Laneve

9th International School on Formal Methods for the Design ofComputer, Communication and Software Systems: Web Services

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 1 / 65

Page 2: Contract-based Discovery and Adaptation of Web Services

Contracts for Web services

We’ve got. . .

• behavioral descriptions of Web services (wsdl, wscl, ws-bpel, putyour favorite technology here)

• repositories of Web services descriptions (uddi)

We’d like to. . .

• look for Web services with a given behavior

• see if it’s safe to replace a service with another one

• if not, see whether we can adapt one service to safely replaceanother

We’re gonna use. . .

• contracts = abstractions of Web services’ behavior

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 2 / 65

Page 3: Contract-based Discovery and Adaptation of Web Services

Finding Web services by contract

Compliance = client’s satisfaction

ρ a σ

Running a query with compliance

Q(ρ) = {σ | ρ a σ}

Running a query with duality ρ⊥ and subcontract σ � τ

Q(ρ) = {σ | ρ⊥ � σ}

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 3 / 65

Page 4: Contract-based Discovery and Adaptation of Web Services

The quest for �

Desired properties of �• reduction of nondeterminism (a⊕ b � a)

• extension of functionalities (a � a+ b)

• some permutation of messages (a.c � c.a)

The problem

• reduction alone is too strict

• extension is unsafe

• extension;reduction is not transitive

• permutation is not allowed

The solution

• use (simple) orchestrators

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 4 / 65

Page 5: Contract-based Discovery and Adaptation of Web Services

Summary

1 contracts

2 simple orchestrators

3 simple orchestrators with buffers

4 duality

5 recursive behaviors

6 orchestrator synthesis

7 related and ongoing work

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 5 / 65

Page 6: Contract-based Discovery and Adaptation of Web Services

Oh no! More ws-bpel!

<process><sequence><receive operation="Order" variable="Request"/>

<flow><invoke operation="Deposit" inputVariable="Request" outputVariable="Deposit"/><invoke operation="Charge" inputVariable="Request" outputVariable="Charge"/>

</flow>

<switch><case condition="getVariableData(Deposit) == true && getVariableData(Charge) == true)"><invoke operation="Ship" inputVariable="Request"/><reply operation="Order" value="OK"/>

</case>

<case condition="getVariableData(Charge) == true)"><invoke operation="Refund" inputVariable="Request"/><reply operation="Order" value="NO"/>

</case>

<otherwise><reply operation="Order" value="NO"/>

</otherwise></switch>

</sequence></process>

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 6 / 65

Page 7: Contract-based Discovery and Adaptation of Web Services

What’s in a contract

Actions

O OrderD DepositC ChargeS ShipR Refund

Traces

{ODCSO,OCDSO,ODCRO,OCDRO,ODCO,OCDO}

Branching points

• OD . . . and OC . . . is an external choice

• . . .SO, . . .RO, and . . .O is an internal choice

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 7 / 65

Page 8: Contract-based Discovery and Adaptation of Web Services

Basic theory of contracts

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 8 / 65

Page 9: Contract-based Discovery and Adaptation of Web Services

Contracts

Syntax

σ ::= contract0 (null)

| α.σ (action prefix)| σ + σ (external choice)| σ ⊕ σ (internal choice)

α ::= actiona (input)

| a (output)

Example

O.(D.C.D.C.(S.O⊕ R.O⊕ O)+ C.D.D.C.(S.O⊕ R.O⊕ O))

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 9 / 65

Page 10: Contract-based Discovery and Adaptation of Web Services

Operational semantics

α.σα-→ σ σ ⊕ τ -→ σ

σα-→ σ ′

σ + τ α-→ σ ′

σ -→ σ ′

σ + τ -→ σ ′ + τ

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 10 / 65

Page 11: Contract-based Discovery and Adaptation of Web Services

Compliance, formally

Systems

ρ ‖ σ

System transitions

ρ -→ ρ′

ρ ‖ σ -→ ρ′ ‖ σ

σ -→ σ ′

ρ ‖ σ -→ ρ ‖ σ ′ρ

α-→ ρ′ σ

α-→ σ ′

ρ ‖ σ -→ ρ′ ‖ σ ′

Compliance

ρ a σ def⇐⇒ ρ ‖ σ =⇒ ρ′ ‖ σ ′ X-→ implies ρ′ e-→

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 11 / 65

Page 12: Contract-based Discovery and Adaptation of Web Services

Compliance, examples

a.e a ? a ,

a.e⊕ b.e a ? a+ b ,

e a ? σ ,

a.e⊕ b.e a ? a⊕ b /

a.e a ? a⊕ 0 /

0 a ? σ /

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 12 / 65

Page 13: Contract-based Discovery and Adaptation of Web Services

Subcontract, formally

Set-theoretic interpretation of contracts

Jσ Ks def= {ρ | ρ a σ}

Subcontract

σ v τ def⇐⇒ Jσ Ks ⊆ JτKs

' = v∩w

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 13 / 65

Page 14: Contract-based Discovery and Adaptation of Web Services

Subcontract, (counter)examples

a.e a+ b 6v a⊕ b

a.e a 6v 0

e+ a 0 6v a

Reduction of nondeterminism

σ ⊕ τ v σ

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 14 / 65

Page 15: Contract-based Discovery and Adaptation of Web Services

Properties of strong subcontract

Internal choice = intersection

Jσ ⊕ τKs = Jσ Ks ∩ JτKs

External choice 6= union

• there are clients in Ja+ bKs that are not in JaKs ∪ JbKs:

a.e⊕ b.e ∈ Ja+ bKs a.e⊕ b.e 6∈ JaKs a.e⊕ b.e 6∈ JbKs

• sometimes + is ⊕ in disguise:

α.σ +α.τ ' α.(σ ⊕ τ)

• interferences:

a.e+ b ∈ JaKs a.e+ b 6∈ Ja+ bKs

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 15 / 65

Page 16: Contract-based Discovery and Adaptation of Web Services

Properties of strong subcontract

Proposition

v is a precongruence

σ v τ ⇒

α.σ v α.τσ ⊕ σ ′ v τ ⊕ σ ′

σ + σ ′ v τ + σ ′

+ nice axiomatization

+ can be used for safe replacement of parts of services

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 16 / 65

Page 17: Contract-based Discovery and Adaptation of Web Services

Strong subcontract: axioms

(e1) σ + σ = σ(e2) σ + τ = τ + σ(e3) σ + (σ ′ + σ ′′) = (σ + σ ′)+ σ ′′(e4) σ + 0 = σ

(i1) σ ⊕ σ = σ(i2) σ ⊕ τ = τ ⊕ σ(i3) σ ⊕ (σ ′ ⊕ σ ′′) = (σ ⊕ σ ′)⊕ σ ′′

(d1) σ + (σ ′ ⊕ σ ′′) = (σ + σ ′)⊕ (σ + σ ′′)(d2) σ ⊕ (σ ′ + σ ′′) = (σ ⊕ σ ′)+ (σ ⊕ σ ′′)(d3) α.σ +α.τ = α.(σ ⊕ τ)(d4) α.σ ⊕α.τ = α.(σ ⊕ τ)

(red) σ ⊕ τ ≤ σ

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 17 / 65

Page 18: Contract-based Discovery and Adaptation of Web Services

Orchestrators

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 18 / 65

Page 19: Contract-based Discovery and Adaptation of Web Services

Limitations of v

v does not support extensions. . .

a 6v a+ b

. . . because extra actions may cause interferences

a.e+ b a a a.e+ b 6a a+ b

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 19 / 65

Page 20: Contract-based Discovery and Adaptation of Web Services

Why not all failures are equal

Failure due to client nondeterminism

a.e⊕ b.e ‖ a -→ b.e ‖ a

Failure due to service nondeterminism

a.e ‖ a⊕ b -→ a.e ‖ a

Failure due to “system” nondeterminism

a.e+ b.c.e ‖ a+ b.d -→ c.e ‖ d

a.e+ b.c.e ‖ a+ b.d -→ e ‖ 0

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 20 / 65

Page 21: Contract-based Discovery and Adaptation of Web Services

Idea: orchestrated interaction

client n orchestrator n service

a → 〈a,a〉 → a

a ← 〈a,a〉 ← a

α α

α 〈α,α〉

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 21 / 65

Page 22: Contract-based Discovery and Adaptation of Web Services

Synchronous orchestrators

f ::= orchestrator0 (null)

| µ.f (action prefix)| f ∨ f (disjunction)

µ ::= orchestration action〈a,a〉 (input/output)

| 〈a,a〉 (output/input)

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 22 / 65

Page 23: Contract-based Discovery and Adaptation of Web Services

Orchestrator semantics

Orchestrator transitions

µ.fµ-→ f

fµ-→ f ′

f ∨ gµ-→ f ′

Trace semantics for orchestrators

Jf K def= {µ1 · · ·µn | ∃g : fµ1-→ ·· · µn-→ g}

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 23 / 65

Page 24: Contract-based Discovery and Adaptation of Web Services

Orchestrated compliance, formally

Orchestrated systems

ρ ‖f σ

Orchestrated system transitions

ρ -→ ρ′

ρ ‖f σ -→ ρ′ ‖f σ

σ -→ σ ′

ρ ‖f σ -→ ρ ‖f σ ′

ρα-→ ρ′ f

〈α,α〉-→ f ′ σ

α-→ σ ′

ρ ‖f σ -→ ρ′ ‖f ′ σ ′

Weak compliance

f : ρ a | σdef⇐⇒ ρ ‖f σ =⇒ ρ′ ‖f ′ σ ′ X-→ implies ρ′ e

-→

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 24 / 65

Page 25: Contract-based Discovery and Adaptation of Web Services

Weak compliance, examples

〈a,a〉 : a.e a | ? a+ b ,

〈a,a〉 ∨ 〈b,b〉 : a.e a | ? a+ b ,

〈a,a〉 ∨ 〈b,b〉 : a.e⊕ b.e a | ? a+ b ,

0 : e+ a a | ? a ,

f : a.e⊕ b.e a | ? a⊕ b /

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 25 / 65

Page 26: Contract-based Discovery and Adaptation of Web Services

Weak subcontract, formally

Set-theoretic interpretation of contracts

Jσ Kw def= {ρ | ∃f : f : ρ a | σ}

Weak subcontract

σ � τ def⇐⇒ Jσ Ks ⊆ JτKw

A few doubts. . .

• is � the subcontract relation we’re looking for?

• is � a preorder?

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 26 / 65

Page 27: Contract-based Discovery and Adaptation of Web Services

Universal orchestrators

σ � τ ⇐⇒ for every ρ,ρ a σ implies f : ρ a | τ for some f

Universal orchestrator

f : σ � τ def⇐⇒ for every ρ,ρ a σ implies f : ρ a | τ

f is the universal orchestrator for σ � τ

Proposition (existence of universal orchestrator)

σ � τ if and only if f : σ � τ for some orchestrator f

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 27 / 65

Page 28: Contract-based Discovery and Adaptation of Web Services

Orchestrators as morphisms

Orchestrator application f (σ)

f σ f (σ)〈a,a〉 ∨ 〈b,b〉 a+ b a+ b〈a,a〉 ∨ 〈b,b〉 a⊕ b a⊕ b

〈a,a〉 a+ b a〈a,a〉 a⊕ b a⊕ 0

0 σ 0

Theorem

f : ρ a | σ if and only if ρ a f (σ)

Corollary

f : σ � τ if and only if σ v f (τ)

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 28 / 65

Page 29: Contract-based Discovery and Adaptation of Web Services

Weak subcontract, examples

Reduction of nondeterminism (� embeds v)

〈a,a〉 ∨ 〈b,b〉 : a⊕ b � am

a⊕ b v (〈a,a〉 ∨ 〈b,b〉)(a) = a

Width extension

〈a,a〉 : a � a+ bm

a v 〈a,a〉(a+ b) = a

Depth extension

0 : 0 � σm

0 v 0(σ) = 0

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 29 / 65

Page 30: Contract-based Discovery and Adaptation of Web Services

On transitivity of �Is � transitive?

f : σ � σ ′ g : σ ′ � τ ?=⇒ h : σ � τ

〈a,a〉 ∨ 〈b,b〉.〈c, c〉 : a⊕ b.c � a〈a,a〉 : a � a+ b.d

??? : a⊕ b.c � a+ b.d

Proposition (Orchestrator application is monotone)

σ v τ implies f (σ) v f (τ)

σ v f (σ ′) σ ′ v g(τ) =⇒ σ v f (g(τ))

� is transitive if f ◦ g is an orchestrator

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 30 / 65

Page 31: Contract-based Discovery and Adaptation of Web Services

Orchestrator composition and transitivity of �

Orchestrator composition

f ∧ g

• f ∧ g permits the traces permitted by f and by g

• f ∧ g forbids the traces forbidden by either f or by g

Jf ∧ gK def= Jf K∩ JgK

Proposition

f (g(σ)) ' (f ∧ g)(σ)

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 31 / 65

Page 32: Contract-based Discovery and Adaptation of Web Services

Towards a deduction system for �Problem: � is not a precongruence w.r.t. +

0 � aa.b � a.ba.b + 0 6� a.b + a ' a.(b ⊕ 0)

Proposition (distributivity of orchestration application)

1 f (σ)+ f (τ) ' f (σ + τ)2 f (σ)⊕ f (τ) ' f (σ ⊕ τ)

Corollary

f : σ1 � τ1 and f : σ2 � τ2 implies f : σ1 + σ2 � τ1 + τ2

• precongruence is granted if the orchestrator is oblivious of theparticular branch taken

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 32 / 65

Page 33: Contract-based Discovery and Adaptation of Web Services

Deduction system for �

(red) I(σ) : σ ⊕ τ ≤ σ

(width)JI(σ)∧ I(τ)K = {ε}I(σ) : σ ≤ σ + τ

(trans)f : σ ≤ σ ′ g : σ ′ ≤ σ ′′

f ∧ g : σ ≤ σ ′′

(prefix)f : σ ≤ τ

〈α,α〉.f : α.σ ≤ α.τ

(int)f : σ ≤ σ ′ f : τ ≤ τ′

f : σ ⊕ τ ≤ σ ′ ⊕ τ′

(ext)f : σ ≤ σ ′ f : τ ≤ τ′

f : σ + τ ≤ σ ′ + τ′

The deduction system is sound and complete

f : σ � τ ⇐⇒ f : σ ≤ τ

• completeness regards orchestrators too

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 33 / 65

Page 34: Contract-based Discovery and Adaptation of Web Services

Interpretations of orchestrators

As mediatorsρ ‖f σ

As morphisms/behavioral coercions

f : σ � τ ⇐⇒ σ v f (τ) f : τ → σ

As assumptions on the environment

〈a,a〉 : a � a+ b

• it is safe to replace a with a+ b if nobody ever tries to perform b

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 34 / 65

Page 35: Contract-based Discovery and Adaptation of Web Services

Buffered orchestrators

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 35 / 65

Page 36: Contract-based Discovery and Adaptation of Web Services

Buffered orchestrators

client n orchestrator n service

a → 〈a, ε〉 σ...

ρ 〈ε,a〉 → a

ρ 〈ε,a〉 ← a...

a ← 〈a, ε〉 σ

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 36 / 65

Page 37: Contract-based Discovery and Adaptation of Web Services

Syntax of buffered orchestrators

f ::= orchestrator0 (null)

| µ.f (action prefix)| f ∨ f (disjunction)

µ ::= orchestration action〈a,a〉 (input/output)

| 〈a,a〉 (output/input)| 〈α, ε〉 (action/–)| 〈ε,α〉 (–/action)

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 37 / 65

Page 38: Contract-based Discovery and Adaptation of Web Services

Valid k-orchestrators

Not every orchestrator makes sense

orchestrator valid rank

〈ε,a〉.〈a, ε〉 , ≥ 1

〈a, ε〉.〈a, ε〉 , ≥ 2

〈a, ε〉 /

〈ε,a〉 /

〈a, ε〉.〈a, ε〉 /

Valid k-orchestrators are. . .

• directional• finite-state• fair

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 38 / 65

Page 39: Contract-based Discovery and Adaptation of Web Services

Weak k-compliance, formally

Orchestrated systems

ρ ‖f σ

Orchestrated system transitions

· · ·

ρ α-→ ρ′ f

〈α,ε〉-→ f ′

ρ ‖f σ -→ ρ′ ‖f ′ σf〈ε,α〉-→ f ′ σ α

-→ σ ′

ρ ‖f σ -→ ρ ‖f ′ σ ′

Weak k-compliance

f : ρ a |k σdef⇐⇒ ρ ‖f σ =⇒ ρ′ ‖f ′ σ ′ X-→ implies ρ′ e

-→

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 39 / 65

Page 40: Contract-based Discovery and Adaptation of Web Services

Weak k-compliance, an example

〈a, ε〉.〈b, ε〉.〈ε,b〉.〈ε,a〉.〈c, c〉 : a.b.c.e a |1 b.a.c

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 40 / 65

Page 41: Contract-based Discovery and Adaptation of Web Services

Weak k-subcontract, formally

Set-theoretic interpretation of contracts

Jσ Kwk

def= {ρ | ∃f : f : ρ a |k σ}

Weak subcontract

σ � τ def⇐⇒ Jσ Ks ⊆ JτKwk

Proposition (existence of universal orchestrator)

σ �k τ if and only if f : σ �k τ for some k-orchestrator f

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 41 / 65

Page 42: Contract-based Discovery and Adaptation of Web Services

Orchestrators as morphisms

Orchestrator application f (σ)

f σ f (σ)〈a, ε〉.〈b,b〉 b a.b〈ε,a〉.〈b,b〉 a.b b

〈a, ε〉.〈b, ε〉.〈ε,b〉.〈ε,a〉 b.a a.b

Theorem

f : ρ a |k σ if and only if ρ a f (σ)

Corollary

f : σ �k τ if and only if σ v f (τ)

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 42 / 65

Page 43: Contract-based Discovery and Adaptation of Web Services

Orchestrator composition and transitivity of �k

We’ve got a problem

σ def= b + d

fdef= 〈a, ε〉.〈c, ε〉.(〈ε,a〉.〈b,b〉 ∨ 〈ε, c〉.〈d,d〉)

gdef= 〈a, ε〉.〈b,b〉 ∨ 〈c, ε〉.〈d,d〉

f (g(σ)) ' f (a.b + c.d) ' a.c.(b ⊕ d)

No single orchestrator can turn b + d into a.c.(b ⊕ d)

IdeaFind an orchestrator f ·g such that f (g(σ)) v (f ·g)(σ)

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 43 / 65

Page 44: Contract-based Discovery and Adaptation of Web Services

Orchestrator composition, formally

f ·g def=∨

f〈α,ε〉7 -→ f ′

〈α, ε〉.(f ′ ·g)∨∨

g〈ε,α〉7 -→ g′

〈ε,α〉.(f ·g′)

∨∨

f〈ϕ,α〉7 -→ f ′,g

〈α,ϕ′〉7 -→ g′,ϕϕ′ 6=ε

〈ϕ,ϕ′〉.(f ′ ·g′)

∨∨

f〈ε,α〉7 -→ f ′,g〈α,ε〉7 -→ g′

(f ′ ·g′)

Theorem

f (g(σ)) v (f ·g)(σ)

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 44 / 65

Page 45: Contract-based Discovery and Adaptation of Web Services

Deduction system for �k

No complete deduction system for �k is known

(swap-inputs)a.b.σ = b.a.σ

(swap-outputs)

a.b.σ = b.a.σ(postpone-input)

a.b.σ ≤ b.a.σ

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 45 / 65

Page 46: Contract-based Discovery and Adaptation of Web Services

Duality

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 46 / 65

Page 47: Contract-based Discovery and Adaptation of Web Services

Duality

ρ⊥

the �-smallest service that satisfies ρ

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 47 / 65

Page 48: Contract-based Discovery and Adaptation of Web Services

Duality, examples

ρ ρ⊥

a.e aa.e⊕ b.e a+ ba.e+ b.e a⊕ b

e 0

a.b.e+ a.c.e a.(b + c)

0 /a.e⊕ 0 /

a.0 /. . .

Definition (viable contract)

ρ is viable if there exists σ such that ρ a σContract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 48 / 65

Page 49: Contract-based Discovery and Adaptation of Web Services

Duality, formally

ρ⊥ def=∑

ρ⇓r,e6∈r

⊕α∈r,viable(ρ(α))

α.ρ(α)⊥

TheoremLet ρ be a viable client contract. Then

1 ρ a ρ⊥

2 ρ a σ implies ρ⊥ �0 σ

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 49 / 65

Page 50: Contract-based Discovery and Adaptation of Web Services

Recursive behaviors

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 50 / 65

Page 51: Contract-based Discovery and Adaptation of Web Services

Finite syntax for finite behaviors

σ ::= contract0 (null)

| α.σ (action prefix)| σ + σ (external choice)| σ ⊕ σ (internal choice)

α ::= actiona (input)

| a (output)

What about recursive behavior?

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 51 / 65

Page 52: Contract-based Discovery and Adaptation of Web Services

Describing recursive behavior

Many different ways. . .

rec X .a.X ⊕ b.0

X = a.X ⊕ b.0

σ∗

. . . but it’s just syntax!

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 52 / 65

Page 53: Contract-based Discovery and Adaptation of Web Services

Infinite syntax for infinite behaviors

σ ::= contract0 (null)

| α.σ (action prefix)| σ + σ (external choice)| σ ⊕ σ (internal choice)

α ::= actiona (input)

| a (output)

Definition

The set of contracts is the set of possibly infinite trees generated bythe grammar above such that

1 they have finitely many different subtrees

2 every infinite branch has infinitely many prefixes

Every finite contracts satisfies these conditions

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 53 / 65

Page 54: Contract-based Discovery and Adaptation of Web Services

Examples

X = a.X= a.a.X= · · · ,

X = a.X ⊕ b.0= a.(a.X ⊕ b.0)⊕ b.0= a.(a.(a.X ⊕ b.0)⊕ b.0)⊕ b.0= a.(a.(a.(a.X ⊕ b.0)⊕ b.0)⊕ b.0)⊕ b.0= · · · ,

X = X + X /

X = X ⊕ X /

X = X /

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 54 / 65

Page 55: Contract-based Discovery and Adaptation of Web Services

Recursion: summary

• all the results stated previously still hold (coinduction)

• use your own preferred syntax (but beware of Kleene ∗)

Why does it work?

Proposition

Let D(σ) def= {σ ′ | σϕ=⇒ σ ′}. Then D(σ) is finite for every σ

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 55 / 65

Page 56: Contract-based Discovery and Adaptation of Web Services

Algorithm

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 56 / 65

Page 57: Contract-based Discovery and Adaptation of Web Services

Towards an algorithm for deciding �k

Problem: the orchestrator is not necessarily unique

0 : a⊕ b ⊕ 0 � a+ b〈a,a〉 : a⊕ b ⊕ 0 � a+ b〈b,b〉 : a⊕ b ⊕ 0 � a+ b

〈a,a〉 ∨ 〈b,b〉 : a⊕ b ⊕ 0 � a+ b

f à g: g is better (more permissive) than f

f à gdef⇐⇒ Jf K ⊆ JgK

Idea

• synthesize the best orchestrator

• the best orchestrator is unique

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 57 / 65

Page 58: Contract-based Discovery and Adaptation of Web Services

Deciding �k

ar = {〈ϕ,ϕ′〉 | σϕ=⇒, τ

ϕ′=⇒,B `k 〈ϕ,ϕ′〉}

a = {〈ϕ,ϕ′〉 ∈ ar | B〈ϕ,ϕ′〉 `k f〈ϕ,ϕ′〉 : σ(ϕ) ô τ(ϕ′)}τ ⇓ s⇒ (∃r : σ ⇓ r∧ r ⊆ a ◦ s)∨ (∅• a)∩ s 6= ∅

B `k∨µ∈a µ.fµ : σ ô τ

Theorem

The following properties hold:

1 (termination) the algorithm always terminates

2 (correctness) f : σ ôk τ implies that f has rank k and f : σ �k τ3 (completeness) f : σ �k τ implies g : σ ôk τ for some g á f

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 58 / 65

Page 59: Contract-based Discovery and Adaptation of Web Services

An example from Wil’s lecture (1/3)

σ def= order.(money + food.money)

ρ1def= order.food.money .e

ρ⊥1 = order.food.money

f1 = 〈order,order〉.〈food, food〉.〈money ,money〉

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 59 / 65

Page 60: Contract-based Discovery and Adaptation of Web Services

An example from Wil’s lecture (2/3)

σ def= order.(money + food.money)

ρ2def= order.(food.money .e+money .food.e)

ρ⊥2 = order.(food.money ⊕money .food)

f2 = 〈order,order〉.〈food, food〉.〈money ,money〉

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 60 / 65

Page 61: Contract-based Discovery and Adaptation of Web Services

An example from Wil’s lecture (3/3)

σ def= order.(money + food.money)

ρ3def= order.money .food.e

ρ⊥3 = order.money .food

f3 = 〈order,order〉.〈money , ε〉.〈food, food〉.〈ε,money〉

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 61 / 65

Page 62: Contract-based Discovery and Adaptation of Web Services

Conclusions

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 62 / 65

Page 63: Contract-based Discovery and Adaptation of Web Services

Wrap-up

Subcontract relation

• tool for searching and reasoning about services by their contracts(= behavioral types)

• � combines reduction, extension, and permutation into a singlepreorder

• � gives safe substitution of services modulo orchestration

• � is decidable

(Simple) orchestrators

• have nice properties (universality, compositionality)

• can be automatically synthesized

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 63 / 65

Page 64: Contract-based Discovery and Adaptation of Web Services

Contracts vs session types

What is being typed

• contract = type of a process

• session type = type of a channel

• session type = type of a process projected on a channel

Testing approach

• session types: subtyping preserves correctness

• contracts: compliance defines subcontracting

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 64 / 65

Page 65: Contract-based Discovery and Adaptation of Web Services

Essential bibliography

Contracts with static interfaces and divergence

• C. Laneve, L. Padovani. The must preorder revisited(CONCUR’07)

Synthesis of orchestrators

• G. Castagna, N. Gesbert, and L. Padovani. A theory of contractsfor Web services (POPL’08)

• G. Castagna, N. Gesbert, and L. Padovani. A theory of contractsfor Web Services. (ACM TOPLAS 2009) to appear

• L. Padovani. Contract-directed synthesis of simpleorchestrators (CONCUR’08)

Describing name-passing in contracts

• G. Castagna, L. Padovani. Contracts for Mobile Processes(CONCUR’09)

Contract-based Discovery and Adaptation of Web Services (Luca Padovani) SFM’09 65 / 65