-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMetadataServer.py
72 lines (55 loc) · 2 KB
/
MetadataServer.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
import sys
sys.path.append('gen-py')
# Thrift specific imports
from thrift import Thrift
from thrift.transport import TSocket
from thrift.server import TServer
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
# Protocol specific imports
from metadataServer import MetadataServerService
from shared.ttypes import *
class MetadataServerHandler():
def __init__(self, config_path, my_id):
# Initialize block
pass
def getFile(self, filename):
# Function to handle download request from file
pass
def storeFile(self, file):
# Function to handle upload request
pass
def deleteFile(self, filename):
# Function to handle download request from file
pass
def readServerPort(self):
# Get the server port from the config file.
# id field will determine which metadata server it is 1, 2 or n
# Your details will be then either metadata1, metadata2 ... metadatan
# return the port
pass
# Add other member functions if needed
# Add additional classes and functions here if needed
if __name__ == "__main__":
if len(sys.argv) < 4:
print "Invocation <executable> <config_file> <id>"
exit(-1)
config_path = sys.argv[1]
my_id = sys.argv[2]
print "Initializing metadata server"
handler = MetadataServerHandler(config_path, my_id)
port = handler.readServerPort()
# Define parameters for thrift server
processor = MetadataServerService.Processor(handler)
transport = TSocket.TServerSocket(port=port)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
# Create a server object
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
print "Starting server on port : ", port
try:
server.serve()
except (Exception, KeyboardInterrupt) as e:
print "\nExecption / Keyboard interrupt occured: ", e
exit(0)