diff --git a/Final_Presentation.pdf b/Final_Presentation.pdf index 33acfa8..80b1e6b 100644 Binary files a/Final_Presentation.pdf and b/Final_Presentation.pdf differ diff --git a/coordinator/app.py b/coordinator/app.py index 52bf29c..a9a3955 100644 --- a/coordinator/app.py +++ b/coordinator/app.py @@ -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 diff --git a/coordinator/scripts/build_push_restart.ps1 b/coordinator/scripts/build_push_restart.ps1 new file mode 100755 index 0000000..ad09303 --- /dev/null +++ b/coordinator/scripts/build_push_restart.ps1 @@ -0,0 +1,3 @@ +docker build ./coordinator -t markodorko/coordinator +docker push markodorko/coordinator +kubectl rollout restart -n default deployment coordinator-deployment \ No newline at end of file diff --git a/k8s/ingress-service.yaml b/k8s/ingress-service.yaml index 772eb6a..849c271 100644 --- a/k8s/ingress-service.yaml +++ b/k8s/ingress-service.yaml @@ -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: diff --git a/order-sharding-service/app.py b/order-sharding-service/app.py index f85d40c..b3f5912 100644 --- a/order-sharding-service/app.py +++ b/order-sharding-service/app.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/order-sharding-service/scripts/build_push_restart.ps1 b/order-sharding-service/scripts/build_push_restart.ps1 new file mode 100755 index 0000000..3c693af --- /dev/null +++ b/order-sharding-service/scripts/build_push_restart.ps1 @@ -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 diff --git a/order/app.py b/order/app.py index d41baf5..a64a0dd 100644 --- a/order/app.py +++ b/order/app.py @@ -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/') diff --git a/order/scripts/build_push_restart.ps1 b/order/scripts/build_push_restart.ps1 index 2a79068..3928845 100755 --- a/order/scripts/build_push_restart.ps1 +++ b/order/scripts/build_push_restart.ps1 @@ -1,3 +1,4 @@ docker build ./order -t markodorko/order:latest docker push markodorko/order:latest -kubectl rollout restart -n default deployment order-deployment \ No newline at end of file +kubectl rollout restart -n default deployment order-deployment +kubectl rollout restart -n default deployment order-sharding-deployment \ No newline at end of file diff --git a/stock/app.py b/stock/app.py index ebe6ef1..c262e17 100644 --- a/stock/app.py +++ b/stock/app.py @@ -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() diff --git a/stock/scripts/build_push_restart.ps1 b/stock/scripts/build_push_restart.ps1 old mode 100644 new mode 100755 index 9e391e2..b0428f6 --- a/stock/scripts/build_push_restart.ps1 +++ b/stock/scripts/build_push_restart.ps1 @@ -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