Changeset 7306 for contributed
- Timestamp:
- 07/05/11 11:05:51 (11 months ago)
- Location:
- contributed/trunk/dail
- Files:
-
- 3 edited
-
dail.py (modified) (3 diffs)
-
dail_example.py (modified) (1 diff)
-
start_example.sh (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
contributed/trunk/dail/dail.py
r7305 r7306 1 1 # ---------------------------------------------------------------------- 2 # The dacheAdminInterfaceLib V0. 2 03.04.20092 # The dacheAdminInterfaceLib V0.3 26.04.2009 3 3 # 4 4 # Copyright (c) 2009 DESY IT (Sven Sternberger) … … 24 24 #----------------------------------------------------------------------- 25 25 # 0.2 - Empty results set causes endlless loop 26 # 0.3 - bug resolved if you contact different instances 26 27 # 27 28 #----------------------------------------------------------------------- … … 33 34 from java.io import File 34 35 from java.io import FileNotFoundException 35 import sys,time,types,string,threading 36 import sys,time,types,string,threading,signal 36 37 37 38 DEBUG=False 38 39 39 40 class queryStore: 40 def __init__(self):41 self.storeHash={}41 def __init__(self): 42 self.storeHash={} 42 43 43 def save(self,id,obj):44 if DEBUG: print "Save ID: %d" % id45 self.storeHash[id]=obj44 def save(self,id,obj): 45 if DEBUG: print "Save ID: %d" % id 46 self.storeHash[id]=obj 46 47 47 def retrieve(self,id):48 if self.storeHash.has_key(id):49 return self.storeHash[id]50 else:51 return False48 def retrieve(self,id): 49 if self.storeHash.has_key(id): 50 return self.storeHash[id] 51 else: 52 return False 52 53 53 def check(self,id):54 return self.storeHash.has_key(id)54 def check(self,id): 55 return self.storeHash.has_key(id) 55 56 56 57 57 58 class ourDomainEventListener( DomainEventListener,DomainConnectionListener) : 58 connectionId=059 queryId=060 Connection=None61 activ=False59 connectionId=0 60 queryId=0 61 Connection=None 62 activ=False 62 63 63 def __init__(self,store):64 self.myStore=store64 def __init__(self,store): 65 self.myStore=store 65 66 66 def connectionOpened( self , connection ) : 67 self.__class__.connectionId+=1 68 self.__class__.Connection=connection 69 self.__class__.activ=True 67 def connectionOpened( self , connection ) : 68 #self.__class__.connectionId+=1 69 #self.__class__.Connection=connection 70 #self.__class__.activ=True 71 72 self.connectionId+=1 73 self.Connection=connection 74 self.activ=True 70 75 71 def domainAnswerArrived( self , obj , id ) :72 if DEBUG: print "id=%d" % (id)76 def domainAnswerArrived( self , obj , id ) : 77 if DEBUG: print "Answer id=%d // type=%s" % (id,type(obj)) 73 78 74 self.myStore.save(id,obj)79 self.myStore.save(id,obj) 75 80 76 81 77 def _sendObject(self,cellName,cmd): 78 self.__class__.queryId+=1 79 if DEBUG: 80 print "CellName: %s, Command: %s, queryid: %d" % (cellName,cmd,self.__class__.queryId) 81 self.__class__.Connection.sendObject( cellName, cmd , self, self.__class__.queryId) ; 82 return self.__class__.queryId 82 def _sendObject(self,cellName,cmd): 83 self.__class__.queryId+=1 84 if DEBUG: 85 print "CellName: %s, Command: %s, queryid: %d" % (cellName,cmd,self.__class__.queryId) 86 87 #self.__class__.Connection.sendObject( cellName, cmd , self, self.__class__.queryId) ; 88 self.Connection.sendObject( cellName, cmd , self, self.__class__.queryId) ; 89 90 return self.__class__.queryId 83 91 84 92 85 93 class queryDcache: 86 def __init__(self,door,port,user,passwd,dbg=False): 87 DEBUG=dbg 88 self.myStore=queryStore() 94 def __init__(self,door,port,user,passwd): 95 self.door=door 96 if DEBUG: 97 print "Query DOOR: %s" % (door) 98 99 self.myStore=queryStore() 89 100 90 #91 # Define Host and portnumber92 #93 self.connection=Ssh1DomainConnection(door,port)94 self.connection.setLoginName(user)101 # 102 # Define Host and portnumber 103 # 104 self.connection=Ssh1DomainConnection(door,port) 105 self.connection.setLoginName(user) 95 106 96 # 97 # Establish the secret : either password or identity file 98 # 99 if passwd[0] == "/" : 100 self.connection.setPassword("") 107 # 108 # Establish the secret : either password or identity file 109 # 110 if passwd[0] == "/" : 111 self.connection.setPassword("") 112 try: 113 self.connection.setIdentityFile( File(passwd) ) 114 except FileNotFoundException, e : 115 sys.stderr.write("Authentication Failed ...%s" % (e.getMessage())) 116 System.exit(1) 117 101 118 102 try: 103 self.connection.setIdentityFile( File(passwd) ) 104 except FileNotFoundException, e : 105 sys.stderr("Authentication Failed ...%s" % (e.getMessage())) 106 System.exit(1) 119 else: 120 self.connection.setPassword(passwd) 107 121 108 else: 109 self.connection.setPassword(passwd) 122 # 123 # Define the ListenerObject for all incoming message 124 # 125 self.MyDomainEventListener=ourDomainEventListener(self.myStore) 126 self.connection.addDomainEventListener( self.MyDomainEventListener ) 110 127 111 # 112 # Define the ListenerObject for all incoming message 113 # 114 self.MyDomainEventListener=ourDomainEventListener(self.myStore) 115 self.connection.addDomainEventListener( self.MyDomainEventListener ) 116 117 # 118 # start the dcache connection thread 119 # 120 threading.Thread(target=self._startCellQuery).start() 128 # 129 # start the dcache connection thread 130 # 131 if DEBUG: 132 print "Start Thread for %s" % (door) 133 threading.Thread(target=self._startCellQuery).start() 134 if DEBUG: 135 print "Thread for %s started" % (door) 121 136 122 137 123 def query(self,domain,cmd): 124 while not self.MyDomainEventListener.activ: 125 pass 138 def query(self,domain,cmd): 139 self.timeOutCounter=0 140 if DEBUG: 141 print "Start Query DOOR: %s, CELL: %s, CMD: %s" % (self.door,domain,cmd) 142 143 while not self.MyDomainEventListener.activ: 144 time.sleep(1) 145 self.timeOutCounter+=1 146 if self.timeOutCounter>2: 147 return None 126 148 127 if DEBUG:128 print "CELL: %s, CMD: %s" % (domain,cmd)149 if DEBUG: 150 print "DOOR: %s, CELL: %s, CMD: %s" % (self.door,domain,cmd) 129 151 130 self.queryId=self.MyDomainEventListener._sendObject(domain,cmd)152 self.queryId=self.MyDomainEventListener._sendObject(domain,cmd) 131 153 132 while not self.myStore.check(self.queryId): 133 pass 154 while not self.myStore.check(self.queryId): 155 if DEBUG: print "wait for %d" % (self.queryId) 156 pass 157 158 if DEBUG: 159 print "Got answer: %s" % (type(self.myStore.retrieve(self.queryId))) 134 160 135 return self.myStore.retrieve(self.queryId)161 return self.myStore.retrieve(self.queryId) 136 162 137 163 138 def _startCellQuery(self): 139 try: 140 self.connection.go() 141 except SshAuthenticationException, e : 142 print "Authentication Failed ...",e.getMessage() 143 System.exit(1) 164 def _startCellQuery(self): 144 165 166 def timeout_handler(signum, frame): 167 raise SystemExit 168 169 old_handler=signal.signal(signal.SIGALRM, timeout_handler) 170 signal.alarm(2) 171 172 try: 173 if DEBUG: print "Start connection ..." 174 self.connection.go() 175 except SshAuthenticationException, e : 176 print "Authentication Failed ...",e.getMessage() 177 finally: 178 signal.signal(signal.SIGALRM, old_handler) 179 signal.alarm(0) 180 181 System.exit(1) 182 -
contributed/trunk/dail/dail_example.py
r7304 r7306 5 5 #---------------------------------------------------------------------- 6 6 # 7 from dail import *7 from dail_hl import * 8 8 9 9 if len(sys.argv) < 5 : -
contributed/trunk/dail/start_example.sh
r7304 r7306 2 2 export JAVA_HOME=/usr/lib/jvm/default-java 3 3 export CLASSPATH=/opt/d-cache/classes/cells.jar:/opt/d-cache/classes/dcache.jar 4 ~/jython2.5b3/jython ./dail_example.py your_admin_door 22223 admin your_secret4 /opt/jython/bin/jython ./dail_example.py your_admin_door 22223 admin your_secret 5 5
Note: See TracChangeset
for help on using the changeset viewer.
