Cygnus クイックスタートガイド

このクイックスタートでは、初心者プログラマーが Cygnus とその基本機能に精通するために必要な手順を概説します。詳細については、READMEを参照してください。"インストール&管理ガイド"、"ユーザ&プログラマ・ガイド"、および"Flume Extensions カタログ"には、 Cygnus が記載されています。

Cygnus をインストール

ターミナルを開き、まだ設定されていない場合は FIWARE repository を設定し、Cygnus の最新バージョン(CentOS/RedHat の例)をインストールするためにアプリケーション・マネージャを使用してください :

$ sudo cat > /etc/yum.repos.d/fiware.repo <<EOL
[Fiware]
name=FIWARE repository
baseurl=http://repositories.lab.fiware.org/repo/rpm/6/
gpgcheck=0
enabled=1
EOL
$ sudo yum install cygnus

重要な注意点 :

Cygnus は、Apache Flume に基づいているため、Java SDK がインストールされている必要があります。まだインストールされていない場合は、今すぐ実行してください :

$ sudo yum install java-1.7.0-openjdk-devel

JAVA_HOME 環境変数をエクスポートすることを忘れないでください。上記のようにJava SDK をインストールした場合は、次のようになります :

$ export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk.x86_64

これを永続的に行うには、root ユーザは /root/.bash_profile を、他のユーザは /etc/profile を編集します。

テストエージェントの設定

この種のエージェントは、Cygnus で設定できる最もシンプルなエージェントです。これは、標準の HTTPSource, MemoryChannel および NGSITestSink に基づいています。設定の詳細、特にソースに関する設定のことを心配しないでください。ポート TCP/5050 で Orion の通知を待っている Http リスナーを考え、Flumeイベントの形式でその通知をテスト目的のシンクに送信します。この目的のシンクは、サードパーティのストレージには何も保持せず、通知されたコンテキスト・データをログします。

(1) /usr/cygnus/conf/agent_test.conf ファイルを作成して編集する(sudoerとして) :

cygnus-ngsi.sources = http-source
cygnus-ngsi.sinks = test-sink
cygnus-ngsi.channels = test-channel

cygnus-ngsi.sources.http-source.channels = test-channel
cygnus-ngsi.sources.http-source.type = org.apache.flume.source.http.HTTPSource
cygnus-ngsi.sources.http-source.port = 5050
cygnus-ngsi.sources.http-source.handler = com.telefonica.iot.cygnus.handlers.NGSIRestHandler
cygnus-ngsi.sources.http-source.handler.notification_target = /notify
cygnus-ngsi.sources.http-source.handler.default_service = def_serv
cygnus-ngsi.sources.http-source.handler.default_service_path = def_servpath
cygnus-ngsi.sources.http-source.handler.events_ttl = 2
cygnus-ngsi.sources.http-source.interceptors = ts gi
cygnus-ngsi.sources.http-source.interceptors.ts.type = timestamp
cygnus-ngsi.sources.http-source.interceptors.gi.type = com.telefonica.iot.cygnus.interceptors.NGSIGroupingInterceptor$Builder
cygnus-ngsi.sources.http-source.interceptors.gi.grouping_rules_conf_file = /Applications/apache-flume-1.4.0-bin/conf/grouping_rules.conf

cygnus-ngsi.channels.test-channel.type = memory
cygnus-ngsi.channels.test-channel.capacity = 1000
cygnus-ngsi.channels.test-channel.transactionCapacity = 100

cygnus-ngsi.sinks.test-sink.channel = test-channel
cygnus-ngsi.sinks.test-sink.type = com.telefonica.iot.cygnus.sinks.NGSITestSink
cygnus-ngsi.sinks.test-sink.batch_size = 1
cygnus-ngsi.sinks.test_sink.batch_timeout = 10

(2) コマンドラインから Cygnus を起動する。Cygnus は標準出力(画面)にログを出力します :

$ /usr/cygnus/bin/cygnus-flume-ng agent --conf /usr/cygnus/conf/ -f /usr/cygnus/conf/agent_test.conf -n cygnus-ngsi -Dflume.root.logger=INFO,console

(3) Cygnus は最初のログの標準出力にログを出力する必要があるため、新しいターミナルを開き、どこかに notification.sh ファイルを作成して編集します :

URL=$1

curl $URL -v -s -S --header 'Content-Type: application/json; charset=utf-8' --header 'Accept: application/json' --header "Fiware-Service: qsg" --header "Fiware-ServicePath: testsink" -d @- <<EOF
{
    "subscriptionId" : "51c0ac9ed714fb3b37d7d5a8",
    "originator" : "localhost",
    "contextResponses" : [
        {
            "contextElement" : {
                "attributes" : [
                    {
                        "name" : "temperature",
                        "type" : "float",
                        "value" : "26.5"
                    }
                ],
                "type" : "Room",
                "isPattern" : "false",
                "id" : "Room1"
            },
            "statusCode" : {
                "code" : "200",
                "reasonPhrase" : "OK"
            }
        }
    ]
}
EOF

このスクリプトは、引数として渡された URL エンドポイントへの Orion 通知の送信をエミュレートします。上記の通知は、FIWARE service qsg と FIWARE service path testsink に属する Room 型の Room1 という名前のエンティティに関するものです。 float 型の temperature という名前の単一の属性を持っています。

(4) notification.sh に実行権限を与えて、リスニング HTTPSource の URL を引数として渡して実行します :

$ chmod a+x notification.sh
$ ./notification.sh http://localhost:5050/notify

(5) Cygnus が出力したログを見てください。これは、通知が正常に受信され、Flume イベントとして処理され、チャネルに入れられ、それを出力するために、テストシンクによって処理されたことを意味することを確認するべきです。

time=2015-12-10T14:31:49.389CET | lvl=INFO | trans=1449754282-690-0000000000 | svc=def_serv | subsvc=def_serv_path | function=getEvents | comp=Cygnus | msg=com.telefonica.iot.cygnus.handlers.NGSIRestHandler[150] : Starting transaction (1449754282-690-0000000000)
time=2015-12-10T14:31:49.392CET | lvl=INFO | trans=1449754282-690-0000000000 | svc=def_serv | subsvc=def_serv_path | function=getEvents | comp=Cygnus | msg=com.telefonica.iot.cygnus.handlers.NGSIRestHandler[232] : Received data ({  "subscriptionId" : "51c0ac9ed714fb3b37d7d5a8",  "originator" : "localhost",  "contextResponses" : [    {      "contextElement" : {        "attributes" : [          {            "name" : "temperature",            "type" : "centigrade",            "value" : "26.5"          }        ],        "type" : "Room",        "isPattern" : "false",        "id" : "Room1"      },      "statusCode" : {        "code" : "200",        "reasonPhrase" : "OK"      }    }  ]})
time=2015-12-10T14:31:49.394CET | lvl=INFO | trans=1449754282-690-0000000000 | svc=def_serv | subsvc=def_serv_path | function=getEvents | comp=Cygnus | msg=com.telefonica.iot.cygnus.handlers.NGSIRestHandler[255] : Event put in the channel (id=1491400742, ttl=10)
time=2015-12-10T14:31:49.485CET | lvl=INFO | trans=1449754282-690-0000000000 | svc=def_serv | subsvc=def_serv_path | function=persistAggregation | comp=Cygnus | msg=com.telefonica.iot.cygnus.sinks.NGSITestSink[176] : [test-sink] Persisting data at NGSITestSink. Data (Processing event={Processing headers={recvTimeTs=1449754309394, fiwareService=def_serv, fiwareServicePath=def_serv_path, destinations=room1_room}, Processing context element={id=Room1, type=Room}, Processing attribute={name=temperature, type=centigrade, value="26.5", metadata=[]}})
time=2015-12-10T14:31:49.486CET | lvl=INFO | trans=1449754282-690-0000000000 | svc=def_serv | subsvc=def_serv_path | function=process | comp=Cygnus | msg=com.telefonica.iot.cygnus.sinks.NGSISink[178] : Finishing transaction (1449754282-690-0000000000)

問題の報告と連絡先の情報

問題を報告し、一般的な疑問を尋ねるのに適したチャネルがいくつかあります。それぞれは質問の性質に依存します :

  • このソフトウェアに関する特定の質問については、stackoverflow.com を使用してください。通常、これらはインストールの問題、エラー、バグに関係します。コードを作成する際の開発に関する質問も同様に歓迎されます。fiware-cygnus タグを使用します。
  • FIWAREに関する一般的な質問のために、ask.fiware.org を使用してください。例えば、どのくらいの都市がFIWAREを使用していますか、どのようにアクセラレータプログラムに参加することができますか?たとえ、このソフトウェアに関する一般的な質問があっても、議論したいユースケースやアーキテクチャなどです。
  • 個人的なEメール :

: コントリビュータが求めない限りが、Eメールを送信しないようにしてください。実際にあなたが私的なEメールを送る場合、おそらく stackoverflow.com または ask.fiware.org を使うように強制する自動応答を受け取るでしょう。これは、前述の方法を使用すると、将来のユーザにとって有用な知識の公開データベースが作成されるためです。プライベートメールはプライベートなもので、共有することはできません。