Exemplo n.º 1
0
    def get_client(self, host):

        host = host.lower()

        with self.client_lock:

            if self.clients.has_key(host):
                # Cached lazy client for this host; use it
                return self.clients[host]

            # Else look up prognum and create a new lazy client
            # for this host and cache it
            try:
                key = 'OBCPtoOBS(sreq)'
                bnch = SOSSrpc.lookup_rpcsvc(key)

            except KeyError:
                raise statusReceiveError("Error creating rpc client: no such key '%s'" % \
                                  key)

            prognum = bnch.server_send_prgnum

            self.clients[host] = SOSSrpc.lazyClient(host=host,
                                                    prognum=prognum,
                                                    logger=self.logger)
            return self.clients[host]
Exemplo n.º 2
0
    def __init__(self,
                 logger,
                 statusObj,
                 threadPool,
                 ev_quit=None,
                 myhost=None,
                 monchannels=[],
                 loghome=None):
        self.recvTSCTasker = self.processRpcMsgTasker(
            self.processTCSstatRpcMsg)
        self.recvSOSSTasker = self.processRpcMsgTasker(
            self.processSOSSstatRpcMsg)
        self.recvDAQTasker = self.processRpcMsgTasker(self.processDAQgetRpcMsg)

        self.statusObj = statusObj
        self.num_SOSSmonunits = 5
        self.num_TSCmonunits = 1
        self.TSCmonunit = {}
        self.SOSSmonunit = {}
        self.ScreenGet = {}
        self.statusInfo = Convert.statusInfo(version=2)

        # For TSC status logging
        self.loghome = loghome
        self.tsclog = {}
        self.tsclog_lock = threading.RLock()
        self.tsclog_hr = 0

        self.logger = logger
        self.monitor = None
        self.threadPool = threadPool
        self.monchannels = monchannels
        if ev_quit:
            self.ev_quit = ev_quit
        else:
            self.ev_quit = threading.Event()
        self.timeout = 0.1
        self.qtask = None
        self.taskqueue = Queue.Queue()

        # For handling updates to the monitor
        self.monUpdateInterval = 1.0
        self.monUpdateSet = set([])
        self.monUpdateLock = threading.RLock()

        # For DAQ status request handing
        self.hostfilter = None
        self.hostfilter_lock = threading.RLock()
        if not myhost:
            myhost = SOSSrpc.get_myhost(short=True)
        self.myhost = myhost
        self.seq_num = SOSSrpc.rpcSequenceNumber()
        self.clients = {}
        self.client_lock = threading.RLock()

        # For task inheritance:
        self.tag = 'StatusReceiver'
        self.shares = ['logger', 'ev_quit', 'timeout', 'threadPool', 'monitor']
Exemplo n.º 3
0
    def __init__(self, channelnum, ev_quit, logger, taskqueue,
                 myhost=None, myport=None, seq_num=None):

        # Initialize common attributes
        super(STARSchannel, self).__init__(ev_quit, logger, None,
                                           taskqueue,
                                           myhost=myhost, myport=myport,
                                           seq_num=seq_num)
        self.channelnum = channelnum
        self.recvTasker = Task.make_tasker(self.cmd_recv)

        self.insconfig = INSconfig()

        # Create an RPC server
        try:
            key = ('OBCtoSTARS%d' % channelnum)

            self.rpcconn = SOSSrpc.clientServerPair(key, initiator=False,
                                                    logger=self.logger,
                                                    ev_quit=self.ev_quit,
                                                    #myhost=self.myhost,
                                                    recvqueue=taskqueue,
                                                    func=self.recvTasker)

        except SOSSrpc.rpcError, e:
            raise STARSsimError("Error creating rpc client-server pair: %s" % \
                                str(e))
    def setUp(self):
        self.env = environment.MockEnvironment()
        self.env.removeTestDirs()  # just in case
        self.env.makeDirs()
        mysqlarchiver._deleteMySQLArchiveDb()  # just in case
        (self.env.con,self.env.cur) = mysqlarchiver.initMySQLArchiveDb()
        self.framedb = archiver.SimFrameDBint(self.env)
        #import test_archiver
        #self.framedb = test_archiver.SimTestFrameDBint(self.env)
        self.iaq = 'SUKA'
        self.archmon = archiver.ArchiveMonitor(self.framedb,self.env)
        self.archivemgr = archiver.ArchiveMgr(self.framedb,self.archmon, self.env)
        self.framesrcSUKA = self.archivemgr.createFrameSourceA("SUK")
        self.basic = ['SIMPLE','BITPIX','NAXIS','EXTEND','PROP-ID',
                      'FRAMEID','RANDOM','OBCPMODE']
        self.basic.sort()
        self.archivemgr.registerKeywords(self.iaq,self.basic)
        import random
        #randokm.seed(0)  # force a random but repeatable sequence
        self.random = str(random.randrange(1000,1010))
        self.mode = "mode_"+str(random.randrange(0,10))

        self.obcpnum = 9
        self.ev_quit = threading.Event()
        # Timeout value for this task
        self.timeout = 20.0

        # Create monitor and other allocations
        self.monitor_name = 'monitor'
        self.monitor = Monitor.Minimon(self.monitor_name, logger=logger)
        
        myhost = SOSSrpc.get_myhost(short=True)
        statusDict = {}
        
        # Create and start the instrument interface
        self.insint = INSint.ocsInsInt(self.obcpnum, myhost, self.env.ARCH_PROP,
                                       statusDict, db=self.monitor,
                                       logger=logger, ev_quit=self.ev_quit)
        self.insint.start()

        # This is our set of allocations
        self.alloc = Bunch.Bunch(monitor=self.monitor,
                                 INSint9=self.insint,
                                 archmgr=self.archivemgr,
                                 status=None)

        # Create and start SIMCAM
        ocsint = DAQtk.ocsInt(self.obcpnum, logger=logger, ev_quit=self.ev_quit)
        simcam = SIMCAM.SIMCAM(logger, self.env, ev_quit=self.ev_quit)
        self.simcam = SIMCAM.OCSInterface(logger, ev_quit=self.ev_quit,
                                          ocsint=ocsint, instrument=simcam)
        self.simcam.start()

        # Create and start our task manager
        self.tm = TaskManager.TaskManager(logger=logger, internal_allocs=self.alloc)
        self.tm.setAllocs(['monitor', 'INSint9', 'archmgr'])
        self.tm.start()
Exemplo n.º 5
0
def main(options, args, ui):

    myhost = SOSSrpc.get_myhost(short=False)

    basename = 'g2disp-%s' % (myhost.replace('.', '_'))
    logger = ssdlog.make_logger(basename, options)

    # Make our callback object
    mobj = g2Disp(logger=logger, basename=basename)

    ui.ui(mobj)
Exemplo n.º 6
0
    def __init__(self, options, logger):
        """Constructor for the INSintTester object.
        """

        # Invoke our base class constructor.
        INSintGUI.__init__(self)

        self.logger = logger
        self.insconfig = INSconfig()

        # Set up default connection parameters from command line
        self.obcpnum = options.obcpnum
        self.monunitnum = options.monunitnum
        if not options.obcphost:
            self.obcphost = SOSSrpc.get_myhost(short=True)
        else:
            self.obcphost = options.obcphost
        self.raidpath = options.fitsdir
        self.transfermethod = options.transfermethod
        self.username = options.username
        self.password = options.password

        self.ev_quit = threading.Event()
        self.ev_mainquit = threading.Event()
        self.soss = None

        # Did user specify a Gen2 status source?
        if options.statussvc:
            ro_status = ro.remoteObjectProxy(options.statussvc)
            statusObj = INSint.FetchStatusWrapper_Gen2(ro_status)

        # Did user specify a SOSS status source?
        elif options.statushost:
            from SOSS.status import cachedStatusObj

            statusDict = cachedStatusObj(options.statushost)
            statusObj = INSint.FetchStatusWrapper_SOSS(statusDict)

        # Did user specify a SOSS status file?
        elif options.statusfile:
            try:
                in_f = open(options.statusfile, 'r')
                statusDict = eval(in_f.read())
                in_f.close()

            except Exception, e:
                self.showStatus("Error reading status file '%s': %s" % \
                                (options.statusfile, str(e)))
                statusDict = {}

            statusObj = INSint.FetchStatusWrapper_SOSS(statusDict)
Exemplo n.º 7
0
    def make_SOSSmonunit(self, unitnum):
        try:
            key = ('toOBS%d(sdst)' % (unitnum))
            bnch = SOSSrpc.lookup_rpcsvc(key)

        except KeyError:
            raise statusReceiveError("Error creating rpc server: no such key '%s'" % \
                              key)

        prognum = bnch.server_receive_prgnum

        server = SOSSstatusRpcServer(prognum,
                                     ev_quit=self.ev_quit,
                                     logger=self.logger,
                                     queue=self.taskqueue,
                                     func=self.recvSOSSTasker)
        return server
Exemplo n.º 8
0
    def make_DAQGetRpc(self):
        try:
            key = 'OBCPtoOBS(sreq)'
            bnch = SOSSrpc.lookup_rpcsvc(key)

        except KeyError:
            raise statusReceiveError("Error creating rpc server: no such key '%s'" % \
                              key)

        prognum = bnch.server_receive_prgnum

        server = DAQGetRpcServer(prognum,
                                 ev_quit=self.ev_quit,
                                 logger=self.logger,
                                 queue=self.taskqueue,
                                 func=self.recvDAQTasker)
        return server
Exemplo n.º 9
0
    def handle_1(self):

        try:
            #rpcstr = self.unpacker.get_buffer()
            data = self.unpacker.unpack_broadcastForm()
            rpcmsg = SOSSrpc.TCSstatRpcMsg(rpcmsg=data)

            # Process rpc message
            #self.func((rpcmsg, data))
            self.func((rpcmsg, data.contents))

            self.turn_around()

        except rpc.RPCUnextractedData:
            self.logger.error("*** Unextracted Data in request!")

        except Exception, e:
            self.logger.error("Error processing RPC packet: %s" % (str(e)))
Exemplo n.º 10
0
    def make_ScreenGet(self, unitnum):
        try:
            #key = ('ScreenGetOBS' % (unitnum))
            # Unitnum ignored for now
            key = ('ScreenGetOBS')
            bnch = SOSSrpc.lookup_rpcsvc(key)

        except KeyError:
            raise statusReceiveError("Error creating rpc server: no such key '%s'" % \
                              key)

        prognum = bnch.server_receive_prgnum

        server = ScreenGetRpcServer(prognum,
                                    ev_quit=self.ev_quit,
                                    logger=self.logger,
                                    queue=self.taskqueue,
                                    func=self.recvSOSSTasker)
        return server
Exemplo n.º 11
0
    def handle_1(self):

        # Process rpc message
        res = False
        try:
            data = self.unpacker.unpack_FM_NetForm()
            rpcmsg = SOSSrpc.TCSstatRpcMsg(rpcmsg=data)

            self.func((rpcmsg, data))

            self.turn_around()

            res = True

        except rpc.RPCUnextractedData:
            self.logger.error("*** Unextracted Data in request!")

        except Exception, e:
            self.logger.error("Exception raised processing RPC packet: %s" %
                              (str(e)))
    def setUp(self):
        self.env = environment.MockEnvironment()
        self.env.removeTestDirs()  # just in case
        self.env.makeDirs()
        self.obcpnum = 9
        self.ev_quit = threading.Event()

        # Create monitor and other allocations
        self.monitor_name = 'monitor'
        self.monitor = Monitor.Minimon(self.monitor_name, logger)
        
        myhost = SOSSrpc.get_myhost(short=True)

        # Create and start STARS simulator
        self.stars = STARSint.STARSsimulator(logger=logger, ev_quit=self.ev_quit)
        # Tell STARS how to contact us to copy files
        STARSint.add_transferParams('*',
                                    transfermethod='ssh',
                                    raidpath=self.env.ARCH_PATH,
                                    #username=os.getlogin(),
                                    username=os.environ['LOGNAME'],
                                    password='******')
        
        self.stars.start()

        # Create and start the STARS interface
        self.starsint = STARSint.STARSinterface(starshost=myhost,
                                                db=self.monitor, logger=logger,
                                                ev_quit=self.ev_quit)
        self.starsint.start()

        # This is our set of allocations
        self.alloc = Bunch.Bunch(monitor=self.monitor,
                                 STARSint=self.starsint,
                                 status=None)

        # Create and start our task manager
        self.tm = TaskManager.TaskManager(logger=logger, ev_quit=self.ev_quit,
                                          internal_allocs=self.alloc)
        self.tm.setAllocs(['monitor', 'STARSint'])
        self.tm.start()
    def setUp(self):
        self.env = environment.MockEnvironment()
        self.env.removeTestDirs()  # just in case
        self.env.makeDirs()
        self.obcpnum = 9
        self.fmtstr = 'EXEC SIMCAM FITS_FILE MOTOR=%(motor)s FRAME_NO=%(frame_no)s DELAY=%(delay)f'
        self.ev_quit = threading.Event()

        # Create monitor and other allocations
        self.monitor_name = 'monitor'
        self.monitor = Monitor.Minimon(self.monitor_name, logger)
        
        myhost = SOSSrpc.get_myhost(short=True)
        statusDict = {}
        
        # Create and start the instrument interface
        self.insint = INSint.ocsInsInt(self.obcpnum, myhost, self.env.ARCH_PROP,
                                       statusDict, db=self.monitor,
                                       logger=logger, ev_quit=self.ev_quit)
        self.insint.start()

        # This is our set of allocations
        self.alloc = Bunch.Bunch(monitor=self.monitor,
                                 INSint9=self.insint,
                                 status=None)

        # Create and start SIMCAM
        ocsint = DAQtk.ocsInt(self.obcpnum, logger=logger, ev_quit=self.ev_quit)
        self.simcam = SIMCAM.Instrument(logger, ev_quit=self.ev_quit,
                                        ocsint=ocsint, allowNoPara=True,
                                        env=self.env)
        self.simcam.loadPersonality('SIMCAM')
        #self.simcam.loadParaBuf(fits_file_para)
        self.simcam.start()

        # Create and start our task manager
        self.tm = TaskManager.TaskManager(logger=logger, ev_quit=self.ev_quit,
                                          internal_allocs=self.alloc)
        self.tm.setAllocs(['monitor', 'INSint9'])
        self.tm.start()
Exemplo n.º 14
0
def main(options, args):

    # Create top level logger.
    logger = logging.getLogger('anasink')
    logger.setLevel(logging.DEBUG)

    fmt = logging.Formatter(LOG_FORMAT)

    if options.logfile:
        fileHdlr = logging.handlers.RotatingFileHandler(
            filename=options.logfile, maxBytes=10000000, backupCount=4)
        fileHdlr.setFormatter(fmt)
        fileHdlr.setLevel(options.loglevel)
        logger.addHandler(fileHdlr)
    # Add output to stderr, if requested
    if options.logstderr or (not options.logfile):
        stderrHdlr = logging.StreamHandler()
        stderrHdlr.setFormatter(fmt)
        stderrHdlr.setLevel(options.loglevel)
        logger.addHandler(stderrHdlr)

    try:
        localhost = SOSSrpc.get_myhost(short=True)
        options.keyfile = "/home/builder/bin/%s.key" % localhost
        options.passfile = "/home/builder/bin/%s.pass" % localhost
        logger.debug(
            'fetching a host name by calling get_myhost func key<%s> pass<%s>'
            % (options.keyfile, options.passfile))
    except Exception, e:
        try:
            options.keyfile = "/home/builder/bin/%s.key" % os.environ[
                'HOSTNAME']
            options.passfile = "/home/builder/bin/%s.pass" % os.environ[
                'HOSTNAME']
            logger.debug('fetching host name from environ key<%s>  pass<%s>' %
                         (options.keyfile, options.passfile))
        except KeyError, e:
            logger.error('fetching host name error<%s>' % e)
            sys.exit(1)
Exemplo n.º 15
0
    def setUp(self):
        self.env = environment.MockEnvironment()
        self.env.removeTestDirs()  # just in case
        self.env.makeDirs()

        self.obcpnum = 9
        self.ev_quit = threading.Event()

        # Create mini monitor for INSint
        self.minimon = Monitor.Minimon('monitor', logger)

        myhost = SOSSrpc.get_myhost(short=True)

        raidpath = self.env.INST_PATH
        statusObj = INSint.FetchStatusWrapper_SOSS({})

        # Create and start the instrument interface
        self.insint = INSint.ocsInsInt(self.obcpnum,
                                       myhost,
                                       raidpath,
                                       statusObj,
                                       db=self.minimon,
                                       logger=logger,
                                       ev_quit=self.ev_quit)
        self.insint.start(wait=True)

        # Create and start SIMCAM
        ocsint = DAQtk.ocsInt(self.obcpnum,
                              logger=logger,
                              ev_quit=self.ev_quit)
        self.simcam = SIMCAM.Instrument(logger,
                                        ev_quit=self.ev_quit,
                                        ocsint=ocsint,
                                        allowNoPara=False,
                                        env=self.env)
        self.simcam.loadPersonality('SIMCAM')
        self.simcam.loadParaBuf(('SIMCAM', 'FITS_FILE'), fits_file_para)
        # Wait until SIMCAM is up and running
        self.simcam.start(wait=True)
Exemplo n.º 16
0
    def message2str(self):
        
        tstamp = SOSSrpc.time2timestamp(self.time)

##         msgstr = "%(kind)-8.8s%(frame)12.12s%(time)18.18s%(host)4d%(result)2.2s%(preframe)12.12s%(volume)14.14s%(update)2.2s%(seqno)8d%(stat)8d%(manual)2.2s%(tapeset)6.6s%(manuflg)1.1s%3.3s" % (
        msgstr = "%-8.8s%12.12s%18.18s%4d%2.2s%12.12s%14.14s%2.2s%8d%8d%2.2s%6.6s%1.1s%3.3s" % (
            self.kind,
            self.frame,
            tstamp,
            self.host,
            self.result,
            self.preframe,
            self.volume,
            self.update,
            self.seqno,
            self.stat,
            self.manual,
            self.tapeset,
            self.manuflg,
            self.reserved )

        self.msgCheck(msgstr)

        return msgstr
Exemplo n.º 17
0
    def make_TSCmonunit(self, stype, unitnum):
        try:
            key = ('%s%d->' % (stype, unitnum))
            bnch = SOSSrpc.lookup_rpcsvc(key)

            rpcKlassDict = {
                'TSCS': TSCSstatusRpcServer,
                'TSCL': TSCLstatusRpcServer,
                'TSCV': TSCVstatusRpcServer,
            }
            klass = rpcKlassDict[stype]

        except KeyError:
            raise statusReceiveError("Error creating rpc server: no such key '%s'" % \
                              key)

        prognum = bnch.server_receive_prgnum

        server = klass(prognum,
                       ev_quit=self.ev_quit,
                       logger=self.logger,
                       queue=self.taskqueue,
                       func=self.recvTSCTasker)
        return server
    def __init__(self, options):
        """
        Constructor for the STARSintTester object.
        """
        self.starshost = SOSSrpc.get_myhost(short=True)
        self.starsdir = 'data'
        self.channels = [7, 8]
        self.numchannels = len(self.channels)
        self.ev_quit = threading.Event()
        self.ev_mainquit = threading.Event()
        self.stars = None
        self.mode = 'stopped'
        self.monitor = options.monitor
        self.counter = 0

        # Invoke our base class constructor.
        STARSintGUI.__init__(self)

        # Initialize setup gui defaults
        sw = self.widgets['location']
        sw.set_active(0)
        self.widgets['channels'].set_text('7,8')
        self.widgets['starshost'].set_text(self.starshost)
        self.widgets['starsdir'].set_text(self.starsdir)
Exemplo n.º 19
0
    def setUp(self):
        self.env = environment.MockEnvironment()
        self.env.removeTestDirs()  # just in case
        self.env.makeDirs()

        self.ev_quit = threading.Event()

        # Create mini monitor for STARSint
        self.minimon = Monitor.Minimon('monitor', logger)

        myhost = SOSSrpc.get_myhost(short=True)

        # Create and start STARS simulator
        self.starssim = STARSint.STARSsimulator(logger=logger,
                                                ev_quit=self.ev_quit)
        # Tell STARS how to contact us to copy files
        STARSint.add_transferParams(
            '*',
            transfermethod='ssh',
            raidpath=self.env.ARCH_PATH,
            #username=os.getlogin(),
            username=os.environ['LOGNAME'],
            password='******')

        self.starssim.start()

        # Create and start the STARS interface
        self.starsint = STARSint.STARSinterface(starshost=myhost,
                                                db=self.minimon,
                                                logger=logger,
                                                ev_quit=self.ev_quit)
        self.starsint.start()

        # Wait until STARS simulator is up and running
        # TODO: figure out a way to synchronize on the portmapper
        time.sleep(0.0)
Exemplo n.º 20
0
def make_env_vgw(options):
    """
    Make needed environment variables to run the VGW subsystem.
    """

    # What host(s) are we supposed to be talking to?
    myhost = SOSSrpc.get_myhost(short=True)
    if options:
        if options.gen2:
            hosts = get_hosts('VGW')

            obchost = hosts.obchost
            obshost = hosts.obshost
            gethost = hosts.gethost
            stathost = hosts.stathost

        elif options.daqhost:
            obchost = options.daqhost
            obshost = options.daqhost
            gethost = options.daqhost
            stathost = options.daqhost

        else:
            if options.obchost:
                obchost = options.obchost
            else:
                obchost = myhost

            if options.obshost:
                obshost = options.obshost
            else:
                obshost = myhost

            if options.gethost:
                gethost = options.gethost
            else:
                gethost = myhost

            if options.stathost:
                stathost = options.stathost
            else:
                stathost = myhost

    envvars = make_env_common(options)

    display = envvars.get('DISPLAY', ':0')

    envvars.update({
        # DAQvgw
        'DAQVGWHOME':		daqvgwhome,
        'DAQVGW_IPCKEY_UP': 	268435456,
        'SLEEP_TIME_SKYCAT':	4,
        'SLEEP_TIME_INIT':	2,
        'SLEEP_TIME_NEWWINDOW':	2,
        'AG_ID':		'0006',
        'SV_ID':		'0007',
        'SH_ID':		'0009',
        'FMOS_ID':		'003B',
        'VGW_RCV_TIME':		1,
        'VGW_WAIT_TIME':	10,
        'VGW_FRAME_NAME':	'VGW',
        'MAX_RPC_LOG':		100000,
        'MAX_DATA_LOG':		100000,
        'MAX_FTP_LOG':		10000000,
        'MAX_BYTE_ERR_LOG':	10000000,
        'VGW_OBS_CMD':		obshost,
        'VGW_OBS_STAT':		stathost,
        'OBS_CMD2':		obshost,
        'OBS_STAT2':		stathost,
        'MON_DISPLAY':		display,
        'MON_AG_DISPLAY':	display,
        'MON_SV_DISPLAY':	display,
        'MON_SH_DISPLAY':	display,
        'VGW_SUBSYS_GEOMETRY':  '1286x808+4-76',
        'AG_SKYCAT_GEOMETRY':   '713x812+8+24',
        'SV_SKYCAT_GEOMETRY':	'713x812+729+33',
        'SH_SKYCAT_GEOMETRY':	'713x812+1199+34',
        #
        # for QDASvgw
        #
        'QDASVGWHOME':		qdasvgwhome,
        'QDAS_SKYCAT_GEOMETRY': '713x812+1151-31',
        'QDAS_AGLIST_GEOMETRY': '57x11+46-39',
        'QDASVGW_IPCKEY_UP':	'268435456',
        'SKYCAT_CONFIG':	'file:///' + qdasvgwhome + '/skycat/skycat.cfg',
        'MAX_OFF_ALPHA':	0.00028,
        'MAX_OFF_DELTA':	0.00028,
        'QDAS_SLEEP_TIME_SKYCAT': 2,
        'SLEEP_TIME_AUTO':	2,
        'QDASVGW_DSS_NAME':	'dss1@summit_faster',
        'QDASVGW_DSS1_NAME':	'dss1@summit_faster',
        'QDASVGW_DSS2R_NAME':	'dss2r@summit_faster',
        'QDASVGW_DSS2B_NAME':	'dss2b@summit_faster',
        'QDASVGW_DSS2I_NAME':	'dss2i@summit_faster',
        'QDASVGW_DSS_EQUINOX':	2000,
        #
        # for DAQvgw toolkit (a version of DAQtk)
        #
        'RO_CONFIG':            daqvgwhome + '/dat/remoteObjects.cfg',
        'DAQTKHOME':		daqvgwhome + '/toolkit',
        'MAX_BYTE_RPC_LOG':	'10000000',
        'MAX_GNRT_RPC_LOG':	'11',
        'MAX_BYTE_ERR_LOG':	'10000000',
        'FITS_KEYWD_INF':	daqvgwhome + '/dat/fits.txt',
        'DAQTK_IPCKEY_UP':	'0',
        'CMDOBCP':		myhost,
        'CMDOBS':		obshost,
        'THROUGHOBCP':		myhost,
        'THROUGHOBS':	        obshost,
        'STATOBCP':		myhost,
        'STATOBS':		stathost,
        'DATOBCP':		myhost,
        'DATOBC':		obchost,
        'GETOBCP':		myhost,
        'GETOBS':		gethost,
        })

    return check_env(envvars)
Exemplo n.º 21
0
    def __init__(self,
                 ev_quit,
                 logger,
                 db,
                 taskqueue,
                 myhost=None,
                 myport=None,
                 seq_num=None):
        """Class constructor.
        
        Required parameters:
          ev_quit: a threading.Event object to synchronize any thread
          termination.  If None, then any RPC servers created by the
          subclass will create their own termination event object.

          logger: a Python logger object.  Must NOT be None.  Logs
          various events happening in the interface.

          db: a Monitor.Monitor object.  Used to inform the monitor of
          our activities, as well as a local hierarchical store of
          shared auxillary data.

          taskqueue: a Queue.Queue compatible object.  Passed through
          to the RPC servers.  When a packet arrives for a particular
          interface, the RPC server drops a processing task containing
          the packet into the queue.  The tasks are processed by a
          threadPool shared by all interfaces.

        Optional parameters:
          myhost: specifies the host interface to bind the RPC servers.
          Best left to None, in which case all host interfaces are
          bound--that way you don't have to care how the host network
          interfaces are configured.

          myport: specifies the host interface to bind the RPC servers.
          Best left to None, in which case a random, open port is
          chosen.

          seq_num: specifies a SOSSrpc.rpcSequenceNumber object to be
          used by this interface.  If left to None, a unique one is
          created for each interface.
        """

        super(BaseInterface, self).__init__()

        self.ev_quit = ev_quit
        self.logger = logger
        self.db = db
        self.taskqueue = taskqueue
        # Set interface for RPC server
        if myhost:
            self.myhost = myhost
        else:
            self.myhost = SOSSrpc.get_myhost(short=True)
            # None binds to all available interfaces
            #self.myhost = None
        # If None, will choose random, open port
        self.myport = myport
        # This will hold the client-server RPC object assigned by the
        # base class
        self.rpcconn = None

        # TODO: should seq_num be shared by all interfaces?
        # Check SOSS logs, but engineering night testing says it doesn't
        # matter...
        if seq_num:
            self.seq_num = seq_num
        else:
            # Create unique sequence number for this interface
            self.seq_num = SOSSrpc.rpcSequenceNumber()
Exemplo n.º 22
0
            minimon.stop(wait=True)

    def SigHandler(signum, frame):
        """Signal handler for all unexpected conditions."""
        logger.error('Received signal %d' % signum)
        quit()
        ev_quit.set()

    # Set signal handler for signals
    signal.signal(signal.SIGINT, SigHandler)
    signal.signal(signal.SIGTERM, SigHandler)

    logger.info("Starting status service...")
    try:
        if not options.statint:
            stathost = SOSSrpc.get_myhost(short=True)
        else:
            stathost = options.statint

        #cso = gen2StatusObj(logger, stathost)
        cso = st.cachedStatusObj(stathost)

        # Create mini monitor to reflect to main monitor
        mymonname = ('%s.mon' % svcname)
        minimon = Monitor.Monitor(mymonname, logger, numthreads=15)
        minimon.start()
        minimon.start_server(usethread=True)
        mon_started = True

        if options.monitor:
            # Subscribe main monitor to our updates
Exemplo n.º 23
0
\<Default_Parameter\>(?P<params>.+)\</Default_Parameter\>.*
\<Command\>(?P<cmd>.+)\</Command\>.*$""",
    re.MULTILINE | re.IGNORECASE | re.DOTALL)
# new style
sk_regex2 = re.compile(
    r"^(?P<top>.*)\:HEADER\s+(?P<hdr>.*)"
    ":(DEFAULT_)?PARAMETER\s+(?P<params>.*)"
    ":COMMAND\s+(?P<cmd>.+)$", re.MULTILINE | re.IGNORECASE | re.DOTALL)


class skError(Exception):
    pass


# For generating serial numbers, an atomic bump-type counter
seq_num = SOSSrpc.rpcSequenceNumber(0)

# HELPER FUNCTIONS


def mk_error(buf, errbnch, deltalines):
    """Make a formatted error message.
    """
    lines = buf.split('\n')
    res = [errbnch.errstr]

    if errbnch.lineno != 0:
        # Define the range of lines to be shown
        startline = max(1, errbnch.lineno - deltalines)
        endline = min(errbnch.lineno + deltalines, len(lines))
Exemplo n.º 24
0
        options.logfile='/tmp/ana.log'
        options.loglevel=0

    logger = ssdlog.make_logger(svcname, options)

    try:
        os.chmod(options.logfile,0666)
    except Exception,e:
        logger.warn('warning: changing permission.<%s> ' %(e))
  
    logger.debug('ana menu started')

    logger.debug('PROPID:<%s>' %(options.propid))

    try:
        localhost = SOSSrpc.get_myhost(short=True)
        logger.debug('fetching host name<%s>' %localhost) 
    except Exception,e:
        try:
            localhost = os.environ['HOST']
            logger.debug('fetching host name from environ<%s>' %localhost)  
        except KeyError,e:
            logger.error('fetching host name error<%s>' %e)
            sys.exit(1)

    host_key="/home/builder/bin/%s.key" %localhost
    host_pass="******" %localhost

    logger.debug('KEY:<%s>' %(host_key))
    logger.debug('PASS:<%s>' %(host_pass))
    
Exemplo n.º 25
0
        # Format of command should be STATUS,ALIAS,ALIAS,...
        try:
            (cmd, aliases) = data.cmdstr.split(',')
            if cmd != 'STATUS':
                raise statusRequestError(
                    "Status request command format error: '%s'" %
                    rpcmsg.payload)

        except (ValueError, TypeError), e:
            raise statusRequestError(
                "Status request command format error: '%s'" % rpcmsg.payload)

        # TODO: check for validity of all status variables

        # Create buffer for RPC message
        rpcbuf = SOSSrpc.SOSScmdRpcMsg(sender=self.myhost, pkt_type='CT')

        # Send AB message
        rpcbuf.pack_ab(rpcmsg.seq_num,
                       0,
                       receiver=rpcmsg.sender,
                       seq_num=self.seq_num.bump())

        # Get client handle back to requestor
        rpcconn = self.get_client(sender)

        try:
            res = rpcconn.callrpc(rpcbuf)

        except SOSSrpc.rpcClientError, e:
            raise statusRequestError("rpc error sending AB reply: %s" % str(e))