forked from KateStarovoit/DataNode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
54 lines (40 loc) · 1.37 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import flask
import json
class DataNode:
def __init__(self, my_number):
self.queue_sectors=dict()
def create_queue(self,queue_name):
self.queue_sectors[queue_name] = []
def delete_queue(self, queue_name):
del self.queue_sectors[queue_name]
def write_message(self, queue_name, message):
self.queue_sectors[queue_name].append(message)
def read_message(self, queue_name):
return self.queue_sectors[queue_name].pop()
Node = DataNode(1)
Server = flask.Flask(__name__)
@Server.route('/')
def init():
return "Start"
@Server.route('/write_message/')
def write_message():
content =json.loads(flask.request.json)
Node.write_message(content["qname"], content["message"])
return content
@Server.route('/read_message/')
def read_message():
json.loads(flask.request.json)
return Node.read_message(content["qname"])
@Server.route('/create_queue/')
def create_queue():
content = json.loads(flask.request.json)
Node.create_queue(content["qname"])
return content
@Server.route('/delete_queue/')
def delete_queue(q_name):
content = json.loads(flask.request.json)
Node.delete_queue_queue(content["qname"])
return "deleted"
if __name__ == '__main__':
# Server.run("localhost",2000)
Server.run(host="192.168.43.40", port="2000")