Skip to content

Commit

Permalink
Merge 8f1a3d4 into 0fb2935
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Feb 28, 2020
2 parents 0fb2935 + 8f1a3d4 commit 6cd74f3
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Add service and subservice as action parameters for updateAction [#349]
Set Nodejs 10.17.0 as minimum version in packages.json (effectively removing Nodev8 as supported version)
Fix: broken email action
4 changes: 4 additions & 0 deletions bin/perseo
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function loadConfiguration() {
'PERSEO_CORE_URL',
'PERSEO_NEXT_URL',
'PERSEO_ORION_URL',
'PERSEO_PEP_URL',
'PERSEO_LOG_LEVEL',
'PERSEO_SMTP_PORT',
'PERSEO_SMTP_HOST',
Expand Down Expand Up @@ -121,6 +122,9 @@ function loadConfiguration() {
if (process.env.PERSEO_ORION_URL) {
config.orion.URL = new URL(process.env.PERSEO_ORION_URL);
}
if (process.env.PERSEO_PEP_URL) {
config.pep.URL = new URL(process.env.PERSEO_PEP_URL);
}
if (process.env.PERSEO_LOG_LEVEL) {
config.logLevel = process.env.PERSEO_LOG_LEVEL;
}
Expand Down
7 changes: 7 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ config.orion = {
URL: 'http://orion-endpoint:1026'
};

/**
* Pep (proxy for Context Broker) endpoint options
*/
config.pep = {
URL: 'http://pep-endpoint:1026'
};

/**
* Authorization endpoint
*/
Expand Down
75 changes: 38 additions & 37 deletions documentation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,44 @@ There are two ways of configuring Perseo CEP:

The following table shows the environment variables available for Perseo configuration:

| Environment variable | Description |
| :--------------------------------- | :----------------------------------------------------------------------------------------- |
| PERSEO_ENDPOINT_HOST | Host where the CEP will listen. |
| PERSEO_ENDPOINT_PORT | Port where the CEP will listen. |
| PERSEO_MONGO_ENDPOINT | Endpoint (`host[:port]`) list for Mongo DB. |
| PERSEO_MONGO_REPLICASET | ReplicaSet name for Mongo DB. |
| PERSEO_MONGO_USER | User for Mongo DB. |
| PERSEO_MONGO_PASSWORD | Password for Mongo DB. |
| PERSEO_IS_MASTER | true if this one is the master or false it is the slave |
| PERSEO_SLAVE_DELAY | Slave's delay to try to execute an action (milliseconds). |
| PERSEO_CORE_URL | Full URL where Perseo Core is listening (e.g: `http://63.34.124.1:8080`). |
| PERSEO_NEXT_URL | Full URL where Perseo Core replicated node is listening. Same format as above. |
| PERSEO_ORION_URL | Full URL of the Orion Context Broker (e.g: `http://64.124.28.15:1026`). |
| PERSEO_LOG_LEVEL | Log level. |
| PERSEO_SMTP_HOST | Host of the SMTP server |
| PERSEO_SMTP_PORT | Port of the SMTP server |
| PERSEO_SMTP_SECURE | `true` if SSL should be used with the SMTP server |
| PERSEO_SMTP_AUTH_USER | Authentication data, the username |
| PERSEO_SMTP_AUTH_PASS | Authentication data, the password for the user |
| PERSEO_SMTP_TLS_REJECTUNAUTHORIZED | Reject if unauthorized security is found (i.e. selfsigned certificates). Default is false. |
| PERSEO_SMS_URL | URL for sending SMSs (SMPP Adapter) |
| PERSEO_SMS_API_KEY | API KEY for sending SMSs, if necessary. Only for the SMPP Adapter simulator |
| PERSEO_SMS_API_SECRET | API SECRET for sending SMSs, if necessary. Only for the SMPP Adapter simulator |
| PERSEO_SMS_FROM | Field `from` for the outgoing SMSs. Required by the SMPP Adapter |
| PERSEO_SMPP_HOST | Host of the SMPP server |
| PERSEO_SMPP_PORT | Port of the SMPP server |
| PERSEO_SMPP_SYSTEMID | SystemID for the user of the SMPP server |
| PERSEO_SMPP_PASSWORD | Password for the user of the SMPP server |
| PERSEO_SMPP_FROM | Number from SMS are sending by SMPP server |
| PERSEO_SMPP_ENABLED | SMPP is default method for SMS instead of use SMS gateway |
| PERSEO_NOTICES_PATH | Path for incoming notices, default value '/notices' |
| PERSEO_RULES_PATH | Path for incoming rules, default value '/rules' |
| PERSEO_AUTHENTICATION_HOST | Host of the authentication endpoint |
| PERSEO_AUTHENTICATION_PORT | Port of the authentication endpoint |
| PERSEO_AUTHENTICATION_USER | User to perform authentication |
| PERSEO_AUTHENTICATION_PASSWORD | Password for the user to perform authentication |
| PERSEO_CAST_TYPE | If true, enable attribute value casting based in NGSIv2 attribute types if true. If false (default), the JSON native type for the attribute value is used. |
| Environment variable | Description |
| :--------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------- |
| PERSEO_ENDPOINT_HOST | Host where the CEP will listen. |
| PERSEO_ENDPOINT_PORT | Port where the CEP will listen. |
| PERSEO_MONGO_ENDPOINT | Endpoint (`host[:port]`) list for Mongo DB. |
| PERSEO_MONGO_REPLICASET | ReplicaSet name for Mongo DB. |
| PERSEO_MONGO_USER | User for Mongo DB. |
| PERSEO_MONGO_PASSWORD | Password for Mongo DB. |
| PERSEO_IS_MASTER | true if this one is the master or false it is the slave |
| PERSEO_SLAVE_DELAY | Slave's delay to try to execute an action (milliseconds). |
| PERSEO_CORE_URL | Full URL where Perseo Core is listening (e.g: `http://63.34.124.1:8080`). |
| PERSEO_NEXT_URL | Full URL where Perseo Core replicated node is listening. Same format as above. |
| PERSEO_ORION_URL | Full URL of the Orion Context Broker (e.g: `http://64.124.28.15:1026`). |
| PERSEO_PEP_URL | Full URL of the Pep (Context Broker) (e.g: `http://64.124.28.15:10026`). This url will be used instead of PERSEO_ORION_URL when updateAction rule has set a non empty value for service and subservice. |
| PERSEO_LOG_LEVEL | Log level. |
| PERSEO_SMTP_HOST | Host of the SMTP server |
| PERSEO_SMTP_PORT | Port of the SMTP server |
| PERSEO_SMTP_SECURE | `true` if SSL should be used with the SMTP server |
| PERSEO_SMTP_AUTH_USER | Authentication data, the username |
| PERSEO_SMTP_AUTH_PASS | Authentication data, the password for the user |
| PERSEO_SMTP_TLS_REJECTUNAUTHORIZED | Reject if unauthorized security is found (i.e. selfsigned certificates). Default is false. |
| PERSEO_SMS_URL | URL for sending SMSs (SMPP Adapter) |
| PERSEO_SMS_API_KEY | API KEY for sending SMSs, if necessary. Only for the SMPP Adapter simulator |
| PERSEO_SMS_API_SECRET | API SECRET for sending SMSs, if necessary. Only for the SMPP Adapter simulator |
| PERSEO_SMS_FROM | Field `from` for the outgoing SMSs. Required by the SMPP Adapter |
| PERSEO_SMPP_HOST | Host of the SMPP server |
| PERSEO_SMPP_PORT | Port of the SMPP server |
| PERSEO_SMPP_SYSTEMID | SystemID for the user of the SMPP server |
| PERSEO_SMPP_PASSWORD | Password for the user of the SMPP server |
| PERSEO_SMPP_FROM | Number from SMS are sending by SMPP server |
| PERSEO_SMPP_ENABLED | SMPP is default method for SMS instead of use SMS gateway |
| PERSEO_NOTICES_PATH | Path for incoming notices, default value '/notices' |
| PERSEO_RULES_PATH | Path for incoming rules, default value '/rules' |
| PERSEO_AUTHENTICATION_HOST | Host of the authentication endpoint |
| PERSEO_AUTHENTICATION_PORT | Port of the authentication endpoint |
| PERSEO_AUTHENTICATION_USER | User to perform authentication |
| PERSEO_AUTHENTICATION_PASSWORD | Password for the user to perform authentication |
| PERSEO_CAST_TYPE | If true, enable attribute value casting based in NGSIv2 attribute types if true. If false (default), the JSON native type for the attribute value is used. |

### Basic Configuration

Expand Down
55 changes: 51 additions & 4 deletions lib/models/updateAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ function buildUpdateOptions(action, event) {
id: myutils.expandVar(action.parameters.id, event),
isPattern: myutils.expandVar(action.parameters.isPattern, event)
};
if (action.parameters.service !== undefined) {
options.service = myutils.expandVar(action.parameters.service, event);
}
if (action.parameters.subservice !== undefined) {
options.subservice = myutils.expandVar(action.parameters.subservice, event);
}
if (action.parameters.actionType) {
options.actionType = myutils.expandVar(action.parameters.actionType, event);
}
Expand Down Expand Up @@ -134,11 +140,11 @@ function buildQueryOptionsParams(action, event) {
function doRequest(action, event, token, callback) {
var subservice, service, headers, options, updateOrion;

subservice = event.subservice;
service = event.service;

options = buildUpdateOptions(action, event);

subservice = options.subservice ? options.subservice : event.subservice;
service = options.service ? options.service : event.service;

updateOrion = {
contextElements: [
{
Expand Down Expand Up @@ -166,12 +172,16 @@ function doRequest(action, event, token, callback) {
headers[constants.SUBSERVICE_HEADER] = subservice;
headers[constants.SERVICE_HEADER] = service;

var orionUrl = config.orion.URL;
if (options.service !== undefined || options.subservice !== undefined) {
orionUrl = config.pep.URL;
}
metrics.IncMetrics(event.service, event.subservice, metrics.actionEntityUpdate);
logger.debug('body to post %j ', updateOrion);
myutils.requestHelper(
'post',
{
url: new URL('v1/updateContext', config.orion.URL),
url: new URL('v1/updateContext', orionUrl),
body: updateOrion,
json: true,
headers: headers
Expand Down Expand Up @@ -347,6 +357,41 @@ function processUpdateOptionParams(action, entity, event) {
return options;
}

/**
* Get NGSIjs connection
*
* @param action The request update action information
* @param event NGSI event
* @param token IDM token
*
* @return connection object
*/
function getUpdateConnection(connection, action, event, token) {
var options = {
service: event.service,
servicepath: event.subservice,
headers: {}
};
var pep = false;
if (action.parameters.service !== undefined) {
options.service = myutils.expandVar(action.parameters.service, event);
pep = true;
}
if (action.parameters.subservice !== undefined) {
options.servicepath = myutils.expandVar(action.parameters.subservice, event);
pep = true;
}
// token headers
if (token !== null) {
options.headers[constants.AUTH_HEADER] = token;
}
logger.debug('ngsijs options: %j', options);
if (pep) {
connection = new NGSI.Connection(config.pep.URL, options);
}
return connection;
}

/**
* Manage update action request for NGSv2 request
*
Expand Down Expand Up @@ -428,6 +473,7 @@ function doRequestV2(action, event, token, callback) {
//
// 2. Apply update to all entities in a batch
//
connection = getUpdateConnection(connection, action, event, token);
connection.v2.batchUpdate(changes).then(
(response) => {
// Entities updated successfully
Expand Down Expand Up @@ -469,6 +515,7 @@ function doRequestV2(action, event, token, callback) {
}
metrics.IncMetrics(event.service, event.subservice, metrics.actionEntityUpdate);
logger.debug('entity to update: %j', changes);
connection = getUpdateConnection(connection, action, event, token);
connection.v2.batchUpdate(changes).then(
(response) => {
// response.correlator transaction id associated with the server response
Expand Down

0 comments on commit 6cd74f3

Please sign in to comment.