SlideShare a Scribd company logo
Contact twitter
@fermingalan
Contact email
fermin.galanmarquez@telefonica.com
kengunnar.zangelin@telefonica.com
(Reference Orion Context Broker version: 1.1.0)
Managing Context Information
at large scale
(Introduction)
Introduction
• Context Management in FIWARE
• Orion Context Broker
• Creating and pulling data
• Pushing data and notifications
• Standard operations
Orion Context Broker
2
Being “Smart” requires first being “Aware”
• Implementing a Smart Application requires gathering and
managing context information
• Context information refers to the values of attributes
characterizing entities relevant to the application
Bus
• Location
• No. passengers
• Driver
• Licence plate
Citizen
• Name-Surname
• Birthday
• Preferences
• Location
• ToDo list
Shop
• Location
• Business name
• Franchise
• offerings
Context Information
Application
3
Being “Smart” requires first being “Aware”
• Implementing a Smart Application requires gathering and
managing context information
• Context information refers to the values of attributes
characterizing entities relevant to the application
Boiler
• Manufacturer
• Last revision
• Product id
• temperature
Users
• Name-Surname
• Birthday
• Preferences
• Location
• ToDo list
Flowerpot
• Humidity
• Watering plan
Context Information
Application
4
Different sources of context need to be handle
• Context information may come from many sources:
– Existing systems
– Users, through mobile apps
– Sensor networks (Internet of Things)
• Source of info for a given entity.attribute may vary over
time
Place = “X”, temperature = 30º
What’s the current
temperature in place “X”?
Standard API
A sensor in a
pedestrian street
The Public Bus Transport
Management systemA person from his smartphone
It’s too hot!
Notify me the changes of
temperature in place “X”
5
A non-intrusive approach is required
• Capable to integrate with existing or future systems dealing with
management of municipal services without impact in their
architectures
• Info about attributes of one entity may come from different
systems, which work either as Context Producers or Context
Providers
• Applications rely on a single model adapting to systems of each city
Application/Service
Standard API
System A System B
Context Producer Context Provider
attribute “location” attribute “driver”
6
FIWARE NGSI: “The SNMP for IoT”
• Capturing data from, or Acting upon, IoT devices becomes
as easy as to read/change the value of attributes linked to
context entities using a Context Broker
Context Broker
NGSI APINGSI API
GET <Oauth token>
/V1/contextEntities/lamp1/attributes/presenceSensor
PUT <Oauth token>
/V1/contextEntities/lamp1/attributes/status
“light on”
Setting up the value of attribute
“status” to “light on” triggers
execution of a function in the IoT
device that switches the lamp on
Issuing a get operation on the
“presenceSensor” attribute
enables the application to get
info about presence of people
near the lamp
7
Connecting to the Internet of Things
• Capturing data from, or Acting upon, IoT devices becomes
as easy as to read/change the value of attributes linked to
context entities using a Context Broker
Context Broker
Standard APIStandard API
GET <Oauth token>
/V1/contextEntities/lamp1/attributes/presenceSensor
PUT <Oauth token>
/V1/contextEntities/lamp1/attributes/status
“light on”
Setting up the value of attribute
“status” to “watering” triggers
execution of a function in the IoT
device that waters the plant
Issuing a get operation on the
“humidity” attribute enables the
application to find out whether
the plant has to be watered
8
Context Management in FIWARE
• The FIWARE Context Broker GE implements the OMA NGSI-
9/10 API: a simple yet powerful standard API for managing
Context information complying with the requirements of a
smart city
• The FIWARE NGSI API is Restful: any web/backend
programmer gets quickly used to it
Application/Service
Context Broker
NGSI API
Boiler
• Manufacturer
• Last revision
• Product id
• temperature
Users
• Name-Surname
• Birthday
• Preferences
• Location
• ToDo list
Flowerpot
• Humidity
• Watering plan
9
Orion Context Broker
• Main functions:
– Context management
– Context availability management (advanced topic)
• HTTP and REST-based
– JSON payload support
• Context in NGSI is based in an entity-attribute model:
Attributes
• Name
• Type
• Value
Entity
• EntityId
• EntityType
1 n
“has”
10
Orion Context Broker in a nutshell
Orion Context Broker
Context
Producers
Context
Consumers
subscriptions
update
query
notify
notify
update
update
DB
1026
1026
11
GET <cb_host>:1026/version
{
"orion" : {
"version" : "0.28.0",
"uptime" : "7 d, 21 h, 33 m, 39 s",
"git_hash" : "5c1afdb3dd748580f10e1809f82462d83d2a17d4",
"compile_time" : "Mon Feb 29 11:52:53 CET 2016",
"compiled_by" : "fermin",
"compiled_in" : "centollo"
}
}
12
Orion Context Broker – check health
Orion Context Broker Basic Operations
Entities
• GET /v1/contextEntities/{entityID}
• Retrieves an entity
• POST /v1/contextEntities/{entityID}
• Creates an entity
• PUT /v1/contextEntities/{entityID}
• Updates an entity
• DELETE /v1/contextEntities/{entityID}
• Deletes an entity
13
Orion Context Broker Basic Operations
Attributes
• GET /v1/contextEntities/{entityID}/attributes/{attrName}
• Retrieves an attribute’s value
• POST /v1/contextEntities/{entityID}/attributes/{attrName}
• Creates a new attribute for an entity
• PUT /v1/contextEntities/{entityID}/attributes/{attrName}
• Updates an attribute’s value
• DELETE /v1/contextEntities/{entityID}/attributes/{attrName}
• Deletes an attribute
14
Context Broker operations: create & pull data
• Context Producers publish data/context elements by invoking the
updateContext operation on a Context Broker.
• Context Consumers can retrieve data/context elements by invoking the
queryContext operation on a Context Broker
Context Consumer
queryContext
Context Producer
updateContext
Context Broker
15
Quick Usage Example: Car Create
200 OK
...
{
"contextResponses": [
{
"attributes": [
{
"name": "speed",
"type": "float",
"value": ""
}
],
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
],
"id": “Car1",
"isPattern": "false",
"type": “Car"
}
16
Entity id and type can be included in the URL, e.g.
POST /v1/contextEntities/type/Car/id/Car1
POST <cb_host>:1026/v1/contextEntities
...
{
"id": "Car1",
"type": "Car",
"attributes": [
{
"name": "speed",
"type": "float",
"value": "98"
}
]
}
Quick Usage Example: Car UpdateContext (1)
PUT <cb_host>:1026/v1/contextEntities/type/Car/id/Car1/attributes/speed
...
{
"value": "110"
}
200 OK
...
{
"code": "200",
"reasonPhrase": "OK"
}
17
Quick Usage Example: Car QueryContext (1)
200 OK
...
{
"attributes": [
{
"name": "speed",
"type": "float",
"value": "110"
}
],
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
18
You can get all the attributes of the entity using the
entity URL:
GET/v1/contextEntities/type/Car/id/Car1
GET <cb_host>:1026/v1/contextEntities/type/Car/id/Car1/attributes/speed
Quick Usage Example: Car UpdateContext (2)
PUT <cb_host>:1026/v1/contextEntities/type/Car/id/Car1/attributes/speed
...
{
"value": "115"
}
200 OK
...
{
"code": "200",
"reasonPhrase": "OK"
}
19
Quick Usage Example: Car QueryContext (2)
200 OK
...
{
"attributes": [
{
"name": "speed",
"type": "float",
"value": "115"
}
],
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
20
GET <cb_host>:1026/v1/contextEntities/type/Car/id/Car1/attributes/speed
200 OK
...
{
"contextResponses": [
{
"attributes": [
{
"name": "temperature",
"type": "float",
"value": ""
},
{
"name": "pressure",
"type": "float",
"value": ""
}
],
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
}
Quick Usage Example: Room Create (1)
POST <cb_host>:1026/v1/contextEntities
...
{
"id": "Room1",
"type": "Room",
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "24"
},
{
"name": "pressure",
"type": "integer",
"value": "718"
}
]
}
21
200 OK
...
{
"contextResponses": [
{
"attributes": [
{
"name": "temperature",
"type": "float",
"value": ""
},
{
"name": "pressure",
"type": "integer",
"value": ""
}
],
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
}
Quick Usage Example: Room UpdateContext (1)
22
PUT <cb_host>:1026/v1/contextEntities/type/Room/id/Room1
...
{
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "25"
},
{
"name": "pressure",
"type": "integer",
"value": "720"
}
]
}
Quick Usage Example: Room QueryContext (1)
23
200 OK
...
{
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "25"
}
],
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
GET <cb_host>:1026/v1/contextEntities/type/Room/id/Room1/attributes/temperature
Quick Usage Example: Room QueryContext (2)
24
200 OK
...
{
"contextElement": {
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "25"
},
{
"name": "pressure",
"type": "float",
"value": "720"
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
GET <cb_host>:1026/v1/contextEntities/type/Room/id/Room1
200 OK
...
{
"contextResponses": [
{
"attributes": [
{
"name": "temperature",
"type": "float",
"value": ""
},
{
"name": "pressure",
"type": "float",
"value": ""
}
],
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
}
Quick Usage Example: Room Create (2)
POST <cb_host>:1026/v1/contextEntities
...
{
"id": "Room2",
"type": "Room",
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "29"
},
{
"name": "pressure",
"type": “integer",
"value": "730"
}
]
}
25
Quick Usage Example: Room QueryContext (3)
26
POST <cb_host>:1026/v1/queryContext
...
{
"entities": [
{
"type": "Room",
"isPattern": "true",
"id": "Room.*"
} ,
"attributes": [
"temperature"
]
]
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "25"
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
},
{
"contextElement": {
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "29"
}
],
"id": "Room2",
"isPattern": "false",
"type": "Room"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Context Broker operations: push data
• Context Consumers can subscribe to receive context information that satisfy
certain conditions using the subscribeContext. Such subscriptions may have
a duration.
• The Context Broker notifies updates on context information to subscribed
Context Consumers by invoking the notifyContext operation they export
subscription_id = subscribeContext (consumer, expr, duration)
Context Consumer
notifyContext (subscription_id, data/context)
Context Broker
Application
27
Quick Usage Example: Subscription
POST <cb_host>:1026/v1/subscribeContext
…
{
"entities": [
{
"type": "Room",
"isPattern": "false",
"id": "Room1"
}
],
"attributes": [
"temperature"
],
"reference": "http://<host>:<port>/publish",
"duration": "P1M",
"notifyConditions": [
{
"type": "ONCHANGE",
"condValues": [
"temperature"
]
}
],
"throttling": "PT5S"
}
200 OK
...
{
"subscribeResponse": {
"duration": "P1M",
"subscriptionId": "51c0ac9ed714fb3b37d7d5a8",
"throttling": "PT5S"
}
}
28
You can use also condValues: [ ] to mean
“change in any attribute”
25
19
Quick Usage Example: Notification
29
POST http://<host>:<port>/publish
…
{
"subscriptionId" : "51c0ac9ed714fb3b37d7d5a8",
"originator" : "localhost",
"contextResponses" : [
{
"contextElement" : {
"attributes" : [
{
"name" : "temperature",
"type" : "float",
"value" : "19"
}
],
"type" : "Room",
"isPattern" : "false",
"id" : "Room1"
},
"statusCode" : {
"code" : "200",
"reasonPhrase" : "OK"
}
}
]
}
Quick Usage Example: Notification
30
List existing subscriptions
• It can be done with the following NGSIv2 operation
– GET /v2/subscriptions
• NGSIv2 is yet in beta status. Draft specification can be found at
– http://telefonicaid.github.io/fiware-orion/api/v2/
31
GET <cb_host>:1026/v2/subscriptions
…
[
{
"id": " 51c0ac9ed714fb3b37d7d5a8",
"subject": {
"entities": [ { "id": "Room1", "type": "Room“ }],
"condition": {
"attrs": [ "temperature" ]
},
},
"notification": {
"callback": " http://<host>:<port>/publish ",
"attributes": [ "temperature“ ],
"throttling": 5,
"count": 12,
"lastNotification": "2015-10-05T16:00:00.00Z"
},
"expires": "2016-04-05T14:00:00.00Z",
"status": "active"
}]
Orion Context Broker Standard Operations
Functions Operations
NGSI10
• Query,
• Update and
• Subscribe to context elements
• updateContext
• queryContext
• subscribeContext
• updateContextSubscription
• unsubscribeContextSubscription
32
• They are equivalent to previous convenience operations in functionality
• All them use POST as verb, including the parameters in the payload
• More expressive than convenience operations. Some advance functionality is
only supported with standar operations (e.g. geo-aware query)
• They are not a substitute but a complement to convenience operations
How to get Orion? (Virtual Machines)
33
• FIWARE Lab image
– Image: orion-psb-image-R4.4
– Blueprints
• VirtualBox image
– http://bit.ly/fiware-orion024-vbox (it’s big!)
– User/pass:
• fiware/fiware
• root/fiware
• Hint: update Orion package once the VM is deployed
How to get Orion? (Docker containers)
34
• Assuming docker is installed in your system
• Documentation in https://github.com/telefonicaid/fiware-
orion/tree/develop/docker
• Quick guide
git clone https://github.com/telefonicaid/fiware-orion.git
cd fiware-orion/docker
sudo docker-compose up
• That’s all!
– curl --header 'Accept: application/json' localhost:1026/version
Orion Context Explorer
• Publicly available browser-based front-end for Orion
Context Broker
– Open source development by VM9
• Authentication integrated with FIWARE Lab account
• Have a look!
– http://orionexplorer.com/
35
Orion Context Broker to Backbone Sync
• https://github.com/digitalilusion/o2bb
36
NGSI Context Adaptor for CartoDB
Show your entities in a map with no effort, create history animations,
heat maps and clusters representations
• https://github.com/telefonicaid/fiware-dataviz
NGSI Plugin for Freeboard
Create a real time dashboard for your entities, representing gauges,
spark lines and maps. No coding required!
• https://github.com/telefonicaid/fiware-dataviz
In addition, Freeboard freemium version integrates Orion off-the-shelf
Would you like to know more?
• The easy way
– This presentation: google for “fermingalan slideshare” and search the one
named “Managing Context Information at large scale”
– Orion User Manual: google for “Orion FIWARE manual” and use the first
hit
– Orion Catalogue page: google for “Orion FIWARE catalogue” and use the
first hit
• References
– This presentation
• http://www.slideshare.net/fermingalan/fiware-managing-context-
information-at-large-scale
– Orion Catalogue:
• http://catalogue.fiware.org/enablers/publishsubscribe-context-broker-
orion-context-broker
– Orion support trhough StackOverflow
• Ask your questions using the “fiware-orion” tag
• Look for existing questions at
http://stackoverflow.com/questions/tagged/fiware-orion
39
Contact twitter
@fermingalan
Contact email
fermin.galanmarquez@telefonica.com
kengunnar.zangelin@telefonica.com
(Reference Orion Context Broker version: 1.1.0)
Managing Context Information
at large scale
(Advanced Topics)
Advanced Features • Pagination
• Compound attribute values
• Filtering
• Geo-location
• Metadata
• Special update action types
• Registrations & context providers
• Multitenancy
• Entity service paths
• CORS
• Notifiying services in private
networks
Orion Context Broker
41
• Pagination helps clients organize query and
discovery requests with a large number of
responses.
• Three URI parameters:
– limit
• Number of elements per page (default: 20, max: 1000)
– offset
• Number of elements to skip (default: 0)
– details
• Returns total elements (default: "off")
Pagination
42
Pagination
• Example, querying the first 100 entries:
POST <orion_host>:1026/v1/queryContext?limit=100&details=on
• The first 100 elements are returned, along with the following errorCode in
the response:
"errorCode": {
"code": "200",
"details": "Count: 322",
"reasonPhrase": "OK"
}
• Now we now there are 322 entities, we can keep querying the broker for
them:
– POST <orion_host>:1026/v1/queryContext?offset=100&limit=100
– POST <orion_host>:1026/v1/queryContext?offset=200&limit=100
– POST <orion_host>:1026/v1/queryContext?offset=300&limit=100
43
Pagination
• By default, results are ordered by entity creation date
• This behaviour can be overridden using orderBy URI parameter
– A comma-separated list of attributes. Results are ordered by the first attribute.
On ties, the results are ordered by the second attribute and so on. A "!" before
the attribute name means that the order is reversed.
• Example: get the first 10 entities ordered by temp in ascending order,
then humidity in descending order
POST
<orion_host>:1026/v1/queryContext?limit=20&offset=0&orderBy=temp,!humidity
• dateCreated and dateModified can be used to ordering by entity
creation and modification date, respectively
44
Compound Attribute Values
• An attribute can have a structured value. Vectors
and key-value maps are supported.
• It maps directly to JSON's objects and arrays.
45
Compound Attribute Values
• Example: we have
a car whose four
wheels' pressure
we want to
represent as a
compound
attribute for a car
entity. We would
create the car
entity like this:
{
"contextElements": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1",
"attributes": [
{
"name": "tirePressure",
"type": "kPa",
"value": {
"frontRight": "120",
"frontLeft": "110",
"backRight": "115",
"backLeft": "130"
}
}
]
}
],
"updateAction": "APPEND"
}
46
Filtering
• Query results can be filtered
– scope element in queryContext
– Special URI params in GET
convenience operations
• Different filter types available
– Entity type existence
– Entity type no-existence
– Geo location (described later in this
document)
– General string filter
47
POST <cb_host>:1026/v1/queryContext
…
{
"entities": [
{
"type": "City",
"isPattern": "true",
"id": ".*"
}
],
"restriction": {
"scopes": [
{
"type" : "FIWARE::<FilterType>",
"value" : <Expression>
}
}
]
}
}
GET <cb_host>:1026/v1/entities?filter=value
String filter
• Allows to express the following matching
conditions for attribute values
– Equal, unequal
– Great than, less than
– Inside (outside) a range
– Regex
• Uses the same syntax than the q
parameter in NGSI v2
– See http://telefonicaid.github.io/fiware-
orion/api/v2/
• Example: retrieve all sensor entities
that match all this conditions
– temperature attribute is less than 24
degrees
– humidity attribute is in the range of 75%
to 90%
– status attribute is equal to “running”
• Caveat: arithmetic filters (great than,
range, etc.) requires that number values
for attributes has been set using NGSIv2
methods
48
POST <cb_host>:1026/v1/queryContext
…
{
"entities": [
{
"type": “sensor",
"isPattern": "true",
"id": ".*"
}
],
"restriction": {
"scopes": [
{
"type" : "FIWARE::StringFilter",
"value" : "temperature<24;humidity==75..90;status=running"
}
}
]
}
}
Metadata
• Users may attach metadata to attributes
• Reserved metadatas: ID, Location, creDate and modDate
• Examples:
49
…
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "26.5",
"metadatas": [
{
"name": "accuracy",
"type": "float",
"value": "0.9"
}
]
}
]
…
…
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "26.5",
"metadatas": [
{
"name": "average",
"type": "float",
"value": "22.4"
}
]
}
]
…
Complete NGSI Model
Attributes
• Name
• Type
• Value
Entity
• EntityId
• EntityType
1 n
“has”
Metadata
• Name
• Type
• Value1 n
“has”
50
• Used by updateContext (standard operation)
• Conventional actionTypes
– APPEND: append (or update if the attribute already
exists)
– UPDATE: update
– DELETE: delete
• Special actionTypes
– APPEND_STRICT: strict append (returns error if some of
the attributes to add already exists)
– REPLACE: delete all the entity attributes, next append
the ones in the update request
Special update action types
51
Geo-location
• Entities can have an attribute
that specifies its location
– Using the geo:point attribute type
• Example: create an entity called
Madrid
…and create a couple more towns:
• Leganés
• Alcobendas
POST <cb_host>:1026/v1/updateContext
{
"contextElements": [
{
"type": "City",
"isPattern": "false",
"id": "Madrid",
"attributes": [
{
"name": "position",
"type": "geo:point",
"value": "40.418889, -3.691944"
}
]
}
],
"updateAction": "APPEND"
}
52
Geo-location – Circle
53
Geo-location – Circle
54
POST <cb_host>:1026/v1/queryContext
…
{
"entities": [
{
"type": "City",
"isPattern": "true",
"id": ".*"
}
],
"restriction": {
"scopes": [
{
"type" : "FIWARE::Location",
"value" : {
"circle": {
"centerLatitude": "40.418889",
"centerLongitude": "-3.691944",
"radius": "13500"
}
}
}
]
}
}
Geo-location – Inverse Circle
55
POST <cb_host>:1026/v1/queryContext
…
{
"entities": [
{
"type": "City",
"isPattern": "true",
"id": ".*"
}
],
"restriction": {
"scopes": [
{
"type" : "FIWARE::Location",
"value" : {
"circle": {
"centerLatitude": "40.418889",
"centerLongitude": "-3.691944",
"radius": "13500",
"inverted": "true"
}
}
}
]
}
}
• As alternative, you can use
“FIWARE::Location::NGSIv2”
to use NGSIv2 geoqueries
(richer that
“FIWARE::Location”)
– Eg. coveredBy, near with
minDistance
• Based in georel, geometry
and coords parameter
• Check NGSIv2 “Geographical
Queries” section
– http://telefonicaid.github.io/fiware-
orion/api/v2/
Geo-location à la NGSIv2
56
POST <cb_host>:1026/v1/queryContext
…
{
...
"scopes": [
{
"type" : "FIWARE::Location::NGSIv2",
"value" : {
"georel": [ "near", "minDistance:13500"
],
"geometry": "point",
"coords": [ [40.418889,-3.691944] ] }
}
}
]
…
}
Registration & Context Providers
• Uncached queries and updates
57
Application
ContextBroker ContextProvider
1. registerContext(provider= )
db
2. queryContext(id) 3. queryContext(id)
4. data5. data
Context
Consumer
POST <cb_host>:1026/v1/registry/registerContext
…
{
"contextRegistrations": [
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1"
},
"attributes": [
{
"name": "speed",
"type": "float",
"isDomain": "false"
}
],
"providingApplication": "http://contextprovider.com/Cars"
}
],
"duration": "P1M"
}
200 OK
...
{
"duration" : "P1M",
"registrationId" : "52a744b011f5816465943d58"
}
58
Registration & Context Providers
59
POST <cb_host>:1026/v1/queryContext
...
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1"
}
]
}
Registration & Context Providers
ContextBroker ContextProvider
db
queryContext(id)
data
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "speed",
"type": "float",
"value": "100"
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"details": "Redirected to context provider
http://contextprovider.com/Cars",
"reasonPhrase": "OK"
}
}
]
}
Orion Context Broker - Operations
Functions Operations
NGSI9
• Register,
• Search and
• Subscribe for context sources
• registerContext
• discoverContextAvailability
• subscribeContextAvailability
• updateContextAvailabilitySubscription
• unsubscribeContextAvailability
NGSI10
• Query,
• Update and
• Subscribe to context elements
• updateContext
• queryContext
• subscribeContext
• updateContextSubscription
• unsubscribeContextSubscription
60
Multitenancy
• Simple multitenant model based on
logical database separation.
• It eases tenant-based authorization
provided by other components.
• Just use an additional HTTP header
called "Fiware-Service", whose value
is the tenant name. Example:
Fiware-Service: Tenant1
Context
Broker
Tenant1
Tenant2
…
61
Entity Service Paths
• A service path is a hierarchical scope assigned to an entity
at creation time (with updateContext).
62
Entity Service Paths
• In order to use a service path we put in a new HTTP header
called “Fiware-ServicePath". For example:
Fiware-ServicePath: /Madrid/Gardens/ParqueNorte/Parterre1
• Properties:
– A query on a service path will look only into the specified node
– Use "ParentNode/#" to include all child nodes
– Queries without Fiware-ServicePath resolve to "/#"
– Entities will fall in the "/" node by default
ParqueNorte
Parterre2Parterre1
63
Entity Service Paths
• Properties (continued):
– You can OR a query using a comma (,)
operator in the header
• For example, to query all street lights that are either in
ParqueSur or in ParqueOeste you would use:
ServicePath: Madrid/Gardens/ParqueSur,
Madrid/Gardens/ParqueOeste
• You can OR up to 10 different scopes.
– Maximum scope levels: 10
• Scope1/Scope2/.../Scope10
– You can have the same element IDs in
different scopes (be careful with this!)
– You can't change scope once the element is
created
– One entity can belong to only one scope
– It works not only with queries, but also with
subscriptions/notifications
– It works not only in NGSI10, but also with
registrations/discoveries (NGSI9)
ParqueNorte
Parterre1
light1
light1
A B
A or B
64
Cross-Origin Resource Sharing
(CORS)
• Useful for programming clients that run entirely in browser
without backend
• Support in GET requests
• Controlled by the -corsOrigin CLI parameter at boot time
65
200 OK
Access-Control-Allow-Origin: *
...
{
"attributes": [
….
],
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
GET <cb_host>:1026/v1/contextEntities/Car1
Notifiying services in private networks
66
Context Consumer
notifyContext
Context Broker
Private Network
Context Consumer
Context Broker
Private Network
./ngrok http 8080
http://9762d35a.ngrok.io
ngrok.io
Would you like to know more?
• The easy way
– This presentation: google for “fermingalan slideshare” and search the one
named “Managing Context Information at large scale”
– Orion User Manual: google for “Orion FIWARE manual” and use the first
hit
– Orion Catalogue page: google for “Orion FIWARE catalogue” and use the
first hit
• References
– This presentation
• http://www.slideshare.net/fermingalan/fiware-managing-context-
information-at-large-scale
– Orion Catalogue:
• http://catalogue.fiware.org/enablers/publishsubscribe-context-broker-
orion-context-broker
– Orion support trhough StackOverflow
• Ask your questions using the “fiware-orion” tag
• Look for existing questions at
http://stackoverflow.com/questions/tagged/fiware-orion
67
Thanks!Thanks!
BACKUP SLIDES
Backup slides
69
Integration with existing systems
• Context adapters will be developed to interface with existing systems (e.g.,
municipal services management systems in a smart city) acting as Context
Providers, Context Producers, or both
• Some attributes from a given entity may be linked to a Context Provider
while other attributes may be linked to Context Producers
queryContext (e1,
attr1, attr2)
Context Provider
queryContext (e1,
attr1)
Context Consumer
updateContext (e1,
attr2)
Application
Context Broker
System BSystem A
70
Integration with sensor networks
• The backend IoT Device Management GE enables creation and
configuration of NGSI IoT Agents that connect to sensor networks
• Each NGSI IoT Agent can behave as Context Consumers or Context
Providers, or both
FIWARE Context Broker
IoT
Agent-1
IoT
Agent-2
IoT
Agent-n
IoT Agent
Manager
create/monitor
FIWARE Backend IoT
Device Management
OMA NGSI API (northbound interface)
(southbound interfaces)
MQTTETSI M2M IETF CoAP
71
• Federation of infrastructures (private/public regions)
• Automated GE deploymentCloud
• Complete Context Management Platform
• Integration of Data and Media ContentData
•Easy plug&play of devices using multiple protocols
•Automated Measurements/Action Context updatesIoT
•Visualization of data (operation dashboards)
•Publication of data sets/servicesApps
•Easy support of UIs with advanced web-based 3D and AR
capabilities
•Visual representation of context information.
Web UI
•Advanced networking capabilities (SDN) and Middleware
•Interface to robotsI2ND
•Security Monitoring
•Built-in Identity/Access/Privacy ManagementSecurity
Context Management in FIWARE
72
FI-WARE Context/Data Management Platform
Context/Data Management Platform
Applications
OMA NGSI-9/10
Processing/Analysis
Algorithms
Gathered data is
injected for
processing/analysis
Distributed
Context
Sources Complex Event
Processing
(PROTON)
BigData
(COSMOS)
Processed data is
injected for
processing/analysi
s
Data generated either by CEP
or BigData is published
Gathered data injected
for CEP-like processing
Direct
bigdata
injection
Programming of
rules
73
More on Convenience Operations
Subscriptions
• POST /v1/contextSubscriptions
• Creates a subscription
• PUT /v1/contextSubscriptions/{subID}
• Updates a subscription
• DELETE /v1/contextSubscriptions/{subID}
• Cancel a subscription
74
More on Convenience Operations
Entity Types
• GET /v1/contextTypes
• Retrieve a list of all entity types currently in Orion,
including their corresponding attributes
• GET /v1/contextTypes/{typeID}
• Retrieve attributes associated to an entity type
PRO TIP
GET /v1/contextTypes?collapse=true
Retrieves a list of all entity types without attribute info
75
Std Op Example: Car Create
POST localhost:1026/v1/updateContext
...
{
"contextElements": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1",
"attributes": [
{
"name": "speed",
"type": "float",
"value": “98"
}
]
}
],
"updateAction": “APPEND"
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "speed",
"type": "float",
"value": ""
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
76
Std Op Example: Car UpdateContext (1)
POST localhost:1026/v1/updateContext
...
{
"contextElements": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1",
"attributes": [
{
"name": "speed",
"type": "float",
"value": "110"
}
]
}
],
"updateAction": "UPDATE"
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "speed",
"type": "float",
"value": ""
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
77
Std Op Example: Car QueryContext (1)
POST <cb_host>:1026/v1/queryContext
...
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1"
}
]
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "speed",
"type": "float",
"value": "110"
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
78
Std Op Example: Car UpdateContext (2)
POST localhost:1026/v1/updateContext
...
{
"contextElements": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1",
"attributes": [
{
"name": "speed",
"type": "float",
"value": "115"
}
]
}
],
"updateAction": "UPDATE"
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "speed",
"type": "float",
"value": ""
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
79
Std Op Example: Car QueryContext (2)
80
POST <cb_host>:1026/v1/queryContext
...
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1"
}
]
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "speed",
"type": "float",
"value": "115"
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Std Op Example: Room Create (1)
81
POST localhost:1026/v1/updateContext
...
{
"contextElements": [
{
"type": "Room",
"isPattern": "false",
"id": "Room1",
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "24"
},
{
"name": "pressure",
"type": "integer",
"value": "718"
}
]
}
],
"updateAction": "APPEND"
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "temperature",
"type": "float",
"value": ""
},
{
"name": "pressure",
"type": "integer",
"value": ""
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Std Op Example: Room UpdateContext (1)
POST localhost:1026/v1/updateContext
...
{
"contextElements": [
{
"type": "Room",
"isPattern": "false",
"id": "Room1",
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "25"
},
{
"name": "pressure",
"type": "integer",
"value": "720"
}
]
}
],
"updateAction": "UPDATE"
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "temperature",
"type": "float",
"value": ""
},
{
"name": "pressure",
"type": "integer",
"value": ""
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
82
Std Op Example: Room QueryContext (1)
83
POST <cb_host>:1026/v1/queryContext
...
{
"entities": [
{
"type": "Room",
"isPattern": "false",
"id": "Room1"
} ,
"attributes": [
"temperature"
]
]
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "25"
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Std Op Example: Room QueryContext (2)
84
POST <cb_host>:1026/v1/queryContext
...
{
"entities": [
{
"type": "Room",
"isPattern": "false",
"id": "Room1"
}
]
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "temperature",
"type": "float",
"value": "25"
},
{
"name": "pressure",
"type": "integer",
"value": "720"
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Std Op Example: Room Create (2)
85
POST localhost:1026/v1/updateContext
...
{
"contextElements": [
{
"type": "Room",
"isPattern": "false",
"id": "Room2",
"attributes": [
{
"name": "temperature",
"type": "float",
"value": “29"
},
{
"name": "pressure",
"type": "integer",
"value": "730"
}
]
}
],
"updateAction": "APPEND"
}
200 OK
...
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "temperature",
"type": "float",
"value": ""
},
{
"name": "pressure",
"type": "integer",
"value": ""
}
],
"id": "Room1",
"isPattern": "false",
"type": "Room"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}

More Related Content

FIWARE: Managing Context Information at Large Scale (NGSIv1)

  • 1. Contact twitter @fermingalan Contact email fermin.galanmarquez@telefonica.com kengunnar.zangelin@telefonica.com (Reference Orion Context Broker version: 1.1.0) Managing Context Information at large scale (Introduction)
  • 2. Introduction • Context Management in FIWARE • Orion Context Broker • Creating and pulling data • Pushing data and notifications • Standard operations Orion Context Broker 2
  • 3. Being “Smart” requires first being “Aware” • Implementing a Smart Application requires gathering and managing context information • Context information refers to the values of attributes characterizing entities relevant to the application Bus • Location • No. passengers • Driver • Licence plate Citizen • Name-Surname • Birthday • Preferences • Location • ToDo list Shop • Location • Business name • Franchise • offerings Context Information Application 3
  • 4. Being “Smart” requires first being “Aware” • Implementing a Smart Application requires gathering and managing context information • Context information refers to the values of attributes characterizing entities relevant to the application Boiler • Manufacturer • Last revision • Product id • temperature Users • Name-Surname • Birthday • Preferences • Location • ToDo list Flowerpot • Humidity • Watering plan Context Information Application 4
  • 5. Different sources of context need to be handle • Context information may come from many sources: – Existing systems – Users, through mobile apps – Sensor networks (Internet of Things) • Source of info for a given entity.attribute may vary over time Place = “X”, temperature = 30º What’s the current temperature in place “X”? Standard API A sensor in a pedestrian street The Public Bus Transport Management systemA person from his smartphone It’s too hot! Notify me the changes of temperature in place “X” 5
  • 6. A non-intrusive approach is required • Capable to integrate with existing or future systems dealing with management of municipal services without impact in their architectures • Info about attributes of one entity may come from different systems, which work either as Context Producers or Context Providers • Applications rely on a single model adapting to systems of each city Application/Service Standard API System A System B Context Producer Context Provider attribute “location” attribute “driver” 6
  • 7. FIWARE NGSI: “The SNMP for IoT” • Capturing data from, or Acting upon, IoT devices becomes as easy as to read/change the value of attributes linked to context entities using a Context Broker Context Broker NGSI APINGSI API GET <Oauth token> /V1/contextEntities/lamp1/attributes/presenceSensor PUT <Oauth token> /V1/contextEntities/lamp1/attributes/status “light on” Setting up the value of attribute “status” to “light on” triggers execution of a function in the IoT device that switches the lamp on Issuing a get operation on the “presenceSensor” attribute enables the application to get info about presence of people near the lamp 7
  • 8. Connecting to the Internet of Things • Capturing data from, or Acting upon, IoT devices becomes as easy as to read/change the value of attributes linked to context entities using a Context Broker Context Broker Standard APIStandard API GET <Oauth token> /V1/contextEntities/lamp1/attributes/presenceSensor PUT <Oauth token> /V1/contextEntities/lamp1/attributes/status “light on” Setting up the value of attribute “status” to “watering” triggers execution of a function in the IoT device that waters the plant Issuing a get operation on the “humidity” attribute enables the application to find out whether the plant has to be watered 8
  • 9. Context Management in FIWARE • The FIWARE Context Broker GE implements the OMA NGSI- 9/10 API: a simple yet powerful standard API for managing Context information complying with the requirements of a smart city • The FIWARE NGSI API is Restful: any web/backend programmer gets quickly used to it Application/Service Context Broker NGSI API Boiler • Manufacturer • Last revision • Product id • temperature Users • Name-Surname • Birthday • Preferences • Location • ToDo list Flowerpot • Humidity • Watering plan 9
  • 10. Orion Context Broker • Main functions: – Context management – Context availability management (advanced topic) • HTTP and REST-based – JSON payload support • Context in NGSI is based in an entity-attribute model: Attributes • Name • Type • Value Entity • EntityId • EntityType 1 n “has” 10
  • 11. Orion Context Broker in a nutshell Orion Context Broker Context Producers Context Consumers subscriptions update query notify notify update update DB 1026 1026 11
  • 12. GET <cb_host>:1026/version { "orion" : { "version" : "0.28.0", "uptime" : "7 d, 21 h, 33 m, 39 s", "git_hash" : "5c1afdb3dd748580f10e1809f82462d83d2a17d4", "compile_time" : "Mon Feb 29 11:52:53 CET 2016", "compiled_by" : "fermin", "compiled_in" : "centollo" } } 12 Orion Context Broker – check health
  • 13. Orion Context Broker Basic Operations Entities • GET /v1/contextEntities/{entityID} • Retrieves an entity • POST /v1/contextEntities/{entityID} • Creates an entity • PUT /v1/contextEntities/{entityID} • Updates an entity • DELETE /v1/contextEntities/{entityID} • Deletes an entity 13
  • 14. Orion Context Broker Basic Operations Attributes • GET /v1/contextEntities/{entityID}/attributes/{attrName} • Retrieves an attribute’s value • POST /v1/contextEntities/{entityID}/attributes/{attrName} • Creates a new attribute for an entity • PUT /v1/contextEntities/{entityID}/attributes/{attrName} • Updates an attribute’s value • DELETE /v1/contextEntities/{entityID}/attributes/{attrName} • Deletes an attribute 14
  • 15. Context Broker operations: create & pull data • Context Producers publish data/context elements by invoking the updateContext operation on a Context Broker. • Context Consumers can retrieve data/context elements by invoking the queryContext operation on a Context Broker Context Consumer queryContext Context Producer updateContext Context Broker 15
  • 16. Quick Usage Example: Car Create 200 OK ... { "contextResponses": [ { "attributes": [ { "name": "speed", "type": "float", "value": "" } ], "statusCode": { "code": "200", "reasonPhrase": "OK" } } ], "id": “Car1", "isPattern": "false", "type": “Car" } 16 Entity id and type can be included in the URL, e.g. POST /v1/contextEntities/type/Car/id/Car1 POST <cb_host>:1026/v1/contextEntities ... { "id": "Car1", "type": "Car", "attributes": [ { "name": "speed", "type": "float", "value": "98" } ] }
  • 17. Quick Usage Example: Car UpdateContext (1) PUT <cb_host>:1026/v1/contextEntities/type/Car/id/Car1/attributes/speed ... { "value": "110" } 200 OK ... { "code": "200", "reasonPhrase": "OK" } 17
  • 18. Quick Usage Example: Car QueryContext (1) 200 OK ... { "attributes": [ { "name": "speed", "type": "float", "value": "110" } ], "statusCode": { "code": "200", "reasonPhrase": "OK" } } 18 You can get all the attributes of the entity using the entity URL: GET/v1/contextEntities/type/Car/id/Car1 GET <cb_host>:1026/v1/contextEntities/type/Car/id/Car1/attributes/speed
  • 19. Quick Usage Example: Car UpdateContext (2) PUT <cb_host>:1026/v1/contextEntities/type/Car/id/Car1/attributes/speed ... { "value": "115" } 200 OK ... { "code": "200", "reasonPhrase": "OK" } 19
  • 20. Quick Usage Example: Car QueryContext (2) 200 OK ... { "attributes": [ { "name": "speed", "type": "float", "value": "115" } ], "statusCode": { "code": "200", "reasonPhrase": "OK" } } 20 GET <cb_host>:1026/v1/contextEntities/type/Car/id/Car1/attributes/speed
  • 21. 200 OK ... { "contextResponses": [ { "attributes": [ { "name": "temperature", "type": "float", "value": "" }, { "name": "pressure", "type": "float", "value": "" } ], "statusCode": { "code": "200", "reasonPhrase": "OK" } } ], "id": "Room1", "isPattern": "false", "type": "Room" } Quick Usage Example: Room Create (1) POST <cb_host>:1026/v1/contextEntities ... { "id": "Room1", "type": "Room", "attributes": [ { "name": "temperature", "type": "float", "value": "24" }, { "name": "pressure", "type": "integer", "value": "718" } ] } 21
  • 22. 200 OK ... { "contextResponses": [ { "attributes": [ { "name": "temperature", "type": "float", "value": "" }, { "name": "pressure", "type": "integer", "value": "" } ], "statusCode": { "code": "200", "reasonPhrase": "OK" } } ], "id": "Room1", "isPattern": "false", "type": "Room" } Quick Usage Example: Room UpdateContext (1) 22 PUT <cb_host>:1026/v1/contextEntities/type/Room/id/Room1 ... { "attributes": [ { "name": "temperature", "type": "float", "value": "25" }, { "name": "pressure", "type": "integer", "value": "720" } ] }
  • 23. Quick Usage Example: Room QueryContext (1) 23 200 OK ... { "attributes": [ { "name": "temperature", "type": "float", "value": "25" } ], "statusCode": { "code": "200", "reasonPhrase": "OK" } } GET <cb_host>:1026/v1/contextEntities/type/Room/id/Room1/attributes/temperature
  • 24. Quick Usage Example: Room QueryContext (2) 24 200 OK ... { "contextElement": { "attributes": [ { "name": "temperature", "type": "float", "value": "25" }, { "name": "pressure", "type": "float", "value": "720" } ], "id": "Room1", "isPattern": "false", "type": "Room" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } GET <cb_host>:1026/v1/contextEntities/type/Room/id/Room1
  • 25. 200 OK ... { "contextResponses": [ { "attributes": [ { "name": "temperature", "type": "float", "value": "" }, { "name": "pressure", "type": "float", "value": "" } ], "statusCode": { "code": "200", "reasonPhrase": "OK" } } ], "id": "Room1", "isPattern": "false", "type": "Room" } Quick Usage Example: Room Create (2) POST <cb_host>:1026/v1/contextEntities ... { "id": "Room2", "type": "Room", "attributes": [ { "name": "temperature", "type": "float", "value": "29" }, { "name": "pressure", "type": “integer", "value": "730" } ] } 25
  • 26. Quick Usage Example: Room QueryContext (3) 26 POST <cb_host>:1026/v1/queryContext ... { "entities": [ { "type": "Room", "isPattern": "true", "id": "Room.*" } , "attributes": [ "temperature" ] ] } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "temperature", "type": "float", "value": "25" } ], "id": "Room1", "isPattern": "false", "type": "Room" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } }, { "contextElement": { "attributes": [ { "name": "temperature", "type": "float", "value": "29" } ], "id": "Room2", "isPattern": "false", "type": "Room" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] }
  • 27. Context Broker operations: push data • Context Consumers can subscribe to receive context information that satisfy certain conditions using the subscribeContext. Such subscriptions may have a duration. • The Context Broker notifies updates on context information to subscribed Context Consumers by invoking the notifyContext operation they export subscription_id = subscribeContext (consumer, expr, duration) Context Consumer notifyContext (subscription_id, data/context) Context Broker Application 27
  • 28. Quick Usage Example: Subscription POST <cb_host>:1026/v1/subscribeContext … { "entities": [ { "type": "Room", "isPattern": "false", "id": "Room1" } ], "attributes": [ "temperature" ], "reference": "http://<host>:<port>/publish", "duration": "P1M", "notifyConditions": [ { "type": "ONCHANGE", "condValues": [ "temperature" ] } ], "throttling": "PT5S" } 200 OK ... { "subscribeResponse": { "duration": "P1M", "subscriptionId": "51c0ac9ed714fb3b37d7d5a8", "throttling": "PT5S" } } 28 You can use also condValues: [ ] to mean “change in any attribute”
  • 29. 25 19 Quick Usage Example: Notification 29
  • 30. POST http://<host>:<port>/publish … { "subscriptionId" : "51c0ac9ed714fb3b37d7d5a8", "originator" : "localhost", "contextResponses" : [ { "contextElement" : { "attributes" : [ { "name" : "temperature", "type" : "float", "value" : "19" } ], "type" : "Room", "isPattern" : "false", "id" : "Room1" }, "statusCode" : { "code" : "200", "reasonPhrase" : "OK" } } ] } Quick Usage Example: Notification 30
  • 31. List existing subscriptions • It can be done with the following NGSIv2 operation – GET /v2/subscriptions • NGSIv2 is yet in beta status. Draft specification can be found at – http://telefonicaid.github.io/fiware-orion/api/v2/ 31 GET <cb_host>:1026/v2/subscriptions … [ { "id": " 51c0ac9ed714fb3b37d7d5a8", "subject": { "entities": [ { "id": "Room1", "type": "Room“ }], "condition": { "attrs": [ "temperature" ] }, }, "notification": { "callback": " http://<host>:<port>/publish ", "attributes": [ "temperature“ ], "throttling": 5, "count": 12, "lastNotification": "2015-10-05T16:00:00.00Z" }, "expires": "2016-04-05T14:00:00.00Z", "status": "active" }]
  • 32. Orion Context Broker Standard Operations Functions Operations NGSI10 • Query, • Update and • Subscribe to context elements • updateContext • queryContext • subscribeContext • updateContextSubscription • unsubscribeContextSubscription 32 • They are equivalent to previous convenience operations in functionality • All them use POST as verb, including the parameters in the payload • More expressive than convenience operations. Some advance functionality is only supported with standar operations (e.g. geo-aware query) • They are not a substitute but a complement to convenience operations
  • 33. How to get Orion? (Virtual Machines) 33 • FIWARE Lab image – Image: orion-psb-image-R4.4 – Blueprints • VirtualBox image – http://bit.ly/fiware-orion024-vbox (it’s big!) – User/pass: • fiware/fiware • root/fiware • Hint: update Orion package once the VM is deployed
  • 34. How to get Orion? (Docker containers) 34 • Assuming docker is installed in your system • Documentation in https://github.com/telefonicaid/fiware- orion/tree/develop/docker • Quick guide git clone https://github.com/telefonicaid/fiware-orion.git cd fiware-orion/docker sudo docker-compose up • That’s all! – curl --header 'Accept: application/json' localhost:1026/version
  • 35. Orion Context Explorer • Publicly available browser-based front-end for Orion Context Broker – Open source development by VM9 • Authentication integrated with FIWARE Lab account • Have a look! – http://orionexplorer.com/ 35
  • 36. Orion Context Broker to Backbone Sync • https://github.com/digitalilusion/o2bb 36
  • 37. NGSI Context Adaptor for CartoDB Show your entities in a map with no effort, create history animations, heat maps and clusters representations • https://github.com/telefonicaid/fiware-dataviz
  • 38. NGSI Plugin for Freeboard Create a real time dashboard for your entities, representing gauges, spark lines and maps. No coding required! • https://github.com/telefonicaid/fiware-dataviz In addition, Freeboard freemium version integrates Orion off-the-shelf
  • 39. Would you like to know more? • The easy way – This presentation: google for “fermingalan slideshare” and search the one named “Managing Context Information at large scale” – Orion User Manual: google for “Orion FIWARE manual” and use the first hit – Orion Catalogue page: google for “Orion FIWARE catalogue” and use the first hit • References – This presentation • http://www.slideshare.net/fermingalan/fiware-managing-context- information-at-large-scale – Orion Catalogue: • http://catalogue.fiware.org/enablers/publishsubscribe-context-broker- orion-context-broker – Orion support trhough StackOverflow • Ask your questions using the “fiware-orion” tag • Look for existing questions at http://stackoverflow.com/questions/tagged/fiware-orion 39
  • 40. Contact twitter @fermingalan Contact email fermin.galanmarquez@telefonica.com kengunnar.zangelin@telefonica.com (Reference Orion Context Broker version: 1.1.0) Managing Context Information at large scale (Advanced Topics)
  • 41. Advanced Features • Pagination • Compound attribute values • Filtering • Geo-location • Metadata • Special update action types • Registrations & context providers • Multitenancy • Entity service paths • CORS • Notifiying services in private networks Orion Context Broker 41
  • 42. • Pagination helps clients organize query and discovery requests with a large number of responses. • Three URI parameters: – limit • Number of elements per page (default: 20, max: 1000) – offset • Number of elements to skip (default: 0) – details • Returns total elements (default: "off") Pagination 42
  • 43. Pagination • Example, querying the first 100 entries: POST <orion_host>:1026/v1/queryContext?limit=100&details=on • The first 100 elements are returned, along with the following errorCode in the response: "errorCode": { "code": "200", "details": "Count: 322", "reasonPhrase": "OK" } • Now we now there are 322 entities, we can keep querying the broker for them: – POST <orion_host>:1026/v1/queryContext?offset=100&limit=100 – POST <orion_host>:1026/v1/queryContext?offset=200&limit=100 – POST <orion_host>:1026/v1/queryContext?offset=300&limit=100 43
  • 44. Pagination • By default, results are ordered by entity creation date • This behaviour can be overridden using orderBy URI parameter – A comma-separated list of attributes. Results are ordered by the first attribute. On ties, the results are ordered by the second attribute and so on. A "!" before the attribute name means that the order is reversed. • Example: get the first 10 entities ordered by temp in ascending order, then humidity in descending order POST <orion_host>:1026/v1/queryContext?limit=20&offset=0&orderBy=temp,!humidity • dateCreated and dateModified can be used to ordering by entity creation and modification date, respectively 44
  • 45. Compound Attribute Values • An attribute can have a structured value. Vectors and key-value maps are supported. • It maps directly to JSON's objects and arrays. 45
  • 46. Compound Attribute Values • Example: we have a car whose four wheels' pressure we want to represent as a compound attribute for a car entity. We would create the car entity like this: { "contextElements": [ { "type": "Car", "isPattern": "false", "id": "Car1", "attributes": [ { "name": "tirePressure", "type": "kPa", "value": { "frontRight": "120", "frontLeft": "110", "backRight": "115", "backLeft": "130" } } ] } ], "updateAction": "APPEND" } 46
  • 47. Filtering • Query results can be filtered – scope element in queryContext – Special URI params in GET convenience operations • Different filter types available – Entity type existence – Entity type no-existence – Geo location (described later in this document) – General string filter 47 POST <cb_host>:1026/v1/queryContext … { "entities": [ { "type": "City", "isPattern": "true", "id": ".*" } ], "restriction": { "scopes": [ { "type" : "FIWARE::<FilterType>", "value" : <Expression> } } ] } } GET <cb_host>:1026/v1/entities?filter=value
  • 48. String filter • Allows to express the following matching conditions for attribute values – Equal, unequal – Great than, less than – Inside (outside) a range – Regex • Uses the same syntax than the q parameter in NGSI v2 – See http://telefonicaid.github.io/fiware- orion/api/v2/ • Example: retrieve all sensor entities that match all this conditions – temperature attribute is less than 24 degrees – humidity attribute is in the range of 75% to 90% – status attribute is equal to “running” • Caveat: arithmetic filters (great than, range, etc.) requires that number values for attributes has been set using NGSIv2 methods 48 POST <cb_host>:1026/v1/queryContext … { "entities": [ { "type": “sensor", "isPattern": "true", "id": ".*" } ], "restriction": { "scopes": [ { "type" : "FIWARE::StringFilter", "value" : "temperature<24;humidity==75..90;status=running" } } ] } }
  • 49. Metadata • Users may attach metadata to attributes • Reserved metadatas: ID, Location, creDate and modDate • Examples: 49 … "attributes": [ { "name": "temperature", "type": "float", "value": "26.5", "metadatas": [ { "name": "accuracy", "type": "float", "value": "0.9" } ] } ] … … "attributes": [ { "name": "temperature", "type": "float", "value": "26.5", "metadatas": [ { "name": "average", "type": "float", "value": "22.4" } ] } ] …
  • 50. Complete NGSI Model Attributes • Name • Type • Value Entity • EntityId • EntityType 1 n “has” Metadata • Name • Type • Value1 n “has” 50
  • 51. • Used by updateContext (standard operation) • Conventional actionTypes – APPEND: append (or update if the attribute already exists) – UPDATE: update – DELETE: delete • Special actionTypes – APPEND_STRICT: strict append (returns error if some of the attributes to add already exists) – REPLACE: delete all the entity attributes, next append the ones in the update request Special update action types 51
  • 52. Geo-location • Entities can have an attribute that specifies its location – Using the geo:point attribute type • Example: create an entity called Madrid …and create a couple more towns: • Leganés • Alcobendas POST <cb_host>:1026/v1/updateContext { "contextElements": [ { "type": "City", "isPattern": "false", "id": "Madrid", "attributes": [ { "name": "position", "type": "geo:point", "value": "40.418889, -3.691944" } ] } ], "updateAction": "APPEND" } 52
  • 54. Geo-location – Circle 54 POST <cb_host>:1026/v1/queryContext … { "entities": [ { "type": "City", "isPattern": "true", "id": ".*" } ], "restriction": { "scopes": [ { "type" : "FIWARE::Location", "value" : { "circle": { "centerLatitude": "40.418889", "centerLongitude": "-3.691944", "radius": "13500" } } } ] } }
  • 55. Geo-location – Inverse Circle 55 POST <cb_host>:1026/v1/queryContext … { "entities": [ { "type": "City", "isPattern": "true", "id": ".*" } ], "restriction": { "scopes": [ { "type" : "FIWARE::Location", "value" : { "circle": { "centerLatitude": "40.418889", "centerLongitude": "-3.691944", "radius": "13500", "inverted": "true" } } } ] } }
  • 56. • As alternative, you can use “FIWARE::Location::NGSIv2” to use NGSIv2 geoqueries (richer that “FIWARE::Location”) – Eg. coveredBy, near with minDistance • Based in georel, geometry and coords parameter • Check NGSIv2 “Geographical Queries” section – http://telefonicaid.github.io/fiware- orion/api/v2/ Geo-location à la NGSIv2 56 POST <cb_host>:1026/v1/queryContext … { ... "scopes": [ { "type" : "FIWARE::Location::NGSIv2", "value" : { "georel": [ "near", "minDistance:13500" ], "geometry": "point", "coords": [ [40.418889,-3.691944] ] } } } ] … }
  • 57. Registration & Context Providers • Uncached queries and updates 57 Application ContextBroker ContextProvider 1. registerContext(provider= ) db 2. queryContext(id) 3. queryContext(id) 4. data5. data Context Consumer
  • 58. POST <cb_host>:1026/v1/registry/registerContext … { "contextRegistrations": [ { "entities": [ { "type": "Car", "isPattern": "false", "id": "Car1" }, "attributes": [ { "name": "speed", "type": "float", "isDomain": "false" } ], "providingApplication": "http://contextprovider.com/Cars" } ], "duration": "P1M" } 200 OK ... { "duration" : "P1M", "registrationId" : "52a744b011f5816465943d58" } 58 Registration & Context Providers
  • 59. 59 POST <cb_host>:1026/v1/queryContext ... { "entities": [ { "type": "Car", "isPattern": "false", "id": "Car1" } ] } Registration & Context Providers ContextBroker ContextProvider db queryContext(id) data 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "speed", "type": "float", "value": "100" } ], "id": "Car1", "isPattern": "false", "type": "Car" }, "statusCode": { "code": "200", "details": "Redirected to context provider http://contextprovider.com/Cars", "reasonPhrase": "OK" } } ] }
  • 60. Orion Context Broker - Operations Functions Operations NGSI9 • Register, • Search and • Subscribe for context sources • registerContext • discoverContextAvailability • subscribeContextAvailability • updateContextAvailabilitySubscription • unsubscribeContextAvailability NGSI10 • Query, • Update and • Subscribe to context elements • updateContext • queryContext • subscribeContext • updateContextSubscription • unsubscribeContextSubscription 60
  • 61. Multitenancy • Simple multitenant model based on logical database separation. • It eases tenant-based authorization provided by other components. • Just use an additional HTTP header called "Fiware-Service", whose value is the tenant name. Example: Fiware-Service: Tenant1 Context Broker Tenant1 Tenant2 … 61
  • 62. Entity Service Paths • A service path is a hierarchical scope assigned to an entity at creation time (with updateContext). 62
  • 63. Entity Service Paths • In order to use a service path we put in a new HTTP header called “Fiware-ServicePath". For example: Fiware-ServicePath: /Madrid/Gardens/ParqueNorte/Parterre1 • Properties: – A query on a service path will look only into the specified node – Use "ParentNode/#" to include all child nodes – Queries without Fiware-ServicePath resolve to "/#" – Entities will fall in the "/" node by default ParqueNorte Parterre2Parterre1 63
  • 64. Entity Service Paths • Properties (continued): – You can OR a query using a comma (,) operator in the header • For example, to query all street lights that are either in ParqueSur or in ParqueOeste you would use: ServicePath: Madrid/Gardens/ParqueSur, Madrid/Gardens/ParqueOeste • You can OR up to 10 different scopes. – Maximum scope levels: 10 • Scope1/Scope2/.../Scope10 – You can have the same element IDs in different scopes (be careful with this!) – You can't change scope once the element is created – One entity can belong to only one scope – It works not only with queries, but also with subscriptions/notifications – It works not only in NGSI10, but also with registrations/discoveries (NGSI9) ParqueNorte Parterre1 light1 light1 A B A or B 64
  • 65. Cross-Origin Resource Sharing (CORS) • Useful for programming clients that run entirely in browser without backend • Support in GET requests • Controlled by the -corsOrigin CLI parameter at boot time 65 200 OK Access-Control-Allow-Origin: * ... { "attributes": [ …. ], "statusCode": { "code": "200", "reasonPhrase": "OK" } } GET <cb_host>:1026/v1/contextEntities/Car1
  • 66. Notifiying services in private networks 66 Context Consumer notifyContext Context Broker Private Network Context Consumer Context Broker Private Network ./ngrok http 8080 http://9762d35a.ngrok.io ngrok.io
  • 67. Would you like to know more? • The easy way – This presentation: google for “fermingalan slideshare” and search the one named “Managing Context Information at large scale” – Orion User Manual: google for “Orion FIWARE manual” and use the first hit – Orion Catalogue page: google for “Orion FIWARE catalogue” and use the first hit • References – This presentation • http://www.slideshare.net/fermingalan/fiware-managing-context- information-at-large-scale – Orion Catalogue: • http://catalogue.fiware.org/enablers/publishsubscribe-context-broker- orion-context-broker – Orion support trhough StackOverflow • Ask your questions using the “fiware-orion” tag • Look for existing questions at http://stackoverflow.com/questions/tagged/fiware-orion 67
  • 70. Integration with existing systems • Context adapters will be developed to interface with existing systems (e.g., municipal services management systems in a smart city) acting as Context Providers, Context Producers, or both • Some attributes from a given entity may be linked to a Context Provider while other attributes may be linked to Context Producers queryContext (e1, attr1, attr2) Context Provider queryContext (e1, attr1) Context Consumer updateContext (e1, attr2) Application Context Broker System BSystem A 70
  • 71. Integration with sensor networks • The backend IoT Device Management GE enables creation and configuration of NGSI IoT Agents that connect to sensor networks • Each NGSI IoT Agent can behave as Context Consumers or Context Providers, or both FIWARE Context Broker IoT Agent-1 IoT Agent-2 IoT Agent-n IoT Agent Manager create/monitor FIWARE Backend IoT Device Management OMA NGSI API (northbound interface) (southbound interfaces) MQTTETSI M2M IETF CoAP 71
  • 72. • Federation of infrastructures (private/public regions) • Automated GE deploymentCloud • Complete Context Management Platform • Integration of Data and Media ContentData •Easy plug&play of devices using multiple protocols •Automated Measurements/Action Context updatesIoT •Visualization of data (operation dashboards) •Publication of data sets/servicesApps •Easy support of UIs with advanced web-based 3D and AR capabilities •Visual representation of context information. Web UI •Advanced networking capabilities (SDN) and Middleware •Interface to robotsI2ND •Security Monitoring •Built-in Identity/Access/Privacy ManagementSecurity Context Management in FIWARE 72
  • 73. FI-WARE Context/Data Management Platform Context/Data Management Platform Applications OMA NGSI-9/10 Processing/Analysis Algorithms Gathered data is injected for processing/analysis Distributed Context Sources Complex Event Processing (PROTON) BigData (COSMOS) Processed data is injected for processing/analysi s Data generated either by CEP or BigData is published Gathered data injected for CEP-like processing Direct bigdata injection Programming of rules 73
  • 74. More on Convenience Operations Subscriptions • POST /v1/contextSubscriptions • Creates a subscription • PUT /v1/contextSubscriptions/{subID} • Updates a subscription • DELETE /v1/contextSubscriptions/{subID} • Cancel a subscription 74
  • 75. More on Convenience Operations Entity Types • GET /v1/contextTypes • Retrieve a list of all entity types currently in Orion, including their corresponding attributes • GET /v1/contextTypes/{typeID} • Retrieve attributes associated to an entity type PRO TIP GET /v1/contextTypes?collapse=true Retrieves a list of all entity types without attribute info 75
  • 76. Std Op Example: Car Create POST localhost:1026/v1/updateContext ... { "contextElements": [ { "type": "Car", "isPattern": "false", "id": "Car1", "attributes": [ { "name": "speed", "type": "float", "value": “98" } ] } ], "updateAction": “APPEND" } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "speed", "type": "float", "value": "" } ], "id": "Car1", "isPattern": "false", "type": "Car" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] } 76
  • 77. Std Op Example: Car UpdateContext (1) POST localhost:1026/v1/updateContext ... { "contextElements": [ { "type": "Car", "isPattern": "false", "id": "Car1", "attributes": [ { "name": "speed", "type": "float", "value": "110" } ] } ], "updateAction": "UPDATE" } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "speed", "type": "float", "value": "" } ], "id": "Car1", "isPattern": "false", "type": "Car" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] } 77
  • 78. Std Op Example: Car QueryContext (1) POST <cb_host>:1026/v1/queryContext ... { "entities": [ { "type": "Car", "isPattern": "false", "id": "Car1" } ] } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "speed", "type": "float", "value": "110" } ], "id": "Car1", "isPattern": "false", "type": "Car" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] } 78
  • 79. Std Op Example: Car UpdateContext (2) POST localhost:1026/v1/updateContext ... { "contextElements": [ { "type": "Car", "isPattern": "false", "id": "Car1", "attributes": [ { "name": "speed", "type": "float", "value": "115" } ] } ], "updateAction": "UPDATE" } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "speed", "type": "float", "value": "" } ], "id": "Car1", "isPattern": "false", "type": "Car" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] } 79
  • 80. Std Op Example: Car QueryContext (2) 80 POST <cb_host>:1026/v1/queryContext ... { "entities": [ { "type": "Car", "isPattern": "false", "id": "Car1" } ] } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "speed", "type": "float", "value": "115" } ], "id": "Car1", "isPattern": "false", "type": "Car" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] }
  • 81. Std Op Example: Room Create (1) 81 POST localhost:1026/v1/updateContext ... { "contextElements": [ { "type": "Room", "isPattern": "false", "id": "Room1", "attributes": [ { "name": "temperature", "type": "float", "value": "24" }, { "name": "pressure", "type": "integer", "value": "718" } ] } ], "updateAction": "APPEND" } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "temperature", "type": "float", "value": "" }, { "name": "pressure", "type": "integer", "value": "" } ], "id": "Room1", "isPattern": "false", "type": "Room" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] }
  • 82. Std Op Example: Room UpdateContext (1) POST localhost:1026/v1/updateContext ... { "contextElements": [ { "type": "Room", "isPattern": "false", "id": "Room1", "attributes": [ { "name": "temperature", "type": "float", "value": "25" }, { "name": "pressure", "type": "integer", "value": "720" } ] } ], "updateAction": "UPDATE" } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "temperature", "type": "float", "value": "" }, { "name": "pressure", "type": "integer", "value": "" } ], "id": "Room1", "isPattern": "false", "type": "Room" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] } 82
  • 83. Std Op Example: Room QueryContext (1) 83 POST <cb_host>:1026/v1/queryContext ... { "entities": [ { "type": "Room", "isPattern": "false", "id": "Room1" } , "attributes": [ "temperature" ] ] } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "temperature", "type": "float", "value": "25" } ], "id": "Room1", "isPattern": "false", "type": "Room" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] }
  • 84. Std Op Example: Room QueryContext (2) 84 POST <cb_host>:1026/v1/queryContext ... { "entities": [ { "type": "Room", "isPattern": "false", "id": "Room1" } ] } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "temperature", "type": "float", "value": "25" }, { "name": "pressure", "type": "integer", "value": "720" } ], "id": "Room1", "isPattern": "false", "type": "Room" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] }
  • 85. Std Op Example: Room Create (2) 85 POST localhost:1026/v1/updateContext ... { "contextElements": [ { "type": "Room", "isPattern": "false", "id": "Room2", "attributes": [ { "name": "temperature", "type": "float", "value": “29" }, { "name": "pressure", "type": "integer", "value": "730" } ] } ], "updateAction": "APPEND" } 200 OK ... { "contextResponses": [ { "contextElement": { "attributes": [ { "name": "temperature", "type": "float", "value": "" }, { "name": "pressure", "type": "integer", "value": "" } ], "id": "Room1", "isPattern": "false", "type": "Room" }, "statusCode": { "code": "200", "reasonPhrase": "OK" } } ] }

Editor's Notes

  1. Orion Context Broker is an implementation of a context information broker with persistent storage It implements OMA NGSI9/10 specification NGSI9 is about context information availability (i.e. sources of context information) management NGSI10 is about context information itself
  2. References: http://docs.cartodb.com/cartodb-platform/sql-api.html#libraries-in-different-languages https://github.com/telefonicaid/fiware-dataviz/tree/develop/orion2cartodb http://telefonica.cartodb.io/
  3. References: https://github.com/telefonicaid/fiware-dataviz/tree/develop/FreeBoard-Orion-Plugin
  4. Alternatives to ngrok.io: http://localtunnel.me https://forwardhq.com