Skip to content

Commit c797540

Browse files
Merge pull request #97 from GillisWerrebrouck/development
Development
2 parents 013cc89 + 66cdc3b commit c797540

File tree

82 files changed

+2461
-429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2461
-429
lines changed

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
1-
# RailwayCompany
1+
# Railway System Architecture
2+
3+
## Run all the services
4+
5+
### Run Docker setup
6+
7+
Execute the following command to build all microservices and start all docker containers.
8+
9+
```
10+
bash build.sh && docker-compose up --build
11+
```
12+
13+
To initialise a basic railway network with stations, use the following REST calls (either both should be executed or none);
14+
```
15+
curl -X POST http://localhost:8080/station/init
16+
curl -X POST http://localhost:8080/network/init
17+
```
18+
19+
### Run Kubernetes setup
20+
21+
```
22+
kubectl create -f kubernetes-deployment.yaml
23+
```
24+
25+
All services will start and all pods will be created. Execute the following command to check if all pods are running stable;
26+
27+
```
28+
while true; do clear; kubectl get pods; sleep 3; done;
29+
```
30+
31+
To access the frontend you should have portforwarding enabled for the frontend service, as well as for the route-db service and the apigateway service. The reason why the route-db service needs to be port forwarded is due to the fact that there is a canvas displaying all station nodes and route nodes on the frontend which uses a package that needs access to the Neo4j database.
32+
33+
If portforwarding is not an option, then try ssh tunneling (for all three services mentioned above) by using the following command as a template.
34+
35+
```
36+
ssh -L <port>:<hosted_ip>:<port> -i '<ssl cert>' <username>@<ip> -oPort=22
37+
-oProxyCommand="ssh -i <ssl cert> -oPort=22 <username>@<domain|url> -W %h:%p"
38+
```
39+
40+
To initialise a basic railway network with stations, use the following REST calls (either both should be executed or none);
41+
42+
```
43+
curl -X POST http://localhost:8080/station/init
44+
curl -X POST http://localhost:8080/network/init
45+
```
46+
47+
There is also a bash script `chaos.sh` in the root of this project that automatically kills services that aren't labelled as immune. This script has a default delay of 30 seconds. This can be changed by setting the environment variable DELAY to a certain value. Execute the following command to see all pods that are or aren't labelled immune.
48+
49+
```
50+
kubectl --namespace default -l 'chaos=immune' get pods
51+
kubectl --namespace default -l 'chaos!=immune' get pods
52+
```

build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /bin/bash
2+
3+
base="railway-app-"
4+
declare -a services=(
5+
"api-gateway"
6+
"delay"
7+
"maintenance"
8+
"route-management"
9+
"staff"
10+
"station"
11+
"ticket-sale"
12+
"ticket-validation"
13+
"timetable"
14+
"train"
15+
)
16+
17+
for s in "${services[@]}"
18+
do
19+
cd $base$s
20+
chmod +x mvnw
21+
./mvnw package -DskipTests
22+
cd ..
23+
done

chaos.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Randomly delete pods in a Kubernetes namespace.
3+
# Pods with label 'chaos=immune' will be spared.
4+
set -ex
5+
6+
: ${DELAY:=30}
7+
: ${NAMESPACE:=default}
8+
9+
while true; do
10+
kubectl \
11+
--namespace "${NAMESPACE}" \
12+
-o 'jsonpath={.items[*].metadata.name}' \
13+
-l 'chaos!=immune' \
14+
get pods | \
15+
tr " " "\n" | \
16+
shuf | \
17+
head -n 1 |
18+
xargs -t --no-run-if-empty \
19+
kubectl --namespace "${NAMESPACE}" delete pod
20+
sleep "${DELAY}"
21+
done

docker-compose.yaml

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
version: "3"
2+
services:
3+
zookeeper-container:
4+
image: confluentinc/cp-zookeeper
5+
environment:
6+
- ZOOKEEPER_CLIENT_PORT=2181
7+
kafka-container:
8+
image: confluentinc/cp-kafka
9+
depends_on:
10+
- zookeeper-container
11+
environment:
12+
- KAFKA_BROKER_ID=1
13+
- KAFKA_ZOOKEEPER_CONNECT=zookeeper-container:2181
14+
- KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-container:9092
15+
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
16+
17+
route-db:
18+
image: neo4j:3.5.6
19+
environment:
20+
- NEO4J_AUTH=neo4j/route
21+
ports:
22+
- 7687:7687
23+
# not good to expose a database port but this is just for the purpose of the frontend (graph visualisation)
24+
25+
delay-request-db:
26+
image: redis
27+
28+
staff-db:
29+
image: mongo
30+
train-db:
31+
image: mongo
32+
33+
maintenance-db:
34+
image: mysql:5.7
35+
command: --default-authentication-plugin=mysql_native_password
36+
environment:
37+
- MYSQL_ROOT_PASSWORD=maintenancedatabase
38+
- MYSQL_DATABASE=Maintenance
39+
station-db:
40+
image: mysql:5.7
41+
command: --default-authentication-plugin=mysql_native_password
42+
environment:
43+
- MYSQL_ROOT_PASSWORD=stationdatabase
44+
- MYSQL_DATABASE=Station
45+
ticket-sale-db:
46+
image: mysql:5.7
47+
command: --default-authentication-plugin=mysql_native_password
48+
environment:
49+
- MYSQL_ROOT_PASSWORD=ticketsaledatabase
50+
- MYSQL_DATABASE=TicketSale
51+
ticket-validation-db:
52+
image: mysql:5.7
53+
command: --default-authentication-plugin=mysql_native_password
54+
environment:
55+
- MYSQL_ROOT_PASSWORD=ticketvalidationdatabase
56+
- MYSQL_DATABASE=TicketValidation
57+
timetable-db:
58+
image: mysql:5.7
59+
command: --default-authentication-plugin=mysql_native_password
60+
environment:
61+
- MYSQL_ROOT_PASSWORD=timetabledatabase
62+
- MYSQL_DATABASE=Timetable
63+
64+
delay-service:
65+
build: ./railway-app-delay
66+
image: gilliswerrebrouck/railway-app-delay-service
67+
volumes:
68+
- ./railway-app-delay/target:/app
69+
links:
70+
- kafka-container
71+
- zookeeper-container
72+
depends_on:
73+
- kafka-container
74+
- zookeeper-container
75+
maintenance-service:
76+
build: ./railway-app-maintenance
77+
image: gilliswerrebrouck/railway-app-maintenance-service
78+
volumes:
79+
- ./railway-app-maintenance/target:/app
80+
links:
81+
- kafka-container
82+
- zookeeper-container
83+
- maintenance-db
84+
depends_on:
85+
- kafka-container
86+
- zookeeper-container
87+
- maintenance-db
88+
route-service:
89+
build: ./railway-app-route-management
90+
image: gilliswerrebrouck/railway-app-route-management-service
91+
volumes:
92+
- ./railway-app-route-management/target:/app
93+
links:
94+
- kafka-container
95+
- zookeeper-container
96+
- route-db
97+
depends_on:
98+
- kafka-container
99+
- zookeeper-container
100+
- route-db
101+
staff-service:
102+
build: ./railway-app-staff
103+
image: gilliswerrebrouck/railway-app-staff-service
104+
volumes:
105+
- ./railway-app-staff/target:/app
106+
links:
107+
- kafka-container
108+
- zookeeper-container
109+
- staff-db
110+
depends_on:
111+
- kafka-container
112+
- zookeeper-container
113+
- staff-db
114+
station-service:
115+
build: ./railway-app-station
116+
image: gilliswerrebrouck/railway-app-station-service
117+
volumes:
118+
- ./railway-app-station/target:/app
119+
links:
120+
- kafka-container
121+
- zookeeper-container
122+
- station-db
123+
- delay-request-db
124+
depends_on:
125+
- kafka-container
126+
- zookeeper-container
127+
- station-db
128+
- delay-request-db
129+
ticket-sale-service:
130+
build: ./railway-app-ticket-sale
131+
image: gilliswerrebrouck/railway-app-ticket-sale-service
132+
volumes:
133+
- ./railway-app-ticket-sale/target:/app
134+
links:
135+
- kafka-container
136+
- zookeeper-container
137+
- ticket-sale-db
138+
depends_on:
139+
- kafka-container
140+
- zookeeper-container
141+
- ticket-sale-db
142+
ticket-validation-service:
143+
build: ./railway-app-ticket-validation
144+
image: gilliswerrebrouck/railway-app-ticket-validation-service
145+
volumes:
146+
- ./railway-app-ticket-validation/target:/app
147+
links:
148+
- kafka-container
149+
- zookeeper-container
150+
- ticket-validation-db
151+
depends_on:
152+
- kafka-container
153+
- zookeeper-container
154+
- ticket-validation-db
155+
timetable-service:
156+
build: ./railway-app-timetable
157+
image: gilliswerrebrouck/railway-app-timetable-service
158+
volumes:
159+
- ./railway-app-timetable/target:/app
160+
links:
161+
- kafka-container
162+
- zookeeper-container
163+
- timetable-db
164+
- route-service
165+
- station-service
166+
- train-service
167+
depends_on:
168+
- kafka-container
169+
- zookeeper-container
170+
- timetable-db
171+
- route-service
172+
- station-service
173+
- train-service
174+
train-service:
175+
build: ./railway-app-train
176+
image: gilliswerrebrouck/railway-app-train-service
177+
volumes:
178+
- ./railway-app-train/target:/app
179+
links:
180+
- kafka-container
181+
- zookeeper-container
182+
- train-db
183+
depends_on:
184+
- kafka-container
185+
- zookeeper-container
186+
- train-db
187+
apigateway:
188+
build: ./railway-app-api-gateway
189+
image: gilliswerrebrouck/railway-app-api-gateway-service
190+
volumes:
191+
- ./railway-app-api-gateway/target:/app
192+
links:
193+
- kafka-container
194+
- zookeeper-container
195+
- delay-service
196+
- maintenance-service
197+
- route-service
198+
- staff-service
199+
- station-service
200+
- ticket-sale-service
201+
- ticket-validation-service
202+
- timetable-service
203+
- train-service
204+
depends_on:
205+
- kafka-container
206+
- zookeeper-container
207+
- delay-service
208+
- maintenance-service
209+
- route-service
210+
- staff-service
211+
- station-service
212+
- ticket-sale-service
213+
- ticket-validation-service
214+
- timetable-service
215+
- train-service
216+
ports:
217+
- 8080:8080
218+
219+
frontend:
220+
build: ./railway-app-frontend
221+
image: gilliswerrebrouck/railway-app-frontend
222+
volumes:
223+
- ./railway-app-frontend/target:/app
224+
links:
225+
- apigateway
226+
- route-db
227+
depends_on:
228+
- apigateway
229+
- route-db
230+
ports:
231+
- 80:80

0 commit comments

Comments
 (0)