def main(options, args): logname = 'sendlog' logger = ssdlog.make_logger(logname, options) ro.init() tm = ro.remoteObjectProxy('taskmgr0') tm.loadModule('LOGTask') tm.addAllocs(['STARS']) today = datetime.date.today() one_day = datetime.timedelta(days=1) yesterday = today - one_day if not options.fromdate: obs_time_from = '%s 17:00:00' % (yesterday) day_time_from = '%s 08:00:00' % (yesterday) else: obs_time_from = options.fromdate day_time_from = options.fromdate if not options.todate: obs_time_to = '%s 08:00:00' % (today) day_time_to = '%s 17:00:00' % (yesterday) else: obs_time_to = options.todate day_time_to = options.fromdate try: logdir = os.environ['LOGHOME'] except KeyError, e: logdir = '/gen2/logs'
def start(self, wait=True): """Start the task manager. This method creates a fresh thread pool and starts it, and creates a single compound task that executes tasks concurrently from a queue. """ # Start our thread pool (if we created it) if self.mythreadpool: self.threadPool.startall(wait=True) # Start monitor (if we created it) if self.mymonitor: self.monitor.start(wait=True) self.monitor.start_server(wait=True, usethread=True) ro.init() # Subscribe to g2task from main monitor feed self.monitor.subscribe_remote('monitor', ['g2task'], {}) # Publish our feeds to the main monitor monchannels = [self.myname] self.monitor.publish_to('monitor', monchannels, {}) self.start_sktask_environment() self.logger.debug("start completed")
def main(options, args): """Main program. _options_ is an OptionParser object that holds parsed options. _args_ is a list of the remaining non-option parameters. """ # Create top level logger. logger = ssdlog.make_logger('INSintTester', options) # Only import and initialize remoteObjects if we are trying to # use Gen2 services if options.monitor or options.statussvc: ro.init() # Create app and display app = INSintTester(options, logger) app.show() # TODO: find a better way to keep these dialogs suppressed at # startup. sw = app.widgets['setup_obcp'] sw.window.hide() sw = app.widgets['dialog_filechooser'] sw.window.hide() # Enter GUI event-processing loop. while not app.ev_mainquit.isSet(): # Process X events while gtk.events_pending(): gtk.main_iteration() # Sleep and let other threads run time.sleep(0.25)
def main(options, args): ro.init() auth = None if options.auth: auth = options.auth.split(':') elif os.environ.has_key('LTCSAUTH'): auth = os.environ['LTCSAUTH'].split(':') if options.rohost: (rohost, roport) = options.rohost.split(':') roport = int(roport) ro_svc = ro.remoteObjectClient(rohost, roport, auth=auth) #ro_svc = ro.remoteObjectClient(rohost, roport, auth=auth, # secure=True) if options.laserimpacted: val = options.laserimpacted.upper() if not val in ('NO', 'YES', 'CALC'): raise Exception( "Valid values for --laser_impacted are NO|YES|CALC") ro_svc.set('laserimpacted', val) if options.laserstate: val = options.laserstate.upper() if not val in ('OFF', 'ON', 'ON-SKY'): raise Exception("Valid values for --laser_state are OFF|ON|ON-SKY") ro_svc.set('laserstate', val) sys.exit(0)
def __init__(self, interval=None, statusKeys=("TSCS.AZ", "TSCL.WINDD", "TSCL.WINDS_O"), size=DIRN_DEFAULTSIZE, mode=None, logger=None, parent=None): super(Directions, self).__init__(parent) self.setupUi(self, size=size) self.wind_direction=0 self.subaru_az=0 self.wind_speed=0 self.logger=logger self.statusKeys = statusKeys if mode=='test': interval=1000*interval # milli sec self.logger.debug('setting interval %d' %interval ) timer_d = QTimer(self) self.connect(timer_d, SIGNAL("timeout()"), self.fetch_fake_data) self.logger.debug('timer connected to fetchData' ) timer_d.start(interval) elif mode == 'solo': ro.init() #st.g2StatusObj('status') self.status = ro.remoteObjectProxy('status') interval=1000*interval # milli sec self.logger.debug('setting interval %d' %interval ) timer_d = QTimer(self) self.connect(timer_d, SIGNAL("timeout()"), self.fetch_solo_data) self.logger.debug('timer connected to fetchData' ) timer_d.start(interval)
def get_hosts(insname): try: # Query the name server on the Gen2 host for the service # names of the instrument and the status subsystems ro.init() ns = ro.getns() insint_hosts = ns.getHosts(insname) if len(insint_hosts) == 0: raise Error("No instrument interface found") status_hosts = ns.getHosts('status') if len(insint_hosts) == 0: raise Error("No status interface found") # Strip off FQDN to short name cmds = insint_hosts[0][0].split('.')[0] sdst = status_hosts[0][0].split('.')[0] d = Bunch(obshost=cmds, gethost=cmds, obchost=cmds, stathost=sdst) return d except Exception, e: raise Error("Couldn't get information: %s" % str(e))
def setUp(self): self.env = environment.MockEnvironment() self.myhost = ro.get_myhost() self.rohosts = [] self.ns = remoteObjectNameSvc.remoteObjectNameService( self.rohosts, name='remoteObjectNameServer', host=self.myhost, port=ro.nameServicePort) self.ns.ro_start() waitForService(self.ns, 'names') #print "Hosts for",'names',self.ns.getHosts('names') ro.init() self.initval = 'init' self.server = FakeServer(self.initval) self.servicename = 'TestServiceName2' self.ROserver = ro.remoteObjectServer(obj=self.server, name=self.servicename, svcname=self.servicename, usethread=True) self.ROserver.ro_start() waitForService(self.ns, self.servicename) #print "Hosts for",self.servicename,self.ns.getHosts(self.servicename) self.ROclient = ro.remoteObjectProxy(self.servicename)
def setUp(self): self.env = environment.MockEnvironment() self.env.removeTestDirs() # just in case self.env.makeDirs() self.myhost = ro.get_myhost() self.rohosts = [] self.ns = remoteObjectNameSvc.remoteObjectNameService( self.rohosts, name='remoteObjectNameServer', host=self.myhost, port=ro.nameServicePort) self.ns.ro_start() waitForService(self.ns, 'names') #print "Status",self.ns.init0_up1_down2 #print "Hosts for",'names',self.ns.getHosts('names') ro.init() #time.sleep(1) self.servicename = 'TestServiceName' self.ROserver = FakeROServer(self.servicename, usethread=True) self.ROserver.ro_start() waitForService(self.ns, self.servicename) #print "Hosts for",self.servicename,self.ns.getHosts(self.servicename) self.ROclient = ro.remoteObjectProxy(self.servicename) self.val1 = '1' self.val2 = self.val1 + "22" self.rofilename = self.env.INST_PATH + "/ROfilename"
def main(options, args): ro.init() select = options.action if select == 'server': testro = TestRO(options, usethread=False) print "Starting TestRO service..." try: testro.ro_start() except KeyboardInterrupt: print "Shutting down..." elif select == 'file': infile = args[0] # Create data block of fixed size try: in_f = open(infile, 'r') except IOError, e: print "Can't open input file '%s': %s" % (infile, str(e)) sys.exit(1) # Convert binary file to test data data = in_f.read() in_f.close() client(options, data, True)
def start(options): # Create logger logger = ssdlog.make_logger('ltcs-remote', options) # Initialize remote objects service, necessary before any ro.init() svc = LTCSRemoteService(options, logger, usethread=True)
def main(options, args): logger = ssdlog.make_logger('test', options) ro.init() ev_quit = threading.Event() queue = Queue.Queue() # make a name for our monitor myMonName = options.name # monitor channels we are interested in channels = options.channels.split(',') # Create a local monitor mymon = Monitor.Monitor(myMonName, logger, numthreads=20) # Make our callback functions m = Make_cb(logger=logger, monitor=mymon, queue=queue, monpath=options.monpath, watch_execs=options.watch_execs, history=options.history) # Subscribe our callback functions to the local monitor mymon.subscribe_cb(m.anon_arr, channels) server_started = False try: # Startup monitor threadpool mymon.start(wait=True) # start_server is necessary if we are subscribing, but not if only # publishing mymon.start_server(wait=True, port=options.port) server_started = True # subscribe our monitor to the central monitor hub mymon.subscribe_remote(options.monitor, channels, ()) while not ev_quit.isSet(): try: (path, tree, time) = queue.get(block=True, timeout=1.0) printTree(path, tree, time) except Queue.Empty: continue except KeyboardInterrupt: logger.error("Received keyboard interrupt!") ev_quit.set() finally: if server_started: mymon.stop_server(wait=True) mymon.stop(wait=True)
def start_server(self, rohosts, options): # Initialize remoteObjects subsystem try: ro.init(rohosts) except ro.remoteObjectError, e: self.logger.error("Error initializing remote objects subsystem: %s" % \ str(e)) return
def service(options, bootmgr, logger): # Initialize remote objects subsystem. try: ro.init() except ro.remoteObjectError, e: logger.error("Error initializing remote objects subsystem: %s" % str(e)) sys.exit(1)
def main(options, args): logger = ssdlog.make_logger('test', options) print "mode<%s>" % (options.mode) if not options.mode == 'test': ro.init() # make a name for our monitor #myMonName = ('testmon-%d' % os.getpid()) myMonName = ('testmon') # monitor channels we are interested in channels = options.channels.split(',') # Create a local monitor mymon = Monitor.Monitor(myMonName, logger, numthreads=4) # Startup monitor threadpool mymon.start(wait=True) # start_server is necessary if we are subscribing, but not if only # publishing mymon.start_server(port=options.port, wait=True) #mymon.start_server(wait=True) # Make our callback functions m = Make_cb(logger=logger, monitor=mymon) # Subscribe our callback functions to the local monitor mymon.subscribe_cb(m.anon_arr, channels) try: # subscribe our monitor to the central monitor hub #monitor = ro.remoteObjectProxy(options.monitor) mymon.subscribe_remote(options.monitor, channels, ()) except: logger.error("subscribe to the central monitor faild") else: feed_test_data() mymon = None try: gtk.gdk.threads_init() task_view = TreeView(logger) task_view.start_updating() gtk.main() stop_service(task_view, mymon=mymon) print 'GUI END' except KeyboardInterrupt: #gtk.main_quit() stop_service(task_view, mymon=mymon)
def main(options, args): logger = ssdlog.make_logger('test', options) if options.mode == 'test': print 'test mode' feed_test_data() mymon = None else: ro.init() # make a name for our monitor #myMonName = ('testmon-%d' % os.getpid()) myMonName = ('testmon') # monitor channels we are interested in channels = options.channels.split(',') # Create a local monitor mymon = Monitor.Monitor(myMonName, logger, numthreads=4) # Startup monitor threadpool mymon.start(wait=True) # start_server is necessary if we are subscribing, but not if only # publishing mymon.start_server(wait=True) # Make our callback functions m = Make_cb(logger=logger, monitor=mymon) # Subscribe our callback functions to the local monitor mymon.subscribe_cb(m.anon_arr, channels) try: # subscribe our monitor to the central monitor hub monitor = ro.remoteObjectProxy(options.monitor) monitor.subscribe(myMonName, channels, ()) except: logger.error("subscribe to the central monitor faild") try: app = QtGui.QApplication(sys.argv) tv = TreeView() tv.start_updating() tv.show() sys.exit(app.exec_()) stop_service(tv, mymon=mymon) print 'GUI END' except KeyboardInterrupt: print 'Keyboard' #gtk.main_quit() stop_service(tv, mymon=mymon)
def main(options, args): ro_hosts = options.gen2host.split(',') ro.init(ro_hosts) svcname = options.svcname monname = svcname + '.mon' # create a real logger if you want logging logger = ssdlog.make_logger(svcname, options) ev_quit = threading.Event() # Create a local subscribe object myhost = ro.get_myhost(short=True) mymon = Monitor.Monitor(monname, logger) channels = options.channels.split(',') relay = StatusRelay(logger, options.statsvc, options.monitor, mymon, channels) # Startup monitor mymon.start(wait=True) monport = options.monport if not monport: monport = options.port + 1 mymon.start_server(wait=True, port=monport) threadPool = mymon.get_threadPool() svc = ro.remoteObjectServer(svcname=options.svcname, obj=relay, logger=logger, port=options.port, default_auth=None, ev_quit=ev_quit, usethread=False, threadPool=threadPool) try: relay.update_statusProxy() relay.update_monitorFeed() try: print "Press ^C to terminate the server." svc.ro_start(wait=True) svr_started = True except KeyboardInterrupt: logger.error("Caught keyboard interrupt!") ev_quit.set() finally: logger.info("Shutting down...") mymon.unsubscribe_remote('monitor', channels, {}) mymon.stop_server() mymon.stop()
def main(options, args): # Create top level logger. logger = ssdlog.make_logger(options.svcname, options) # Initialize remote objects subsystem. try: ro.init() except ro.remoteObjectError, e: logger.error("Error initializing remote objects subsystem: %s" % str(e)) sys.exit(1)
def main(options, args): # Initialize remote objects service, necessary before any ro.init() svcname = options.svcname auth = None if options.auth: auth = options.auth.split(':') if options.server: authDict = {} if auth: authDict[auth[0]] = auth[1] print "Starting '%s' service..." % svcname svc = MyRemoteService(svcname, usethread=False, authDict=authDict, secure=options.secure, cert_file=options.cert, default_auth=False) try: # Start remote objects server. Since usethread=False # in the constructor, we will block here until server # exits. svc.ro_start() except KeyboardInterrupt: print "Shutting down '%s' ..." % svcname else: # Create proxy object for service svc = ro.remoteObjectProxy(svcname, auth=auth, secure=options.secure) try: i = options.count while i > 0: # Call remote method on service try: res = svc.search(1.0, 2.0, 3.0, 4.0) print "(%5d) res=%s" % (i, str(res)) except ro.remoteObjectError, e: print "Call error: %s" % (str(e)) i -= 1 if i > 0: time.sleep(options.interval) except KeyboardInterrupt: print "Keyboard interrupt received!"
def main(options, args): #logger = ssdlog.make_logger('checkstat', options) ro.init() st = ro.remoteObjectProxy(options.statussvc) insdata = INSdata() statusDict = {} lookupDict = {} # Get all the names of the 'ALIVE' status tables for the instruments for insname in insdata.getNames(): if insname == 'VGW': continue inscode = insdata.getCodeByName(insname) tblname = '%3.3sS0001' % inscode alias = 'GEN2.STATUS.TBLTIME.%s' % tblname statusDict[alias] = 0 lookupDict[alias] = insname # Additional tables to check for tblname in ('TSCS', 'TSCL', 'TSCV', 'VGWD', 'VGWQ'): alias = 'GEN2.STATUS.TBLTIME.%s' % tblname statusDict[alias] = 0 lookupDict[alias] = tblname fetchDict = st.fetch(statusDict) if options.sorttime: times = fetchDict.items() times.sort(_timecmp) keys = [(alias, lookupDict[alias]) for alias in \ map(lambda x: x[0], times)] else: keys = lookupDict.items() keys.sort(lambda x, y: cmp(x[1], y[1])) #print keys for alias, name in keys: timeval = fetchDict[alias] if timeval == '##NODATA##': time_s = 'No record' elif isinstance(timeval, float): time_s = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timeval)) else: time_s = 'ERROR: %s' % str(timeval) print "%-8.8s %s" % (name, time_s)
def main(options, args): basename = options.svcname logger = ssdlog.make_logger(basename, options) # Initialize remoteObjects subsystem try: ro.init() except ro.remoteObjectError, e: logger.error("Error initializing remote objects subsystem: %s" % \ str(e)) sys.exit(1)
def main(options, args): ro.init() insconfig = INSdata() archiver = ro.remoteObjectProxy('archiver') if options.infile: with open(options.infile, 'r') as in_f: buf = in_f.read() else: buf = sys.stdin.read() for line in buf.split('\n'): line = line.strip() # skip blank lines and comments if (len(line) == 0) or line.startswith('#'): continue (frameid, path) = line.split() if ':' in path: host, path = path.split(':') else: host = None finfo = frame.getFrameInfoFromPath(frameid) # TODO: we could do in groups, would be faster if there are # a lot of files to transfer framelist = [(finfo.frameid, path)] # Look up the instrument transfer info obcpinfo = insconfig.getOBCPInfoByCode(finfo.inscode) if not host: host = obcpinfo['obcphost'] transfermethod = obcpinfo['transfermethod'] # Make a call to the archiver to transfer this file print "Attempting to archive %s: %s" % (frameid, path) if not options.dry_run: res = archiver.archive_framelist(host, transfermethod, framelist) if res != ro.OK: print "Archiver returned error code %d" % (res) else: print "Archived file." time.sleep(options.interval) else: print "Host: %s Method: %s Framelist: %s" % (host, transfermethod, str(framelist))
def client_set(options, args): if len(args) != 2: print "Usage: %s [options] <insname> <frameid>" print "Use '%s --help' for options" sys.exit(1) # Initialize remote objects subsystem. try: ro.init() except ro.remoteObjectError, e: print "Error initializing remote objects subsystem: %s" % str(e) sys.exit(1)
def main(options, args): # Initialize remote objects service, necessary before any ro.init() svcname = options.svcname auth = None if options.auth: auth = options.auth.split(':') if options.server: authDict = {} if auth: authDict[auth[0]] = auth[1] print "Starting '%s' service..." % svcname svc = MyRemoteService(svcname, usethread=False, authDict=authDict, secure=options.secure, cert_file=options.cert, default_auth=False) try: # Start remote objects server. Since usethread=False # in the constructor, we will block here until server # exits. svc.ro_start() except KeyboardInterrupt: print "Shutting down '%s' ..." % svcname else: # Create proxy object for service svc = ro.remoteObjectProxy(svcname, auth=auth, secure=options.secure) try: i = options.count while i > 0: # Call remote method on service try: res = svc.search(1.0, 2.0, 3.0, 4.0) print "(%5d) res=%s" % (i, str(res)) except ro.remoteObjectError, e: print "Call error: %s" % (str(e)) i -= 1 if i > 0: time.sleep(options.interval) except KeyboardInterrupt: print "Keyboard interrupt received!"
def main(options, args): svcname = options.svcname logger = ssdlog.make_logger(svcname, options) monchannels = ['statint', 'logs'] # Initialize remote objects subsystem. try: ro.init() except ro.remoteObjectError, e: logger.error("Error initializing remote objects subsystem: %s" % str(e)) sys.exit(1)
def main(options, args): # Create top level logger. logger = ssdlog.make_logger('EnviMonitor', options) # init remote object ro.init() # init status stat_val=init_status() try: envi_file=os.path.join(os.environ['GEN2COMMON'], 'db', 'envi.shelve') except OSError,e: envi_file=='/gen2/share/db/envi.shelve'
def client_get(options, args): if (len(args) < 2) or (len(args) > 3): print "Usage: %s [options] <insname> A|Q <count>" print "Use '%s --help' for options" sys.exit(1) # Initialize remote objects subsystem. try: ro.init() except ro.remoteObjectError, e: print "Error initializing remote objects subsystem: %s" % str(e) sys.exit(1)
def __init__(self, logger): starsdb = STARSdb(logger) self.isSTARS = starsdb.is_log_stars ro.init() self.tm = ro.remoteObjectProxy('taskmgr0') self.tm.loadModule('LOGTask') self.tm.addAllocs(['STARS']) self.sendcmd_tpl = 'EXEC LOG Send_Log logpath="%s" indexdir="%s" name=%s logstarttime="%s" logendtime="%s" ' self.removecmd_tpl = 'EXEC LOG Remove_Log logpath="%s"' self.logger = logger
def main(options, args): # Not used yet. if options.rohosts: rohosts = options.rohosts.split(',') else: rohosts = None ro.init(ro_hosts=rohosts) if options.connect: svcs = options.connect.split(',') else: svcs = [] # Get a remote object shell instance ro_sh = Shell(connects=svcs) # If there are command line arguments (after stripping options) # then treat them as a command and try to execute it. Otherwise # enter an interactive command line shell. if len(args) > 0: cmdstr = ('%s(%s)' % (args[0], ', '.join(args[1:]))) ro_sh.execute(cmdstr) else: quit = False while not quit: try: ro_sh.shell() except (EOFError, KeyboardInterrupt): print "" if not options.confirm: quit = True else: try: ans = raw_input("Really quit? ") ans = ans.upper() if (ans == 'Y') or (ans == 'YES'): quit = True except (EOFError, KeyboardInterrupt): print "" quit = True sys.exit(0)
def main(options, args): logger = ssdlog.make_logger('monlog', options) ev_quit = threading.Event() # monitor channels we are interested in channels = options.channels.split(',') # Initialize remote objects subsystem. try: ro.init() except ro.remoteObjectError, e: logger.error("Error initializing remote objects subsystem: %s" % str(e)) sys.exit(1)
def main(options, args): svcname = options.svcname # Make top-level logger. logger = ssdlog.make_logger(svcname, options) # TODO: parameterize monitor channels monchannels = ['status', 'statupd', 'statint'] # Initialize remote objects subsystem. try: ro.init() except ro.remoteObjectError, e: logger.error("Error initializing remote objects subsystem: %s" % str(e)) sys.exit(1)
def __init__(self, svcname='status', host=None, suppress_fetch_errors=False, suppress_conversion_errors=False): super(g2StatusObj, self).__init__() self.svcname = svcname # holds all kinds of data about SOSS status aliases self.info = Convert.statusInfo() if host: ro.init([host]) else: ro.init() self.reset()