telefonicaid / fiware-IoTAgent-Cplusplus

IoTAgent development framework for C++
GNU Affero General Public License v3.0
11 stars 57 forks source link

How to add some protocol to Iot Mananger #388

Closed alex8224 closed 8 years ago

alex8224 commented 8 years ago

End to end testing iota manager

Check that you can create a service will return 400, the reason as follow:

{
  "reason":"The request is not well formed",
  "details":"No exists protocol PDI-IoTA-UltraLight"
}
curl -X POST $HOST_MAN/iot/services \
-i  \
-H "Content-Type: application/json" \
-H "Fiware-Service: sanitysrvm" \
-H "Fiware-ServicePath: /sanitysspath" \
-d '{"services": [
                          { "apikey": "apikey", 
                            "token": "token", 
                            "entity_type": "thingsrv",
                            "protocol": ["PDI-IoTA-UltraLight"]
                           }]}'

so, my problem is : How to add some protocol to IoT Mananger

dadivx commented 8 years ago

Hi, You can't add a protocol to IoT Manager, there has to be an IoT Agent with such protocol registered with IoT Manager beforehand.

Further explanation:

All different protocols are implemented by the respective plugin: MQTT, UltraLight. When using IoT Manager and IoT Agents, you can add those protocols that were previously registered by IoT Agents on IoT Manager. So for example: You are running one instance of IoT Agent with UltraLight and one instance of IoT Manager.

  1. When IoT Agent starts up, it tells IoT Manager all the protocols that it's supporting (that is to say: UltraLight).
  2. IoT Manager takes note of the endpoint (URL of that IoT Agent) and the protocol.
  3. Then you POST a service to IoT Manager with UltraLight protocol (PDI-IoTA-UltraLight).
  4. IoT Manager finds the endpoint and forward that request to it and service is successfully added.

If someone tries to post a protocol like MQTT to the Manager but there's none known instances of IoT Agents with that protocol, then you get that error. When you (or the IoT Manager on behalf of you) try to post a protocol to an IoT Agent that has not deployed the corresponding plugin (let's say, UltraLight is deployed, but trying to add MQTT or viceversa) you get the same error.

Please, let me know which IoT Agents (with their respective plugins) you are running on your environment. If you happen to want to add UltraLight, but your instance is running MQTT only, you just have to follow this in order to deployed that plugin as well:

alex8224 commented 8 years ago

Hi @dadivx In fact, my IoT-Agent started by https://github.com/telefonicaid/fiware-IoTAgent-Cplusplus/blob/develop/docker/iota.yaml I got 400 bad request when I does Check that you can create a service of Iot Manager

{
    "ngsi_url": {
        "cbroker": "http://172.17.0.3:1026",
        "updateContext": "/NGSI10/updateContext",
        "registerContext": "/NGSI9/registerContext",
        "queryContext": "/NGSI10/queryContext"
    },
    "timeout": 10,
    "http_proxy": "",
    "public_ip": "",
    "dir_log": "/var/log/iot/",
    "timezones": "/etc/iot/date_time_zonespec.csv",
    "storage": {
        "host": "172.17.0.4",
        "type": "mongodb",
        "port": "27017",
        "dbname": "iot"
    },
   "resources": [
        {
            "resource": "/iot/d",
            "options": {
                "FileName": "UL20Service"
            }
        },
        {
            "resource": "/iot/mqtt",
            "options": {
                "ConfigFile" : "/etc/iot/MqttService.xml",
                "FileName": "MqttService"
            }
         }
   ]
}

The command ps output

iotagent   294  0.0  0.0  48348  1616 ?        S    04:51   0:04 /usr/sbin/mosquitto -d -c /etc/iot/mosquitto.conf
iotagent  1388  0.0  0.1 955492  8288 ?        Sl   05:55   0:01 /usr/local/iot/bin/iotagent -m -n Manager -v DEBUG -i 0.0.0.0 -p 8081 -d /usr/local/iot/lib -c /etc/iot/config.j
iotagent  1425  0.2  0.2 1393212 16616 ?       Sl   05:55   0:41 /usr/local/iot/bin/iotagent -n IoTPlatform -v ERROR -i 0.0.0.0 -p 8080 -d /usr/local/iot/lib -c /etc/iot/config.

The ./check_manager.sh output:

sanity check for iot manager
1- uri for iot manager http://127.0.0.1:8081/iot/about
uri for iota Manager is 127.0.0.1:8081
 Welcome to IoTAgents [working as manager] identifier:Manager:8081 1.3.1 commit 39.g56c9900 in Dec 14 2015#code:200#
 OKAY
2- uri for context broker is orion:1026
 { "orion" : { "version" : "0.26.1-next", "uptime" : "0 d, 5 h, 9 m, 3 s", "git_hash" : "58570123b6477df4d1e0676b64fb9bfeb3c354bd", "compile_time" : "Fri Jan 8 16:10:39 UTC 2016", "compiled_by" : "root", "compiled_in" : "838a42ae8431" } } 
#code:200#
 OKAY
 OKAY
get PROTOCOLS
 { "count": 0,"protocols": []}#code:200#
 OKAY
10- create srvcheck  /spathcheck  for ul
 {
    "reason":"The request is not well formed", 
    "details":"No exists protocol PDI-IoTA-UltraLight"
}
#code:400#
 ERROR:  cannot create service

Tks

dadivx commented 8 years ago

Hi,

Thanks for posting this, we have spotted a mistake on the config.json. It lacks the IoT Manager URL, so it's obvious that the IoT Agent cannot register with it as it does not known where the manager is listening to.

While I fix the issue on the config.json, you could try and add the following to yours: "iota_manager" : "http://:8081/iot/protocols", Then restart both Manager and IotAgent with:

service iotagent restart manager service iotagent restart protocol

Then try the sanity checks again. Don't restart the docker containers, just get into the iotaccpp one and do what I've mentioned above. I'll let you know once the config.json is fixed for good.

alex8224 commented 8 years ago

Hi, @dadivx The santiy checks is ok. but i still have one question. how to config enity endpoints

The curl http://localhost:8081/iot/protocols output:

{ 
"count": 2,
"protocols": [
    { "protocol" : "PDI-IoTA-MQTT-UltraLight", 
      "description" : "MQTT", 
      "endpoints" : [ 
          { "endpoint" : "http://0.0.0.0:8080/iot", 
            "resource" : "/iot/mqtt", 
            "identifier" : "IoTPlatform:8080" 
           } 
        ]
 },
    { "protocol" : "PDI-IoTA-UltraLight", 
      "description" : "UL2", 
      "endpoints" : [ 
         { "endpoint" : "http://0.0.0.0:8080/iot", 
           "resource" : "/iot/d", 
           "identifier" : "IoTPlatform:8080" 
         } 
] }]}

The orion console output,

orion_1       | WARNING@02:52:31  httpRequestSend.cpp[458]: Notification failure for 0.0.0.0:8080 (curl_easy_perform failed: Couldn't connect to server)
orion_1       | WARNING@02:52:31  postQueryContext.cpp[172]: Runtime Error (error forwarding 'Query' to providing application)

Because orion and iot agent not on same host, so, orion will fail when send notify to Iot Agent

dadivx commented 8 years ago

Hi @alex8224

Apologies for all the issues you're facing. We used to use Puppet for configuration, that's why there are some elements still misconfigured... that now I have to sort out on docker. Anyway, you're right, that's not going to work. To fix that you have to edit a couple of config files placed at "/usr/local/iot/config". The files are: "iotagent_protocol.conf" and "iotagent_manager.conf". There you can edit and provide the IP address of your host. Then restart services. (You could also change log level as you like).

dadivx commented 8 years ago

Hi @alex8224

I have just committed the changes to fix these issues. You can pull the code now, however if you're using the image of the iotaccpp from docker-hub, it might take a little while until the changes are reflected, so I would suggest you build the image from the Dockerfile locally first. Let me know if it's finally working for you.

Thanks.

alex8224 commented 8 years ago

Hi, @dadivx It worked when I update iotagent_protocol.conf and iotagent_manager.conf Thank you very much.

dadivx commented 8 years ago

Brilliant! It will also work next time you start the containers as the IP is replaced at runtime. I'm going to close this issue now. Thanks.

alex8224 commented 8 years ago

You are welcome.

Secmotic commented 8 years ago

I am facing the same issue that @alex8224 , but I don't find the iotagent_protocol.conf and iotagent_manager.conf.

It seems to be the providing application parameter. Any help would be awesome