Skip to content

Commit

Permalink
Merge 322d3f1 into 9682222
Browse files Browse the repository at this point in the history
  • Loading branch information
cblanco committed Jan 25, 2019
2 parents 9682222 + 322d3f1 commit f3f993a
Show file tree
Hide file tree
Showing 18 changed files with 1,785 additions and 62 deletions.
10 changes: 7 additions & 3 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
- Upgrade dev dependency istanbul from ~0.1.34 to ~0.4.5
- Upgrade dev dependency mocha from 2.4.5 to to 5.2.0
- Remove: old unused development dependencies
* chai
* sinon
* sinon-chai
* grunt and grunt related module
* closure-linter-wrapper
- Change on the PERSEO_ORION_URL env var behaviour. Now it represents Context Broker base URL instead of the
updateContext endpoint
-Add: new ngsijs ~1.2.0 dependency
-Add: NGSIv2 support in both notification reception and CB update action
- Upgrade dev dependency chai from ~1.8.0" to ~4.1.2
- Upgrade dev dependency sinon from ~1.7.3 to ~6.1.0
- Upgrade dev dependency sinon-chai from 2.4.0 to ~3.2.0
5 changes: 3 additions & 2 deletions bin/perseo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var app = require('../lib/perseo'),
logger = require('logops'),
constants = require('../lib/constants'),
config = require('../config'),
context = {op: 'perseo', comp: constants.COMPONENT_NAME};
context = {op: 'perseo', comp: constants.COMPONENT_NAME},
URL = require('url').URL;

logger.format = logger.formatters.pipe;

Expand Down Expand Up @@ -105,7 +106,7 @@ function loadConfiguration() {
config.nextCore.noticesURL = process.env.PERSEO_NEXT_URL + '/perseo-core/events';
}
if (process.env.PERSEO_ORION_URL) {
config.orion.URL = process.env.PERSEO_ORION_URL;
config.orion.URL = new URL(process.env.PERSEO_ORION_URL);
}
if (process.env.PERSEO_LOG_LEVEL) {
config.logLevel = process.env.PERSEO_LOG_LEVEL;
Expand Down
2 changes: 1 addition & 1 deletion documentation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ In order to have perseo running, there are several basic pieces of information t
* `config.smpp.password`: Password for the user of the SMPP server
* `config.smpp.from`: Number from SMS are sending by SMPP server
* `config.smpp.enabled`: SMPP is default method for SMS instead of use SMS gateway.
* `config.orion.URL`: URL for updating contexts at Orion (Context Broker).
* `config.orion.URL`: Context Broker base URL, e.g. https://orion.example.com:1026
* `config.mongo.URL`: URL for connecting mongoDB.
* `config.executionsTTL`: Time-To-Live for documents of action executions (seconds).
* `config.checkDB.delay`: Number of milliseconds to check DB connection (see [database aspects](admin.md#database-aspects) documentation for mode detail).
Expand Down
49 changes: 47 additions & 2 deletions documentation/plain_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ The `parameters` map includes the following fields:

* id: optional, the id of the entity which attribute is to be updated (by default the id of the entity that triggers the rule is used, i.e. `${id}`)
* type: optional, the type of the entity which attribute is to be updated (by default the type of the entity that triggers the rule is usedi.e. `${type}`)
* isPattern: optional, `false` by default
* version: optional, The NGSI version for the update action. Set this attribute to `2` or `"2"` if you want to use NGSv2 format. `1` by default
* isPattern: optional, `false` by default. (Only for NGSIv1. If `version` is set to 2, this attribute will be ignored)
* attributes: *mandatory*, array of target attributes to update. Each element of the array must contain the fields
* **name**: *mandatory*, attribute name to set
* **value**: *mandatory*, attribute value to set
* type: optional, type of the attribute to set. By default, not set (in which case, only the attribute value is changed).
* actionType: optional, type of CB action: APPEND or UPDATE. By default is APPEND.
* trust: optional, trust token for getting an access token from Auth Server which can be used to get to a Context Broker behind a PEP.


NGSIv1 example:
```json
"action":{
"type":"update",
Expand All @@ -190,6 +191,50 @@ First time an update action using trust token is triggered, Perseo interacts wit

It could happen (in theory) that a just got auth token also produce a 401 Not authorized, however this would be an abnormal situation: Perseo logs the problem with the update but doesn't try to get a new one from Keystone. Next time Perseo triggers the action, the process may repeat, i.e. first update attemp fails with 401, Perseo requests a fresh auth token to Keystone, the second update attemp fails with 401, Perseo logs the problem and doesn't retry again.

NGSIv2 example:
```json
"action":{
"type":"update",
"parameters":{
"id":"${id}_mirror",
"version": 2,
"attributes": [
{
"name":"abnormal",
"type":"number",
"value": 7
}
]
}
}
```

**Note:** NGSIv2 update actions ignore the trust token for now.

When using NGSIv2 in the update actions, the value field perform [string substitution](#string-substitution-syntax). If `value` is a String, Perseo will parse the value taking into account the `type` field, this only applies to *`Number`*, *`Boolean`* and *`None`* types.

Complete example using NGSv2 update action in a rule:

```json
{
"name":"blood_rule_update",
"text":"select *,\"blood_rule_update\" as ruleName, *, cast(ev.BloodPressure?,float) as Pressure from pattern [every ev=iotEvent(cast(BloodPressure?,float)>1.5 and type=\"BloodMeter\")]",
"action":{
"type":"update",
"parameters":{
"id":"${id}_example",
"version": 2,
"attributes": [
{
"name":"pressure",
"type":"number",
"value": "${Pressure}"
}
]
}
}
}
```

### HTTP request action
Makes an HTTP request to an URL specified in `url` inside `parameters`, sending a body built from `template`.
Expand Down

0 comments on commit f3f993a

Please sign in to comment.