Commit 08547f16 authored by Manuela Kuhn's avatar Manuela Kuhn
Browse files

Added attributes to tango server template

parent 2356c512
......@@ -8,44 +8,49 @@ PORT = 7651
# assume that the server listening to 7651 serves p09
#
port2BL = {
"7650": "P08"
"7651": "P09",
"7652": "P09",
"7653": "P09",
"7654": "P09"}
"7652": "P10",
"7653": "P11"}
class Eiger():
class ZmqDT():
'''
this class holds getter/setter for all parameters
and function members that control the operation.
'''
def __init__( self, Beamline):
#
def __init__ (self, beamline):
# Beamline is read-only, determined by portNo
#
self.Beamline = Beamline
#
# the Eiger address and port number
#
self.host = None
self.port = None
#
# the file names will be:
# /gpfs/current/raw/ge_00005/eigerName/ge_000005_<EigerGeneratedNo>.cbf
#
# FileDir: /gpfs/current/raw/ge_00005/eigerName
#
self.FileDir = "None"
#
# FilePrefix: ge_00005
#
self.FilePrefix = "None"
#
# FilePostfix: .cbf
#
self.FilePostfix = "None"
return
self.beamline = beamline
self.procname = "zeromq-data-transfer_" + self.beamline
# TangoDevices to talk with
self.detectorDevice = None
self.filewriterDevice = None
def execMsg( self, msg):
# TODO replace TangoDevices with the following
# IP of the EIGER Detector
# self.eigerIp = None
# Number of events stored to look for doubles
self.historySize = None
# Target to move the files into
# e.g. /beamline/p11/current/raw
self.localTarget = None
# Flag describing if the data should be stored in localTarget
self.storeData = None
# Flag describing if the files should be removed from the source
self.removeData = None
# List of hosts allowed to connect to the data distribution
self.whitelist = None
def execMsg (self, msg):
'''
set filedir /gpfs/current/raw/ge_00005
returns DONE
......@@ -54,119 +59,223 @@ class Eiger():
do reset
return DONE
'''
tokens = msg.split( ' ')
tokens = msg.split(' ')
if len( tokens) == 0:
return "ERROR"
if tokens[0].lower() == 'set':
if len( tokens) != 3:
return "ERROR"
return self.set( tokens[1], tokens[2])
return self.set(tokens[1], tokens[2])
elif tokens[0].lower() == 'get':
if len( tokens) != 2:
return "ERROR"
return self.get( tokens[1])
return self.get(tokens[1])
elif tokens[0].lower() == 'do':
if len( tokens) != 2:
return "ERROR"
return self.do( tokens[1])
return self.do(tokens[1])
else:
return "ERROR"
def set( self, param, value):
def set (self, param, value):
'''
set a parameter, e.g.: set filedir /gpfs/current/raw/ge_00005
'''
if param.lower() == "filedir":
self.FileDir = value
key = param.lower()
if key == "detectordevice":
self.detectorDevice = value
return "DONE"
elif key == "filewriterdevice":
self.filewriterDevice = value
return "DONE"
# TODO replace detectordevice and filewriterDevice with eigerIP
# elif key == "eigerIp":
# self.eigerIP = value
# return "DONE"
elif key == "historysize":
self.historySize = value
return "DONE"
elif param.lower() == "fileprefix":
self.FilePrefix = value
elif key == "localtarget":
self.localTarget = value
return "DONE"
elif param.lower() == "filepostfix":
self.FilePostfix = value
elif key == "storedata":
self.storeData = value
return "DONE"
elif key == "removedata":
self.removeData = value
return "DONE"
elif key == "whitelist":
self.whitelist = value
return "DONE"
else:
return "ERROR"
def get( self, param):
def get (self, param):
'''
return the value of a parameter, e.g.: get filedir
return the value of a parameter, e.g.: get locatarget
'''
if param.lower() == "filedir":
return self.FileDir
elif param.lower() == "fileprefix":
return self.FilePrefix
elif param.lower() == "filepostfix":
return self.FilePostfix
key = param.lower()
if key == "detectordevice":
self.detectorDevice = value
return "DONE"
elif key == "filewriterdevice":
self.filewriterDevice = value
return "DONE"
# TODO replace detectordevice and filewriterDevice with eigerIP
# elif key == "eigerIP":
# return self.eigerIp
elif key == "historysize":
return self.historySize
elif key == "localtarget":
return self.localTarget
elif key == "storedata":
return self.storeData
elif key == "removedata":
return self.removeData
elif key == "whitelist":
return self.whitelist
else:
return "ERROR"
def do( self, cmd):
def do (self, cmd):
'''
executes commands
'''
if cmd.lower() == "reset":
return self.reset()
elif cmd.lower() == "start":
key = cmd.lower()
if key == "start":
return self.start()
elif key == "stop":
return self.stop()
# elif key == "restart":
# return self.stop()
# elif key == "status":
# return self.stop()
else:
return "ERROR"
def reset( self):
return "DONE"
def start( self):
def start (self):
'''
start ...
'''
#
# see, if all required params are there.
#
if self.FileDir == 'None':
return "ERROR"
if self.FilePrefix == 'None':
return "ERROR"
if self.FilePostfix == 'None':
if self.FileDir
and self.FilePrefix
and self.FilePostfix:
if self.detectorDevice
and self.filewriterDevice
# TODO replace TangoDevices with the following
#and self.eigerIp
and self.historySize
and self.localTarget
and self.storeData
and self.removeData
and self.whitelist:
#
# execute the start action ...
#
#write configfile
#start service
# python src/sender/DataManager.py --verbose --procname self.procname --detectorDevice self.detectorDevice --filewriterDevice self.filewriterDevice --historySize self.historySize --localTarget self.localTarget --storeData self.storeData --removeData self.removeData --whitelist self.whitelist
return "DONE"
else:
return "ERROR"
#
# execute the start action ...
#
def stop (self):
return "DONE"
class sockel( object):
def restart (self):
return "DONE"
def status (self):
return "DONE"
class sockel (object):
'''
one socket for the port, accept() generates new sockets
'''
#
# one socket for the port, accept() generates new sockets
#
sckt = None
def __init__( self):
def __init__ (self):
self.conn = None
self.addr = None
self.host = socket.gethostname()
self.port = PORT # TODO init variable
if sockel.sckt is None:
print "create the main socket"
try:
sockel.sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except Exception, e:
print "socket() failed", e
sys.exit()
self.host = socket.gethostname()
try:
sockel.sckt.bind( (self.host, PORT))
except Exception, e:
raise Exception( "sockel.__init__: bind() failed %s" % str(e))
self.port = PORT
print "bind( %s, %d) ok" % (self.host, self.port)
sockel.sckt.listen(5)
self.createSocket()
self.conn, self.addr = sockel.sckt.accept()
if not str(PORT) in port2BL.keys():
raise Exception( "sockel.__init__: port %d not identified" % str(PORT))
self.eiger = Eiger( port2BL[ str(PORT)])
self.zmqDT = ZmqDT( port2BL[ str(PORT)])
def close( self):
def createSocket (self):
print "create the main socket"
try:
sockel.sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except Exception, e:
print "socket() failed", e
sys.exit()
try:
sockel.sckt.bind( (self.host, self.port))
except Exception, e:
raise Exception( "sockel.__init__: bind() failed %s" % str(e))
print "bind( %s, %d) ok" % (self.host, self.port)
sockel.sckt.listen(5)
def close (self):
#
# close the 'accepted' socket only, not the main socket
# because it may still be in use by another client
......@@ -174,28 +283,36 @@ class sockel( object):
if not self.conn is None:
self.conn.close()
def finish( self):
def finish (self):
sockel.sckt.close()
def recv( self):
def recv (self):
argout = None
try:
argout = self.conn.recv(1024)
except Exception, e:
print e
argout = None
print "recv (len %2d): %s" % (len( argout.strip()), argout.strip())
return argout.strip()
def send( self, msg):
def send (self, msg):
try:
argout = self.conn.send( msg)
except:
argout = ""
print "sent (len %2d): %s" % (argout, msg)
return argout
def socketAcceptor():
def socketAcceptor ():
# waits for new accepts on the original socket,
# receives the newly created socket and
# creates threads to handle each client separatly
......@@ -204,23 +321,30 @@ def socketAcceptor():
print "socketAcceptor: new connect"
thread.start_new_thread( socketServer, (s, ))
def socketServer(s):
global msgBuf
def socketServer (s):
while True:
msg = s.recv()
if len( msg) == 0:
if len(msg) == 0:
print "received empty msg"
continue
if msg.lower().find('bye') == 0:
elif msg.lower().find('bye') == 0:
print "received 'bye', closing socket"
s.close()
break
if msg.find('exit') >= 0:
elif msg.find('exit') >= 0:
s.close()
s.finish()
os._exit(1)
reply = s.eiger.execMsg( msg)
if s.send( reply) == 0:
reply = s.zmqDT.execMsg (msg)
if s.send (reply) == 0:
s.close()
break
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment