Skip to content

Commit

Permalink
final fixes and presentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Matusovic committed Jun 22, 2022
1 parent 641da39 commit 72406d3
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 21 deletions.
Binary file modified Final_Presentation.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion coordinator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def pay_order(user_id, order_id, price):
# boolean value specifies if items should be locked too, can be removed if we want a less strict 2PC
if is_user_item_locked(user_id, item_ids):
return 'Could not satisfy request as the user or item(s) are locked', 403
lock(user_id, item_ids, False)
lock(user_id, item_ids, True)
if not is_user_item_locked(user_id, item_ids):
return 'Error during locking', 500

Expand Down
3 changes: 3 additions & 0 deletions coordinator/scripts/build_push_restart.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docker build ./coordinator -t markodorko/coordinator
docker push markodorko/coordinator
kubectl rollout restart -n default deployment coordinator-deployment
16 changes: 8 additions & 8 deletions k8s/ingress-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ spec:
rules:
- http:
paths:
- path: /orders-shard/?(.*)
pathType: Prefix
backend:
service:
name: order-sharding-service
port:
number: 5000
- path: /orders/?(.*)
pathType: Prefix
backend:
service:
name: order-service
name: order-sharding-service
port:
number: 5000
# - path: /orders/?(.*)
# pathType: Prefix
# backend:
# service:
# name: order-service
# port:
# number: 5000
- path: /stock/?(.*)
pathType: Prefix
backend:
Expand Down
13 changes: 7 additions & 6 deletions order-sharding-service/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
from flask import Flask
from flask import request as flask_request
from flask import jsonify
import kubernetes as k8s

import sys
Expand Down Expand Up @@ -63,7 +64,7 @@ def create_order(user_id):
if shard['ret']:
return_val = requests.post(
'http://' + str(shard['val']['ip']) + ':5000/create/' + str(user_id) + '/' + str(order_id))
return return_val.content, 200
return return_val.json(), return_val.status_code
else:
return "could not find pod", 500

Expand All @@ -73,7 +74,7 @@ def remove_order(order_id):
shard = getShard(order_id)
if shard['ret']:
return_val = requests.delete('http://' + str(shard['val']['ip']) + ':5000/remove/' + str(order_id))
return return_val.content, 200
return return_val.content, return_val.status_code
else:
return "could not find pod", 500

Expand All @@ -84,7 +85,7 @@ def add_item(order_id, item_id):
if shard['ret']:
return_val = requests.post('http://' + str(shard['val']['ip'])
+ ':5000/addItem/' + str(order_id) + "/" + str(item_id))
return return_val.content, 200
return return_val.json(), return_val.status_code
else:
return "could not find pod", 500

Expand All @@ -95,7 +96,7 @@ def all(order_id):
if shard['ret']:
return_val = requests.get('http://' + str(shard['val']['ip'])
+ ':5000/all/' + str(order_id))
return return_val.content, 200
return return_val.content, return_val.status_code
else:
return "could not find pod", 500

Expand All @@ -105,7 +106,7 @@ def remove_item(order_id, item_id):
if shard['ret']:
return_val = requests.delete('http://' + str(shard['val']['ip'])
+ ':5000/removeItem/' + str(order_id) + "/" + str(item_id))
return return_val.content, 200
return return_val.content, return_val.status_code
else:
return "could not find pod", 500

Expand All @@ -116,7 +117,7 @@ def checkout(order_id):
if shard['ret']:
return_val = requests.post('http://' + str(shard['val']['ip'])
+ ':5000/checkout/' + str(order_id))
return return_val.content, 200
return return_val.content, return_val.status_code
else:
return "could not find pod", 500

Expand Down
3 changes: 3 additions & 0 deletions order-sharding-service/scripts/build_push_restart.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
docker build ./order-sharding-service -t markodorko/order-sharding
docker push markodorko/order-sharding
kubectl rollout restart -n default deployment order-sharding-deployment
5 changes: 3 additions & 2 deletions order/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def create_order(user_id, order_id):
db.orders.insert_one(order.__dict__)
# db_queue.append(order)
# order.order_id = str(order.__dict__.pop('_id'))
print(str(order.dumps()), file=sys.stderr)
return order.dumps(), 200
order.__dict__.pop('_id')
print(str(jsonify(order.__dict__)), file=sys.stderr)
return jsonify(order.__dict__), 200


@app.delete('/remove/<order_id>')
Expand Down
3 changes: 2 additions & 1 deletion order/scripts/build_push_restart.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
docker build ./order -t markodorko/order:latest
docker push markodorko/order:latest
kubectl rollout restart -n default deployment order-deployment
kubectl rollout restart -n default deployment order-deployment
kubectl rollout restart -n default deployment order-sharding-deployment
3 changes: 2 additions & 1 deletion stock/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ def add_stock_to_db(stock_update: StockUpdate) -> Stock:
if stock == None:
# stock did not exist: insert stock
stock = Stock(item_id=stock_update.item_id, stock=stock_update.amount, price=stock_update.price)
db.stock.insert_one({'_id': ObjectId(stock.item_id), **stock.__dict__})
if db.stock.find_one({'_id': ObjectId(stock.item_id)}) == None:
db.stock.insert_one({'_id': ObjectId(stock.item_id), **stock.__dict__})
else:
stock = Stock.loads(stock)
stock.load_id()
Expand Down
4 changes: 2 additions & 2 deletions stock/scripts/build_push_restart.ps1
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
docker build .\stock -t mwschutte/stock:latest
docker push mwschutte/stock:latest
docker build ./stock -t markodorko/stock:latest
docker push markodorko/stock:latest
kubectl rollout restart -n default deployment stock-deployment

0 comments on commit 72406d3

Please sign in to comment.