MongoUK 2012


Published on

Monica Wilkinson and Andy Piper present how to use Cloud Foundry and how to deploy an Activity Stream Engine on Cloud Foundry written in Node.js using MongoDB and Redis on the back end.

Published in: Technology, Education
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

MongoUK 2012

  1. 1. Activity Streams on Cloud Foundry with MongoDB and Node.js MongoUK - 2012 By Monica Wilkinson and Andy Piper © 2012 VMware, Inc. All rights reservedWednesday, June 20, 12
  2. 2. Andy Piper social bridgebuilder, techie Developer Advocate @ Cloud Foundry 15 years in enterprise middleware & messaging social web enthusiast OSS supporter / contributor excited by “what’s next”, Internet of Things, etc. @andypiper CONFIDENTIAL 2Wednesday, June 20, 12
  3. 3. About Monica Wilkinson Loves the web and data portability. Developer Advocate @ Cloud Foundry 12 years development experience. Last 5 years in Social Web Open Web Standards Advocate Contact Me: @ciberch CONFIDENTIAL 3Wednesday, June 20, 12
  4. 4. Agenda 1.Overview of Cloud Foundry 2.What is Activity Streams ? 3.Building an Activity Stream Engine CONFIDENTIAL 4Wednesday, June 20, 12
  5. 5. About Cloud Foundry The first Open PaaS Multi(n) Languages, Frameworks, Services & Clouds Open Source CONFIDENTIAL 5Wednesday, June 20, 12
  6. 6. Traditional web app architecture ! Browser client Web Application ! Monolithic WAR / other deployment artefact StoreFront ! RDBMS AccountingService MySQL Desktop Database Apache Browser InventoryService “easy” to... ShippingService ! develop ! test Container (e.g. Tomcat) ! deploy ! scale ...apart from: provisioning, setup, need to replicate, shard, scale to massive numbers of mobile clients, provide polyglot support, run multiple dev teams, collaborate... CONFIDENTIAL 6Wednesday, June 20, 12
  7. 7. Need to handle massive loads and the data explosion Scalable architectures! ! Application tier: •Replicated/clustered servers •Modular so that components can be scaled differently •Asynchronous architecture - communication via a message broker ! Database tier: •Replication •Sharding •Polyglot persistence: Relational, NoSQL, NewSQL databases CONFIDENTIAL 7Wednesday, June 20, 12
  8. 8. Modern application architecture billing web applicationDesktop Browser Accounting Service StoreUI Native Mobile NodeJS NodeJS inventory web application Application front-end MySQL StoreUI application StoreUI InventoryService HTML5 mobile application StoreUI Redis shipping web application RabbitMQ Mongo ShippingService CONFIDENTIAL 8Wednesday, June 20, 12
  9. 9. Platform-as-a-Service is the solution Deployment Services Easy deployment SQL databases Application management NoSQL databases + Easy scaling up and down Message Broker CONFIDENTIAL 9Wednesday, June 20, 12
  10. 10. The Open Platform as a Service “Deploy and scale applications in seconds, without locking yourself into a single cloud or vendor” , xible n, Fle Ope e ple, l Si m Sc alab CONFIDENTIAL 10Wednesday, June 20, 12
  11. 11. Cloud Foundry open PaaS - Choice of clouds OSS community Private( Ap I) Data Services CP Clouds( pli vFabric ( ca ce Postgres tio r fa nS e Int er Public v ic r ide eI Msg Services ov Clouds nt e Pr r fa vFabric RabbitMQTM d ou ce Cl Micro Other Services Clouds to h: d eploy c) ! bos et N EW PIs (AWS n at e C Additional partner services … alter CONFIDENTIALWednesday, June 20, 12
  12. 12. Multi-cloud flexibility is critical to long-term success ! Make use of both public and private clouds without rewriting your applications ! Protect against vendor lock-in ! Meet different compliance and geographical needs ! Accommodate peak loads while optimizing costs ! Manage your growth and changing needs over time CONFIDENTIAL 12Wednesday, June 20, 12
  13. 13. Getting Started on Cloud Foundry CONFIDENTIAL 13Wednesday, June 20, 12
  14. 14. Register! optional promo CONFIDENTIAL 14Wednesday, June 20, 12
  15. 15. Ways to use Cloud Foundry command line... IDE plugin... toolchain plugin... Cloud IDEs CONFIDENTIAL 15Wednesday, June 20, 12
  16. 16. Example vmc commands $"gem"install"vmc $"vmc"target"<any"cloud> $"vmc"login"<credentials> $"vmc"push"<my7app> " "">"bind"services?"Yes $"vmc"update"<my7app> $"vmc"instances"<my7app>"+100" CONFIDENTIAL 16Wednesday, June 20, 12
  17. 17. Logging into$"vmc"target"api.cloudfoundry.comSuccessfully"targeted"to"""""""""[]$"vmc"loginAttempting"login"to"""[]Email:"apiper@vmware.comPassword:"********Successfully"logged"into"""[] CONFIDENTIAL 17Wednesday, June 20, 12
  18. 18. Cloud Foundry Integration plugin for Eclipse CONFIDENTIAL 18Wednesday, June 20, 12
  19. 19. What is Activity Streams ? CONFIDENTIAL 19Wednesday, June 20, 12
  20. 20. ! Activity Streams is a simple open specification used to describe social actions around the web. ! The goal of Activity Streams is data portability ! Some publishers of Activity Streams: Socialcast, MySpace, Facebook and G+ ! The default format is JSON but Atom is also supported. The JSON format was added after we saw some initial limitations with JSON ! Core concepts are: Actor, Verb, Object and Target CONFIDENTIAL 20Wednesday, June 20, 12
  21. 21. Actor -> Monica Verb -> Pinned(Bookmarked) Object -> Rosa Parks’ Bio Page Target -> Female Leaders Board Source -> Pinterest Published -> MLK Day 2012 © 2012 VMware, Inc. All rights reservedWednesday, June 20, 12
  22. 22. With Timeline Actions Posting with a richer protocol like Activity Streams allows you to do: - Richer messages and links - Aggregate - Assign relevance © 2012 VMware, Inc. All rights reservedWednesday, June 20, 12
  23. 23. Example in JSON CONFIDENTIAL 23Wednesday, June 20, 12
  24. 24. What is an Activity Stream Engine ? ! An activity stream engine allows you to publish events and subscribe to events. ! Many activity stream engines support aggregation of events via Streams. ! Many activity stream engines support fanning out activities to subscribers. CONFIDENTIAL 24Wednesday, June 20, 12
  25. 25. So how did we build this Activity Stream Engine on Cloud Foundry ? CONFIDENTIAL 25Wednesday, June 20, 12
  26. 26. Building an Activity Streams Engine CONFIDENTIAL 26Wednesday, June 20, 12
  27. 27. What should we use to store Activities ?Key-Value Column Document Graph Redis, Cassandra, MongoDB Neo4J Riak HBase CONFIDENTIAL 27Wednesday, June 20, 12
  28. 28. Mongo DB schema-less documents are perfect for ActivitiesKey-Value Column Document Graph MongoDB (so easy) CONFIDENTIAL 28Wednesday, June 20, 12
  29. 29. About MongoDB 1. No-SQL database development : { 2. Stores JSON-style tools: many, documents with language_support: superb, embedded documents = agility: high 3. Horizontally scalable }, production: { 4. Full Indexing Support speed: fast 5. Open Source so great fault_tolerance: true ORMs and drivers. scalability: high CONFIDENTIAL 29Wednesday, June 20, 12
  30. 30. Step 1- Build the persistence Model var MediaLinkHash = {         duration: Number,         height: Number,         width: Number,         url: String     };     var ActivityObjectHash = {        id: {type: String},        image: MediaLinkHash,        displayName: {type: String},        summary: {type: String},        content: {type: String},        url: {type:String},        author: {type: ObjectId, ref: activityObject},        published: {type: Date, default:},        updated: {type: Date, default:},        objectType: {type: String},        attachments: [{type: ObjectId, ref: activityObject}],        upstreamDuplicates: [String],        downstreamDuplicates: [String]     };     var ActivityObjectSchema = new Schema(ActivityObjectHash)     this.ActivityObject = mongoose.model(activityObject, ActivityObjectSchema); CONFIDENTIAL 30Wednesday, June 20, 12
  31. 31.     var ActivitySchema = new Schema({        id: {type: String},        verb: {type: String},        url: {type: String},        title: {type: String},        content: {type: String},        icon: MediaLinkHash,        object: ActivityObjectHash,        actor: ActivityObjectHash,        target: {type: ObjectId, ref: activityObject},        published: { type: Date, default:},        updated: { type: Date, default:},        inReplyTo: {type: ObjectId, ref: activity}    });    this.Activity = mongoose.model(activity, ActivitySchema);    return this;}; CONFIDENTIAL 31Wednesday, June 20, 12
  32. 32. Step 2 - Expose helpers for the queries ! The most important is to be able to list the activities in descending order by published time. ! It is also important to hydrate any objects for which we have references ! With Mongoose you can do:  ! this.getActivityStream = function(n, fx) { Activity.find().sort(published, descending).limit(n).populate(target).run (fx);     } ! CONFIDENTIAL 32Wednesday, June 20, 12
  33. 33. How do we make our engine faster and more scalable ? ! Add support for PubSub ! In a PubSub model as soon as an event is published it gets sent to all the subscribers. ! The Publisher doesn’t know who the subscribers are, it simply knows where to publish. ! Redis has nice support for Pub Sub pubsub CONFIDENTIAL 33Wednesday, June 20, 12
  34. 34. Using ! Server Side: • Subscribe to a Stream • When there is a new event send it to the client as JSON ! Client Side • Add support to publish activities to the Stream • Change the client rendering to use ! Benefits • Richer messaging • Activity Syndication CONFIDENTIAL 34Wednesday, June 20, 12
  35. 35. Demo Part 1: App 1 and walkthrough 2012/05/17/node-activity-streams-app-1/ Part 2: App 2 and walkthrough 2012/06/05/node-activity-streams-app-2/ Part 3: © 2012 VMware, Inc. All rights reservedWednesday, June 20, 12
  36. 36. Thank You - Questions ? Cloud Foundry Activity Streams Libraries are at: Questions: @cloudfoundry, @ciberch or @andypiper © 2012 VMware, Inc. All rights reservedWednesday, June 20, 12
  37. 37. Resources Primary Site: Open Source Site: Twitter: @cloudfoundry or #cloudfoundry Blog: FB: Documentation: Full “bootcamp” presentation: © 2012 VMware, Inc. All rights reservedWednesday, June 20, 12