The Global pandemic CoronaVirus COVID-19 also called as SARS-CoV-2 has already affected millions of people all over the world. The COVID-19 Web App is a prototype of a Cloud Application developed in Python and Flask that gives the global statistics of COVID-19 affected cases. This App makes use of a REST API service to get the daily statistics of COVID-19 and the application is deployed in the AWS EC2 instance.
Get the summary of all countries and global stats.
Get the list of all countries along with slug and country code details.
This loads the database with COVID 19 country stats using the external API 'https://api.covid19api.com/summary'
The Home page displays the Global statistics of COVID 19 along with links to view the Country wise stats and interaction with external REST API. One can use the curl command:
Get the stats of all countries from the database. Can be executed using following curl command:
curl -i -k https://0.0.0.0/summary/country
Get the global stats from the database. Can be executed using the following curl command:
curl -i -k https://0.0.0.0/summary/global
Get the country specific stats from the database. Can be executed using the follwing curl command:
curl -i -k https://0.0.0.0/summary/country/TestCountry
Add a new country to the database. The user must provided the following:
This is a POST request and can be executed by using the following curl command:
curl -i -k -H "Content-Type: application/json" -X POST -d '{"NewConfirmed":2,"TotalConfirmed":3,"NewDeaths":3,"TotalDeaths":3,"NewRecovered":3,"TotalRecovered":3,"Country":"TestCountry"}' https://0.0.0.0/summary/country
Update an existing country to the database. The user must provide the following:
This is a PUT request and can be executed using the following curl command:
curl -i -k -H "Content-Type: application/json" -X PUT -d '{"NewConfirmed":999,"TotalConfirmed":3,"NewDeaths":3,"TotalDeaths":3,"NewRecovered":3,"TotalRecovered":3,"Country":"TestCountry"}' https://0.0.0.0/summary/country
Deletes a country record from the database. The user must provide the following:
This is a DELETE request and can be executed using the following curl command:
curl -i -k -H "Content-Type: application/json" -X DELETE -d '{"Country":"TestCountry"}' https://0.0.0.0/summary/country
Add the global stats to the database. The user must provide the following:
Here 'key' refers to value 'Global'. This is a POST request and can be executed using the following command:
curl -i -k -H "Content-Type: application/json" -X POST -d '{"NewConfirmed":9,"TotalConfirmed":3,"NewDeaths":3,"TotalDeaths":3,"NewRecovered":3,"TotalRecovered":3,"Key":"TestGlobal"}' https://0.0.0.0/summary/global
Updates the global stats to the database. The user must provide the following:
Here 'key' refers to value 'Global'. This is a PUT request and can be executed using the following command:
curl -i -k -H "Content-Type: application/json" -X PUT -d '{"NewConfirmed":1,"TotalConfirmed":10,"NewDeaths":3,"TotalDeaths":3,"NewRecovered":3,"TotalRecovered":3,"Key":"TestGlobal"}' https://0.0.0.0/summary/global
Deletes the global stats record from the database. The user must provide the following:
*Key
Here 'key' referes to value 'Global'. This is a DELETE request and can be executed using the following command:
curl -i -k -H "Content-Type: application/json" -X DELETE -d '{"Key":"TestGlobal"}' https://0.0.0.0/summary/global
sudo apt update
sudo apt install docker.io
sudo docker pull cassandra:latest
sudo docker run --name cassandra-test -p 9042:9042 -d cassandra:latest
wget https://raw.githubusercontent.com/niranjanganesan/ECS781P_Cloud_Computing_Mini_Project/master/country.csv
wget https://raw.githubusercontent.com/niranjanganesan/ECS781P_Cloud_Computing_Mini_Project/master/global.csv
sudo docker cp country.csv cassandra-test:/home/country.csv
sudo docker cp global.csv cassandra-test:/home/global.csv
sudo docker exec -it cassandra-test cqlsh
cqlsh> CREATE KEYSPACE COVID19 WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': '1'};
cqlsh> CREATE TABLE COVID19.summary (Country text PRIMARY KEY,NewConfirmed int,
TotalConfirmed int, NewDeaths int, TotalDeaths int, NewRecovered int,
TotalRecovered int);
cqlsh> CREATE TABLE COVID19.global (Key text PRIMARY KEY,NewConfirmed int,
TotalConfirmed int, NewDeaths int, TotalDeaths int, NewRecovered int,
TotalRecovered int, TimeStamp text);
cqlsh> COPY COVID19.summary(Country, NewConfirmed, TotalConfirmed, NewDeaths, TotalDeaths, NewRecovered, TotalRecovered)
FROM '/home/country.csv' WITH HEADER=TRUE;
cqlsh> COPY COVID19.global(Key, NewConfirmed, TotalConfirmed, NewDeaths, TotalDeaths, NewRecovered, TotalRecovered)
FROM '/home/global.csv' WITH HEADER=TRUE;
The app is served over https by setting up the self-signed certificates as shown below:
$ openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
Generating a RSA private key
.....................................++++
....................................................................................++++
writing new private key to 'key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:UK
State or Province Name (full name) [Some-State]:England
Locality Name (eg, city) []:London
Organization Name (eg, company) [Internet Widgits Pty Ltd]:QMUL
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:localhost
Email Address []:[email protected]
if __name__ == "__main__":
context = ('cert.pem','key.pem')
app.run(host='0.0.0.0',port=443,ssl_context=context)
Below are the steps to build the docker image and deploy application in kubernetes
sudo snap install microk8s --classic
sudo microk8s enable registry
apiVersion: apps/v1
kind: Deployment
metadata:
name: covidapp-deployment
labels:
app: covidapp
spec:
selector:
matchLabels:
app: covidapp
replicas: 3
template:
metadata:
labels:
app: covidapp
spec:
containers:
- name: covidapp
image: localhost:32000/covidapp:registry
ports:
- containerPort: 443
sudo docker build . -t localhost:32000/covidapp:registry
sudo docker push localhost:32000/covidapp:registry
{
"insecure-registries" : ["localhost:32000"]
}
Note: This step is optional and must be done only if docker push has failed.
sudo systemectl restart docker
sudo docker start cassandra-test
sudo microk8s.kubectl apply -f ./deployment.yaml
The we app is now deployed in kubernetes
sudo microk8s.kubectl get deployment
sudo microk8s.kubectl get pods
sudo microk8s.kubectl expose deployment covidapp-deployment --port=443 --type=LoadBalancer
sudo microk8s.kubectl get services
Below is the sample status of the service:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/covidappv3-deployment LoadBalancer 10.152.183.77 <pending> 443:30873/TCP 17h
service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 9d
Here we can see the deployed web app is exposed to Nodeport '30873'. By default the kubernetes service allocates a port within range '30000-32767'.
Finally view the web app in the browser using the public DNS of AWS EC2 account along with this Nodeport that starts with '30xxx'.
sudo microk8s.kubectl delete deployment covidapp-deployment
sudo microk8s.kubectl delete service covidapp-deployment
sudo docker rm cassandra-test