Exemplo n.º 1
0
                                                        conftype=conftype,
                                                        logfile=True)

    try:
        with PidFile(pidname=mynameis.lower(), piddir=pidpath) as p:
            # Print the preamble of this particular instance
            #   (helpful to find starts/restarts when scanning thru logs)
            common.printPreamble(p, config)

            # Specify our custom listener that will really do all the work
            #   Since we're hardcoding for the DCTConsumer anyways, I'll take
            #   a bit shortcut and hardcode for the DCT influx database.
            # TODO: Figure out a way to create a dict of listeners specified
            #   in some creative way. Could add a configuration item to the
            #   file and then loop over it, and change connAMQ accordingly.
            amqtopics = amq.getAllTopics(config, comm)
            amqs = connSetup.connAMQ(comm, amqtopics, amqlistener=amqlistener)

            # Just hardcode this for now. It's a prototype!
            conn = amqs['broker-dct'][0]

            # Semi-infinite loop
            while runner.halt is False:
                # Check on our connections
                amqs = amq.checkConnections(amqs, subscribe=True)

                # Do some stuff!
                print("Doing some sort of loop ...")
                time.sleep(15.)
                print("Done stuff!")
Exemplo n.º 2
0
    config, comm, args, runner = workerSetup.toServeMan(devices,
                                                        passes,
                                                        logfile,
                                                        desc=desc,
                                                        extraargs=eargs,
                                                        conftype=deviceconf,
                                                        logfile=False)

    try:
        with PidFile(pidname=mynameis.lower(), piddir=pidpath) as p:
            # Print the preamble of this particular instance
            #   (helpful to find starts/restarts when scanning thru logs)
            common.printPreamble(p, config)

            amqlistener = amq.ParrotSubscriber()
            amqtopics = amq.getAllTopics(config, comm, queuerole='client')
            # Manually stuff the
            amqs = connSetup.connAMQ(comm, amqtopics, amqlistener=amqlistener)

            # Just hardcode this for now. It's a prototype!
            conn = amqs['broker-dct'][0]
            queue = comm['queue-mrfreeze']

            # Semi-infinite loop
            while runner.halt is False:
                # Check on our connections
                amqs = amq.checkConnections(amqs, subscribe=True)

                # Leaving this in a loop for testing for now; Victor will
                #   turn into a single-shooter when he's ready
                # inst = 'NIHTS'
Exemplo n.º 3
0
def main():
    """
    """
    # Define the default files we'll use/look for. These are passed to
    #   the worker constructor (toServeMan).
    conf = './config/iago.conf'
    passes = './config/passwords.conf'
    logfile = '/tmp/jester.log'
    desc = "Jester: A Useful Idiot"
    eargs = iago.parseargs.extraArguments
    conftype = classes.snoopTarget

    # Interval between successive runs of the polling loop (seconds)
    bigsleep = 15

    # config: dictionary of parsed config file
    # comm: common block from config file
    # args: parsed options
    # runner: class that contains logic to quit nicely
    config, comm, args, runner = workerSetup.toServeMan(conf,
                                                        passes,
                                                        logfile,
                                                        desc=desc,
                                                        extraargs=eargs,
                                                        conftype=conftype,
                                                        logfile=False)

    # Get this PID for diagnostics
    pid = os.getpid()

    # Print the preamble of this particular instance
    #   (helpful to find starts/restarts when scanning thru logs)
    common.printPreamble(pid, config)

    # Check to see if there are any connections/objects to establish
    idbs = connSetup.connIDB(comm)

    # Specify our custom listener that will really do all the work
    #   Since we're hardcoding for the DCTConsumer anyways, I'll take
    #   a bit shortcut and hardcode for the DCT influx database.
    # TODO: Figure out a way to create a dict of listeners specified
    #   in some creative way. Could add a configuration item to the
    #   file and then loop over it, and change connAMQ accordingly.
    dctdb = idbs['database-dct']
    dctdb.tablename = config['dctbroker'].tablename
    amqlistener = iago.listener.DCTConsumer(dbconn=dctdb)
    amqtopics = amq.getAllTopics(config, comm)
    amqs = connSetup.connAMQ(comm, amqtopics, amqlistener=amqlistener)

    # Check to see if there are any connections/objects to establish
    amqtopics = amq.getAllTopics(config, comm)

    # Semi-infinite loop
    while runner.halt is False:
        # Check on our connections
        amqs = amq.checkConnections(amqs, subscribe=True)

        # There really isn't anything to actually *do* in here;
        #   all the real work happens in the listener, so we really
        #   just spin our wheels here.

        # Consider taking a big nap
        if runner.halt is False:
            print("Starting a big sleep")
            # Sleep for bigsleep, but in small chunks to check abort
            for _ in range(bigsleep):
                time.sleep(0.5)
                if runner.halt is True:
                    break

    # The above loop is exited when someone sends SIGTERM
    print("PID %d is now out of here!" % (pid))

    # Disconnect from all ActiveMQ brokers
    amq.disconnectAll(amqs)

    # The PID file will have already been either deleted/overwritten by
    #   another function/process by this point, so just give back the
    #   console and return STDOUT and STDERR to their system defaults
    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__
    print("STDOUT and STDERR reset.")
Exemplo n.º 4
0
def main():
    """
    """
    # Define the default files we'll use/look for. These are passed to
    #   the worker constructor (toServeMan).
    devices = '../../conf/mrfreeze.conf'
    deviceconf = classes.instrumentDeviceTarget
    passes = None
    logfile = '../../logs/nora.log'
    desc = "Nora: Heart of the Instrument Cooler Manager"
    eargs = None
    logenable = True

    # Interval between successive runs of the polling loop (seconds)
    bigsleep = 1

    # config: dictionary of parsed config file
    # comm: common block from config file
    # args: parsed options
    # runner: class that contains logic to quit nicely
    config, comm, _, runner = workerSetup.toServeMan(devices,
                                                     passes,
                                                     logfile,
                                                     desc=desc,
                                                     extraargs=eargs,
                                                     conftype=deviceconf,
                                                     enableCheck=False,
                                                     logfile=logenable)

    # Get this PID for diagnostics
    pid = os.getpid()

    # Print the preamble of this particular instance
    #   (helpful to find starts/restarts when scanning thru logs)
    common.printPreamble(pid, config)

    # Reorganize the configuration to be per-instrument so it's a little
    #   easier to loop over and do other stuff with
    allInsts = confparsers.regroupConfig(config,
                                         groupKey='instrument',
                                         ekeys=['devtype', 'extratag'],
                                         delim="+")

    # We need to store our NIHTS compatibility stuff in the above NIHTS
    #   section, to guarantee that it's shared between all devices for that
    #   instrument.  So it needs to be in this level!
    # Also hack in the required password
    print("Looking for NIHTS compatibility section...")
    try:
        compatConfig = confparsers.rawParser("../../conf/compat.conf")
        np = compatConfig['nihts']
        # A cheap hack inside of a cheap hack!
        if np['enabled'].lower() == "false":
            np = None
            print("Warning! Compat info found, but was disabled!")
        else:
            compatClass = compatibility.upfileNIHTS(np)
            allInsts["nihts"].update({"compatibility": compatClass})
            print("NIHTS compatibility layer enabled.")
    except Exception as err:
        print("None found! Skipping.")
        print(str(err))
        np = None

    print("Config:")
    print(allInsts)

    # Check to see if there are any connections/objects to establish
    idbs = connSetup.connIDB(comm)

    # Specify our custom listener that will really do all the work
    #   Since we're hardcoding for the DCTConsumer anyways, I'll take
    #   a bit shortcut and hardcode for the DCT influx database.
    # Someone more clever than I can clean up.
    db = idbs['database-dct']
    amqlistener = listener.MrFreezeConsumer(db=db)

    # TODO: Figure out a way to create a dict of listeners specified
    #   in some creative way. Could add a configuration item to the
    #   file and then loop over it, and change connAMQ accordingly.
    amqtopics = amq.getAllTopics(config, comm, queuerole='master')
    amqs = connSetup.connAMQ(comm, amqtopics, amqlistener=amqlistener)

    # Just hardcode this for now. It's a prototype!
    conn = amqs['broker-dct'][0]
    queue = comm['queue-mrfreeze']

    # Assemble our *initial* schedule of actions. This will be adjusted
    #   by any inputs from the broker once we're in the main loop
    sched = schedule.Scheduler()
    sched = actions.scheduleInstruments(sched,
                                        allInsts,
                                        amqs,
                                        idbs,
                                        debug=True)

    # Before we start the main loop, query all the defined actions
    #   in turn. This will help avoid triggering alerts/warnings/etc.
    # We need to make sure the connection to the broker is up first,
    #   though, because we need to get the LOIS reply topics connected.
    amqs = amq.checkConnections(amqs, subscribe=True)
    sched.run_all(delay_seconds=0.5)

    # Semi-infinite loop
    while runner.halt is False:
        # Check on our connections
        amqs = amq.checkConnections(amqs, subscribe=True)
        # Make sure we update our hardcoded reference
        conn = amqs['broker-dct'][0]

        # Check for any actions, and do them if it's their time
        print("Checking schedule for pending tasks...")
        sched.run_pending()
        for job in sched.jobs:
            remaining = (job.next_run - datetime.now()).total_seconds()
            print("    %s in %f seconds" % (job.tags, remaining))

        # Check for any updates to those actions, or any commanded
        #   actions in general
        print("Cleaning out the queue...")
        queueActions = amqlistener.emptyQueue()
        print("%d items obtained from the queue" % (len(queueActions)))

        # Process and deal with the things in the queue
        allInsts = actions.queueProcessor(sched, queueActions, allInsts, conn,
                                          queue)

        # Diagnostic output
        nleft = len(amqlistener.brokerQueue.items())
        print("%d items still in the queue" % (nleft))
        print("Done for now!")

        # Consider taking a big nap
        if runner.halt is False:
            print("Starting a big sleep")
            # Sleep for bigsleep, but in small chunks to check abort
            for _ in range(bigsleep):
                time.sleep(1)
                if runner.halt is True:
                    break

    # The above loop is exited when someone sends SIGTERM
    print("PID %d is now out of here!" % (pid))

    # Disconnect from all ActiveMQ brokers
    amq.disconnectAll(amqs)

    # The PID file will have already been either deleted/overwritten by
    #   another function/process by this point, so just give back the
    #   console and return STDOUT and STDERR to their system defaults
    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__
    print("STDOUT and STDERR reset.")