REST Tutorial

4 downloads 4069 Views 3MB Size Report
Jun 12, 2011 - From REST-* http://w w w .jboss.org/reststar/specifications/w orkflow .html .... ... Cesare [email protected]. .
Push-Enabling RESTful Business Processes Cesare Pautasso

Faculty of Informatics, University of Lugano, Switzerland [email protected] http://www.pautasso.info @pautasso 6.12.2011

Erik Wilde EMC [email protected] http://dret.net @dret

RESTful Business Processes Cesare Pautasso

Faculty of Informatics, University of Lugano, Switzerland [email protected] http://www.pautasso.info @pautasso 6.12.2011

Erik Wilde EMC [email protected] http://dret.net @dret

Abstract  Representational State Transfer (REST) as an architectural style for service design has seen substantial uptake in the past years. However, some areas such as Business Process Modeling (BPM) and push services so far have not been addressed in the context of REST principles.  In this work, we look at how both BPM and push can be combined so that business processes can be modeled and observed in a RESTful way. Based on this approach, clients can subscribe to be notied when certain states in a business process are reached. Our goal is to design an architecture that brings REST's claims of loose coupling and good scalability to the area of BPM, and still allow process-driven composition and interaction between resources to be modeled.

©2011 - Cesare Pautasso

3

BPM ©2011 - Cesare Pautasso

REST 4

Business Process Management

©2011 - Cesare Pautasso

RESTful Web Services

5

RESTful APIs…

©2011 - Cesare Pautasso

6

RESTful APIs…

©2011 - Cesare Pautasso

7

WS-* Standards Stack

©2009-2010 - Cesare Pautasso - 30.6.2010

8

WS-* Standards Stack Management

State

Transactions

Security

©2009-2010 - Cesare Pautasso - 30.6.2010

Reliability

Metadata

Interoperability

BPM

Messaging 9

Management

State

Transactions

Security

Reliability

Metadata

Interoperability

BPM

Messaging Can you do

with REST? ©2011 - Cesare Pautasso

it 10



We believe there is huge potential to marrying REST with workflow and BPM. […] Combined with the architecture of the Web, a workflow service can provide both a truly simple, portable, and flexible way to build workflow driven integrations and applications.



©2011 - Cesare Pautasso

http://www.jboss.org/reststar/specifications/workflow.html

From REST-*

11

REST in one slide  Web Services expose their PUT data and functionality trough resources identified by URI R GET  Uniform Interface constraint: Clients interact with resources POST DELETE through a fix set of verbs. Example HTTP: GET (read), POST (create), PUT (update), DELETE  Multiple representations for the same resource  Hyperlinks model resource relationships and valid state transitions for dynamic protocol description and discovery ©2011 - Cesare Pautasso

12



We believe there is huge potential to marrying REST with workflow and BPM.  The HATEOAS (hypermedia and linking) principal of REST is logically a dynamic state machine and fits very well with how workflow and BPM systems are designed.  Combined with the architecture of the Web, a workflow service can provide both a truly simple, portable, and flexible way to build workflow driven integrations and applications. ©2011 - Cesare Pautasso

http://www.jboss.org/reststar/specifications/workflow.html

From REST-*

13

Business Process Management Workflow Users/Clients

Process Model Act 4

Act 2 Act 1

Act 5 Act 3

Workflow Participants

Act 7

Act 6 RESTful Workflow Management Engine

PUT GET

R

POST

©2011 - Cesare Pautasso

Adapters Applications

DELETE

Bus Web Services

Databases 14

BPM with REST Process Model Act 2 Act 1

Act 5 Act 3

R

Act 4 Act 7

Publishing Processes as Resources

Act 6 RESTful Workflow Management Engine

R ©2011 - Cesare Pautasso

R

R

RESTful Service Composition 15

BPM with REST

BPEL for REST BPMN for REST

R

Publishing Processes as Resources

RESTful Workflow Management Engine

R ©2011 - Cesare Pautasso

R

R

RESTful Service Composition 16

BPM with REST

R

We are here

Publishing Processes as Resources

RESTful Workflow Management Engine

R ©2011 - Cesare Pautasso

R

R

RESTful Service Composition 17

BPM  Processes  Tasks  Control Flow  Data Flow … ©2011 - Cesare Pautasso

REST  Resources/URIs  Uniform Interface  Representations  Hypermedia 18

Everything is a resource /process/X

Process

Process Instance

Task

Task Instance

/task/Y

©2011 - Cesare Pautasso

/process/X/1

/task/Y/1 19

Hypermedia /process

Process

Process Instance

Task

Task Instance

GET /process/name GET /process/name/instance GET /process/name/instance/taskname

Follow links to discover the processes deployed as resources ©2011 - Cesare Pautasso

20

Representations Web page with form to start a new process ContentType: instance

ContentType:

BPMN2.0 process source code

text/html application/bpmn+xml GET /process/name

ContentType:

text/plain Basic textual description of the process ©2011 - Cesare Pautasso

ContentType:

ContentType:

application/json

image/svg+xml

Process metadata in JSON 21

Uniform Interface and Hypermedia GET /process GET /process/name POST /process/name

List the deployed processes

Get a form describing how to start the process Start a new process instance Check what

GET /process/name/instance DELETE /process/name/instance ©2011 - Cesare Pautasso

is the state of the instance

Clean up (once it is done) 22

Starting or Running processes? /process  Should the client be kept

POST /process

200 OK (Process Finished Reply) ©2011 - Cesare Pautasso

waiting for the process to run until completion?

 Clients may want to block until the whole process has completed its execution (or it decides to reply to them) 23

Starting or Running processes? /process  The client starting a long

POST /process 202 Accepted Location: x GET /process/x

running process is redirected to a location x representing the newly started process instance  The process and the client run asynchronously  The client may retrieve the current state of the process instance at any time

200 OK

©2011 - Cesare Pautasso

24

Push vs. Pull Notification /process  Problem: how can the process

instance tell the client that it has reached a certain state?

GET /process/x 200 OK

PULL

 Easy to use a PULL-based event notification with HTTP

PUSH

 Can we also support PUSHbased event notification with HTTP?

©2011 - Cesare Pautasso

25

Push-Enabling RESTful Business Processes Cesare Pautasso

Faculty of Informatics, University of Lugano, Switzerland [email protected] http://www.pautasso.info @pautasso 6.12.2011

Erik Wilde EMC [email protected] http://dret.net @dret

What is your SOA connector?

RPC

BUS

REST/HTTP

©2011 - Cesare Pautasso

27

REST as a new connector

RPC

BUS Publish/Subscribe

Call

REST/HTTP Get/Put/Post/Delete ©2011 - Cesare Pautasso

28

What about event notifications?

BUS

RPC

Publish/Subscribe Callback

REST/HTTP

?

Get/Put/Post/Delete ©2011 - Cesare Pautasso

29

Solutions

1.Web Feeds (PubSubHubbub) 2.HTTP Long Polling 3.Inverted REST (HTTP Callbacks) 4.WebSockets 5.(XMPP)

©2011 - Cesare Pautasso

30

Representations GET /process/name ContentType:

application/atom+xml Web feed representing the collection of process instances with links to each instance 31

Representations GET /process/name/instance ContentType:

application/atom+xml Web feed representing the current state of the process instance (collection of task instances) 32

Loan Approval Example Process Published as a Resource

External Resources

Task Published as a Resource ©2011 - Cesare Pautasso

33

Process as a Web Feed Loan Approval Process Instance x http://rest.jopera.org/loan/x 2011-06-10T11:11:30Z Cesare [email protected] Choose Task (Ready) http://rest.jopera.org/loan/x/choose 2011-06-10T11:12:20Z State: ready Approve Task (Waiting) http://rest.jopera.org/loan/x/approve 2011-06-10T11:11:30Z State: waiting ©2011 - Cesare Pautasso

34

BPM  Process Instance  Task  Process User  Task State  Task Timestamp  Task Instance URI ©2011 - Cesare Pautasso

Feed  Feed  Feed Entry  Feed Author  Summary  Updated  Link 35

Link Relations Loan Approval Process Instance x http://rest.jopera.org/loan/x

Template Process

©2011 - Cesare Pautasso

Process Instance

Self

36

PubSubHubbub Get Feed Consumer

Feed

Hub Subscribe

Feed Producer

Ping

Hub

Notify/Poll ©2011 - Cesare Pautasso

37

Architecture

http://www.jopera.org/ ©2011 - Cesare Pautasso

38

Conclusion  Thanks to hypermedia, URIs and the HTTP uniform interface, REST resources are a very good abstraction to publish executable business processes on the Web  RESTful HTTP is good enough to interact without any extension with process execution engines to drive the execution of process and task instances and to deliver notifications  The state of a process instance can be projected to be represented as a standard Web feed  The PubSubHubbub protocol can be used as an optimization to scale the corresponding delivery of notication callbacks ©2011 - Cesare Pautasso

39

References  Roy Fielding, Architectural Styles and the Design of Network-based Software Architectures, PhD Thesis, University of California, Irvine, 2000  Leonard Richardson, Sam Ruby, RESTful Web Services, O’Reilly, May 2007  Jim Webber, Savas Parastatidis, Ian Robinson, REST in Practice: Hypermedia and Systems Architecture, O‘Reilly, 2010  Subbu Allamaraju, RESTful Web Services Cookbook: Solutions for Improving Scalability and Simplicity, O’Reilly, 2010  Stevan Tilkov, HTTP und REST, dpunkt Verlag, 2009, http://rest-http.info/  Thomas Erl, Raj Balasubramanians, Cesare Pautasso, Benjamin Carlyle, SOA with REST, Prentice Hall, end of 2010  Martin Fowler, Richardson Maturity Model: steps toward the glory of REST, http://martinfowler.com/articles/richardsonMaturityModel.html ©2009-2010 - Cesare Pautasso, Erik Wilde

40

Self-References  Cesare Pautasso, Olaf Zimmermann, Frank Leymann, RESTful Web Services vs. Big Web Services: Making the Right Architectural Decision, Proc. of the 17th International World Wide Web Conference (WWW2008), Bejing, China, April 2008.  Cesare Pautasso and Erik Wilde. Why is the Web Loosely Coupled? A MultiFaceted Metric for Service Design, Proc of the 18th International World Wide Web Conference (WWW2009), Madrid, Spain, April 2009.  Cesare Pautasso, BPEL for REST, Proc. of the 6th International Conference on Business Process Management (BPM 2008), Milan, Italy, September 2008.  Cesare Pautasso, BPMN for REST, Proc. of the 3rd BPMN Workshop (BPMN 2011), Luzern, Switzerland, November 2011  Cesare Pautasso, RESTful Web Service Composition with JOpera, Proc. Of the International Conference on Software Composition (SC 2009), Zurich, Switzerland, July 2009.  Cesare Pautasso, Gustavo Alonso: From Web Service Composition to Megaprogramming In: Proceedings of the 5th VLDB Workshop on Technologies for E-Services (TES-04), Toronto, Canada, August 2004. ©2009-2010 - Cesare Pautasso, Erik Wilde

41

Raj Balasubramanians, Benjamin Carlyle, Thomas Erl, Cesare Pautasso, SOA with REST, Prentice Hall, 2012

©2011 - Cesare Pautasso

42

10th International Conference on Business Process Management (BPM 2012) September 3-6 2012, Tallinn, Estonia http://bpm2012.ut.ee ©2011 - Cesare Pautasso

43

16-20 April 2012, Lyon, France http://ws-rest.org/2012 ©2011 - Cesare Pautasso

44

PhD Positions Available

Cesare Pautasso http://www.pautasso.info/ @pautasso ©2011 Cesare Pautasso

45