In this Code Pattern, we will a podcast downloader using Microservices and OpenWhisk. [Explain briefly how things work]. [Give acknowledgements to others if necessary]
When the reader has completed this Code Pattern, they will understand how to:
- compose a microservices style app
- utilize the power of OpenWhisk
- Step 1.
- Step 2.
- Step 3.
- Step 4.
- Step 5.
- OpenWhisk: Execute code on demand in a highly scalable, serverless environment.
- Microservices: Collection of fine-grained, loosely coupled services using a lightweight protocol to provide building blocks in modern application composition in the cloud.
Use the Deploy to IBM Cloud
button OR create the services and run locally.
- Create database
- Server side
- Create a zip python action
- Deploy Downloader action to openwhisk platform as a web action
- Invoke downloader action from podcast manager
Make sure you have a Bluemix account. Suppose you're familiar with Basic OpenWhisk programming Model and idea
- Python2.7 Installed.
- pip install -r requirements.txt
- Mysql DB server instance installed locally or provisioned on remote cloud server.
- curl command tool or similar tools available.
Provision a mysql dabatase instance, use the podcasts_downloader.sql to create the database tables. Use curl to create the users, subscriptions, and podcasts. For example, suppose your podcast manager api server runs locally and listen on port 5000.
- create a user.
curl -X POST "http://localhost:5000/customer?name=liu"
- create a podcast.
curl -X POST "http://localhost:5000/podcast?podname=google&url=https://www.ted.com/talks/rss"
- create a subscription.
curl -X POST "http://localhost:5000/sub?customerid=2&podid=2"
Start the podcasts manager api server.
export FLASK_APP=podcasts_manager.py
export FLASK_DEBUG=1
flask run
Make sure you have docker installed locally and you have openwhisk/python2action docker images already built successfully.
cp DownloaderAction.py __main__.py
In order to persist the downloaded podcast content on storage, now we support integrate with OpenStack swift client, to persist the downloaded content on IBM object storage. First, you need to provision an object storage service, and copy all your storage service authentication information to VCAP_SERVICES.json, the Downloader Action will read the VCAP_SERVICES.json file, to pass the storage services authentication.
Make the zip python aciton.
-
docker run --rm -v "$PWD:/tmp" openwhisk/python2action sh \ -c "cd tmp; virtualenv virtualenv; source virtualenv/bin/activate; pip install -r requirements.txt;"
-
zip -r wgetPython.zip virtualenv __main__.py VCAP_SERVICES.json
wsk action create /[email protected]_dliu/demo/wgetPython --kind python:2 --web true wgetPython.zip
curl -X POST -m 50 "http://localhost:5000/download?customername=liu&downloader_url=https://openwhisk.ng.bluemix.net/api/v1/web/[email protected]_dliu/demo/wgetPython"