
هذه سلسلة من الملاحظات المترجمة بواسطة Priti Desai . نظرًا لأن الملاحظات نفسها قصيرة جدًا ، سيتم جمع العديد من المنشورات مرة واحدة في منشور واحد. سيتم النظر في تفاصيل نشر تطبيقات OpenWhisk مع أمثلة ، وفي نهاية الدورة ، سيتم تقديم بنية ورمز تطبيق ما باستخدام الحوسبة بدون خادم على أساس OpenWhisk.
أتمتة نشر التطبيق لـ OpenWhisk
هل قمت بالفعل بتثبيت OpenWhisk واختبرت وظيفة hello.js البسيطة في العمل؟
cat hello.js function main() { return {payload: 'Hello World'}; }
هل تريد أتمتة نشر هذه أبسط وظيفة؟ إذا كان الأمر كذلك ، تابع قراءة هذه الملاحظة. سأوضح كيفية استخدام openwhisk-wskdeploy لأتمتة نشر وظيفة بسيطة.
المكونات المطلوبة
الخطوة الأولى
قم بإنشاء ملف بيان (manifest.yaml) بالمحتويات التالية:
packages: helloworld: actions: helloworld: location: src/hello.js runtime: nodejs:6 outputs: payload: type: string description: a simple greeting message, Hello World.
الخطوة الثانية
قم بإنشاء ملف للنشر (publish.yaml):
application: name: SampleHelloWorld namespace: _ packages: helloworld: actions: helloworld:
في الواقع ، هذا الملف غير مطلوب لتسليم helloworld
، البيان helloworld
من الخطوة الأولى يكفي.
الخطوة الثالثة
إنشاء بنية الدليل. يبدو شيء مثل هذا:
# ls -1R ~/SampleHelloWorldApp/ deployment.yaml manifest.yaml src/ ./src: hello.js
الخطوة الرابعة
نشر وظيفة HelloWorld:
./wskdeploy -p ~/SampleHelloWorldApp/ ____ ___ _ _ _ _ _ /\ \ / _ \ _ __ ___ _ __ | | | | |__ (_)___| | __ /\ /__\ \ | | | | '_ \ / _ \ '_ \| | | | '_ \| / __| |/ / / \____ \ / | |_| | |_) | __/ | | | |/\| | | | | \__ \ < \ \ / \/ \___/| .__/ \___|_| |_|__/\__|_| |_|_|___/_|\_\ \___\/ |_| Packages: Name: helloworld * action: helloworld bindings: Triggers: Rules Do you really want to deploy this? (y/N): y Deploying pacakge helloworld ... Done! Deploying action helloworld/helloworld ... Done! Deployment completed successfully.
الخطوة الخامسة
تحقق الأداء:
# wsk action invoke --blocking --result helloworld/helloworld { "payload": "Hello World" }
الخطوة السادسة
افرحوا!
النشر: الوظيفة والشرط والقاعدة
دعونا نلقي نظرة على الأشياء الإضافية اللازمة في الأتمتة:
تمرير المعلمات إلى وظيفة
تعديل الكود:
function main(params) { return {payload: 'Hello, ' + params.name + ' from ' + params.place}; }
الخطوة الأولى
قم بإنشاء ملف بيان:
packages: helloworld: actions: helloworld: location: src/hello.js runtime: nodejs:6 inputs: name: type: string description: name of a person place: type: string description: location of a person outputs: payload: type: string description: a simple greeting message, Hello World!
يمكنك تحديد قيم المعلمات في ملف البيان وتخطي إنشاء الملف للنشر:
packages: helloworld: actions: helloworld: location: src/hello.js runtime: nodejs:6 inputs: name: Amy place: Paris outputs: payload: type: string description: a simple greeting message, Hello World!
الخطوة الثانية
قم بإنشاء ملف للنشر:
نقوم بتعيين القيم الافتراضية عن طريق إضافة قسم "المدخلات" المتداخل في وظيفة "helloworld":
application: name: SampleHelloWorld namespace: _ packages: helloworld: actions: helloworld: inputs: name: Amy place: Paris
تحقق من أن بنية الدليل لم تتغير من آخر مرة.
الخطوة الثالثة
توسيع الوظيفة:
# ./wskdeploy -p ~/SampleHelloWorldApp/ ____ ___ _ _ _ _ _ /\ \ / _ \ _ __ ___ _ __ | | | | |__ (_)___| | __ /\ /__\ \ | | | | '_ \ / _ \ '_ \| | | | '_ \| / __| |/ / / \____ \ / | |_| | |_) | __/ | | | |/\| | | | | \__ \ < \ \ / \/ \___/| .__/ \___|_| |_|__/\__|_| |_|_|___/_|\_\ \___\/ |_| Packages: Name: helloworld * action: helloworld bindings: - name: name value: Amy - name: place value: Paris Triggers: Rules Do you really want to deploy this? (y/N): y Deploying pacakge helloworld ... Done! Deploying action helloworld/helloworld ... Done! Deployment completed successfully.
الخطوة الرابعة
تحقق الأداء:
wsk action invoke --blocking --result helloworld/helloworld { "payload": "Hello, Amy from Paris" }
تجاوز القيم الافتراضية بتمرير القيم باستخدام المعلمة --param :
wsk action invoke --blocking --result helloworld/helloworld --param name Mark --param place Barcelona { "payload": "Hello, Mark from Barcelona" }
خلق شرط وقواعد ملزمة
الخطوة الأولى
إضافة قسمين إلى البيان:
packages: helloworld: actions: helloworld: location: src/helloworld.js runtime: nodejs:6 inputs: name: type: string description: name of a person place: type: string description: location of a person outputs: payload: type: string description: a simple greeting message, Hello World! triggers: locationUpdate: rules: helloworldOnLocationUpdate: action: helloworld trigger: locationUpdate
الخطوة الثانية
توسيع الوظيفة والشرط وقاعدة الربط:
./wskdeploy -p ~/SampleHelloWorldApp/ ____ ___ _ _ _ _ _ /\ \ / _ \ _ __ ___ _ __ | | | | |__ (_)___| | __ /\ /__\ \ | | | | '_ \ / _ \ '_ \| | | | '_ \| / __| |/ / / \____ \ / | |_| | |_) | __/ | | | |/\| | | | | \__ \ < \ \ / \/ \___/| .__/ \___|_| |_|__/\__|_| |_|_|___/_|\_\ \___\/ |_| Packages: Name: helloworld * action: helloworld bindings: - name: name value: Amy - name: place value: Paris Triggers: * trigger: locationUpdate bindings: Rules * rule: helloworldOnLocationUpdate - trigger: locationUpdate - action: helloworld Do you really want to deploy this? (y/N): y Deploying pacakge helloworld ... Done! Deploying action helloworld/helloworld ... Done! Deploying trigger locationUpdate ... Done! Deploying rule helloworldOnLocationUpdate ... Done! Deployment completed successfully.
الخطوة الثالثة
تحقق الأداء:
- نحن ننظر إلى وظائف العمل:
wsk activation poll Enter Ctrl-c to exit. Polling for activation logs
- افتح محطة أخرى وأدخل الأمر لتنشيط الاستجابة الشرطية:
wsk trigger fire locationUpdate ok: triggered locationUpdate with id 4c3a8b1792d546a68ac58538c3f5d637
- إلقاء نظرة على النتائج في المحطة الأولى:
Activation: helloworld (d545c458f3d34d6fbf5c29173be3d29e) [] Activation: locationUpdate (4c3a8b1792d546a68ac58538c3f5d637) [] Activation: helloworldOnLocationUpdate (c099355c1f1f4d6d8d30f54e8dac2b84) []
- نحدد معرف الاستجابة الشرطية ونتحقق من نتائج الوظيفة:
wsk activation get d545c458f3d34d6fbf5c29173be3d29e ok: got activation d545c458f3d34d6fbf5c29173be3d29e { ... "activationId": "d545c458f3d34d6fbf5c29173be3d29e", "start": 1489444142544, "end": 1489444142598, "response": { "status": "success", "statusCode": 0, "success": true, "result": { "payload": "Hello, Amy from Paris" } }, ... }
إعلان
الحوسبة بدون خادم على أساس OpenWhisk ، الجزء 1
الحوسبة بدون خادم على أساس OpenWhisk ، الجزء 2
الحوسبة بدون خادم على أساس OpenWhisk ، الجزء 3
الحوسبة بدون خادم على أساس OpenWhisk ، الجزء 4