Giter VIP home page Giter VIP logo

wassimz / icp-airways Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibm/icp-airways

0.0 2.0 0.0 8.96 MB

Build an airline booking platform with a microservices architecture deployed on a private cloud

Home Page: https://developer.ibm.com/patterns/build-an-airline-booking-platform-on-a-private-cloud/

License: Apache License 2.0

JavaScript 4.41% Shell 33.26% Dockerfile 1.67% TypeScript 35.38% Python 0.65% Smarty 2.26% HTML 13.33% CSS 9.02%

icp-airways's Introduction

ICP-Airways


Lotion
Air-Line ticketing and booking application on IBM Cloud Private

Powered by IBM Cloud Private

Travis Build


Building an Airline Booking Application based on Microservices Architecture on IBM Cloud Private

Introduction

In this Code Pattern, we will build a cloud native application based on microservice architecture, IBM Middlewares and following 12 factor practices. This application is an Airline Booking app, and the technologies behind this app are:-

  • Nodejs (Typescript)
  • IBM DB2
  • IBM ODM
  • RabbitMQ,
  • Celery
  • Angular
  • Hypereledger Fabric
  • Hyperledger Burrow
  • Solidity
  • Docker
  • Kubernetes
  • IBM Cloud Private

Cloud native application is a buzzword these days. Technologies like Kubernetes and Docker are picking up reputation and popularity in Cloud native world. This Pattern will show an end to end process of building highly available Cloud Native Application on IBM Cloud Private. The Application backend is based on Nodejs and DB2 as a Database. The frontend is built using Angular4. Distributed Asynchronous task queue is based on RabbitMQ and Celery. Container orchestration is managed by Kubernetes. Finally, the Blockchain is based on Hyperledger Fabric, Hyperledger Burrow and Ethereum Smart Contract.

Learning objectives

When you've completed this Code Pattern, you will understand how to:

  • Break the application into different microservices
  • Deploying microservices based application on IBM Cloud Private
  • Leveraging IBM Middlewares such as ODM and DB2 on Kubernetes
  • Designing business rules and decision by IBM ODM
  • Create distributed task ques using RabbitMQ and Celery
  • Leveraging DB2 as backend data storage
  • Deploying Ethereum smart contract on Hyperledger fabric by leveraging Hyperledger Burrow
  • Learn how to use IBM Cloud Private, Docker, and Kubernetes

App Screenshot

  1. icp8

  2. icp9

  3. icp10

Flow

  1. USER:- End user who will access the application
  2. APPUI:- The user interface is built using Angular4. It leverages restful endpoints by backend microservices
  3. Login Microservice:- This Microservice allows the user to login to the application
  4. Signup Microservice:- This Microservice allows the user to signup to the application
  5. Checkin Microservice:- This Microservice allows the user to checkin to a given booked flight
  6. Listing Microservice:- This Microservice allows the user to list and browse the available flights
  7. Booking Microservice:- This Microservice allows the user to to book an available flight
  8. Blockchain Microservice:- This Microservice helps to communicate with the Blockchain
  9. IBM DB2:- SQL Database for storing data
  10. ODM Microservice:- This Microservice helps to communicate with the ODM Service
  11. ODM:- IBM Operational Decision Manager is an advanced business rules management system that helps you capture, automate and govern frequent, repeatable business decisions and adds real-time decision making to your day-to-day operations
  12. Email Microservice:- Email Microservice communicates with RabbitMQ and Celery to send email in asynchronous ques
  13. RabbitMQ:- RabbitMQ is a messaging broker - an intermediary for messaging. It gives your applications a common platform to send and receive messages, and your messages a safe place to live until received.
  14. Celery:- Celery is an asynchronous task queue/job queue based on distributed message passing
  15. Ethereum Proxy:- Allows to communicate with Ethereum Virtual Machine
  16. Hyperledger Burrow EVM Chaincode Plugin:- Allows Ethereum Capabilities on top of Hyperledger Fabric by leveraging Hyperledger Burrow
  17. Hyperledger Fabric:- Hyperledger Fabric is a blockchain framework implementation and one of the Hyperledger projects hosted by The Linux Foundation. Intended as a foundation for developing applications or solutions with a modular architecture, Hyperledger Fabric allows components, such as consensus and membership services, to be plug-and-play

high

Featured technologies

  1. Angular4:- Angular is a platform that makes it easy to build applications with the web. Angular combines declarative templates, dependency injection, end to end tooling, and integrated best practices to solve development challenges
  2. Nodejs:- An open-source JavaScript run-time environment for executing server-side JavaScript code.
  3. Typescript:- TypeScript is an open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, and adds optional static typing to the language
  4. Docker:- Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.
  5. Kubernetes:- Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications
  6. IBM DB2:- DB2 is a database product from IBM. It is a Relational Database Management System (RDBMS)
  7. IBM ODM:- IBM® Operational Decision Manager is a comprehensive decision automation platform that helps you capture, analyze, automate and govern rules-based business decisions
  8. RabbitMQ:- RabbitMQ is lightweight and easy to deploy on premises and in the cloud. It supports multiple messaging protocols. RabbitMQ can be deployed in distributed and federated configurations to meet high-scale, high-availability requirements
  9. Celery:- Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well
  10. Hyperledger Fabric:- Hyperledger Fabric is a blockchain framework implementation and one of the Hyperledger projects hosted by The Linux Foundation. Intended as a foundation for developing applications or solutions with a modular architecture, Hyperledger Fabric allows components, such as consensus and membership services, to be plug-and-play
  11. Hyperledger Burrow:- Hyperledger Burrow is one of the Hyperledger projects hosted by The Linux Foundation. Hyperledger Burrow was originally contributed by Monax and co-sponsored by Intel. Hyperledger Burrow provides a modular blockchain client with a permissioned smart contract interpreter partially developed to the specification of the Ethereum Virtual Machine (EVM
  12. Solidity:- Solidity is a contract-oriented, high-level language for implementing smart contracts. It was influenced by C++, Python and JavaScript and is designed to target the Ethereum Virtual Machine (EVM)

Watch the Video

If you want a quick walkthrough of the end result, a video is available here

Deploy to IBM Cloud Private

Pre-req installation

  1. Install Nodejs
  2. Install Kubectl
  3. Intall Docker
  4. Install Angular4Cli
  5. Install DBVisualiser
  6. Install gulpcli
$ npm i gulp-cli -g

Connect Docker (Private registery) with IBM Cloud Private

  1. From your terminal type
$ sudo nano /etc/hosts

icp-docker

  1. Type in your ICP ip and provide a dns name, quit and save the file
  2. Go to Docker prefernces

pref

  1. Navigate to Daemon tab, click on + button and add an entry “icpdns:85000”, click Apply & Restart button to restart Docker service.

dock-pi

  1. In your terminal type
$ docker login icpdns:8500

Install all dependencies, create images and upload it to Private registery of IBM Cloud Private

  1. Booking Microservice
$ cd booking-microservice
$ npm i
$ docker build -t booking-microservice --no-cache .
$ docker tag booking-microservice <icpdns>:8500/default/booking-microservice:latest
$ docker push <icpdns>:8500/default/booking-microservice:latest
  1. Checkin Microservice
$ cd checkin-microservice
$ npm i
$ docker build -t checkin-microservice --no-cache .
$ docker tag checkin-microservice <icpdns>:8500/default/checkin-microservice:latest
$ docker push <icpdns>:8500/default/checkin-microservice:latest
  1. Listing Microservice
$ cd listing-microservice
$ npm i
$ docker build -t listing-microservice --no-cache .
$ docker tag listing-microservice <icpdns>:8500/default/listing-microservice:latest
$ docker push <icpdns>:8500/default/listing-microservice:latest
  1. Login Microservice
$ cd login-microservice
$ npm i
$ docker build -t login-microservice --no-cache .
$ docker tag login-microservice <icpdns>:8500/default/login-microservice:latest
$ docker push <icpdns>:8500/default/login-microservice:latest
  1. Signup Microservice
$ cd signup-microservice
$ npm i
$ docker build -t signup-microservice --no-cache .
$ docker tag signup-microservice <icpdns>:8500/default/signup-microservice:latest
$ docker push <icpdns>:8500/default/signup-microservice:latest
  1. Celery Microservice
$ cd celery
$ docker build -t celery --no-cache .
$ docker tag celery <icpdns>:8500/default/celery:latest
$ docker push <icpdns>:8500/default/celery:latest
  1. Email Microservice
$ cd email-microservice
$ npm i
$ docker build -t email-microservice --no-cache .
$ docker tag email-microservice <icpdns>:8500/default/email-microservice:latest
$ docker push <icpdns>:8500/default/email-microservice:latest
  1. Ethereum Microservice
$ cd ethereum-microservice
$ npm i
$ docker build -t ethereum-microservice --no-cache .
$ docker tag ethereum-microservice <icpdns>:8500/default/ethereum-microservice:latest
$ docker push <icpdns>:8500/default/ethereum-microservice:latest
  1. Odm Microservice
$ cd odm-microservice
$ npm i
$ docker build -t odm-microservice --no-cache .
$ docker tag odm-microservice <icpdns>:8500/default/odm-microservice:latest
$ docker push <icpdns>:8500/default/odm-microservice:latest
  1. Angular Frontend
$ cd icp-frontend
$ npm i
$ docker build -t frontend --no-cache .
$ docker tag frontend <icpdns>:8500/default/frontend:latest
$ docker push <icpdns>:8500/default/frontend:latest

Find all your images in https://icpip:8443/console/manage/images

images

Connect kubesctl with IBM Cloud Private Kubernetes

  1. Login to your icp instance by going to https://icpip:8443
  2. Click on configure, click on copy, and paste all these commands in your terminal icp5

Configuring Persistance storage in IBM Cloud Private

  1. ssh to your icp proxy and create a folder in a specific directory
$ ssh icpproxyip
  1. Login to IBM Cloud Private by going to this link https://icplink:8443

icp1

  1. Click on Platform and choose Storage, then click on Create PersistentVolume icp2

  2. Provide the name shared for persistance volume

  3. Provide storage capacity for around 30GB

  4. Access mode change to Read Write Many

  5. Storage type to NFS

  6. Click on parameters tab and add the follow parameters

server : youricpip
path: your folder path you created in your icp proxy

This screenshot is an example icp3

  1. Click Create
  2. Click on Persistance Volume Claim tab
  3. Click on Create Persistance Volume Claim
  4. Give the name shared-pvc
  5. Provide storage request 30GB
  6. Provide access mode Read Write Many
  7. Click on Create

Deploying DB2

  1. Go to Catalog and filter db2

icp4

  1. Click on configure, fil up the required field and deploy
  2. Follow this tutorial to deploy db2 in IBM Cloud Private

Note: when asked for persistance volume claim give shared-pvc while filling the form tio deploy DB2

Database creation and configuration of DB2

  1. ssh to db2 pod
$ kubectl exec -it <podname> bash
  1. switch the user you have created
$ su - <username>
  1. Connect to SAMPLE db
$ db2 connect to SAMPLE
  1. Download existing flight data from github and set permissions
$ wget https://raw.githubusercontent.com/SaifRehman/ICP-Airways/master/dataset/flights.csv
  1. Create Database and importing existing data to Flights table
  • Flights Table
db2 CREATE TABLE "SAMPLE.FlightsData (ID int NOT NULL , Year varchar(255) NULL , Month varchar(255) NULL, DayofMonth varchar(255) NULL, DepTime varchar(255) NULL,  CRSDepTime varchar(255) NULL, ArrTime varchar(255) NULL, CRSArrTime varchar(255) NULL, FlightNum varchar(255) NULL, TailNum varchar(255) NULL, ActualElapsedTime varchar(255) NULL, CRSElapsedTime varchar(255) NULL, Airtime varchar(255) NULL, ArrDelay varchar(255) NULL, DepDelay varchar(255) NULL,   Origin varchar(255) NULL, Dest varchar(255) NULL, Distance varchar(255) NULL, PRIMARY KEY (ID))"
  • User Table
db2 CREATE TABLE "SAMPLE.UserData (UserID int NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) , LastName varchar(255) NULL , FirstName varchar(255) NULL, Location varchar(255) NULL, Email varchar(255) NULL,  Password varchar(255) NULL, Age int NULL, Tier varchar(255) NULL, PRIMARY KEY (UserID))"
  • Booking Table
db2 CREATE TABLE "SAMPLE.Booking (BookingID int NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) ,TS TIMESTAMP NOT NULL , Checkin varchar(2555) NOT NULL, OfferNamePricing varchar(2555) NOT NULL, OfferTypePricing varchar(2555) NOT NULL , CostPricing varchar(2555) NOT NULL, OfferNameUpgrade varchar(2555) NOT NULL, OfferTypeUpgrade varchar(2555) NOT NULL , CostNameUpgrade varchar(2555) NOT NULL,  UserID INT NOT NULL, FlightID INT NOT NULL, FOREIGN KEY (UserID) REFERENCES SAMPLE.UserData(UserID), FOREIGN KEY (FlightID) REFERENCES SAMPLE.FlightsData(ID), PRIMARY KEY (BookingID))"
  • Importing existing data to flights table
$ db2  IMPORT FROM "path-where-flights.cvs-is-saved/flights.csv" OF DEL INSERT INTO SAMPLE.FlightsData

Deplying RabbitMQ

  1. Go to Catalog and filter rabbitmq
  2. Select RabbitMQ, Click Configure, fill the form and click on deploy
  3. Expose ampq port of rabbitmq
$ kubectl expose deployment <rabbitmq deployment name> --name=mq-amqp --type=NodePort --port=5671

Deploying ODM

  1. Go to Catalog and filter odm
  2. Select odm, Click Configure, fill the form and click on deploy

Configuring ODM and loading buisness rules

  1. Go to http://icpip:odmport/teamserver/faces/login.jsp, and login with username:- rtsAdmin, and pass rtsAdmin icp11

  2. Click on Configure tab, then click on import project. Select the zip file under odm-microservice folder icp12

  3. Go to http://icpip:odmport/decisioncenter/t/library, and login with username:- rtsAdmin, and pass rtsAdmin

  4. Select New Release from ICPAirlines-Rules, then select ICPAirlinesDeployment and click deploy

icp12

icp12

Deploying Blockchain

  1. Navigate to fabric-deploy/cs-offerings/scripts
$ cd fabric-deploy/cs-offerings/scripts
  1. Run the create all script
$ ./create_all.sh
  1. Give it sometime to load and finish

Deploying Ethereum Proxy

  1. Navigate to fabric-evm-proxy/fabric-evm-deployment/cs-offerings
  2. run kubesctl get pods
  3. copy any of blockchain pod name which is deployed by create_all.sh script
  4. Delete the crypto-config folder
  5. run kubectl cp <pod name>:/shared/crypto-config crypto-config
  6. Open fabric-cluster.yml in fabric-evm-proxy folder
  7. Find and replace <path-to-crypto-config-directory> in the file with crypto-config directory
  8. Find and replace <cluster-ip> in the file with cluster ip of your cluster
  9. Navigate to fabric-evm-proxy
  10. Deploy Ethereum Proxy image to ICP Private registery
$ docker build -t ethereumproxy --no-cache .
$ docker tag ethereumproxy <icpdns>:8500/default/ethereumproxy:latest
$ docker push <icpdns>:8500/default/ethereumproxy:latest

Configuring and deploying secrets

icp6

  1. UID is ur database username
  2. PASSWORD is your database password
  3. SECRET is your unique secret you give for your app for jwt authentication
  4. EMAILUSERNAME is your gmail email username from which email would be sent
  5. EMAILPASSWORD is your email password of your gmail email
  6. Navigate to secrets folder in configMaps-secrets/secrets
  7. Deploy secrets to kubernetes
$ kubectl create -f secrets.yml
  1. If you need to redeploy with certain changes
$ kubectl apply -f secrets.yml

NOTE:- all these are base64 represenation encoding.

$ echo -n 'admin' | base64
YWRtaW4=

Configuring and deploying config-maps

icp7

  1. DATABASE:- is your database name, which should be SAMPLE
  2. PORT:- is your exposed db2 port from port 5000, get this port by running and finding db2 service kubectl get service
  3. HOSTNAME:- is your icpip
  4. ODM:- is your ODM buisness api you have created, get odm port number by running and finding the exposed port kubectl get service
  5. HttpProvider:- replace the ip with your icp ip. This is provider to connect with ethereum proxy
  6. CONTRACTADRESS and ETHEREUMACCOUNT:- get your contract address and ethereum account by running app.js in contracts folder. also, replace ip with your icp ip
$ npm i
$ node app.js
  1. CELERY_RESULT_BACKEND and CELERY_BROKER_URL:- replace with your icp ip, and replace it with amqp port. get amqp port by running kubesctl get service mq-amqp
  2. EMAILAPI:- replace ip with your icpip

Deploying all services and deployments

  1. Booking Microservice
$ cd booking-microservice
$ kubectl create -f service-deployment.yml
  1. Checkin Microservice
$ cd checkin-microservice
$ kubectl create -f service-deployment.yml
  1. Listing Microservice
$ cd listing-microservice
$ kubectl create -f service-deployment.yml
  1. Login Microservice
$ cd login-microservice
$ npm i
$ kubectl create -f service-deployment.yml
  1. Signup Microservice
$ cd signup-microservice
$ kubectl create -f service-deployment.yml
  1. Celery Microservice
$ cd celery
$ kubectl create -f service-deployment.yml
  1. Email Microservice
$ cd email-microservice
$ kubectl create -f service-deployment.yml
  1. Ethereum Microservice
$ cd ethereum-microservice
$ kubectl create -f service-deployment.yml
  1. Ethereum Proxy
$ cd fabric-evm-proxy
$ kubectl create -f service-deployment.yml
  1. Odm Microservice
$ cd odm-microservice
$ kubectl create -f service-deployment.yml
  1. Angular Frontend
$ cd icp-frontend
$ kubectl create -f service-deployment.yml

Microservices available

  • Booking-microservice [3000:30090]
  • Checkin-microservice [3001:30091]
  • Listing-microservice [3002:30092]
  • Login-microservice [3003:30093]
  • Signup-microservice [3004:30094]
  • Blockchain-microservice [3006:30199]
  • Angular frontend [80:30080]
  • Ethereum Proxy microservice [5000:30081]
  • Celery microservice [4000:30989]
  • Odm Microservice [3005:30095]

Docs

Documentation of all the backend endpoints is available here

icp-airways's People

Contributors

jkomg avatar saifrehman avatar

Watchers

James Cloos avatar wassim.znaidi avatar

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.