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.

Orion Context Broker Exercises

3,835 views

Published on

This is a complement of http://www.slideshare.net/fermingalan/fiware-managing-context-information-at-large-scale, including a set of basic and advanced exercises with Orion to be done by FIWARE Deverlopers Week participants.

Published in: Education
  • Be the first to comment

Orion Context Broker Exercises

  1. 1. Orion Context Broker Exercises (Basic) Contact twitter @fermingalan @LeandroJGuillen Contact email fermin.galanmarquez@telefonica.com leandro.guillen@imdea.org daniel.moranjimenez@telefonica.com
  2. 2. Outline •CB-1. Deploy your own Orion instance •CB-2. Create entities using standard ops •CB-3. Query entities using standard ops •CB-4. Update entity using standard ops •CB-5. Update two entities using standard ops •CB-6. Update two attributes same entities using standard ops •CB-7. Create entities using conv ops •CB-8. Query entities using conv ops •CB-9. Update entity using conv ops •CB-10. Browsing entity types •CB-11. Basic subscription/notifications •CB-12. Advanced subscription/notification •CB-13. Expert subscription/notification •CB-14. Get X-Auth-Token •CB-15. Browse types at Orion Global instance •CB-16. Query entities at Orion Global instance •CB-17. Subscribe to public information 2
  3. 3. CB-1. Deploy your own Orion instance •Prerequisite –To have a FIWARE Lab account •Steps –Go to Orion catalogue page –Follow the steps in “Deploying a dedicated GE instance based on an image” in the “Creating Instances tab” –Check Orion is working using the “/version” operation from your local computer •Hints –Image should be orion-psb-image-R4.2, installed in all FIWARE Lab regions. If you don’t find it ask us –Minimum recommended size: m1.small –Remember to set the security group properly (typically to port 1026) Easy
  4. 4. CB-1(b). Deploy your own Orion instance •Alternative in the case you already have a VM in FIWARE Lab and don’t want to deploy another one •Prerequisite –CentOS 6.x VM •Steps –Set FIWARE yum repository –Install Context Broker and MongoDB using yum •Hints –See Orion Admin Guide –Remember to set the security group properly (typically to port 1026) Medium
  5. 5. CB-1(c). Deploy your own Orion instance •Alternative, you can install in your local computer using a pre-created VirtualBox image •Prerequisite –VirtualBox installed in your computer •Steps –Download from bit.ly/fiware-orion-vbox –Install the image in your VirtualBox Easy
  6. 6. CB-1(d). Deploy your own Orion instance •You can also deploy using Docker •Prerequisite –Docker installed in your computer –(Optional) Docker-compose •Steps –Follow the instructions provided in this link. Medium
  7. 7. CB-2. Create entities using standard ops •Prerequisites –Exercise CB-1 •Steps –Create the following entities in your Orion instance •See table in next slide •Hints –Orion User Manual section Entity Creation Easy
  8. 8. CB-2. Create entities using standard ops Easy Entity Entity Type Bedroom1 Room Bedroom2 Room Kitchen Room Frontdoor Door Backdoor Door Entity Type Attr. Name Attr. Type Example value Room Temperature float 27.8 Presence boolean true Status string OK Door Locked boolean false Closed boolean false
  9. 9. CB-3. Query entities using standard ops •Prerequisites –Exercise CB-2 •Steps –Write a program (or web/mobile application) that does the following queries and prints the result •Obtain all attributes of Bedroom1 entity •Obtain only the Temperature attribute of Kitchen entity •Obtain all attributes of Kitchen and Bedroom2 entities in one query •Obtain all attributes of entities that match the pattern Bedroom.* •Find out whether the doors are closed using the pattern .*door and the Closed attribute –Run and test your program/application •Hints –Orion User Manual section Query Context. Easy
  10. 10. CB-4. Update entity using standard ops •Prerequisites –Exercise CB-2 •Steps –Write a program (or web/mobile application) that •Asks for user input (one value) •Updates Locked attribute of Frontdoor entity using that input •Queries the entity and check the result –Run and test your program/application •Hints –Orion User Manual section Update Context. Easy
  11. 11. CB-5. Update two entities using standard ops •Prerequisites –Exercise CB-2 •Steps –Write a program (or web/mobile application) that •Asks for user input (two values) •Updates the Temperature attribute of Beedroom1 and Bedroom2 entities using that input with a single update operation •Queries the entities and check the result –Run and test your program/application •Hints –Orion User Manual sections Query Context and Update Context Medium
  12. 12. CB-6. Update two attributes same entities using standard ops •Prerequisites –Exercise CB-2 •Steps –Write a program (or web/mobile application) that •Asks for user input (two values) •Updates the Locked and Closed attributes of Frontdoor entity using that input with a single update operation •Queries the entities and check the result –Run and test your program/application •Hints –Orion User Manual sections Query Context and Update Context Medium
  13. 13. CB-7. Create entities using conv ops •Prerequisites –Exercise CB-1 •Steps –Create the following entities in your Orion instance •See table in next slide •Hints –Similar to exercise CB-2 in the standard ops set –Orion User Manual section Convenience Entity Creation. Easy
  14. 14. CB-7. Create entities using conv ops Easy Entity Entity Type Garage Room Bathroom Room Light1 Light Light2 Light Light3 Light Entity Type Attr. Name Attr. Type Example value Room Temperature float 27.8 Presence boolean true Status string OK Light Intensity Percent 0.25
  15. 15. CB-8. Query entities using conv ops •Prerequisites –Exercise CB-7 •Steps –Write a program that does the following queries using convenience operations and print the result •Obtain all attributes of the Garage entity •Find out whether there is anyone in the Bathroom entity •Obtain all entities created so far •Obtain all entities of type Room •Obtain the temperature attribute of all entities of type Room –Run and test your program/application •Hints –Similar to exercise CB-3 in the standard ops set –Orion User Manual section Convenience Query Context –To get all entities of a given type, you can use the “contextEntityType” resource Easy
  16. 16. CB-9. Update entity using conv ops •Prerequisites –Exercise CB-7 •Steps –Write a program (or web/mobile application) that •Asks for user input (one value) •Updates Intensity attribute of Light1 entity using that input using a convenience operation •Queries the entity and check the result –Run and test your program/application •Hints –Similar to exercise CB-4 in the std ops set –Orion User Manual sections Convenience Query Context and Getting all entities. Easy
  17. 17. CB-10. Browsing entity types •Prerequisites –Exercise CB-7 •Steps –Write a program (or web/mobile application) that •Lists all entity types •Provides detailed information of type Door –Run and test your program/application •Hints –Orion User Manual section Browsing all types and detailed information on a type. Easy
  18. 18. CB-11. Basic subscription/notifications •Prerequisites –Exercise CB-2 •Steps –Write a program that •Starts a REST server to receive notifications from Orion •Prints the value of the Temperature attribute of Bedroom1 entity each time a notification is received –Subscribe your program to changes in the Temperature attribute of Bedroom1 entity –Update the Temperature attribute of Bedroom1 entity and check that your program prints the updated value •Hints –Orion User Manual section Context Subscriptions (especially subsection on ONCHANGE) –Your program has to run in a machine with network access to Orion’s to be able to send notifications Medium
  19. 19. CB-12. Advanced subscription/notification •Prerequisites –Exercise CB-11 •Steps –Write a program that •Starts a REST server to receive notifications from Orion •If the Temperature attribute of Kitchen entity is equal or greater than 30 then update the Status attribute of Kitchen entity with string TEMP_ALARM •If the Temperature attribute of Kitchen entity is lower than 30 then update the Status attribute of Kitchen entity with string OK –Subscribe your program to changes in the Temperature attribute of Kitchen entity –Update the Temperature attribute of Kitchen entity with 20, 30, 32, 25, etc. and checks that the Status attribute is modified accordingly •Hints –This exercises combines subscriptions/notifications with updates –Modify the program already developed in Exercise CB-11 –Check exercise CB-4 and/or CB-9 about updating entities Hard
  20. 20. CB-13. Expert subscription/notification •Prerequisites –Exercise CB-11 •Steps –Write a program that •Starts a REST server to receive notifications from Orion •If the Temperature attribute of Kitchen entity is greater than 30 then update the Intensity attribute of Ligth3 entity with the current value of Intensity plus 0.10 (with a maximum value of 1.0) –Subscribe your program to changes in the Temperature attribute of Kitchen entity –Update the Temperature attribute of Kitchen entity with 20, 30, 32, 25, etc. and checks that the Intensity attribute of Ligth3 is modified accordingly •Hints –This exercises combines subscriptions/notifications with queries and updates –Modify the program already developed in Exercise CB-11 –To get the current value of Intensity attribute of Light3 your program has to do a query operation. Check exercise CB-3 or CB-8 about querying entities –Check exercise CB-4 and/or CB-9 about updating entities Hard
  21. 21. CB-14. Get X-Auth-Token •Prerequisites: –To have a FIWARE Lab account •Steps –Use your login/password to get the token •Hints –Use the script described and available at Orion Quick Start. Easy
  22. 22. CB-15. Browse types at Orion Global instance •Prerequisites: –Auth token obtained in exercise CB-14 •Steps –Write a program (or web/mobile application) that •Lists all entity types •Provides detailed information of type Taxi –Run and test your program/application •Hints –Orion global instance runs at orion.lab.fiware.org port 1026 –Similar to exercise CB-10 but adding the “X-Auth-Token” HTTP header (set with the auth token) Easy
  23. 23. CB-16. Query entities at Orion Global instance •Prerequisites: –Auth token obtained in exercise CB-14 •Steps –Write a program (or web/mobile application) that does the following queries and print the result •All the attribute of entity MeteoLo (type MeteoLo) •All the entities of type Node •Attribute batteryCharge of entity OUTSMART.NODE_3506 (type Node) •All the entities of type Taxi which id ends in 7 –Run and test your program/application •Hints –Orion global instance runs at orion.lab.fiware.org port 1026 –Similar to exercise CB-3 and/or CB-8 but adding the “X-Auth-Token” HTTP header (set with the auth token) Easy
  24. 24. CB-17. Subscribe to public information •Prerequisites –Auth token obtained in exercise CB-14 •Steps –Write a program that •Starts a REST server to receive notifications from Orion •Prints all the attributes of entities of type santander:device each time a notification is received –Subscribe your program to all attributes of every entity of type santander:device each time TimeInstant attribute changes using throttling of 10 seconds –Check that entities information arrives each 10 seconds and you program prints it •Hints –Orion global instance runs at orion.lab.fiware.org port 1026 –Orion User Manual section Context Subscriptions –Your program has to run in a VM/machine reachable from orion.lab.fiware.org. The port you use in the reference field in the subscription has to be open in your security group –Differently from exercises CB-11/12/13, you don’t need to update the subscribed entities, as santander:devices entities are automatically update by IoT devices interacting with the Orion global instance Hard
  25. 25. Orion Context Broker Exercises (Advanced) Contact twitter @fermingalan Contact email fermin.galanmarquez@telefonica.com leandro.guillen@imdea.org daniel.moranjimenez@telefonica.com
  26. 26. Outline •CB-18. Pagination •CB-19. Geolocation (factory) •CB-20. Geolocation (cities) •CB-21. Compound attributes •CB-22. Query entities with compound attributes •CB-23. Update entities with compound attributes •CB-24. Custom metadata •CB-25. Dynamic attributes addition/deletion •CB-26. Multitenancy •CB-27. Service Paths (create) •CB-28. Service Paths (query) •CB-29. Service Paths (update) 26
  27. 27. CB-18. Pagination •Prerequisites –Access to Orion instance running in 130.206.81.86 port 1026 •Steps –Check how many entities of type Sensor are stored in that Orion instance –Write a program (or web/mobile application) that •Asks for a limit and a page number •Returns the name IDs the entities of type Sensor in the corresponding page –Run and test your program/application •Hints –Orion User Manual section Pagination Medium
  28. 28. CB-19. Geolocation (factory) •Prerequisites –Access to Orion instance running in 130.206.81.86 port 1026 •Steps –Write a program (or web/mobile application) that •Gets all existing types •Gets all entities of each type in areas Red, Green and Blue (see next slide), printing entity IDs and their attributes which their values –Run and test your program/application •Hints –Orion User Manual section Geolocation Medium
  29. 29. 29 -33.596620, -70.666825 -33.607682, -70.670730 -33.6100089, -70.643231 -33.599194, -70.640200 CB-19. Geolocation (factory) Medium
  30. 30. 30 -33.596620, -70.666825 -33.607682, -70.670730 -33.6100089, -70.643231 -33.599194, -70.640200 -33.603458, -70.652788 -33.606123, -70.653790 -33.604231, -70.646032 -33.607108, -70.646781 -33.602391, -70.661781 x 200m CB-19. Geolocation (factory) Medium
  31. 31. CB-20. Geolocation (cities) •Prerequisites –Exercise CB-1 •Steps –Chose 2 European countries (let’s name them A and B) –Chose 3 cities in each country –Create one entity for each city, in the following way •Entity ID: the name of the city •Entity type: “City” •The attribute “location” represent the city location (coordinates) –Write a program (or web/mobile application) that •Does a query to get all cities •Does a query to get all cities in country A •Does a query to get all cities in country B –Run and test your program/application •Hints –Orion User Manual section Geolocation –This page may help to get city coordinates: http://www.gps- coordinates.net/ –Use polygons to model countries (the model doesn’t need to be very precise). Google Maps may help (http://maps.google.com/) Medium
  32. 32. CB-21. Compound attributes •Prerequisites –Exercise CB-1 •Steps –Create the following entities in your Orion instance •See table in next slide •Hints –Orion User Manual section Structure Attribute Values Medium
  33. 33. CB-21. Compound attributes Entity Type Attr. Name Attr. Type Example value Character Name string Fooy Hitpoints integer 110 Class string Barbarian Abilities compound { "STR": "2", "DEX": "4", "CON": "3", "INT": "1", "WIS": "1", "CHA": "2" } Inventory compound { "weapons": [ "sword", "dagger" ], "potions": { "life": "1", "mana": "0" }, "other": ["shield"] } Entity name Entity Type Gandalf Character Aragorn Character Frodo Character Medium
  34. 34. CB-22. Query entities with compound attributes •Prerequisites –Exercise CB-21 •Steps –Write a program (or web/mobile application) that does the following queries and print the result •Obtain all attributes of Aragorn entity •Obtain only the Abilities attribute of Frodo entity –Run and test your program/application •Hints –Orion User Manual section Structure Attribute Values Medium
  35. 35. CB-23. Update entities with compound attributes •Prerequisites –Exercise CB-21 •Steps –Write a program (or web/mobile application) that •Asks for an object name (e.g. “staff”, “hat”, etc.) •Updates Gandalf's Inventory attribute to reflect that he now has a that object test your program –Run and test your program/application •Query the Gandalf's Inventory after that, in order to check that the object has been successfully added •Hints –Orion User Manual section Structure Attribute Values Medium
  36. 36. CB-24. Custom metadata Medium •Prerequisites –Exercise CB-21 •Steps –Update the Gandalf entity so that the inventory attribute has two new metadatas: •name="Weight", type="float", value="1.2" •name="MaxWeight", type="float", value="20" –Query Gandalf again to see the new metadata atached to the corresponding attribute •Hints –Orion User Manual section Attribute metadata
  37. 37. CB-25. Dynamic attributes addition/deletion •Prerequisites –Exercise CB-1 •Steps –Create the following initial entity •Entity ID: Car1 •Entity Type: Car •Initial attribute: name=Speed, type=integer, value=70 –Write a program (or web/mobile application) that •Asks for an operation type (ADD or DELETE) •If user chose ADD –Ask for an attribute name, type and value –Do a query to Orion to check that no other attributes with the same name exists in the entity (in positive case, exit informing the user about the problem) –Create the new attribute at the entity •If user chose DELETE –Ask for an attribute name –Do a query to Orion to check that an attributes with that name exists in the entity (in negative case, exit informing the user about the problem) –Delete the attribute at the entity –Run and test your program/application •Query your entity to check that the attributes are added and deleted as expected •Hints –Orion User Manual section Adding and removing attributes and entities Hard
  38. 38. CB-26. Multitenancy •Prerequisites –Exercise CB-1 •Steps –Write a program (or web/mobile application) that •Creates the following entities in your Orion instance at tenant "Customer1" –See table in next slide •Creates the following entities in your Orion instance at tenant "Customer2" –See table in next slide –Query for the Hammer entity using Customer1 and Customer2 as Fiware-Service alternatively, checking that the result is the right one for the given tenant •Hints –Orion User Manual section Multitenancy –Orion has to be configured to run with multitenancy enabled •BROKER_EXTRA_OPS="-multiservice" at /etc/sysconfig/contextBroker Medium
  39. 39. CB-26. Multitenancy Entity Type Attr. Name Attr. Type Example value Tool stock integer 1234 Tenant Entity Name Stock attribute value Customer1 Hammer 40 Screwdriver 23 Pliers 12 Ducktape 13 Customer2 HeatGun 109 Pliers 832 Hammer 646 Screwdriver 301 Hard
  40. 40. CB-27. Service Paths (create) •Prerequisites –Exercise CB-1 •Steps –Create the following entities •See table in next page •Keep in mind that they have to use Service Paths according to the figure •Hints –Orion User Manual section Entity Service Paths Hard
  41. 41. CB-27. Service Paths (create) Entity Type Attr. Name Attr. Type Example value Laptop owner string Bob MobilePhone owner string Alice Company Sales Dept. phone1 owner: Dave phone2 owner: Alice laptop1 owner: Alice TechSupport Dept. laptop2 owner: Charlie laptop3 owner: Bob phone3 owner: Bob Service Path ¨Fiware-ServicePath¨ header value Company /company Sales Department /company/sales Tech Support Department /company/tech Hard
  42. 42. CB-28. Service Paths (query) •Prerequisites –Exercise CB-27 •Steps –Write a program (or web/mobile application) that does the following queries and prints the result •Query all phones in the company •Query all laptops in the Tech Support department –Run and test your program/application •Hints –Orion User Manual section Entity Service Paths Medium
  43. 43. CB-29. Service Paths (update) •Prerequisites –Exercise CB-27 •Steps –Write a program (or web/mobile application) that does the following •Since Charlie left the Company he has to give back his laptop. Update entity laptop2's owner attribute and set it to "nobody". •Create a new entity phone3 of type MobilePhone in the sales department and set the owner attribute to "Alice" (she needs two phones, she works a lot). Notice that as a result of this there will be two entities with the same id in different Service Paths. –Run and test your program/application •Query entity phone3 and see which one you get when querying with the following service paths –The Sales department –the Tech Support department –All the company •Hints –Orion User Manual section Entity Service Paths Hard
  44. 44. Thanks!Thanks! (Number to manuals sections in this presentation are valid at time of writing this –March 9th 2015-, but they may change along time)

×