1
2
3
4
5
6
7
8
9
10
11 import os, sys, time
12
13 from ConfigParser import SafeConfigParser
14 from constants import Constants
15
17 '''
18 The configuration of the application server.
19 '''
21 self._server = server
22 self._name = None
23 self._numberOfWorkers = Constants.DEFAULT_NUMBER_OF_WORKERS
24 self._password = None
25 self._isMaster = None
26 self._masterAddress = 'localhost'
27 self._masterListeningPort = 0
28 self._serverList = []
29
31 '''
32 Reload the configuration from the conf file
33 '''
34 try:
35 confParser = SafeConfigParser()
36
37
38 confParser.read(os.path.join(self._server.directory(), Constants.SERVER_CONF_FILE))
39 for section in confParser.sections():
40 for option in confParser.options(section):
41 if option == 'name':
42 self.setName(confParser.get(section, option))
43 if option == 'workers':
44 self.setNumberOfWorkers(confParser.get(section, option))
45
46 confParser = SafeConfigParser()
47
48
49 confParser.read(os.path.join(self._server.directory(), Constants.SERVER_LIST_CONF_FILE))
50 for section in confParser.sections():
51 if section == self.name():
52 for option in confParser.options(section):
53 if option == 'password':
54 self.setPassword(confParser.get(section, option))
55 elif option == 'master':
56 self.setIsMaster(confParser.get(section, option) == 'True')
57 elif option == 'masteraddress':
58 self.setMasterAddress(confParser.get(section, option))
59 elif option == 'masterlisteningport':
60 self.setMasterListeningPort(confParser.get(section, option))
61 self._serverList.append((section, confParser.get(section, 'password')))
62
63 except Exception, e:
64 print 'ERROR: Error in ServerConf.load():', e
65 sys.exit(1)
66
68 '''
69 Returns the application server.
70 '''
71 return self._server
72
74 '''
75 Returns the application server list.
76 '''
77 return self._serverList
78
80 '''
81 Returns the name of the server
82 '''
83 return self._name
84
86 '''
87 Sets the name of the server
88 '''
89 self._name = name
90
92 '''
93 Returns the number of workers
94 '''
95 return self._numberOfWorkers
96
98 '''
99 Sets the number of workers
100 '''
101 self._numberOfWorkers = int(workers)
102
104 '''
105 Returns the password of the server to connect to the master server
106 '''
107 return self._password
108
110 '''
111 Sets the password of the server to connect to the master server
112 '''
113 self._password = password
114
116 '''
117 Returns if the server is master.
118 '''
119 return self._isMaster
120
122 '''
123 Sets is the server is master
124 '''
125 self._isMaster = isMaster
126
128 '''
129 Returns the master server address
130 '''
131 return self._masterAddress
132
134 '''
135 Sets is the server is master
136 '''
137 self._masterAddress = masterAddress
138
140 '''
141 Returns the master server listening port
142 '''
143 return int(self._masterListeningPort)
144
146 '''
147 Sets is the server is master
148 '''
149 self._masterListeningPort = masterListeningPort
150