Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to Usergrid - ApacheCon EU 2014

11,041 views

Published on

Whether you are building a mobile app or a web app, Apache Usergrid (incubating) can provide you with a complete backend that supports authentication, persistence and social features like activities and followers all via a comprehensive REST API — and backed by Cassandra, giving you linear scalability. All that, and Usergrid is open source too.

This session will explain how you can use Usergrid to provide a back-end for your application. We’ll start with an overview of Usergrid features, then explore in depth how to authenticate users, store data and query data with the REST API provided by a Usergrid server. We’ll develop a simple HTML5 app and package it as a native mobile app via Apache Cordova. We'll also cover how to run Usergrid locally for development and testing.

Published in: Software
  • Great insight into Usergrid
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Introduction to Usergrid - ApacheCon EU 2014

  1. 1. Introduction to Apache Usergrid: The BaaS built on Cassandra Dave Johnson Apigee
  2. 2. Agenda » Overview: why Usergrid » Exploring the Usergrid API » Creating an app with Usergrid » Running & Deploying Usergrid » Q & A © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 2
  3. 3. Usergrid Overview
  4. 4. Why Usergrid? » Don’t build a server PHP Ruby Java MySQL Node PaaS Services in the “cloud” App Server Cloud © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 4
  5. 5. Why Usergrid? » Focus on building your app Services in the “cloud” & App Cloud © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 5
  6. 6. What is Usergrid? » Complete Back-end as a Service (BaaS) » REST API, backed by Cassandra » Three parts: » Web application, provides REST API » Comprehensive Management Portal » Client SDKs » iOS, Android, JavaScript, Node, Ruby, Java, Perl, .Net, Command-line, … © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 6
  7. 7. What is Usergrid? » Core services you need to build apps: » JSON object indexing & query » Geo-location & geo-queries » Connections & Collections » Users, Groups, Social Graph » Authentication, Roles & Permissions » Asset & File Management » Soon: Push Notifications © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 7
  8. 8. Main limitation » You cannot add server-side logic » If you need server-side logic: App Cloud Your server-side logic Services in the “cloud” & © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 8
  9. 9. An Apache Incubator Project © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 9
  10. 10. Exploring the Usergrid API 8
  11. 11. Usergrid REST API » JSON over HTTP » POST, GET, PUT and DELETE JSON Entities » Entities have UUID, Name, Type » Entities have name/value properties » All Entity properties are indexed » SQL-like syntax for Entity queries © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 11
  12. 12. Usergrid REST API »Usergrid is multi-tenant »Multiple organizations »Each organization has multiple apps »Each application has root URL like this »http:// host/${org}/${app} » Entities exist in Collections »http:// host/${org}/${app}/${collection} © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 12
  13. 13. Usergrid REST API » You can define Collections of custom Entities with any properties you want » Plus special “built-in” Entity Collections: » http:// host/${org}/${app}/users » http:// host/${org}/${app}/groups » http:// host/${org}/${app}/roles » http:// host/${org}/${app}/activities » http:// host/${org}/${app}/assets © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 13
  14. 14. Connections » No joins, but Entities can have Connections to other Entities » For example, to get all Entities that Dave is connected to via a connection of type “pets” » http:// host/${org}/${app}/users/dave/pets © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 14
  15. 15. Collecting Cats » Demo the Portal » Create User Dave with Default Role » Create Cats Collection » Setup “Dave has Cats” Connections © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 15
  16. 16. Creating an app with Usergrid 18
  17. 17. Let’s create a checkin app » A simple checkin app to demonstrate Usergrid features: » Login & signup » Roles & Permissions » Following, Followers and Checkins » Usergrid JavaScript SDK » Built with jQueryMobile & Cordova © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 17
  18. 18. Define the data model » Usergrid provides the basic REST API » You must decide: » Entity Types & Properties » Entity Connections » Users Roles & Permissions © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 18
  19. 19. Entities & Connections » Entity Collections » Users » Checkins » Entity Connections » Users Follow Users » Users Have Checkins © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 19
  20. 20. User Role: Guest » User who has not signed up yet » Permissions User with Guest Role: GET POST PUT DELETE /users/*  ✅   /token  ✅   » Guest user POSTs to register or login » Usergrid takes care of account activation © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 20
  21. 21. User Role: Default » Permissions for User with Default Role: GET POST PUT DELETE /users/${user}/** ✅ ✅ ✅ ✅ /activities/* ✅    /users/* ✅    /users/${user} ✅  ✅  © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 21
  22. 22. App setup in the Portal » Quick demo » Take a look at Roles & Permissions » Ensure they are setup right © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 22
  23. 23. Adding Login & Signup 32
  24. 24. Getting started » Pre-requisites: » Usergrid JavaScript SDK » jQuery Mobile » Apache Cordova » Your favorite dev environment © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 24
  25. 25. jQueryMobile © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 25
  26. 26. Apache Cordova © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 26
  27. 27. Get setup in an IDE © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 27
  28. 28. Login with password » With Javascript SDK var client = new Usergrid.Client({ appName: 'checkin1', orgName: 'test-organization', URI: 'http://10.1.1.161:8080' }); client.login(username, password, function(err, res, entity) { if (err) { // inform user of error } else { // change to View Checkins page } }); © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 28
  29. 29. Login in with password » Without Javascript SDK » POST a JSON object to /token » For example with curl: curl -X POST -i -H "Content-Type: application/json" "http://host/test-org/test-app/token" -d '{"grant_type":"password","username":"dav e","password":"XXX"}' © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 29
  30. 30. Get setup in an IDE » Demo time » Create Cordova project in IDE » Add Login & Registration Page © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 30
  31. 31. What we’ll add add in checkinv1 » index.html » $(document).on(“mobileinit”, … » login-page » signup-page » checkin-list-page (a placeholder) » index.js » login() » logout() » signup() © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 31
  32. 32. Adding Checkins 4
  33. 33. Checkins as Activities » Usergrid supports notion of Activity » And supports a “Following” Connection » Users post Activities to their own Collection » POST /users/${user}/activities » Users can see Activities those they follow » GET /activities © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 33
  34. 34. JavaScript SDK - create checkin var data = { type: “checkin", content: content, verb: “post", actor: { username: user.get(“username") } }; client.createUserActivity(user.get("username"), data, function( err, response, activity ) { if (err) { // alert user of error } else { // send user back to View Checkins page } }); © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 34
  35. 35. What we’ll add in checkinv2 » index.html » checkin-list—page » add-page » view-checkin—page » index.js » buildCheckinList() » checkin() » showCheckinPage() © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 35
  36. 36. Add Follower relationships 36
  37. 37. Usergrid Social Graph » Usergrid provides Social Graph features including Following and Groups » Fred can follow Barney: » POST /users/fred/following/barney » Fred can see his followers: » GET /users/fred/followers © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 37
  38. 38. JavaScript SDK - follow user var target = // user to be followed var options = { method: 'POST', endpoint: ‘/users/' + me + '/following/users/' + target }; client.request(options, function (err, data) { if (err) { alert("Unable to follow user " + target); } else { alert("Followed user " + target); } }); © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 38
  39. 39. What we’ll add in checkinv3 » index.html » user-list-page » view-user—page » index.js » buildUserList() » showUserPage() » followUser() © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 39
  40. 40. Package & run your app 40
  41. 41. Apache Cordova » Demo time » Use Cordova to launch the app in iOS © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 41
  42. 42. What we’ll add in checkinv4 » index.js » deviceReady() » doWhenBothFrameworksLoaded() © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 42
  43. 43. Running & Deploying Usergrid
  44. 44. Developing with Usergrid » Three ways to run Usergrid locally: » All-in-one Usergrid Launcher » Install Tomcat, Cassandra and Usergrid » Start Usergrid instance via Vagrant » Or find a BaaS provider that runs Usergrid: » e.g. Apigee’s API BaaS is free to use © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 44
  45. 45. Usergrid deployment options » Do it yourself with Tomcat, Cassandra and Puppet, Chef, etc. » Do it yourself on AWS via Usergrid AWSCluster » AWS Cloud Formation Template » Plus supporting Bash and Groovy scripts » Let somebody else run it for you… » Hint hint  © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 45
  46. 46. Deployment Architecture UG1 Mobile Cassandra Cluster Load Balancer Web Tomcats (shared nothing) © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 46
  47. 47. Deployment Architecture UG2 Mobile Cassandra Cluster Load Balancer ElasticSearch Cluster Web Tomcats (shared nothing) Distributed Queue © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 47
  48. 48. Wrapping up…
  49. 49. Questions? » Apache Usergrid » http://usergrid.incubator.apache.org » http://twitter.com/usergrid » Apigee API BaaS » http://goo.gl/zcjRxC » Dave Johnson » https://github.com/snoopdave/ » usergrid-mobile (the example code for the presentation) » usergrid-vagrant (scripts to start Usergrid in a VM) » http://twitter.com/snoopdave © 2013 Apigee Confidential © Copyright Apigee T–h Aisl lw Roirgkh ists l iRceensseerdv uendder a Creative Commons Attribution-ShareAlike 4.0 International License. 49
  50. 50. Thank you

×