deploying heterogeneous artifacts to the cloud with osgi - neil bartlett

27
Copyright © 2005 - 2013 Paremus Ltd. May not be reproduced by any means without express permission. All rights reserved. Paremus Packager March 2013 Deploying Heterogeneous Artifacts to the Cloud with OSGi Neil Bartlett - Paremus [email protected] Friday, 29 March 13

Upload: mfrancis

Post on 16-Feb-2017

302 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Copyright © 2005 - 2013 Paremus Ltd.May not be reproduced by any means without express permission. All rights reserved.

Paremus Packager March 2013

Deploying Heterogeneous Artifactsto the Cloud with OSGi

Neil Bartlett - [email protected]

Friday, 29 March 13

Page 2: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Motivation

Good OSGi Bundles are Self-Describing

Dependency Management, Resolving, Provisioning...

Consistent Interface: Bundle Install/Uninstall/Update/Start/Stop, Config Admin, Metatype, Log Service...

If I Have a Bundle, I Always Know How to Deploy It!

Friday, 29 March 13

Page 3: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Unfortunately...

Not All Software is Built in OSGi (yet). Lots of useful things are not even Java!

How do we ensure this software is installed where it needs to go?

Current state-of-the-art: assume it’s already there!

Friday, 29 March 13

Page 4: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Proposal

Wrap Native Artifacts in OSGi Bundles

Tie the Lifecycle. Bundle Start => Launch, etc.

Link to Standard OSGi Services: Configuration Admin, Metatype, Log Service...

Friday, 29 March 13

Page 5: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Separation of Concerns

1. What and How Should we Run?

2. When, How Many, and How Configured?

3. Actually Run and Monitor It.

Friday, 29 March 13

Page 6: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Separation of Concerns

1. What and How Should we Run? => Package Type

2. When, How Many, and How Configured? => Process Guard

3. Actually Run and Monitor It => Watchdog

Friday, 29 March 13

Page 7: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

The PackageType

Usually Contains the Native Parts, or Knows Where to Get Them

Installs the Native Program

Returns Scripts to the Packager for: start, stop, ping...

Is Platform Specific

Friday, 29 March 13

Page 8: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

The PackageType

One Bundle for Each Type/Platform Combo

Use Generic Caps/Reqs, e.g.:

Provide-Capability: packager.type; \ packager.type=mongodb; \ version:Version=2.2.0

Require-Capability: osgi.native; \ filter:=”(& \ (osgi.native.osname=Linux) \ (osgi.native.processor=x86-64) \ )”

Friday, 29 March 13

Page 9: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Example PackageType@Component(properties = "package.type=mongodb")public class MongoPackagerUNIX implements PackageType { @Override public PackageDescriptor create(Map<String,Object> properties, File data) throws Exception { MongoProperties config = Converter.cnv(MongoProperties.class, properties); PackageDescriptor pd = new PackageDescriptor();

// Expand mongod executable File mongod = new File(data, "mongod"); if (!mongod.isFile()) { IO.copy(getClass().getResource("/data/mongod"), mongod); run("chmod a+x " + mongod.getAbsolutePath()); } // Construct the start command StringBuilder sb = new StringBuilder().append(mongod.getAbsolutePath()); if (config.port() != 0) sb.append(" --port ").append(config.port()); pd.startScript = sb.toString(); // ... return pd; }

Friday, 29 March 13

Page 10: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

The ProcessGuard

Gathers Process Config Properties

Signals When to Start/Stop

Receives State Change Events (started, crashed...)

Advertises the Running Package (Optional)

Friday, 29 March 13

Page 11: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

PackagerManager

MongoDBMac OSX

MongoDBGuard

PackageType

type=mongodb

ProcessGuard

type=mongodb

scripts

config

config

state events

Endpointuri=mongodb://10.0.0.1:27017/service.exported.interfaces=*

Friday, 29 March 13

Page 12: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

The ProcessGuard

1. Published Service Means “Start the Process”

2. Packager Calls getProperties() to get Config

3. Passes Config to PackageType, gets Script

4. Unpublished Service Means “Stop the Process”

Friday, 29 March 13

Page 13: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

ProcessGuard Dependencies

Use Declarative Services to Easily Create Dependencies for the Package

E.g. Required Configuration

Can Also Use Service References...

Friday, 29 March 13

Page 14: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Example ProcessGuard

@Reference(target = "(uri=http://*/rest)", type='*') void setRestService(Endpoint ep, Map<String, String> props) throws Exception { this.restSvcUri = new URI(props.get("uri")); }

Friday, 29 March 13

Page 15: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Publishing an Endpoint

Guard can Optionally Publish an Endpoint Service

Just a Marker Interface with a URI Property, e.g.: mongodb://10.0.0.1:27017/

Use OSGi Remote Services (RSA) Discovery to Publish Across the Network

Friday, 29 March 13

Page 16: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

MongoClient

mongodb://10.0.0.1/

mongodb://10.0.0.2/

mongodb://10.0.0.3/

OSG

i Rem

ote

Serv

ices

(RSA

) Disc

over

y

Friday, 29 March 13

Page 17: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Consuming Endpoints

Guards can be Endpoint Consumers as Well

Example, Nginx

Friday, 29 March 13

Page 18: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Nginx LoadBalancer

WebServer

WebServer

WebServer

WebServer

request

forward

Friday, 29 March 13

Page 19: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

NginxProcessGuard

Friday, 29 March 13

Page 20: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Nginx

Guard Tracks Endpoints with a DS Multiple/Dynamic Reference

PackageType Rewrites Nginx Config and Sends a UNIX Signal

Friday, 29 March 13

Page 21: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Watchdog

Java Program that Sits Between OSGi and Native Package

Execs Native as a Child Process

Death of Watchdog => Death of Native Package

Heartbeat UDP Between OSGi and Watchdog

Friday, 29 March 13

Page 22: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Native ProcessOSGi Application Watchdogheartbeat exec

Friday, 29 March 13

Page 23: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Watchdog

Must Be as Simple As Possible!

Mustn’t Crash

Might Need Elevated Privileges (e.g. setuid)

Friday, 29 March 13

Page 24: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

DEMO...

RESTService

LibraryImpl

Library

MongoDBMongoGuard

Endpoint

Friday, 29 March 13

Page 25: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Tooling

Bndtools Highly Recommended

Project Templates Coming Soon...

It’s Just Plain Declarative Services!

Friday, 29 March 13

Page 26: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

Conclusion

Friday, 29 March 13

Page 27: Deploying Heterogeneous Artifacts to the Cloud with OSGi - Neil Bartlett

AvailabilityAPI is Open Source (EPL): github.com/bndtools/bndtools-rt/

Paremus implementation releasing later this week, stay tuned: http://blogs.paremus.com

Register interest: [email protected]

Examples: MongoDb, Mosquitto, Nginx, Derby, Custom Play App

In progress: RabbitMQ, Riak

Friday, 29 March 13