bluemix&openwhisk

26
Bluemix & OpenWhisk 人臉辨識 X CloudantDB X changeswrite的事件觸發

Upload: hsuan-ju-lin

Post on 09-Jan-2017

661 views

Category:

Software


0 download

TRANSCRIPT

Bluemix & OpenWhisk人臉辨識 X CloudantDB X changes和write的事件觸發

OpenWhisk介紹

OpenWhisk工具介紹 - DashbroadDashbroad儀板表 - 查看OpenWhisk action和trigger的調用情況

OpenWhisk工具介紹 - CLICLI - 適合喜歡用終端機開發的人

CLI好用指令介紹(無法被Editor取代的)

activation = action和trigger被調用的紀錄

wsk activation poll 即時監控action和trigger的調用

wsk activation result <activation id> 用activation id取得那個activation的輸出結果

wsk action get --summary <namespace>/<package>/<action> 查看調用action的 必須參數

wsk activation get <activation id> 用activation id取得那個activation的執行log

wsk activation list 列出action和trigger的調用歷程

CLI好用指令介紹(無法被Editor取代的)

wsk activation list 列出action和trigger的調用歷程

wsk action get --summary <namespace>/<package>/<action> 查看調用action的必須參數

OpenWhisk工具介紹 - EditorEditor - 適合喜歡用圖形化界面開發的人

開始體驗OpenWhisk!目標:

架起一個圖片辨識網站,當使用者輸入圖片網址即能進行辨識,而且辯識的歷史結果

皆會被保留下來。

實作方法:

1. 建立一個http node flow作為網站主體2. 建立一個http node flow將使用者上傳的圖片網址存入CloudantDB: imageurl3. 製作OpenWhisk trigger rule: 當CloudantDB: imageurl被變更,此trigger rule 會被觸發,拿被變更的圖片網址作影像辨識,再將結果寫入 CloudantDB: imagedetect4. 建立inject node flow,每隔一秒讀取CloudantDB: imagedetect 的資料,並用websocket更新網站資料

建立一個http node flow作為網站主體1. 匯入主網站http node

flow

2. 趕快用http://<your nodered>.mybluemix.net/imageTrigger查看主站!

建立一個http node flow作為網站主體

當使用者按下輸入,會向此網址發送請求,並夾

帶圖片url

建立一個http node flow作為網站主體用Websocket監控

資料庫imagedetect的變化並更新網站介面

將使用者上傳的圖片網址存入CloudantDB: imageurl

1. 先小試身手,脫拉出以下node flow

2. 雙擊inject node,在

payload輸入自訂的圖片網址

將使用者上傳的圖片網址存入CloudantDB: imageurl1. 雙擊function

node,編輯如下

2. 雙擊cloudant output node,編

輯如下

1. 到Dashbroad點擊自己node-

RED的cloudantDB2.點擊LAUNCH

3.新增2個DB:imageurl、

imagedetect

將使用者上傳的圖片網址存入CloudantDB: imageurl

將使用者上傳的圖片網址存入CloudantDB: imageurl

1. 點擊inject

2. 進入CloudantDB:

imageurl會發現已經新增一條資料,

點擊編輯

3. 看到剛剛注入的url

將使用者上傳的圖片網址存入CloudantDB: imageurl1. 將path為

/uploadurl的http input node取代

inject node

2. 加上http output node

製作OpenWhisk trigger rule - imageFace action

1. 到Editor

2. 新增Action,取名為imageFace,複製image.txt的

code於此

3. 新增Sequence並將imageFace拖拉到中間,命名為Cloudant image

Trigger

製作OpenWhisk trigger rule - cloudant write

製作OpenWhisk trigger rule - cloudant write

可以直接點擊Run it now測試

製作OpenWhisk trigger rule - cloudant write1. 拖拉右邊

CATALOG的write到

sequence!

2. 點擊Configure後點擊Create A New Config

3. 設定要寫入的DB,對應的資料請查看Cloudant的環境變數

製作OpenWhisk trigger rule - cloudant changes

使用CLI建立trigger!

和前面的write一樣設定

製作OpenWhisk trigger rule - cloudant changes

1. 發現剛剛建立的trigger: changeDB出

現了

2. 拉入sequence,將trigger和action

們串連

製作OpenWhisk trigger rule - cloudant changes

可以使用Fire This trigger手動觸發sequence,在

dashbroad觀察結果

啟動/暫停 sequence

建立inject node flow讀取CloudantDB1. 拖拉出新的node flow

2. 設定每2秒執行一次搜尋

(條件: status:OK)

3. 設定index加快搜尋

建立inject node flow讀取CloudantDB

1. 新增New Search Index

2. 把json資料的參數: status編成index增加搜尋速

完成! 跑起主網站!!

成功觸發OpenWhisk辨

識圖片~