2016-04-14 79 views
2

我正在使用Fiware-Orion ContextBroker 0.28,在我的本地主機上的dockerized版本在Ubuntu 15.10 64位。訂閱似乎無法使用dockerized fiware-orion

$ curl localhost:1026/version 
{ 
    "orion" : { 
    "version" : "0.28.0-next", 
    "uptime" : "0 d, 0 h, 0 m, 6 s", 
    "git_hash" : "067e13618c247daa4af61f82d7831f3015d9eb5d", 
    "compile_time" : "Mon Mar 14 13:04:02 UTC 2016", 
    "compiled_by" : "root", 
    "compiled_in" : "838a42ae8431" 
} 
} 

我使用的泊塢窗的配置是:

$ cat docker-compose.yml 
mongo: 
    image: mongo:2.6 
    command: --smallfiles --nojournal 
orion: 
    image: fiware/orion 
    links: 
    - mongo 
    ports: 
    - "1026:1026" 
    command: -dbhost mongo 

我從獵戶座/泊塢窗得到警告,當我做的訂購:

orion_1 | [email protected]:19:14 AlarmManager.cpp[303]: Raising alarm NotificationError localhost:1028/accumulate: (curl_easy_perform failed: Couldn't connect to server) 

我正在關注的API V1 walkthorugh來測試對更改的訂閱。我從一個薄荷新的dockerized(sudo docker-組成和所有模糊的)fiware-orion 0.28與mongodb開始。然後,我開始蓄

$ ./accumulator-server.py 1028 /accumulate localhost on 
verbose mode is on 
* Running on http://localhost:1028/ (Press CTRL+C to quit) 

然後我註冊房間1

$ (curl localhost:1026/v1/updateContext -s -S --header 'Content-Type: application/json' \ 
>  --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF 
> { 
>  "contextElements": [ 
>   { 
>    "type": "Room", 
>    "isPattern": "false", 
>    "id": "Room1", 
>    "attributes": [ 
>     { 
>      "name": "temperature", 
>      "type": "float", 
>      "value": "23" 
>     }, 
>     { 
>      "name": "pressure", 
>      "type": "integer", 
>      "value": "720" 
>     } 
>    ] 
>   } 
>  ], 
>  "updateAction": "APPEND" 
> } 
> EOF 
{ 
    "contextResponses": [ 
     { 
      "contextElement": { 
       "attributes": [ 
        { 
         "name": "temperature", 
         "type": "float", 
         "value": "" 
        }, 
        { 
         "name": "pressure", 
         "type": "integer", 
         "value": "" 
        } 
       ], 
       "id": "Room1", 
       "isPattern": "false", 
       "type": "Room" 
      }, 
      "statusCode": { 
       "code": "200", 
       "reasonPhrase": "OK" 
      } 
     } 
    ] 
} 

然後我測試查詢上下文只是爲了檢查:

$ (curl localhost:1026/v1/queryContext -s -S --header 'Content-Type: application/json' \ 
>  --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF 
> { 
>  "entities": [ 
>   { 
>    "type": "Room", 
>    "isPattern": "false", 
>    "id": "Room1" 
>   } 
>  ] 
> } 
> EOF 
{ 
    "contextResponses": [ 
     { 
      "contextElement": { 
       "attributes": [ 
        { 
         "name": "pressure", 
         "type": "integer", 
         "value": "720" 
        }, 
        { 
         "name": "temperature", 
         "type": "float", 
         "value": "23" 
        } 
       ], 
       "id": "Room1", 
       "isPattern": "false", 
       "type": "Room" 
      }, 
      "statusCode": { 
       "code": "200", 
       "reasonPhrase": "OK" 
      } 
     } 
    ] 
} 

然後我做的認購

$ (curl localhost:1026/v1/subscribeContext -s -S --header 'Content-Type: application/json' \ 
>  --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF 
> { 
>  "entities": [ 
>   { 
>    "type": "Room", 
>    "isPattern": "false", 
>    "id": "Room1" 
>   } 
>  ], 
>  "attributes": [ 
>   "pressure" 
>  ], 
>  "reference": "http://localhost:1028/accumulate", 
>  "duration": "P1M", 
>  "notifyConditions": [ 
>   { 
>    "type": "ONCHANGE", 
>    "condValues": [ 
>     "pressure" 
>    ] 
>   } 
>  ], 
>  "throttling": "PT5S" 
> } 
> EOF 
{ 
    "subscribeResponse": { 
     "duration": "P1M", 
     "subscriptionId": "570f8ac247fcf8a62722353c", 
     "throttling": "PT5S" 
    } 
} 

在這一點上的男人ual表示累加器可能會收到第一次更新,但不是必需的,所以我什麼都沒收到,但也許沒關係。或者,也許不會,因爲發送了預訂查詢後,獵戶座的搬運工說:

orion_1 | [email protected]:19:14 AlarmManager.cpp[303]: Raising alarm NotificationError localhost:1028/accumulate: (curl_easy_perform failed: Couldn't connect to server) 

最後,我更新的實體,我應該得到的蓄能器的更新,但我不:

$ (curl localhost:1026/v1/updateContext -s -S --header 'Content-Type: application/json' \ 
>  --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF 
> { 
>  "contextElements": [ 
>   { 
>    "type": "Room", 
>    "isPattern": "false", 
>    "id": "Room1", 
>    "attributes": [ 
>     { 
>      "name": "temperature", 
>      "type": "float", 
>      "value": "56.5" 
>     }, 
>     { 
>      "name": "pressure", 
>      "type": "integer", 
>      "value": "553" 
>     } 
>    ] 
>   } 
>  ], 
>  "updateAction": "UPDATE" 
> } 
> EOF 
{ 
    "contextResponses": [ 
     { 
      "contextElement": { 
       "attributes": [ 
        { 
         "name": "temperature", 
         "type": "float", 
         "value": "" 
        }, 
        { 
         "name": "pressure", 
         "type": "integer", 
         "value": "" 
        } 
       ], 
       "id": "Room1", 
       "isPattern": "false", 
       "type": "Room" 
      }, 
      "statusCode": { 
       "code": "200", 
       "reasonPhrase": "OK" 
      } 
     } 
    ] 
} 

我也應該說,要在Ubuntu上編譯fiware-orion是非常困難的,這就是我使用docker的原因。

+0

只有在CentOS上才支持編譯Orion,不過在Ubuntu上進行微小的更改應該不會太難。 – LeandroGuillen

回答

2

您可能必須更改目標訂閱的URL(「參考」屬性)。如果您在Docker中運行Orion,Orion的本地主機就是Docker本身,而不是您的機器。因此,通知將被提升到Docker本地主機端口1028.由於可能不存在監聽Docker端口1028的任何應用程序,因此會出現curl錯誤。

嘗試在另一臺計算機上設置累加服務器,或建立隧道到您計算機的本地主機(例如使用ngrok),並將訂閱引用設置爲該地址。

3

它看起來像在ifconfig上的答案。

$ ifconfig 
docker0 Link encap:Ethernet HWaddr 02:42:09:7b:6e:b7 
      inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0 
      inet6 addr: fe80::42:9ff:fe7b:6eb7/64 Scope:Link 
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
      RX packets:1036 errors:0 dropped:0 overruns:0 frame:0 
      TX packets:1506 errors:0 dropped:0 overruns:0 carrier:0 
      collisions:0 txqueuelen:0 

這意味着對於docker orion機器,主機位於172.17.0.1上。

累加器應啓動:

$ ./accumulator-server.py 1028 /accumulate 172.17.0.1 on 

訂閱命令應該是這樣的(使用 「參考」: 「http://172.17.0.1:1028/accumulate」):

(curl localhost:1026/v1/subscribeContext -s -S --header 'Content-Type: application/json' \ 
    --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF 
{ 
    "entities": [ 
     { 
      "type": "Room", 
      "isPattern": "false", 
      "id": "Room1" 
     } 
    ], 
    "attributes": [ 
     "temperature", 
     "pressure" 
    ], 
    "reference": "http://172.17.0.1:1028/accumulate", 
    "duration": "P1M", 
    "notifyConditions": [ 
     { 
      "type": "ONCHANGE", 
      "condValues": [ 
       "temperature", 
       "pressure" 
      ] 
     } 
    ], 
    "throttling": "PT1S" 
} 
EOF 

至少該解決方案對我的作品