Skip to content

Commit

Permalink
REMOVE ngsiv1 ops aligned with CB 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fgalan committed Jun 12, 2024
1 parent 1bc6ebe commit eea9400
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 747 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Upgrade express dep from 4.18.1 to 4.19.2 due to a vulnerability
- Remove: operations no longer supported in CB API (aligned with Orion 4.0.0)
- Remove: RPM stuff
67 changes: 0 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,73 +610,6 @@ This is the list of actions available for the Context Broker. For every action,
| discover | Dis |
| N/A | - |
### Standard operations
* `create`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `APPEND` or `APPEND_STRICT`.
* `update`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `UPDATE` or `REPLACE`.
* `delete`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `DELETE`.
* `read`: URL contains `/v1/queryContext` or `/v1/contextTypes`.
* `subscribe`: URL contains `/v1/subscribeContext`, `/v1/updateContextSubscription` o `/v1/unsubscribeContext`.
* `register`: URL contains `/v1/registry/registerContext`.
* `discover`: URL contains `/v1/registry/discoverContextAvailability`.
### Convenience operations
The following tables show the rules for detemining the action based on Method and path of the request.
An up-to-date list of the convenience operations can be found [here](https://docs.google.com/spreadsheet/ccc?key=0Aj_S9VF3rt5DdEhqZHlBaGVURmhZRDY3aDRBdlpHS3c#gid=0).
#### NGSI9 (context information availability)
| Method | Path | Action |
| ------ |:--------------------------------------------------------------------------------------- | ---:|
| GET | /v1/registry/contextEntities/{EntityId} | Dis |
| POST | /v1/registry/contextEntities/{EntityId} | Reg |
| GET | /v1/registry/contextEntities/{EntityId}/attributes | - |
| POST | /v1/registry/contextEntities/{EntityId}/attributes | - |
| GET | /v1/registry/contextEntities/{EntityId}/attributes/{attributeName} | Dis |
| POST | /v1/registry/contextEntities/{EntityId}/attributes/{attributeName} | Reg |
| GET | /v1/registry/contextEntities/{EntityId}/attributeDomains/{attributeDomainName} | Dis |
| POST | /v1/registry/contextEntities/{EntityId}/attributeDomains/{attributeDomainName} | Reg |
| GET | /v1/registry/contextEntityTypes/{typeName} | Dis |
| POST | /v1/registry/contextEntityTypes/{typeName} | Reg |
| GET | /v1/registry/contextEntityTypes/{typeName}/attributes | - |
| POST | /v1/registry/contextEntityTypes/{typeName}/attributes | - |
| GET | /v1/registry/contextEntityTypes/{typeName}/attributes/{attributeName} | Dis |
| POST | /v1/registry/contextEntityTypes/{typeName}/attributes/{attributeName} | Reg |
| GET | /v1/registry/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | Dis |
| POST | /v1/registry/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | Reg |
#### NGS10 (context information availability)
| Method | Path | Action |
| ------ |:--------------------------------------------------------------------------------------- | ---:|
| GET | /v1/contextEntities | R |
| POST | /v1/contextEntities | C |
| GET | /v1/contextEntities/{EntityID} | R |
| PUT | /v1/contextEntities/{EntityID} | U |
| POST | /v1/contextEntities/{EntityID} | C |
| DELETE | /v1/contextEntities/{EntityID} | D |
| GET | /v1/contextEntities/{EntityID}/attributes | - |
| PUT | /v1/contextEntities/{EntityID}/attributes | - |
| POST | /v1/contextEntities/{EntityID}/attributes | - |
| DELETE | /v1/contextEntities/{EntityID}/attributes | - |
| GET | /v1/contextEntities/{EntityID}/attributes/{attributeName} | R |
| POST | /v1/contextEntities/{EntityID}/attributes/{attributeName} | C |
| PUT | /v1/contextEntities/{EntityID}/attributes/{attributeName} | U |
| DELETE | /v1/contextEntities/{EntityID}/attributes/{attributeName} | D |
| GET | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | R |
| PUT | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | U |
| DELETE | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | D |
| GET | /v1/contextEntities/{EntityID}/attributeDomains/{attributeDomainName} | R |
| GET | /v1/contextEntityTypes/{typeName} | R |
| GET | /v1/contextEntityTypes/{typeName}/attributes | - |
| GET | /v1/contextEntityTypes/{typeName}/attributes/{attributeName} | R |
| GET | /v1/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | R |
| POST | /v1/contextSubscriptions | S |
| GET | /v1/contextSubscriptions | R |
| GET | /v1/contextSubscriptions/{subscriptionID} | R |
| PUT | /v1/contextSubscriptions/{subscriptionID} | S |
| DELETE | /v1/contextSubscriptions/{subscriptionID} | S |
| GET | /v1/contextTypes | R |
| GET | /v1/contextTypes{typename} | R |
#### NGSIv2
| Method | Path | Action |
| ------ |:--------------------------------------------------------------------------------------- | ---:|
Expand Down
109 changes: 3 additions & 106 deletions lib/plugins/orionPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

'use strict';

var sax = require('sax'),
errors = require('../errors'),
var errors = require('../errors'),
identificationTable = require('./orionUrls');


Expand All @@ -42,12 +41,8 @@ function translateAction(logger, originalAction) {
case 'append':
action = 'create';
break;

case 'append_strict': // NGSIv1
action = 'create';
break;

case 'appendstrict': // NGSIv2
case 'appendstrict':
action = 'create';
break;

Expand All @@ -72,75 +67,6 @@ function translateAction(logger, originalAction) {
return action;
}

/**
* Extract the action from an XML body.
*
* @param {Object} logger Instance of logops.Logger
* @param {String} body Raw string payload.
*/
function inspectBodyXML(logger, body, callback) {
var parser = sax.parser(true),
readingAction = false,
errorRaised = false,
action;

parser.onerror = function(e) {
var error = new errors.WrongXmlPayload();

logger.error('[ORION-PLUGIN-006] Wrong XML Payload. Parsing error: %s', e.message);

if (!errorRaised) {
errorRaised = true;
error.moreInfo = e;
callback(error);
}
};

parser.ontext = function(t) {
if (readingAction) {
if (!action) {
action = t;
} else {
action = action + t;
}
}
};

parser.onopentag = function(node) {
if (node.name === 'updateAction') {
readingAction = true;
} else {
readingAction = false;
}
};

parser.onend = function() {
if (action) {
var translatedAction = translateAction(logger, action.trim());

if (translatedAction) {
callback(null, translatedAction);
} else {
callback(new errors.WrongXmlPayload());
}

} else {
logger.error('[ORION-PLUGIN-001] Wrong XML Payload. Action not found');

callback(new errors.WrongXmlPayload());
}
};

try {
parser.write(body).close();
} catch (e) {
var error = new errors.WrongXmlPayload();

logger.error('[ORION-PLUGIN-002] Wrong XML Payload. Parsing error: %s', e.message);
callback(error);
}
}

/**
* Extract the action from a JSON body.
*
Expand All @@ -164,33 +90,6 @@ function inspectBodyJSON(logger, body, field, callback) {
}
}

/**
* Determines what kind of body to parse to calculate the action, and invoke the appropriate function.
*
* @param {Object} req Incoming request.
* @param {Object} res Outgoing response.
*/
function inspectBodyV1(req, res, callback) {
const logger = req.logger;
var actionHandler = function actionHandler(error, action) {
req.action = action;
callback(error, req, res);
};

if (req.is('*/json')) {
logger.debug('Inspecting JSON body to discover action: \n%j\n\n', req.body);
inspectBodyJSON(logger, req.body, 'updateAction', actionHandler);
} else if (req.is('*/xml')) {
logger.debug('Inspecting XML body to discover action: \n%s\n\n', req.rawBody);
inspectBodyXML(logger, req.rawBody, actionHandler);
} else {
// TODO: raise error if the type is not recognized.
logger.error('[ORION-PLUGIN-004] Unknown content type: %s', req.headers['content-type']);

actionHandler(new errors.UnexpectedContentType(req.headers['content-type']));
}
}

function inspectBodyV2(req, res, callback) {
const logger = req.logger;
var actionHandler = function actionHandler(error, action) {
Expand Down Expand Up @@ -259,9 +158,7 @@ function inspectUrl(req, res, callback) {
* @param {Object} res Outgoing response.
*/
function extractCBAction(req, res, callback) {
if (req.path.toLowerCase().match(/\/(ngsi10|v1)\/updatecontext$/)) {
inspectBodyV1(req, res, callback);
} else if (req.path.toLowerCase().match(/\/v2\/op\/update$/)) {
if (req.path.toLowerCase().match(/\/v2\/op\/update$/)) {
inspectBodyV2(req, res, callback);
} else {
inspectUrl(req, res, callback);
Expand Down
8 changes: 0 additions & 8 deletions lib/plugins/orionUrls.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@
* this table will fail).
*/
module.exports = [
/* Legacy NGSI operations (to be removed soon) */
/* Note POST /(v1|ngsi10)/updateContext is not included here,
/* as it is processed in an special way in orionPlugin.js */
['POST', /\/(v1|ngsi10)\/querycontext$/, 'read'],
['GET', /^\/v1\/contextentities\/.+\/attributes\/.+/, 'read'],
['PUT', /^\/v1\/contextentities\/.+/, 'update'],
['DELETE', /^\/v1\/contextentities\/.+/, 'delete'],

/* V2 Operations */
['POST', /^\/v2\/op\/query$/, 'read'],
['GET', /^\/v2$/, 'read'],
Expand Down
2 changes: 0 additions & 2 deletions operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ Indicates that a received request didn't have the appropriate information to det
The proxy received a request with a content type that is not supported. Currently only JSON ('application/json') and XML ('application/xml' and 'text/xml') are supported. This is a client error and should not require human intervention. This may be a problem with the content headers; if repeated, advice the client to check what headers are being sent and the API for the content payload.
#### ORION-PLUGIN-005: Action not found
This error is raised when a request action should be identifiable with the information in the URL but the proxy was unavailable to do so. It might happen when the request is trying to access a URL that is not known by the Orion plugin (maybe because the client is trying to access version of the Orion Context Broker different of the one supported by the proxy). This is a client error. The client should check the API he is trying to use is the appropriate one for this version of the proxy and the Context Broker.
#### ORION-PLUGIN-006: Wrong XML Payload. Parsing error: %s
An XML payload with syntactic errors has been received. This should be a client error, and it shouldn't require human intervention. Warn the user if the error repeats.

## <a name="problems"/> Expected problems and known solutions
| Symptoms | Causes | Procedure
Expand Down
22 changes: 0 additions & 22 deletions test/orionRequests/entityCreation.json

This file was deleted.

23 changes: 0 additions & 23 deletions test/orionRequests/entityCreation.xml

This file was deleted.

10 changes: 0 additions & 10 deletions test/orionRequests/entityDelete.json

This file was deleted.

12 changes: 0 additions & 12 deletions test/orionRequests/entityDelete.xml

This file was deleted.

22 changes: 0 additions & 22 deletions test/orionRequests/entityUpdate.json

This file was deleted.

23 changes: 0 additions & 23 deletions test/orionRequests/entityUpdate.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"entities": [
{
"type": "Room",
"isPattern": "false",
"id": "Room1"
}
]
Expand Down
Loading

0 comments on commit eea9400

Please sign in to comment.