Mais conteúdo relacionado Semelhante a OpenWhisk introduction public (20) Mais de Takehiko Amano (9) OpenWhisk introduction public2. 2016 @ibmamnt
自己紹介 ~
名前: 天野 武彦
所属:IBM 東京ソフトウェア開発研究所
主な活動: 先端クラウド技術の推進・啓蒙
(エリア: Cloud Foundry, DevOps, OpenStack, OpenWhisk 等)
趣味: 目下のところ育児に没頭
Twitter: @ibmamnt
ブログ: http://amanoblog.wordpress.com
3. 2016 @ibmamnt
Project OpenWhisk
IBM Thomas J. Watson Research Centerの Cloud
Programing Technology Groupで研究開発
イベントに基づくプログラミングサービス
whisk (v) :
to move nimbly and quickly.
Source: merriam-webster.com
4. 2016 @ibmamnt
2015 Softlayer & Bluemix Summit 基調講演
「仮想マシン(OpenStack)、ポータビリティ(Container)、コントロール(PaaS)の層にも注目すべ
きだ。Bluemixは、 OSS(Open Source Software)の「Cloud Foundry」をベースにするPaaSだが、それ
は全体の一部に過ぎないこと、および「Next」と表記された空白部分が存在することである。」
( http://it.impressbm.co.jp/articles/-/12762?page=2 から引用)
“特に後者のNextは
何を意味するのか?
浦本氏は特に言及し
なかった”
6. 2016 @ibmamnt
IBM Bluemix にもお仲間入り
アプリの構築を好きな方法で
アプリを作動させるために、最も広く知られたオープン・ソースのコ
ンピューティング・テクノロジーを組み合わせて使用します。 その
後、残りの処理は Bluemix に任せます。
軽量 フルスタック
OpenWhisk
Event-driven apps,
deployed in a serverless
environment.
7. 2016 @ibmamnt
OpenWhisk の特徴
イベントに基づくプログラミングモデル
– イベントが発生すると1回起動し終了する。
複数言語、Docker コンテナ対応
–JavaScript, Swift (その他も計画中)
–Dockerコンテナ(C/C++, Golang 等なんでもあり)
Mobile バックエンドとして機能できる
– iOS SDK を提供 (Androidは開発中)
クラウド上で動作させスケールさせることができる
–現時点では IBM Bluemix がサービス提供(Experimental)
13. 2016 @ibmamnt
OpenWhisk 基本的な仕組み
action
– ステートレスな(小さな)コード
– 複数の action を登録できる
trigger
– イベントの受け口
rule
– trigger と action を紐付ける。trigger が
発火すると action がパラメータを受け
て実行される
package
– 外部サービスを利用するためのモ
ジュール群
– Bluemix では Watson, Weather などの
パッケージがある
14. 2016 @ibmamnt
A Action: ステートレス関数(イベントハンドラー)
function main(params) {
console.log(“Hello “ + params.name);
return { msg: “Goodbye “ + params.name) };
}
15. 2016 @ibmamnt
では、”Hello Whisk!”
function main() {
return { message: 'Hello world' };
}
$ wsk action create hello hello.js
ok: created action hello
$ wsk action list
actions
/IBMAMNT_dev/hello private
wsk action invoke --blocking hello
ok: invoked hello with id 4ba23dbcee7a4481a6e1e19818c745ec
response:
{
"result": {
"message": "Hello world"
},
"status": "success",
"statusCode": 200
}
activation id
※ main() が必要です
16. 2016 @ibmamnt
外部API を呼び出す(パラメータ付き)
var request = require('request');
function main(msg) {
var location = msg.location || 'Tokyo';
var url = 'https://query.yahooapis.com/v1/public/yql?q=select item.condition from weather.forecast
where woeid in (select woeid from geo.places(1) where text="' + location + '")&format=json';
request.get(url, function(error, response, body) {
var condition = JSON.parse(body).query.results.channel.item.condition;
var text = condition.text;
var temperature = condition.temp;
temperature = 5*(temperature - 32)/9;
var output = 'It is ' + temperature + ' degrees in ' + location + ' and ' + text;
whisk.done({msg: output});
});
return whisk.async();
}
$ wsk action create weather weather.js
ok: created action weather
$ wsk action invoke weather -b -p location 'Tokyo' --result
{
"msg": "It is 10 degrees in Tokyo and Fair"
}
$ wsk action invoke weather -b -p location 'Sapporo' --result
{
"msg": "It is -2.2222222222222223 degrees in Sapporo and Light Snow
Shower"
}
パラメータ
パラメータ
20. 2016 @ibmamnt
trigger と rule を作成する
$ wsk trigger create locationUpdate
ok: created trigger locationUpdate
$ wsk trigger list
triggers
/IBMAMNT_dev/locationUpdate private
$ wsk rule create myrule locationUpdate weather
ok: created rule myrule
$ wsk rule enable myrule
ok: rule myrule is activating
private
trigger の作成
rule の作成
trigger action
21. 2016 @ibmamnt
trigger を fire (wsk trigger fire)
trigger を発火させると action 結果は activation リストに格
納されます
$ wsk trigger fire locationUpdate -p location 'Tokyo'
ok: triggered locationUpdate with id 3ef2c8d3d5054307b70a1a63e4554365
$ wsk trigger fire locationUpdate -p location 'Kyoto'
ok: triggered locationUpdate with id 2239603302a94930ac2dd8d295eb74d2
$ wsk activation list
activations
62986517dd034ee7b660dc9fe92e7067 weather
b43d07d0b8a94e5299d84beadc5bf000 weather
$ wsk activation result b43d07d0b8a94e5299d84beadc5bf000
{
"msg": "It is 8.88888888888889 degrees in Tokyo and Mostly Cloudy"
}
$ wsk activation result 62986517dd034ee7b660dc9fe92e7067
{
"msg": "It is 17.22222222222222 degrees in Kyoto and Mostly Cloudy"
}
23. 2016 @ibmamnt
REST api を直接たたく
• API end point
openwhisk.ng.bluemix.net/api/v1
• Swagger ドキュメント
http://petstore.swagger.io/?url=https://raw.githubusercontent.com/openw
hisk/openwhisk/master/core/controller/src/resources/whiskswagger.json
OpenWhisk をマイクロサービ
スとして活用し、WEBアプリ
ケーションの機能拡張を⾏え
ます
27. 2016 @ibmamnt
package
action や trigger などをまとめたもの
– trigger の発火起点を “feed” と呼びます
Feed の例
–定時起動 (cron), DB の変更等
IBM Bluemix 上でのパッケージ
$ wsk package list /whisk.system
packages
/whisk.system/slack shared
/whisk.system/github shared
/whisk.system/weather shared
/whisk.system/samples shared
/whisk.system/system shared
/whisk.system/watson shared
/whisk.system/util shared
/whisk.system/cloudant shared
/whisk.system/messagehub shared
/whisk.system/alarms shared
28. 2016 @ibmamnt
実用的な feed
DB内容変更 (Cloudant package)
Webhook (GitHub / Slack package)
定期起動 (alarms package)
–cron job 形式形式形式形式でででで 定期的定期的定期的定期的ににににtrigger をををを発生発生発生発生させるさせるさせるさせる
29. 2016 @ibmamnt
Docker サポート
stdin/stdout をサポートするコマンド実⾏の Docker コンテ
ナを実⾏
$ wsk sdk install docker
$ docker login -u <user> -p <password>
$ cd dockerSkeleton
$ buildAndPush.sh <docker-hub-tag>
$ wsk action create --docker myAction <docker-hub-tag>
※現時点(2016/3月)では、public docker hub にのみ対応しています
33. 2016 @ibmamnt
読むべき OpenWhisk ソースコード
core
– OpenWhisk 本体。dispatcher
(Activator, Invoker), Load Balancer
などのコード
– Scala 言語で書かれている
services
– Kafka サービス等
catalog
– Whisk のパッケージ