-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvrmsp_main.py
More file actions
153 lines (131 loc) · 5.55 KB
/
vrmsp_main.py
File metadata and controls
153 lines (131 loc) · 5.55 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#
# The Geysers project (work funded by European Commission).
#
# Copyright (C) 2012 Poznan Supercomputing and Network Center
# Authors:
# Damian Parniewicz (PSNC) <damianp_at_man.poznan.pl>
#
# This software is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import sys, os, logging, time
from optparse import OptionParser
from threading import Lock
from omniORB import CORBA
from geysers_psnc_utils.deamon import Daemon
from geysers_psnc_utils.corbaUtils import CorbaServant, CorbaException
import vrmspCorbaServant
import vrmsp_dm
import http_server
##############################################
MODULE_NAME = 'vrmsp'
__version__ = '0.1'
##############################################
class ModuleDaemon(Daemon):
def __init__(self, moduleName, options):
self.moduleName=moduleName
self.options = options
self.logger = logging.getLogger(self.__class__.__name__)
pidFile = "%s/%s.pid" % (self.options.pidDir, self.moduleName)
self.initializeDataModel()
Daemon.__init__(self, pidFile)
#---------------------
def initializeDataModel(self):
self.dataModels = {
'data':{},
'lock':Lock(),
'clients':{},
}
# load configuration to global dictionary
configFile = '%s/%s.conf' % (self.options.confDir, self.moduleName)
execfile(configFile, globals())
# passing clients configuration to servers
self.dataModels.update(INTERFACES)
#---------------------
def run(self):
"""
Method called when starting the daemon.
"""
try:
# starting interfaces threads
vrmspCommandsServer = CorbaServant(vrmspCorbaServant.vrmsp_commands, self.dataModels, self.options.iorDir)
vrmspCommandsServer.start()
vrmspConfServer = CorbaServant(vrmspCorbaServant.vrmsp_conf, self.dataModels, self.options.iorDir)
vrmspConfServer.start()
if 'replanningHTTP' in self.dataModels['servants']:
xcInfoServer = http_server.ReplanningServer(self.dataModels, self.dataModels['servants']['replanningHTTP'])
xcInfoServer.start()
# run any more interface server as a Thread
# try every 10 sec to register in VRM-AP until registered succesfully
time.sleep(1.0)
while True:
try:
vrmsp_dm.registerInVrmAP(self.dataModels, vrmspConfServer.servantObject, vrmspCommandsServer.servantObject)
return
except (CORBA.TRANSIENT, CorbaException):
self.logger.error("Could not connect to VRM-AP - waiting 10 sec")
time.sleep(10.0)
except:
import traceback
self.logger.error("Exception" + traceback.format_exc())
def unregister(self):
try:
vrmsp_dm.unregisterInVrmAP(self.dataModels)
except:
import traceback
self.logger.error("Exception" + traceback.format_exc())
##############################################
if __name__ == "__main__":
# optional command-line arguments processing
usage="usage: %prog start|stop|restart [options]"
parser = OptionParser(usage=usage, version="%prog " + __version__)
parser.add_option("-p", "--pidDir", dest="pidDir", default='/tmp', help="directory for pid file")
parser.add_option("-l", "--logDir", dest="logDir", default='.', help="directory for log file")
parser.add_option("-i", "--iorDir", dest="iorDir", default='/tmp', help="directory for ior file")
parser.add_option("-c", "--confDir", dest="confDir", default='.', help="directory for config file")
options, args = parser.parse_args()
# I do a hack if configDir is default - './' could not point to local dir
if options.confDir == '.':
options.confDir = sys.path[0]
if 'start' in args[0]:
# clear log file
try:
os.remove("%s/%s.log" % (options.logDir, MODULE_NAME))
except:
pass
# creation of logging infrastructure
logging.basicConfig(filename = "%s/%s.log" % (options.logDir, MODULE_NAME),
level = logging.DEBUG,
format = "%(levelname)s - %(asctime)s - %(name)s - %(message)s")
logger = logging.getLogger(MODULE_NAME)
# starting module's daemon
daemon = ModuleDaemon(MODULE_NAME, options)
# mandatory command-line arguments processing
if len(args) == 0:
print usage
sys.exit(2)
if 'start' == args[0]:
logger.info('starting the module')
daemon.start()
elif 'stop' == args[0]:
logger.info('stopping the module')
daemon.unregister()
daemon.stop()
elif 'restart' == args[0]:
logger.info('restarting the module')
daemon.restart()
else:
print "Unknown command"
print usage
sys.exit(2)
sys.exit(0)