Table of Contents
This is a Python based application that was created for the purpose of DEMO. This application does not specific operation that has any business value.
This application can be used as a reference application while you are trying to build your own custom application that you want to deploy on the Predix.io Cloud.
This application can be run and tested both on the local machine as well as the Predix Cloud. The Following section of the document contain a detailed list of all the Tech-Stack required to run this application on local machines for testing and development purpose before it is deployed onto the Predix Cloud.
The following section details the tech-stack requirement that needs to be met for you to be able to test and run this application locally. Any other versions not mentioned in the section below haven't been tested and can be used at your own discretion.
- Python 2.7.6
- Redis >= 3.0
- PostgreSQL >= 9.3.X
- Python pip = 8.1.1
- Any Code editor of your choice.
This section of the document contains details on how to setup the local environment for you to be able to run/test and develop this application locally.
All commands mentioned in the following section refer to a Linux System. You will have to replace them with their equivalent Windows commands if required.
- Setup the Tech-Stack Details mentioned in the section above. Install the versions and softwares as applicable to your machines.
- Install Python Library dependencies.
sudo pip install requirements.txt
- Start the Following Services if they are not already running.
sudo service postgresql start && sudo service redis_6379 status
- Reset PostgreSQL password for the user
postgres
topassword
- Restart the Services for PostgreSQL.
sudo services postgresql restart
- Clone this Repository.
Running this application on local machine is just a single command away.
python app.py
After you run the above command, point the URL to the address mentioned in the Command line using your favorite browser and voila.
Before you can push this application into the Predix.io machine, there are a few pre-requisites that are to be done from your side. Following section of the document contains a detailed information on what needs to be done.
Follow the setps described below to setup the Predix
- Create an account on Predix.io Cloud.
- Create a Space
- Follow the Instructions and tutorials in the Predix.io Cloud. to setup Cloud Foundry items on your machine.
- Access the Catalog Section to Setup Some basic services.
- Key-Value Store : Redis Name this service as
dev
- SQL Database : PostgreSQL Name this service as
testpsql
- Setup CF login in your machine.
This application is a generic application build for the purpose of Demo and can easily be published onto the Predix.io Cloud with very minimal changes. The following set of changes are essential.
- Modify the
manifest.yml
file to change the application name.
---
applications:
- name: predix-demo-raildocs-python #Modify this Application name to a Unique name.
memory: 1G
build_pack: python_buildpack
command: python app.py
stack: cflinuxfs2
services: # If you have named your services differently, update them.
- dev # Redis Service
- testpsql # PostgreSQL Service
2.Perform a cf push
from directory where manifest.yml
file exists.
This application can be customized and modified before you can push to the Predix.io Cloud as well. And follows steps are to be done in order to make sure that there are no problem while doing so.
- Update the Code and Test on Local machine using
- Follow the Steps mentioned in the above section.
This application has some basic routing modes built for the purpose of testing and demo. Below is a list of all the Routes that are available and what each of them do.
Routing Paths | Python Function | Description |
---|---|---|
/ | home | This is the base page that loads up when you point the URL to the default Predix.io Application Home Page |
/sample | sample | This is the first sample URL that routes away from the Home page into a new page/URL |
/signup | signup | This is the HTML form that is used to perform a POST request on the Application |
/submit | submit | This is the HTML page that renders after the request from /signup is successfully completed |
/redis-signup | redis_signup | This is the HTML form that is used to perform a POST request on the application with REDIS and PostgreSQL |
/redis-submit | redis_submit | This is the HTML page that renders after the request from /redis-signup is successfully completed |
/redis-rest-submit | create_redis_item | This is the RESTful Function responsible for storing data into Redis and PostgreSQL. |
/get-redis | get_redis | This is the HTML page that contains the details of each Key-Value pair in REDIS |
/redis-status | redis_status | This is the HTML page that displays the REDIS status information |
/postgres-status | postgres_status | This is the HTML page that displays the PostgreSQL status information |
/get-postgres | get_postgres | This is the HTML page that displays the data stored in PostgreSQL's DEMO table. |
The following section contains the infomration about the Directory strucutre of this application.
|-- app.py # Main Application File.
|-- config.py # Global Config Settings File
|-- handle_postgres.py # PostgreSQL Handler
|-- handle_redis.py # Redis Handler
|-- manifest.yml # CF Manifest File
|-- predix-python-demo.iml # IntelliJ IDEA Config File.
|-- Procfile # Proc File
|-- README.md # Readme.
|-- requirements.txt # Pip Installation List
|-- static
| `-- style.css # Static Style Sheet File.
`-- templates
|-- error.html # Error Display Page.
|-- index.html # Home Page Template
|-- postgres.html # PostgreSQL Info Dispaly Template
|-- postgres_status.html # PostgreSQL Status Display Template
|-- redis.html # Redis Key-Value Display Template
|-- redis_status.html # Redis Status Display Template
|-- sample.html # Sample Template File.
|-- signup.html # HTML Submit Form
`-- submit.html # HTML Respose Page.