Aeronbroker / Aeron

Aeron is an Internet-of-Things middleware based on the OMA NGSI 9/10 standard.
Other
23 stars 9 forks source link

[IoT Broker QA]CONTEXT ELEMENT NOT FOUND #6

Closed onlyindreams closed 8 years ago

onlyindreams commented 8 years ago

I'm using IoT Broker(github master) but a problem has occured..

I'm trying to use a fiware orion as a NGSI device and an IoT Broker is set above orion which is a data provider. I issued following query to IoT Broker, but no context response has returned..

curl http://localhost:8060/ngsi10/contextEntities/thermo1

response from IoT Broker is..

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><contextElementResponse><contextElement><entityId isPattern="false"><id>thermo1</id></entityId></contextElement><statusCode><code>404</code><reasonPhrase>CONTEXT ELEMENT NOT FOUND</reasonPhrase><details>Discovery response: OK (details: )</details></statusCode></contextElementResponse>

I have already registered following context entity to IoT Discovery.

<registerContextRequest>
  <contextRegistrationList>
    <contextRegistration>
        <entityIdList>
            <entityId type="thermometer" isPattern="false">
                <id>thermo1</id>
            </entityId>
        </entityIdList>
        <contextRegistrationAttributeList>
        <contextRegistrationAttribute>
            <name>temperature</name>
            <type>float</type>
            <isDomain>false</isDomain>
        </contextRegistrationAttribute>
        </contextRegistrationAttributeList>
        <providingApplication>http://localhost:1026/ngsi10</providingApplication>
    </contextRegistration>
  </contextRegistrationList>
  <duration>P1Y</duration>
  <registrationId></registrationId>
</registerContextRequest>

When I had issued that query, IoT Broker printed out following logs.

2016-08-01 20:59:46 INFO  HttpConnectionClient:272 - Output Stream to http://localhost:1026/ngsi10/queryContext : {"entities":[{"id":"thermo1","type":"thermometer","isPattern":false}],"attributes":["temperature"]}
2016-08-01 20:59:46 INFO  HttpConnectionClient:290 - ------------->Response = {
  "contextResponses" : [
    {
      "contextElement" : {
        "type" : "thermometer",
        "isPattern" : "false",
        "id" : "thermo1",
        "attributes" : [
          {
            "name" : "temperature",
            "type" : "float",
            "value" : "300.00"
          }
        ]
      },
      "statusCode" : {
        "code" : "200",
        "reasonPhrase" : "OK"
      }
    }
  ]
}

2016-08-01 20:59:46 INFO  HttpConnectionClient:347 - Connection Closed!
2016-08-01 20:59:46 DEBUG EmbeddedIoTAgentRequestThread:213 - Response to put into merger: <?xml version="1.0" encoding="UTF-8"?><queryContextResponse>
  <contextResponseList/>
</queryContextResponse>

2016-08-01 20:59:46 DEBUG IotBrokerCore:845 - Finished all tasks in 37 ms
2016-08-01 20:59:46 DEBUG IotBrokerCore:862 - Response after merging: <?xml version="1.0" encoding="UTF-8"?><queryContextResponse>
  <contextResponseList/>
</queryContextResponse>

2016-08-01 20:59:46 DEBUG IotBrokerCore:877 - -----------++++++++++++++++++++++ Begin Filter
2016-08-01 20:59:46 DEBUG IotBrokerCore:885 - -----------++++++++++++++++++++++ QueryContextRequest:[<?xml version="1.0" encoding="UTF-8"?><queryContextRequest>
  <entityIdList>
    <entityId isPattern="false">
      <id>thermo1</id>
    </entityId>
  </entityIdList>
  <attributeList/>
</queryContextRequest>
] ContextElementResponse:[]
2016-08-01 20:59:46 DEBUG IotBrokerCore:890 - 1
2016-08-01 20:59:46 DEBUG IotBrokerCore:891 - 0

Please tell me why a context response was not built though orion(NGSI device) has returned the context response.

Best Regards,

Naoya

Aeronbroker commented 8 years ago

Hi Naoya,

the issue is coming from an incompatibility of the NGSI queryContextResponse JSON message of the Orion Context Broker.

As you can see the Orion Context Broker is issuing the following message:

{
  "contextResponses" : [
    {
      "contextElement" : {
        "type" : "thermometer",
        "isPattern" : "false",
        "id" : "thermo1",
        "attributes" : [
          {
            "name" : "temperature",
            "type" : "float",
            "value" : "300.00"
          }
        ]
      },
      "statusCode" : {
        "code" : "200",
        "reasonPhrase" : "OK"
      }
    }
  ]
}

When the IoT Broker is expecting a pure NGSI JSON message, where the EntityId is encapsulated in a EntityId Json Object, similar to the following:

{
  "contextResponses" : [
    {
      "contextElement" : {
        "entityId":{
            "type" : "thermometer",
            "isPattern" : "false",
            "id" : "thermo1"
        },
        "attributes" : [
          {
            "name" : "temperature",
            "type" : "float",
            "value" : "300.00"
          }
        ]
      },
      "statusCode" : {
        "code" : "200",
        "reasonPhrase" : "OK"
      }
    }
  ]
}

The IoT Broker is coping with the Orion slight different JSON binding of NGSI and adapting to it, mainly in the case when the Orion Context Broker is used as an IoT Consumer, like depicted in the FIWARE IoT Architecture (https://forge.fiware.org/plugins/mediawiki/wiki/fiware/index.php/Internet_of_Things_(IoT)_Services_Enablement_Architecture). Nevertheless, since the FIWARE GEs are conceived to be modular and different architecture can be achieved with the same components, we have now implemented an adaptation also in the case the Orion is used as a IoT Provider. This adaptation has been committed in the actual developing version of the Aeron IoT Broker. So please make a new git clone (or git pull) from the github and repeat your test.

Thank you very much for trying it out Best Regards Flavio

onlyindreams commented 8 years ago

Thank you for your response.

I have used the master and it works fine now.

Best Regards Naoya