App Service for a Simple SuperHero Voting Application.
100K+
This is the App Service for a basic microservice demo application. This provides a logic layer for a voting system where users can vote for their favorite movie superhero.
Details on deploying the entire demo to a Mantl cluster can be found at
The application was designed to provide a simple demo for Cisco Mantl. It is written as a simple Python Flask application and deployed as a docker container.
Other services are:
The docker containers are available at
Required
pip install -r requirements.txt
In order to run, the service needs 3 pieces of information to be provided:
These details can be provided in one of three ways.
python myhero_app/myhero_app.py --dataserver "http://myhero-data.server.com" --datakey "DATA AUTH KEY" --appsecret "APP AUTH KEY" export myhero_data_server="http://myhero-data.server.com"export myhero_data_key="DATA AUTH KEY"export myhero_app_key="APP AUTH KEY"python myhero_app/myhero_app.pypython myhero_app/myhero_app.pyWhat is the data server address? http://myhero-data.server.comData Server Key: DATA AUTH KEYApp Server Key: APP AUTH KEYA command line argument overrides an environment variable, and raw input is only used if neither of the other two options provide needed details.
When an API request comes in to place a vote, there are two modes that the APP service can run in.
The default mode is "direct". In this mode, the APP service will directly call the data service to place the vote.
There is an optional mode of "queue". In this mode, rather than sending a direct API call to the data service for each vote, the APP service will publish the vote to an MQTT Queue where a seperate service, myhero_ernst, subscribes to the queue and processes the votes. The reason this option is in place is to prevent overloading the data service if a high number and rate of votes is expected. By funnelling through a queueing service, we protect the data service.
To leverage the direct mode, nothing needs to be done, this is the default. To leverage the queue mode, you need to take these additional steps.
python myhero_app/myhero_app.py --mode queueexport myhero_app_mode=queuepython myhero_app/myhero_app.pyInitial and Basic APIs. These are v1 APIs that require no authentication and will eventually be removed
curl http://localhost:5000/hero_listcurl http://localhost:5000/resultscurl http://localhost:5000/vote/<HERO>New v2 APIs These newer APIs require authentication as well as support more features
curl -X GET -H "key: APP AUTH KEY" http://localhost:5000/optionscurl -X PUT -H "key: APP AUTH KEY" http://localhost:5000/options -d '{"option":"Deadpool"}'curl-X POST -H "key: APP AUTH KEY" http://localhost:5000/options -d @sample_post.jsoncurl -X DELETE -H "key: APP AUTH KEY" http://localhost:5000/options/Deadpoolcurl -X POST -H "key: APP AUTH KEY" http://localhost:5000/vote/Deadpoolcurl -X GET -H "key: APP AUTH KEY" http://localhost:5000/resultsI've included the configuration files needed to do local development with Vagrant in the repo. Vagrant will still use Docker for local development and is configured to spin up a CentOS7 host VM for running the container.
To start local development run:
vagrant up
curl -H "key: DevApp" http://localhost:15001/optionsEach of the services in the application (i.e. myhero_web, myhero_app, and myhero_data) include Vagrant support to allow working locally on all three simultaneously.
Content type
Image
Digest
Size
29.8 MB
Last updated
over 8 years ago
docker pull hpreston/myhero_app