Subversion Repositories SmartDukaan

Rev

Rev 3124 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3124 Rev 3183
Line 1... Line 1...
1
'''
1
'''
2
@author: rajveer
2
@author: rajveer
3
'''
3
'''
4
from thrift.transport import TSocket
4
from thrift.transport import TSocket
5
from thrift.transport.TTransport import TFramedTransport
5
from thrift.transport.TTransport import TFramedTransport, TTransportException
6
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
6
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
7
from shop2020.config.client.ConfigClient import ConfigClient
7
from shop2020.config.client.ConfigClient import ConfigClient
8
from shop2020.utils.Utils import log_entry
8
from shop2020.utils.Utils import log_entry
-
 
9
from shop2020.thriftpy.config.ttypes import ConfigException
9
 
10
 
10
class GenericClient:
11
class GenericClient:
11
    
12
    
12
    host = "localhost"
13
    host = "localhost"
13
    port = 8080
14
    port = 0
14
    attemptNumber = 1
15
    attemptNumber = 1
15
    MAX_ATTEMPTS = 3    
16
    MAX_ATTEMPTS = 3    
16
    TOTAL_SERVICES = 2
17
    TOTAL_SERVICES = 2
17
    serviceNumber = 0
18
    serviceNumber = 0
18
    
19
    
19
    def __init__(self, hostConfigKey, portConfigKey):
20
    def __init__(self, hostConfigKey, portConfigKey):
20
        self.hostConfigKey = hostConfigKey
21
        self.hostConfigKey = hostConfigKey
21
        self.portConfigKey = hostConfigKey
22
        self.portConfigKey = hostConfigKey
-
 
23
        try:
22
        self.loadConfigParameters(hostConfigKey, portConfigKey)
24
            self.loadConfigParameters(hostConfigKey, portConfigKey)
23
        self.connectToService(1)
25
            self.connectToService(1)
-
 
26
        except ConfigException:
-
 
27
            log_entry(self, "error getting data from config")
-
 
28
            raise TTransportException(0, "error getting data from config")
24
        
29
        
25
    def loadConfigParameters(self, hostConfigKey, portConfigKey):
30
    def loadConfigParameters(self, hostConfigKey, portConfigKey):
26
        try:
31
        try:
27
            self.config_client = ConfigClient()
32
            self.config_client = ConfigClient()
28
            self.host = self.config_client.get_property(hostConfigKey)
33
            self.host = self.config_client.get_property(hostConfigKey)
29
            self.port = int(self.config_client.get_property(portConfigKey))
34
            self.port = int(self.config_client.get_property(portConfigKey))
30
        except:
35
        except:
31
            log_entry(self, "error getting data from config")
36
            log_entry(self, "error getting data from config")
-
 
37
            raise
32
    
38
    
33
    def connectToService(self, attemptNumber):
39
    def connectToService(self, attemptNumber):
34
        try:
40
        try:
35
            self.openTransport()
41
            self.openTransport()
36
        except:
42
        except: