Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

23
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential. © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential. Creating a REST API for Cloud services using OSGi and Sling Carsten Ziegeler and David Bosschaert

description

OSGi Community Event 2014 Abstract: Let's say you need to provide an internet service to your users. Chances are that your service should be available via REST. Let's say your service should both provide data to users as well as accept data posted by users, and possibly some logic. Now let's assume your service turns out to become incredibly popular, with lots and lots of users. Sounds like you need Sling and OSGi in the cloud. In this talk Carsten and David will go through the OSGi and Sling architecture to achieve this. The talk outlines how the OSGi Cloud Ecosystems RFC is used in combination with Apache jclouds to achieve vendor independence. It also discusses how automatic scaling depending on measured load is achieved to ensure responsiveness. The resulting system is a dynamic cloud application handling any REST API, which can scale up and down depending on the need. Speaker Bios: David Bosschaert David Bosschaert works for Adobe Research and Development. He spends the much of his time on technology relating to OSGi in Apache and other open source projects. He is also co-chair of the OSGi Enterprise Expert Group and an active participant in the OSGi Cloud efforts. Before joining Adobe, David worked for Red Hat/JBoss and IONA Technologies in Dublin, Ireland. Carsten Ziegeler Carsten Ziegeler is senior developer at Adobe Research Switzerland and spends most of his time on architectural and infrastructure topics. Working for over 25 years in open source projects, Carsten is a member of the Apache Software Foundation and heavily participates in several Apache communities including Sling, Felix and ACE. He is a frequent speaker on technology and open source conferences and participates in the OSGi Core Platform and Enterprise expert groups.

Transcript of Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

Page 1: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Creating a REST API for Cloud services using OSGi and SlingCarsten Ziegeler and David Bosschaert

Page 2: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

● David Bosschaert ([email protected])

– R&D Adobe Research Dublin

– Co-chair OSGi EEG

– Open-source and cloud enthusiast

● Carsten Ziegeler ([email protected])

– R&D Adobe Research Switzerland

– OSGi Board, CPEG and EEG member

– ASF member

Speakers

Page 3: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Agenda

● A REST site with Apache Sling

● Scale it up! with OSGi and jclouds

Page 4: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Page 5: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Te Next Great Application

Page 6: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

ROA and REST

● htp://…/products.jsp?id=5643564

● htp://…/slingshot/slingshot1/public/travel/pet.(html|json)

Page 7: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Resource Oriented Architecture

● Every piece of information is a resource

● User home, category, item, image, comment● Descriptive URI

● Stateless web architecture (REST)

● Request contains all relevant information● Targets the resource

● Leverage HTTP

● GET for rendering, POST/PUT/DELETE for operations

Page 8: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

SlingShot Content Structure

/

slingshot1 slingshot2

public

travel

pethome

images comments ratings

pet.jpg

Page 9: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Resource-frst Request Processing

● Request: /slingshot1/public/travel/pet/comments.10.json

● Resource: /slingshot1/public/travel/pet/comments

● Extension: json

● Selector: 10

● Method: GET

● Resource Type : slingshot/comments

Page 10: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Resource-frst Request processing

1. Resolve the resource

2. Resolve processing script

3. Build execution chain

4. Execute

Page 11: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Scripting Inside

● It’s your choice

● JSP, servlet, ESP, Scala, Sightly● javax.script● own script handlers

● Default servlets

● JSON, XML● POST/update/create/delete handling● Error handling

Page 12: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

<sling:defineObjects/><div class="comment"><% final ValueMap attr = resource.getValueMap(); final String title = attr.get(PROPERTY_TITLE, resource.getName()); final String description = attr.get(PROPERTY_DESCRIPTION, ""); final String userId = attr.get(PROPERTY_USER, "");%> <h4><%= ResponseUtil.escapeXml(userId) %> : <%= ResponseUtil.escapeXml(title) %></h4> <p><%= ResponseUtil.escapeXml(description) %></p> <p><%= ResponseUtil.escapeXml( attr.get(SlingshotConstants.PROPERTY_CREATED, "")) %></p></div>

Page 13: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Resource Providers

/

slingshot1

public

travel

pethome

images comments ratings

pet.jpg

MongoDB

FS

JCRApache Jackrabbit

Page 14: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Scale UP!● Efectively use the cloud

● Scale up/down based on need

● start small = cheap

● No downtime

● when moving to larger machines

● No cloud-provider specifcs

Page 15: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

28/10/14© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Sling in the cloud

Load Balancer(s)OSGi NodeOSGi Node

Sling

OSGi NodeOSGi Node

Sling

Director

traffic

Page 16: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

28/10/14© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Director

OSGi NodeOSGi Node

Sling

OSGi NodeOSGi Node

Sling

Director

provisioninspectdiscover

OSGi NodeOSGi Node

Sling

OSGi NodeOSGi Node

Sling

jclouds create destroy

metricsmetrics

OSGi Cloud Ecosystems (RFC 183)FrameworkNodeStatus Service

Page 17: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

28/10/14© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Busy times

Load Balancer(s)

OSGi NodeOSGi Node

Sling

OSGi NodeOSGi Node

Sling

Director

traffic

OSGi NodeOSGi Node

Sling

OSGi NodeOSGi Node

Sling

Page 18: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

28/10/14© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Quiet times

Load Balancer(s)

OSGi NodeOSGi Node

Sling

Director

traffic

Page 19: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

28/10/14© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Really Quiet times

Load Balancer(s)

OSGi NodeOSGi Node

Sling Sling

Sling Sling

Director

traffic

Dockerinstances

Page 20: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Summary● Use Sling to build your REST service

● Write your app using anything that can interact with REST

● Native app

● Javascript

● …

● Use OSGi Cloud Ecosystems, Apache jclouds and Docker to scale

● Be cloud-vendor independent!

Page 21: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Interested in OSGi and Cloud?

● Come to the OSGi Cloud WorkshopWednesday October 29 at 15:15 (Seminarräume 1-3)

Page 22: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.

Innovation at Adobe

22

Links

● Apache Sling – htp://sling.apache.org

● Apache jclouds – htp://jclouds.apache.org

● SlingShot Sample application – htp://svn.apache.org/repos/asf/sling/trunk/samples/slingshot

● OSGi Cloud Ecosystems RFC 183 – htps://github.com/osgi/design/tree/master/rfcs/rfc0183

Page 23: Creating an all-purpose REST API for Cloud services using OSGi and Sling - C Ziegeler & D Bosschaert

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confdential.