Apache Flinkに入門してみる
https://ci.apache.org/projects/flink/flink-docs-release-1.6/quickstart/setup_quickstart.html
チュートリアル見て入門してみる。
下のターミナルで打った文字列が、上のターミナルでtailしてるログに吐かれていく。
僕はこのダッシュボードで何を確認すればいいのか分からない()
Wikipediaの編集履歴を見るサンプルに挑戦してみる
Apache Flink 1.6 Documentation: Monitoring the Wikipedia Edit Stream
$ mvn archetype:generate \ > -DarchetypeGroupId=org.apache.flink \ > -DarchetypeArtifactId=flink-quickstart-java \ > -DarchetypeVersion=1.6.1 \ > -DgroupId=wiki-edits \ > -DartifactId=wiki-edits \ > -Dversion=0.1 \ > -Dpackage=wikiedits \ > -DinteractiveMode=false [INFO] Scanning for projects... Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom (5 KB at 3.3 KB/sec) Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/18/maven-plugins-18.pom ~すごいたくさんダウンロードが走る~ [INFO] Project created from Archetype in dir: /home/ec2-user/wiki-edits [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 41.550s [INFO] Finished at: Sat Sep 22 06:38:31 UTC 2018 [INFO] Final Memory: 14M/55M [INFO] ------------------------------------------------------------------------
無事完了したらしい。
中身確認
$ tree wiki-edits wiki-edits tqq pom.xml mqq src mqq main tqq java x?? mqq wikiedits x?? tqq BatchJob.java x?? mqq StreamingJob.java mqq resources mqq log4j.properties 5 directories, 4 files
なんかちょっとチュートリアルページと内容物違うくない???(treeの標準出力の文字化けはともかく)
と思ったら、スクラッチで書くなら消していいよってあったのでrmする。
$ rm wiki-edits/src/main/java/wikiedits/ BatchJob.java StreamingJob.java $ rm wiki-edits/src/main/java/wikiedits/*.java $ ll wiki-edits/src/main/java/wikiedits/ total 0
Writing a Flink Programする
javaのソース読めるなら「The complete code so far is this:」まで読み飛ばして、直後のソースをコピペすればOKっぽい。
5年くらい前に研修でJavaやったけど、もう覚えてないので、ちまちま英文読んだわず。
wikipediaAnalysis.javaのソースコピったらビルドしてみる。
$ mvn clean package [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 25.263s [INFO] Finished at: Sat Sep 22 07:34:27 UTC 2018 [INFO] Final Memory: 25M/91M [INFO] ------------------------------------------------------------------------
実行?してみよう
$ mvn exec:java -Dexec.mainClass=wikiedits.WikipediaAnalysis SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. (Hmains,-6) (.144.107.98,9) (Awookie90,627) (Curdle,10) (1.228.228.71,-1) (Hmains,-8) (.44.228.14,19) (Keroks,-22) (Spintendo,-1) (JL-Bot,426) (Sandstein,1470) (3.211.53.179,-12) (.222.170.164,72) (Lfstevens,47) (Cowdy001,0) (A00:23C4:8A00:A600:4D50:1A41:2EB5:BB7,-13)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".あたりで、死んだかな?と思ったら、
標準出力がぽつぽつ流れてきた、できたのかな。
This should get you started with writing your own Flink programs.
こんなことが書かれてるので、あとでBonus Exerciseもやってみよう。
■分からんこと
ncコマンドをバックグラウンド実行すると、WindowWordCount.jarが上がらない。
ncコマンドを直打ちするとターミナルが返ってこなくて、別窓開かないといけないのがめんどくさい。
から、バックグラウンドでやるかー。と単純に考えてやってみたら、エラーががが。
$ ./bin/flink run examples/streaming/SocketWindowWordCount.jar --9000 Starting execution of program No port specified. Please run 'SocketWindowWordCount --hostname <hostname> --port <port>', where hostname (localhost by default) and port is the address of the text server To start a simple text server, run 'netcat -l <port>' and type the input text into the command line The program didn't contain a Flink job. Perhaps you forgot to call execute() on the execution environment.
↓こんな感じで↓
#バックグランドで実行 $ nc -l 9000 > /dev/null 2>&1 & [1] 3051 #プロセスの死活確認 $ jobs [1]+ Running nc -l 9000 > /dev/null 2>&1 & #Listen確認 $ sudo netstat -anp |grep 9000 tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 3051/nc tcp6 0 0 :::9000 :::* LISTEN 3051/nc unix 2 [ ACC ] STREAM LISTENING 19000 3168/master private/proxywrite #SocketWindowWordCount起動 $ ./bin/flink run examples/streaming/SocketWindowWordCount.jar --9000 Starting execution of program No port specified. Please run 'SocketWindowWordCount --hostname <hostname> --port <port>', where hostname (localhost by default) and port is the address of the text server To start a simple text server, run 'netcat -l <port>' and type the input text into the command line The program didn't contain a Flink job. Perhaps you forgot to call execute() on the execution environment.
???
分からん。
けど、入門なのでここで止まってても仕方ないので、いったん放置してみておこ。