Buzzword-free RESTful

container-based

OSGi middleware

for NoSQL databases
Bertrand Delacrétaz
@bdelacretaz, grep.codeco...
this talk is about
INTEGRATIONso no details on Docker, Sling
or the NoSQL databases that
we use.
But it’s fun integrating ...
so
whatare we building?
Docker container
MongoDB

server(s)
Redis

server
Docker container
Docker container
uniclient
Apache

Sling
HTTP
front-end...
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
Apache Sling in Docker
# docker-compose....
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
Mongo & Redis in docker-compose.yml
mong...
Gentlemen,
start your
engines!
aka demo1

“the planets”
dem
o
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
The Sling HTTP processing pipeline
Resou...
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
Sling ResourceProvider service API
/** R...
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
PlanetsResourceProvider service
@Compone...
OSGi configs

drive services
that’s what we have so far
ResourceProvider

provides content
and
Didn’t we say
“noSQL” ?
aka demo2

“Mongo and Redis with static configs”
dem
o
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
How about dynamic DB mounts?
OSGi configs...
Mounty

Dynamic

is in town
aka demo3

“Dynamic mounts of new NoSQL containers”
dem
o
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
Docker events at the command line
2016-0...
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
docker-watcher script, simplified
# Extr...
NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble
Coda
Combining the dynamics of
container...
Próxima SlideShare
Cargando en…5
×

RESTful OSGi middleware for NoSQL databases with Docker

2.098 visualizaciones

Publicado el

Slides of my talk at Snowcamp 2016 in Grenoble, http://sched.co/5nB9 - code is at https://github.com/bdelacretaz/sling-nosql-frontend

Publicado en: Internet
  • Sé el primero en comentar

RESTful OSGi middleware for NoSQL databases with Docker

  1. 1. Buzzword-free RESTful
 container-based
 OSGi middleware
 for NoSQL databases Bertrand Delacrétaz @bdelacretaz, grep.codeconsult.ch Principal Scientist, Adobe Basel Apache Software Foundation Member and Director Thanks to Robert Munteanu, Adobe, for the collaboration on the demo.
 Snowcamp Grenoble, January 2016
 slides revision 2016-01-21 I hope you still have some air in your lungs after reading this title.
  2. 2. this talk is about INTEGRATIONso no details on Docker, Sling or the NoSQL databases that we use. But it’s fun integrating all those things. warning
  3. 3. so whatare we building?
  4. 4. Docker container MongoDB
 server(s) Redis
 server Docker container Docker container uniclient Apache
 Sling HTTP front-end Mongo
 ResourceProvider Redis
 ResourceProvider Planets
 ResourceProvider OSGi framework Docker container OSGiconfigs HTTP
 /
 JSON dbwatcher Docker container Docker events Activation of
 ResourceProvider for new DB containers Command line for testing(It’s at https://github.com/bdelacretaz/sling-nosql-frontend )
  5. 5. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble Apache Sling in Docker # docker-compose.yml snippet sling: image: sling-nosql-demo:latest container_name: sling ports: - "8080:8080" # Dockerfile FROM java:8 COPY sling.jar /opt/sling/sling.jar WORKDIR /opt/sling/ EXPOSE 8080 ENV JAVA_OPTS -Xmx512m CMD exec java $JAVA_OPTS -jar sling.jar
  6. 6. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble Mongo & Redis in docker-compose.yml mongo: image: mongo:3.0 container_name: mongo ports: - "27017:27017" redis: image: redis:3.0.6 container_name: redis ports: - "6379:6379"
  7. 7. Gentlemen, start your engines! aka demo1
 “the planets” dem o
  8. 8. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble The Sling HTTP processing pipeline Resource Main Servlet ResourceResolver ResourceProvider #1 ResourceProvider #2 ResourceProvider #N ServletResolver Script or Servlet 1 2 3 4 5 6 7 HTTP
 request HTTP
 response ResourceProviders are
 simple OSGi services (plugins), each
 mounted on a subpath like /nosql/mongo Resource has a path, 
 type and properties Script or servlet is selected based on resource type, HTTP request method, extension and selectors. GET http://example.com/products/bottle.print.a4.html
  9. 9. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble Sling ResourceProvider service API /** Register such an OSGi service with 
 * a “provider.roots” property to * mount it in the Sling resource tree */ interface ResourceProvider { Resource getResource(
 ResourceResolver resourceResolver, 
 String path); Iterator<Resource> listChildren( Resource parent); } Slightly simplified here
  10. 10. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble PlanetsResourceProvider service @Component( metatype=true, configurationFactory = true, policy = ConfigurationPolicy.REQUIRE ) @Service @Properties({ @Property(name=ResourceProvider.ROOTS) }) public class PlanetsResourceProvider implements ResourceProvider { … Creating an OSGi config creates such a service
  11. 11. OSGi configs
 drive services that’s what we have so far ResourceProvider
 provides content and
  12. 12. Didn’t we say “noSQL” ? aka demo2
 “Mongo and Redis with static configs” dem o
  13. 13. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble How about dynamic DB mounts? OSGi configsdbwatcher Docker container Docker events Activation of
 ResourceProvider for new DB containers ResourceProviders Goal: Starting a NoSQL Docker container 
 mounts the DB in Sling. Scenario: Get Docker “container start” event. Does the container have our “DB type label”? If yes, get more info: DB type, IP address, etc And inject an OSGi config in Sling, to instantiate a suitable ResourceProvider
  14. 14. Mounty
 Dynamic
 is in town aka demo3
 “Dynamic mounts of new NoSQL containers” dem o
  15. 15. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble Docker events at the command line 2016-01-20T14:46:53.604770204Z fe31d475: 
 (from busybox) create 2016-01-20T14:46:53.679080597Z fe31d475: 
 (from busybox) attach 2016-01-20T14:46:53.707154497Z fe31d475: 
 (from busybox) start 2016-01-20T14:46:53.859539615Z fe31d475: 
 (from busybox) resize 2016-01-20T14:46:53.970689118Z fe31d475: 
 (from busybox) die
  16. 16. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble docker-watcher script, simplified # Extract container ID from docker start event # And use docker inspect to retrieve labels, IP etc. from container docker events -f event=start | sed -u 's/[^ ]*//' | while read ID do docker inspect $ID > $TMPFILE DBTYPE=$(jq '.[0].Config.Labels["ch.x42.slingdb.type"]' < $TMPFILE) HOST=$(jq .[0].NetworkSettings.Networks.docker.IPAddress < $TMPFILE) PORT=$(jq '.[0].Config.Labels["ch.x42.slingdb.port"]' < $TMPFILE) NAME=$(jq .[0].Name < $TMPFILE | sed 's/[^a-zA-Z0-9_]//g') # create_mongo_config.sh for example injects an OSGi config # in Sling for the Mongo ResourceProvider, via HTTP CMD="create_${DBTYPE}_config.sh $HOST $PORT /nosql/$NAME" echo "Container $ID started, running $CMD" ${MYFOLDER}/${CMD} < /dev/null done IF U CN RD THS YU HV GD EYS
  17. 17. NoSQL DB frontends with Docker and Sling - @bdelacretaz - Snowcamp 2016, Grenoble Coda Combining the dynamics of containers with configuration- driven OSGi ResourceProvider services allows us to create a dynamic system. Apache Sling provides a nice way to aggregate data from very different data sources. Sling’s rendering features can be used to reformat or present the results. NoSQL
 DBs Apache Sling OSGi configs Docker events Code: https://github.com/bdelacretaz/sling-nosql-frontend See also: http://sling.apache.org I’m @bdelacretaz - thanks!

×