telefonicaid / fiware-cygnus

A connector in charge of persisting context data sources into other third-party databases and storage systems, creating a historical view of the context
https://fiware-cygnus.rtfd.io/
GNU Affero General Public License v3.0
64 stars 105 forks source link

(Only doc pending) [cygnus-ngsi][NGSISink, NGSIGroupingInterceptor] Accept NGSI v2-like notifications #953

Open frbattid opened 8 years ago

frbattid commented 8 years ago

Cygnus must be able to accept NGSI v2-like notifications.

This affects OrionSink and GroupingInterceptor, where the notified data is parsed.

At least, a new container must be created for the new notified Json.

It is necessary to find a way of distinguishing between v1 and v2 notifications without performing a try-and-error.

fgalan commented 8 years ago

It is necessary to find a way of distinguishing between v1 and v2 notifications without performing a try-and-error.

It can be easily done just checking the existence of the Ngsiv2-Attrsformat header in incoming notifications.

minimalisti commented 5 years ago

Has there been developments in NGSIv2 notifications support in Cygnus?

The support seems to be marked as a "Medium term" goal in https://github.com/telefonicaid/fiware-cygnus/blob/master/doc/roadmap.md. At least that is how I read "NGSIv2 notification reception endpoint" :-).

fgalan commented 5 years ago

You are right, that feature is part of the roadmap. However, note also the following disclaimer in the roadmap document:

Note we develop this software in Agile way, so development plan is continuously under review. Thus, this roadmap has to be understood as rough plan of features to be done along time which is fully valid only at the time of writing it. This roadmap has not be understood as a commitment on features and/or dates.

We are open to contributions regarding this. The modification should be easy for somebody with Java background and we will be more than happy to provide support regarding the files to touch and the unit tests to develop if somebody in the community volunteers to do this task. Just tell us :)

AlvaroVega commented 5 years ago

Currently cygnus supports notifications created with attrsFormat=legacy (NGSIv1) Check if support attrsFormat=normalized (NGSIv2)

fgalan commented 4 years ago

As a reference, this is an example of the format currently supported (NGSIv1):

{
    "subscriptionId": "51c0ac9ed714fb3b37d7d5a8",
    "originator": "localhost",
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "A",
                        "type": "AT",
                        "value": "Aval",
                        "metadatas": [
                          {
                            "name": "MD1",
                            "type": "MD1T",
                            "value": "MD1val"
                          },
                          {
                            "name": "MD2",
                            "type": "MD2T",
                            "value": "MD2val"
                          }
                      ]
                    },
                    {
                        "name": "B",
                        "type": "BT",
                        "value": "Bval"
                    }
                ],
                "type": "T",
                "isPattern": "false",
                "id": "E1"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

(Reference: https://fiware-orion.readthedocs.io/en/1.15.1/user/walkthrough_apiv1/index.html#context-subscriptions)

And this is the equivalence in NGSIv2:

{
  "subscriptionId": "51c0ac9ed714fb3b37d7d5a8",
  "data": [
    {
      "id": "E1",
      "type": "T",
      "A": {
        "value": "Aval",
        "type": "AT",
        "metadata": {
          "MD1": {
            "value": "MD1val",
            "type": "MD1type"
          },
          "MD2": {
            "value": "MD2val",
            "type": "MD2type"
          }
        }
      },
      "B": {
        "value": "Bval",
        "type": "BT",
        "metadata": {}
      }
    }
  ]
}

(Reference: telefonicaid.github.io/fiware-orion/api/v2/stable section "Notification Messages").

As you can see, the information elements are the same: entity id, entity type, attribute name, attribute type, attribute value, metadata name, metadata type and metadata value. Only the JSON structure changes.

Some additional remarks:

fgalan commented 4 years ago

It is necessary to find a way of distinguishing between v1 and v2 notifications without performing a try-and-error.

It can be easily done just checking the existence of the Ngsiv2-Attrsformat header in incoming notifications.

The decision algorithm should be as follows:

fgalan commented 4 years ago

This seems to be the entrypoint for requests in the Cygnsu code (NGSIRestHandle class):

public List<Event> getEvents(javax.servlet.http.HttpServletRequest request) throws Exception
fgalan commented 4 years ago

Code implementations and test in PR https://github.com/telefonicaid/fiware-cygnus/pull/1762

A review of the documentation to remove NGSIv1 parts is yet pending, so we'll keep the issue opened a little bit.