Giter Site home page Giter Site logo

mianasbat / cloud-miniproject Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arvind-menon/cloud-miniproject

0.0 1.0 0.0 67 KB

Cloud Computing MiniProject - QMUL module 781P

Home Page: https://github.com/Arvind-Menon/Cloud-MiniProject

Dockerfile 1.96% Python 68.62% HTML 29.42%

cloud-miniproject's Introduction

About Awesome Weather App

This README file is a rundown of my Cloud Computing module's (EC781P) Mini-Project's.

This is a simple app to display the weather conditions of a place. It utilized two api's to do so, namely the weather api from Breezometer (API documentation) and LocationIQ's Geocoding API (API documentation)

App in a Nutshell:

The user is shown a html page where he/she is prompted to end the "Place" for which he'd like to see the weather conditions. The "Place" field's input is the passed on a search query in locationiq's api to retrieve the co-ordinates. The co-ordinates received are then passed as search query in breezometer's api, to retrieve the weather information. This information is then flashed to the user in the HTML page. The history of queries is stored in a cassandra database.

How the app run's:

The app's HTML page ustilises bootstrap. At the back-end, the code for the app's functionality is written in python. Flask being python's micro framework, is used. Cassandra is used for the database since it is easy and robust to use. The app is run on an AWS EC2 instance server. Cassandra's latest image is pulled in this instance and the app is run on this container. The source code for the app is the app.py file The app also utilizes a Self-Signed Certificate. Load Balancing is implemented using Kubernetes.

Overview

Application demo

img

Cassandra

Apache Cassandra is a database management system that replicates large amounts of data across many servers, avoiding a single point of failure and reducing latency.Learn More.

To build image

sudo docker build . --tag=cassandrarest:v1

To run it as a service, exposing the deploment to get an external IP:

sudo docker run -p 80:80 cassandrarest:v1
sudo docker run -p 443:443 cassandrarest:v1 for https

Creating RESTful Services

Please note: this REST API uses a self signed certificate for SSL encryption. The curl command doesn't like self signed certificates and will not allow any requests to be made. Therefore, in order be able to make a request run all the below commands using sudo and the command parameter -k.

To implement methods like GET,POST,PUT,DELETE.

  1. GET method

The GET method is for retrieving information.Here to get the list of countries.

Request
https://ec2-18-232-97-191.compute-1.amazonaws.com/places
Response
['Ukraine', 'East Ham', 'statue of liberty', 'west ham'] <--on the browser
  1. POST method

To add a new entry.

Request
curl -kiH "Content-Type: application/json" -X POST -d '{"Place":"Ukraine","Dew":66.55, "Temperature":15.5, "Wind": 10.6, "Humidity":56.7}' https://ec2-18-232-97-191.compute-1.amazonaws.com
Response
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 42
Server: Werkzeug/1.0.1 Python/3.7.7
Date: Tue, 21 Apr 2020 08:34:49 GMT

{
  "message": "deleted: /places/Ukraine"
}
  1. PUT method

To update an entry.

Request
curl -kiH "Content-Type: application/json" -X PUT -d '{"Place":"Ukraine","Dew":56.55, "Temperature":5.5, "Wind": 10.6, "Humidity":56.7}' https://ec2-18-232-97-191.compute-1.amazonaws.com
Response
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 42
Server: Werkzeug/1.0.1 Python/3.7.7
Date: Tue, 21 Apr 2020 08:31:15 GMT

{
  "message": "deleted: /places/Ukraine"
}
  1. DELETE method

To delete an entry.

Request
curl -k -i -H "Content-Type: application/json" -X DELETE -d '{"Place":"Haiti"}' https://ec2-18-232-97-191.compute-1.amazonaws.com/places
Response
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 42
Server: Werkzeug/1.0.1 Python/3.7.7
Date: Tue, 21 Apr 2020 08:29:05 GMT

{
  "message": "deleted: /places/Haiti"
}

Creating a Home page

Index.html is created inside a templates folder. Flash uses this folder and file to render the HTML page to the user

img

Running Flask Application Over HTTPS

Self signed certificates are generated in the command line.

openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365
Generating a 4096 bit RSA private key
......................++
.............++
writing new private key to 'key.pem'
-----
About to be asked to enter information that will be incorporated
into the certificate request.This is called a Distinguished Name or a DN.
There are quite a few fields which can be leftblank
For some fields there will be a default value, enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:UK
State or Province Name (full name) [Some-State]:London
Locality Name (eg, city) []:East Ham
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Mini Project
Organizational Unit Name (eg, section) []: QMUL
Common Name (e.g. server FQDN or YOUR name) []:Funny
Email Address []:[email protected]

This command writes a new certificate in cert.pem with its corresponding private key in key.pem, with a validity period of 365 days. To use this new self-signed certificate in Flask application,ssl_context argument in app.run() is set with a tuple consisting of the certificate and private key files along with port=443. Learn more

Kuberenetes Load Balancing Implementation

In computing, load balancing refers to the process of distributing a set of tasks over a set of resources, with the aim of making their overall processing more efficient. Load balancing techniques can optimise the response time for each task, avoiding unevenly overloading compute nodes while other compute nodes are left idle

To create an External Load Balancer,following steps are required:

Install Kubernetes

sudo snap install microk8s --classic

1.cassandra-image need to be build and push to registry

sudo microk8s enable registry #To install registry
sudo docker build . -t localhost:32000/cassandra-test:registry #To build and tag
sudo docker push localhost:32000/cassandra-test # To push it to the registry

2.restart and start docker again

sudo systemctl restart docker 
sudo docker start cassandra-test

3.Configure the deployment.yaml file

4.Deploy docker container image present in the registry

sudo microk8s.kubectl apply -f ./dev.yaml # To deploy
sudo microk8s kubectl expose deployment app-deployment --type=LoadBalancer --port=443 --target-port=443

Handy:

To see all the services and pods

sudo microk8s.kubectl get all

To delete

sudo microk8s.kubectl delete deployment app-deployment
sudo microk8s.kubectl delete services app-deployment

To learn more about creating external load balancer.link

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.