| Line 14... |
Line 14... |
| 14 |
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
|
14 |
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
|
| 15 |
from thrift.server import TServer
|
15 |
from thrift.server import TServer
|
| 16 |
|
16 |
|
| 17 |
from shop2020.utils.daemon import Daemon
|
17 |
from shop2020.utils.daemon import Daemon
|
| 18 |
from shop2020.config.client.ConfigClient import ConfigClient
|
18 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 19 |
from shop2020.thriftpy.model.v1.catalog import InventoryService
|
19 |
from shop2020.thriftpy.model.v1.catalog import CatalogService
|
| 20 |
from shop2020.model.v1.catalog.impl.InventoryServiceHandler import InventoryServiceHandler
|
20 |
from shop2020.model.v1.catalog.impl.CatalogServiceHandler import CatalogServiceHandler
|
| 21 |
|
21 |
|
| 22 |
class CatalogServer(Daemon):
|
22 |
class CatalogServer(Daemon):
|
| 23 |
|
23 |
|
| 24 |
def __init__(self, logfile='/var/log/services/catalog.log', pidfile='/tmp/catalog-server.pid'):
|
24 |
def __init__(self, logfile='/var/log/services/catalog.log', pidfile='/tmp/catalog-server.pid'):
|
| 25 |
Daemon.__init__(self, pidfile, stdout=logfile, stderr=logfile)
|
25 |
Daemon.__init__(self, pidfile, stdout=logfile, stderr=logfile)
|
| Line 30... |
Line 30... |
| 30 |
host_name = config_client.get_property('catalog_service_server_host')
|
30 |
host_name = config_client.get_property('catalog_service_server_host')
|
| 31 |
port = config_client.get_property('catalog_service_server_port')
|
31 |
port = config_client.get_property('catalog_service_server_port')
|
| 32 |
dbname = config_client.get_property('catalog_service_dbname')
|
32 |
dbname = config_client.get_property('catalog_service_dbname')
|
| 33 |
db_hostname = config_client.get_property('catalog_service_db_hostname')
|
33 |
db_hostname = config_client.get_property('catalog_service_db_hostname')
|
| 34 |
|
34 |
|
| 35 |
handler = InventoryServiceHandler(dbname, db_hostname)
|
35 |
handler = CatalogServiceHandler(dbname, db_hostname)
|
| 36 |
processor = InventoryService.Processor(handler)
|
36 |
processor = CatalogService.Processor(handler)
|
| 37 |
transport = TSocket.TServerSocket(port=port)
|
37 |
transport = TSocket.TServerSocket(port=port)
|
| 38 |
tfactory = TTransport.TFramedTransportFactory()
|
38 |
tfactory = TTransport.TFramedTransportFactory()
|
| 39 |
pfactory = TBinaryProtocolFactory()
|
39 |
pfactory = TBinaryProtocolFactory()
|
| 40 |
server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
|
40 |
server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
|
| 41 |
print "Starting InventoryService at, port " + str(port) + " host " + host_name
|
41 |
print "Starting CatalogService at, port " + str(port) + " host " + host_name
|
| 42 |
sys.stdout.flush()
|
42 |
sys.stdout.flush()
|
| 43 |
server.serve()
|
43 |
server.serve()
|
| 44 |
print "Server functioning"
|
44 |
print "Server functioning"
|
| 45 |
|
45 |
|
| 46 |
if __name__ == "__main__":
|
46 |
if __name__ == "__main__":
|