8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web...

20
8 Sep 2008 NVOSS 2008 - Web Services 1 THE US NATIONAL VIRTUAL OBSERVATORY Introduction to Web Services Matthew J. Graham Caltech

Transcript of 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web...

Page 1: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

8 Sep 2008NVOSS 2008 - Web Services 1

THE US NATIONAL VIRTUAL OBSERVATORY

Introduction to Web Services

Matthew J. GrahamCaltech

Page 2: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

8 Sep 2008NVOSS 2008 - Web Services 2

Web service deoccultation

• Invocations• Strange languages• Action at a distance• High priesthood

Page 3: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

Bluffer’s guide

• Web service (think a (code) library on the web)– A piece of software available over a network with a

formal description of how it is called and what it returns that a computer can understand

• REST (think HTTP GET and POST)– An approach to web services that uses the existing

infrastructure of the web• SOAP (think envelopes)

– An approach to web services that uses an XML-based messaging framework

• WSDL (think a contract)– An XML description of a web service (normally SOAP)

and how to interact with it

8 Sep 2008NVOSS 2008 - Web Services 3

Page 4: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

What we won’t cover (look in the book)

• Data formats:– I want to use something other than XML

• Security:– I want to protect my data/resources

• Attachments– I want to upload/download a file

• State– I want the service to remember things

• Asynchrony– It’s going to take some time

• Messaging– I want more than just request/response

8 Sep 2008NVOSS 2008 - Web Services 4

Page 5: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

Web services in the VO

• SkyNodes, Open SkyQuery and WESIX• Footprint Services and STOMP• Spectrum Services• Registry Interface• VOSpace• CasJobs• CDS • VOServices• (IRAF)…

8 Sep 2008NVOSS 2008 - Web Services 5

Page 6: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

Numquam ponenda est pluralitas sine necessitate

• WWW is the largest, most distributed and scalable application on the planet

• REST (Representation State Transfer) is an architectural style not an implementation:– Distinguishes resources and operations– Each resource is identified by a URI– The only operations are the HTTP methods– Data reflecting the state of a resource is

exchanged (in XML)

8 Sep 2008NVOSS 2008 - Web Services 6

Page 7: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

REST by analogy

HTTP Method

Think Description /proc analogy

PUT CREATE Create a resource with the user specified id

Start a new process

GET RETRIEVE

Retrieve a resource representation

Get the status of a process

POST UPDATE Update a resource/Append to a resource/Create a resource with a server assigned id

Amend a process

DELETE DELETE Delete a resource Kill a process

8 Sep 2008NVOSS 2008 - Web Services 7

Page 8: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

By accident, not by design

• Parameters in HTTP GET URLs:– http://processes.com/123/status– http://processes.com/services?action=getStatus&pid=123

• HTTP GET is safe – it does nothing else than retrieval• HTTP GET, PUT and DELETE are idempotent – the

effects on the system of one or N identical requests are the same

• Consider HTTP GET with: http://processes.com/services/action=cancelJob&pid=123• Services which maintain idempotency whilst allowing

parameterized URLs are accidentally RESTful• 85% of web service traffic, 6x faster allegedly

8 Sep 2008NVOSS 2008 - Web Services 8

Page 9: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

When to use REST

• RESTful services are good for WWW-type functionality

• Limitations:– No formal description:

• WADL not widely used yet• Not an issue for pure REST (no parameters in URL)

– No messaging infrastructure:• Reliable messaging• Message routing

– No message level security:• Digital signatures

– No resource lifecycle management– No transaction support– No asynchronous event notification

8 Sep 2008NVOSS 2008 - Web Services 9

Page 10: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

8 Sep 2008NVOSS 2008 - Web Services 10

What is SOAP?

• Simple Object/Service-Oriented Access Protocol – http://wanderingbarque.com/nonintersecting/2006/11/15/the-

s-stands-for-simple/• W3C specification

– http://www.w3.org/TR/soap• An XML-based messaging framework for exchanging

information between peers in a decentralized, distributed environment

• Defines the message structure but not the message content (needs other technologies)

• Fundamentally stateless (no memory of what has happened previously)

• One-way message exchange paradigm

Page 11: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

8 Sep 2008NVOSS 2008 - Web Services 11

Anatomy of a SOAP message

• SOAP envelope– SOAP header (optional)

• Routing• Transactional• Security• Contextual• User profile

– SOAP body• Message payload (actual data)

– XML namespace and schema

Page 12: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

8 Sep 2008NVOSS 2008 - Web Services 12

SOAP exampleRequest:<soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance

xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ComovingLineOfSight xmlns="http://skyservice.pha.jhu.edu"> <z>float</z> <hubble>float</hubble> <omega>float</omega> <lambda>float</lambda> </ComovingLineOfSight> </soap:Body></soap:Envelope>

Response:<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance”

xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ComovingLineOfSightResponse xmlns=http://skyservice.pha.jhu.edu> <ComovingLineOfSightResult>float</ComovingLineOfSightResult> </ComovingLineOfSightResponse> </soap:Body></soap:Envelope>

Page 13: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

What is WSDL?

• Web Services Description Language• W3C specification

– http://www.w3.org/TR/wsdl

• An XML grammar for describing the public interface of a web service in terms of: – its exposed operations – the message formats – protocol bindings (e.g. SOAP, HTTP)

• Most commonly used with SOAP– defines format of message content in the SOAP

body

8 Sep 2008NVOSS 2008 - Web Services 13

Page 14: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

Anatomy of a WSDL

<definitions> <types> <message> <portType> <operation> <input> <output> <fault> </operation> </portType> <binding> <service></definitions>

8 Sep 2008NVOSS 2008 - Web Services 14

A WSDL document describes:

• a set of services which exchange messages

• the data in the messages is defined in a set of types

• each message transfer in a service defines an operation

• operations have bindings to specific implementations using protocols like HTTP

Page 15: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

8 Sep 2008NVOSS 2008 - Web Services 15

WSDL example<definitions targetNamespace="http://skyservice.pha.jhu.edu" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s=“http://www.w3.org/2001/XMLSchema” xmlns:s0=“http://skyservice.pha.jhu.edu” xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <s:schema elementFormDefault="qualified" targetNamespace="http://skyservice.pha.jhu.edu"> <s:element name="ComovingLineOfSight”>… <s:element name="z" type="s:float" /> <s:element name="hubble" type="s:float" /> <s:element name="omega" type="s:float" /> <s:element name="lambda" type="s:float" />… </s:element> <s:element name="ComovingLineOfSightResponse”>… <s:element name="ComovingLineOfSightResult" type="s:float" />… </s:element> </s:schema> </types> <message name="ComovingLineOfSightSoapIn"> <part name="parameters" element="s0:ComovingLineOfSight" /> </message> <message name="ComovingLineOfSightSoapOut"> <part name="parameters" element="s0:ComovingLineOfSightResponse" /> </message> <portType name="DistanceSoap"> <operation name="ComovingLineOfSight"> <documentation>Return the comoving line of sight distance...</documentation>

<input message="s0:ComovingLineOfSightSoapIn" /> <output message="s0:ComovingLineOfSightSoapOut" />

</operation> </portType> <service name="Distance”> <port name="DistanceSoap" binding="s0:DistanceSoap”> <soap:address location="http://voservices.net/Cosmology/ws_v1_0/Distance.asmx" />

</port> </service></definitions>

Page 16: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

Using SOAP and WSDL

• Start with WSDL (contract-first) vs. start with code (contract-last)

• Frameworks provide APIs:– to handle SOAP:

• (De)serialization: converting code object to/from XML representation

– and code bindings derived from WSDL: • Stub: client-side proxy to service• Skeleton: server-side to handle request and response

• Alternate approach: – SOAP (and WSDL) are just XML– Use XSLT, curl, JavaScript, etc.

8 Sep 2008NVOSS 2008 - Web Services 16

Page 17: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

8 Sep 2008NVOSS 2008 - Web Services 17

Just to scare you (WS-*)• WS-I Basic Profile• WS-I Basic Security Profile• WS-Manageability• WS-Management • WS-MetadataExchange• WS-Notification• WS-Policy• WS-PolicyAssertions• WS-PolicyAttachment• WS-PolicyFramework• WS-Polling• WS-Provisioning• WS-Reliability• WS-ReliableMessaging• WS-RemotePortals• WS-ResourceFramework• WS-ResourceLifetime• WS-ResourceProperties• WS-Routing• WS-SecureConversation• WS-Security• WS-SecurityPolicy

• WS-Addressing• WS-AtomicTransaction• WS-Attachments• WS-BaseNotification• WS-BPEL• WS-BrokeredNotification• WS-BusinessActivity• WS-CAF• WS-Choreography• WS-CDL• WS-Context• WS-Coordination• WS-CoordinationFramework• WS-Discovery• WS-DistributedManagement• WS-Enumeration• WS-Eventing• WS-ExperienceLanguage• WS-Federation• WS-GAF• WS-Inspection• WSIL

• WS-Semantics• WS-Topic• WS-Transaction• WS-Transaction Management• WS-Transfer• WS-Trust • ASAP • ebXML• MTOM• SAML • SOAP• SwA• UBL• UDDI• WSDL• XACML• XML Encryption• XML Signature• XKMS

Page 18: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

Grids and clouds

• Services on supercomputers:– Montage on TeraGrid– NESSSI

• Computing on demand:– Virtualization– Providers:

• Amazon EC2• Google Apps

• Globus– http://www.globus.org

8 Sep 2008NVOSS 2008 - Web Services 18

Page 19: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

Beyond REST

• Data event streams are the future of astronomy:– High volume– Frequent– Low latency

• Hugh percentage of traffic with RESTful services is polling status– Polling does not scale– Not real time

• SOAP is overly complicated• The proposed solution: XMPP (PubSub)

8 Sep 2008NVOSS 2008 - Web Services 19

Page 20: 8 Sep 2008NVOSS 2008 - Web Services1 T HE US N ATIONAL V IRTUAL O BSERVATORY Introduction to Web Services Matthew J. Graham Caltech.

A brief introduction to XMPP/Jabber

• Extensible Messaging and Presence Protocol:– Persistent connections– Stateful– Designed to be an event stream protocol– Natively federated and asynchronous– Identity, security and presence built in

• Jabber servers designed to handle at least 105 concurrent connections

• Sample message: <iq type=“set” from=“[email protected]/events”

to=“pubsub.nvocloud.edu” id=“mjg12345”> <pubsub xmlns='http://jabber.org/protocol/pubsub'> <publish node='/jobs/1234-5678-90AB-CDEF'> <job type=“datadiscovery” id=“ivo://some.voevent”/> </publish> </pubsub>

</iq>

8 Sep 2008NVOSS 2008 - Web Services 20