- Abhijith S - PES1UG19CS013
- Aditya Ramesh - PES1UG19CS033
- Advit Gandhi - PES1UG19CS035
- Amar Prakash Patil - PES1UG19CS051
An arithmetic operations calculator enclosed in a monolithic architecture was provided, with the primary goal of converting it to a microservices-oriented architecture.
python
docker
flask
flask-restful
requests
requirements.txt was completed with all required modules
Dockerfile for the landing-service was created, in which the requirements will be installed and the flask application (app.py) will be started
The inputs coming in were of String type by default, so these were converted to floating-point so as to handle a larger range of numbers in performing the arithmetic operations
By default no values were provided by index.html, causing the app to crash when localhost:5050 was loaded initially. Default values were used, and NoneType and ValueError exceptions were handled gracefully.
Four arithmetic operations were initially residing under landing-service. To convert it into a microservices-oriented architecture, separate flask applications were created for each operation.
Each application consists of a class, and a GET method was defined for each class with two numbers as parameters.
The classes were added as a resource using add_resource function and an API endpoint was defined for each, with a different port.
Any reference to localhost was replaced by host.docker.internal, so the application does not require a static IP address. When run on any system, the calculator can be viewed at localhost:5050
Docker-compose file updated to recognise the newly added Flask applications as separate services, with unique port numbers and network aliases defined for each service.
3 more services (GCD, LCM and Exponent) were added to enhance the calculator
Go to the microservices directory
Execute the command docker-compose build
Then execute docker-compose run
Go to the web browser and open localhost:5050 to access the landing page
Choose any 2 numbers and an arithmetic operation and click submit, after which the result will be displayed on the same page
Internally, the landing-page communicates with all the arithmetic operations flask apps via REST APIs which can also be accessed via the following URLs (num1 and num2 refer to any valid number):
Addition : localhost:5051/num1/num2
Subtraction : localhost:5052/num1/num2
Multiplication : localhost:5053/num1/num2
Division : localhost:5054/num1/num2
GCD : localhost:5055/num1/num2
LCM : localhost:5056/num1/num2
Exponent : localhost:5057/num1/num2