def main():
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.INFO)

    # Check the invocation arguments
    parser = OptionParser(
        '%prog <mom_id_of_LOBOS_group>',
        description=
        'fix loose connections (unprocessed predecessor topologies) in the given LOBOS group and approved them.'
    )
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="MoM")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)
    print()
    print("Using dbcreds:", dbcreds.stringWithHiddenPassword())
    print("Using mom url:", SystemMoMClient().mom_base_url)
    print()

    if len(args) == 0:
        parser.print_help()
        exit()

    group_id = int(args[0])

    if input("Proceed with checking and fixing %s ? y/<n>: " %
             (group_id, )) == 'y':
        fix_predecessor_connections_in_group_if_needed(group_id, dbcreds)
    else:
        print("exiting...")
Exemple #2
0
def main():
    """
    Starts the momqueryservice.GetObjectDetails service
    """
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)

    # Check the invocation arguments
    parser = OptionParser("%prog [options]",
                          description='runs the momqueryservice')
    parser.add_option('-b', '--broker', dest='broker', type='string', default=DEFAULT_BROKER,
                      help='Address of the messaging broker, default: %default')
    parser.add_option("-e", "--exchange", dest="exchange", type="string", default=DEFAULT_BUSNAME,
                      help="Name of the bus exchange on the broker, [default: %default]")
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="MoM")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    logger.info("Using dbcreds: %s", dbcreds.stringWithHiddenPassword())

    with RPCService(service_name=DEFAULT_MOMQUERY_SERVICENAME,
                    handler_type=MoMQueryServiceMessageHandler, handler_kwargs={'dbcreds': dbcreds},
                    broker=options.broker, exchange=options.exchange,
                    num_threads=6):
        waitForInterrupt()
Exemple #3
0
def main():
    # Check the invocation arguments
    parser = OptionParser("%prog [options]",
                          description='runs the resourceassignment database service')
    parser.add_option('-q', '--broker', dest='broker', type='string', default=None, help='Address of the qpid broker, default: localhost')
    parser.add_option("-b", "--busname", dest="busname", type="string", default=DEFAULT_BUSNAME, help="Name of the bus exchange on the qpid broker, default: %s" % DEFAULT_BUSNAME)
    parser.add_option("-s", "--servicename", dest="servicename", type="string", default=DEFAULT_SERVICENAME, help="Name for this service, default: %s" % DEFAULT_SERVICENAME)
    parser.add_option('-Q', '--log-queries', dest='log_queries', action='store_true', help='log all pqsl queries')
    parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging')
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="RADB")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    setQpidLogLevel(logging.INFO)
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.DEBUG if options.verbose else logging.INFO)

    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    with createService(busname=options.busname,
                       servicename=options.servicename,
                       broker=options.broker,
                       verbose=options.verbose,
                       log_queries=options.log_queries,
                       dbcreds=dbcreds):
        waitForInterrupt()
Exemple #4
0
def main():
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.INFO)

    # Check the invocation arguments
    parser = OptionParser(
        "%prog [options]",
        description='runs the resourceassignment database service')
    parser.add_option('-b',
                      '--broker',
                      dest='broker',
                      type='string',
                      default=DEFAULT_BROKER,
                      help='Address of the qpid broker, default: %default')
    parser.add_option(
        '-e',
        "--exchange",
        dest="exchange",
        type="string",
        default=DEFAULT_BUSNAME,
        help=
        "Bus or queue where the OTDB notifications are published. [default: %default]"
    )
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="RADB")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)
    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    with OTDBBusListener(handler_type=OTDBtoRATaskStatusPropagator,
                         exchange=options.exchange,
                         broker=options.broker,
                         num_threads=1):
        waitForInterrupt()
Exemple #5
0
def main():
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)

    # Check the invocation arguments
    parser = OptionParser("%prog [options]",
                          description='runs the systemstatus database service')
    parser.add_option('-q', '--broker', dest='broker', type='string',
                      default=None,
                      help='Address of the qpid broker, default: localhost')
    parser.add_option("-b", "--busname", dest="busname", type="string",
                      default=DEFAULT_SSDB_BUSNAME,
                      help="Name of the bus exchange on the qpid broker. [default: %default]")
    parser.add_option("-s", "--servicename", dest="servicename", type="string",
                      default=DEFAULT_SSDB_SERVICENAME,
                      help="Name for this service. [default: %default]")
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="SSDB")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    with createService(busname=options.busname, servicename=options.servicename, dbcreds=dbcreds, broker=options.broker):
        waitForInterrupt()
Exemple #6
0
def main():
    # Check the invocation arguments
    parser = OptionParser(
        "%prog [options]",
        description='runs the resourceassignment database service')
    parser.add_option('-q',
                      '--broker',
                      dest='broker',
                      type='string',
                      default=None,
                      help='Address of the qpid broker, default: localhost')
    parser.add_option(
        "-b",
        "--busname",
        dest="busname",
        type="string",
        default=DEFAULT_BUSNAME,
        help="Name of the bus exchange on the qpid broker, default: %s" %
        DEFAULT_BUSNAME)
    parser.add_option("-s",
                      "--servicename",
                      dest="servicename",
                      type="string",
                      default=DEFAULT_SERVICENAME,
                      help="Name for this service, default: %s" %
                      DEFAULT_SERVICENAME)
    parser.add_option('-Q',
                      '--log-queries',
                      dest='log_queries',
                      action='store_true',
                      help='log all pqsl queries')
    parser.add_option('-V',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='verbose logging')
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="RADB")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    setQpidLogLevel(logging.INFO)
    logging.basicConfig(
        format='%(asctime)s %(levelname)s %(message)s',
        level=logging.DEBUG if options.verbose else logging.INFO)

    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    with createService(busname=options.busname,
                       servicename=options.servicename,
                       broker=options.broker,
                       verbose=options.verbose,
                       log_queries=options.log_queries,
                       dbcreds=dbcreds):
        waitForInterrupt()
Exemple #7
0
def main():
    # Check the invocation arguments
    parser = OptionParser(
        "%prog [options]",
        description=
        'runs the radb postgres listener which listens to changes on some tables in the radb and publishes the changes as notifications on the bus.'
    )
    parser.add_option('-q',
                      '--broker',
                      dest='broker',
                      type='string',
                      default=None,
                      help='Address of the qpid broker, default: localhost')
    parser.add_option(
        "-b",
        "--busname",
        dest="busname",
        type="string",
        default=DEFAULT_NOTIFICATION_BUSNAME,
        help=
        "Name of the publication bus on the qpid broker, [default: %default]")
    parser.add_option(
        "-n",
        "--notification_prefix",
        dest="notification_prefix",
        type="string",
        default=DEFAULT_NOTIFICATION_PREFIX,
        help=
        "The prefix for all notifications of this publisher, [default: %default]"
    )
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="RADB")
    (options, args) = parser.parse_args()

    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.INFO)

    dbcreds = dbcredentials.parse_options(options)

    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    with RADBPGListener(busname=options.busname,
                        notification_prefix=options.notification_prefix,
                        dbcreds=dbcreds,
                        broker=options.broker) as listener:
        listener.waitWhileListening()
Exemple #8
0
def main():
    from optparse import OptionParser
    from lofar.common import dbcredentials
    import signal

    # Check the invocation arguments
    parser = OptionParser("%prog [options]")
    parser.add_option("-B", "--busname", dest="busname", type="string", default=DEFAULT_BUSNAME,
                      help="Bus on which the status changes are published on. [default: %default]")
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="OTDB")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    # Set signalhandler to stop the program in a neat way.
    signal.signal(signal.SIGINT, signal_handler)

    create_service(options.busname, dbcreds)
Exemple #9
0
def main():
    # make sure we run in UTC timezone
    import os
    os.environ['TZ'] = 'UTC'

    # Check the invocation arguments
    parser = OptionParser(
        "%prog [options]",
        description='runs the resourceassignment database service')
    parser.add_option('-b',
                      '--broker',
                      dest='broker',
                      type='string',
                      default=DEFAULT_BROKER,
                      help='Address of the qpid broker, default: %default')
    parser.add_option(
        "-e",
        "--exchange",
        dest="exchange",
        type="string",
        default=DEFAULT_BUSNAME,
        help="Name of the bus exchange on the broker, default: %default")
    parser.add_option('-V',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='verbose logging')
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="RADB")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    logging.basicConfig(
        format='%(asctime)s %(thread)s %(levelname)s %(message)s',
        level=logging.DEBUG if options.verbose else logging.INFO)

    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    with createService(exchange=options.exchange,
                       broker=options.broker,
                       dbcreds=dbcreds):
        waitForInterrupt()
Exemple #10
0
def main():
    # make sure we run in UTC timezone
    import os
    os.environ['TZ'] = 'UTC'

    # Check the invocation arguments
    parser = OptionParser(
        "%prog [options]",
        description=
        'runs the radb postgres listener which listens to changes on some tables in the radb and publishes the changes as notifications on the bus.'
    )
    parser.add_option(
        '-b',
        '--broker',
        dest='broker',
        type='string',
        default=DEFAULT_BROKER,
        help='Address of the messaging broker, default: %default')
    parser.add_option(
        "-e",
        "--exchange",
        dest="exchange",
        type="string",
        default=DEFAULT_BUSNAME,
        help="Name of the bus exchange on the broker, [default: %default]")

    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="RADB")
    (options, args) = parser.parse_args()

    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.INFO)

    dbcreds = dbcredentials.parse_options(options)

    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    with RADBPGListener(exchange=options.exchange,
                        dbcreds=dbcreds,
                        broker=options.broker) as listener:
        listener.waitWhileListening()
Exemple #11
0
def main():
    '''Starts the momqueryservice.GetProjectDetails service'''

    # Check the invocation arguments
    parser = OptionParser("%prog [options]",
                          description='runs the momqueryservice')
    parser.add_option('-q', '--broker', dest='broker', type='string', default=None, help='Address of the qpid broker, default: localhost')
    parser.add_option("-b", "--busname", dest="busname", type="string", default=DEFAULT_MOMQUERY_BUSNAME, help="Name of the bus exchange on the qpid broker, [default: %default]")
    parser.add_option("-s", "--servicename", dest="servicename", type="string", default=DEFAULT_MOMQUERY_SERVICENAME, help="Name for this service, [default: %default]")
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="MoM")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    # start the service and listen.
    with createService(busname=options.busname,
                       servicename=options.servicename,
                       broker=options.broker,
                       dbcreds=dbcreds):
        waitForInterrupt()
Exemple #12
0
def main():
    # make sure we run in UTC timezone
    import os
    os.environ['TZ'] = 'UTC'

    from optparse import OptionParser
    from lofar.common.util import waitForInterrupt

    # Check the invocation arguments
    parser = OptionParser("%prog [options]",
                          description='runs the resourceassigner service')
    parser.add_option('-b', '--broker', dest='broker', type='string',
                      default=DEFAULT_BROKER,
                      help='Address of the broker, default: localhost')
    parser.add_option('-e', "--exchange", dest="exchange", type="string",
                      default=DEFAULT_BUSNAME,
                      help="Name of the bus on which communication occurs [default: %default]")
    parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging')

    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="RADB")

    (options, args) = parser.parse_args()

    radb_dbcreds = dbcredentials.parse_options(options)

    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.DEBUG if options.verbose else logging.INFO)

    with ResourceAssigner(exchange=options.exchange,
                          broker=options.broker,
                          radb_dbcreds=radb_dbcreds) as assigner:
        with RATaskSpecifiedBusListener(handler_type=SpecifiedTaskEventMessageHandler,
                                        handler_kwargs={"assigner": assigner},
                                        exchange=options.exchange,
                                        broker=options.broker):
            with ScheduleChecker(exchange=options.exchange,
                                 broker=options.broker):
                waitForInterrupt()
Exemple #13
0
def main():
    from optparse import OptionParser
    from lofar.common import dbcredentials
    from lofar.common.util import waitForInterrupt

    # Check the invocation arguments
    parser = OptionParser("%prog [options]")
    parser.add_option('-b',
                      '--broker',
                      dest='broker',
                      type='string',
                      default=DEFAULT_BROKER,
                      help='Address of the qpid broker, default: localhost')
    parser.add_option(
        "-e",
        "--exchange",
        dest="exchange",
        type="string",
        default=DEFAULT_BUSNAME,
        help="Bus on which RPC commands are received. [default: %default]")
    parser.add_option('-V',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='verbose logging')
    # Add options of dbcredentials: --database, --host, ...
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="OTDB")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)
    print("###dbcreds:", dbcreds)

    with create_service(broker=options.broker,
                        exchange=options.exchange,
                        dbcreds=dbcreds):
        waitForInterrupt()

    logger.info("Stopped the OTDB services")
Exemple #14
0
def main():
    '''Starts the momqueryservice.GetProjectDetails service'''

    # Check the invocation arguments
    parser = OptionParser("%prog [options]",
                          description='runs the momqueryservice')
    parser.add_option('-q',
                      '--broker',
                      dest='broker',
                      type='string',
                      default=None,
                      help='Address of the qpid broker, default: localhost')
    parser.add_option(
        "-b",
        "--busname",
        dest="busname",
        type="string",
        default=DEFAULT_MOMQUERY_BUSNAME,
        help="Name of the bus exchange on the qpid broker, [default: %default]"
    )
    parser.add_option("-s",
                      "--servicename",
                      dest="servicename",
                      type="string",
                      default=DEFAULT_MOMQUERY_SERVICENAME,
                      help="Name for this service, [default: %default]")
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="MoM")
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    # start the service and listen.
    with createService(busname=options.busname,
                       servicename=options.servicename,
                       broker=options.broker,
                       dbcreds=dbcreds):
        waitForInterrupt()
Exemple #15
0
def main():
    from optparse import OptionParser
    from lofar.common import dbcredentials

    # Check the invocation arguments
    parser = OptionParser(
        "%prog [options]",
        description=
        'runs the lta scraper and stores results in the speficied database.')
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="LTASO")
    (options, args) = parser.parse_args()

    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.INFO)

    dbcreds = dbcredentials.parse_options(options)

    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    global db
    db = store.LTAStorageDb(dbcreds)

    app.run(debug=False, host='0.0.0.0', port=9632)
Exemple #16
0
def main():
    '''the main function scanning all locations and gathering the results'''

    from optparse import OptionParser
    from lofar.common import dbcredentials
    from lofar.messaging import DEFAULT_BROKER, DEFAULT_BUSNAME
    from lofar.lta.ltastorageoverview.ingesteventhandler import LTASOIngestEventHandler, IngestEventMesssageBusListener

    # Check the invocation arguments
    parser = OptionParser("%prog [options]", description='runs the lta scraper and stores results in the speficied database.')
    parser.add_option('-j', '--parallel', dest='parallel', type='int', default=8, help='number of parallel srmls jobs to run, default: %default')

    parser.add_option('-b', '--broker', dest='broker', type='string', default=DEFAULT_BROKER,
                      help='Address of the messaging broker, default: %default')
    parser.add_option('-e', '--exchange', dest='exchange', type='string',
                      default=DEFAULT_BUSNAME,
                      help='Name of the bus exchange on the broker on which the ingest notifications are published, default: %default')

    parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging')
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="LTASO")
    (options, args) = parser.parse_args()

    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.DEBUG if options.verbose else logging.INFO)
    options.parallel = max(1, min(8*multiprocessing.cpu_count(), options.parallel))
    logger.info("Using maximum number of parallel srmls jobs: %d" % options.parallel)

    dbcreds = dbcredentials.parse_options(options)
    logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword())

    db = store.LTAStorageDb(dbcreds)
    populateDbWithLTASitesAndRootDirs(db)

    # for each site we want one or more ResultGetterThreads
    # so make a dict with a list per site based on the locations
    getters = dict([(site['name'],[]) for site in db.sites()])

    # some helper functions
    def numLocationsInQueues():
        '''returns the total number of locations in the queues'''
        return db.numDirectoriesNotVisitedSince(datetime.datetime.utcnow() - VISIT_INTERVAL)

    def totalNumGetters():
        '''returns the total number of parallel running ResultGetterThreads'''
        return sum([len(v) for v in list(getters.values())])

    def cleanupFinishedGetters():
        # get rid of old finished ResultGetterThreads
        finishedGetters = dict([(site_name, [getter for getter in getterList if not getter.isAlive()]) for site_name, getterList in list(getters.items())])
        for site_name,finishedGetterList in list(finishedGetters.items()):
            for finishedGetter in finishedGetterList:
                getters[site_name].remove(finishedGetter)


    # the main loop
    # loop over the locations and spawn ResultGetterThreads to get the results parallel
    # use load balancing over the different sites and with respect to queue lengths
    # do not overload this host system
    with IngestEventMesssageBusListener(handler_type=LTASOIngestEventHandler,
                                        handler_kwargs={'dbcreds': dbcreds},
                                        exchange=options.exchange, broker=options.broker):
        while True:

            cleanupFinishedGetters()

            # spawn new ResultGetterThreads
            # do not overload this host system
            num_waiting = numLocationsInQueues()
            while (num_waiting > 0 and
                   totalNumGetters() < options.parallel and
                   os.getloadavg()[0] < 4*multiprocessing.cpu_count()):
                sitesStats = db.visitStats(datetime.datetime.utcnow() - VISIT_INTERVAL)

                for site_name, site_stats in list(sitesStats.items()):
                    numGetters = len(getters[site_name])
                    queue_length = site_stats['queue_length']
                    weight = float(queue_length) / float(20 * (numGetters + 1))
                    if numGetters == 0 and queue_length > 0:
                        weight = 1e6 # make getterless sites extra important, so each site keeps flowing
                    site_stats['# get'] = numGetters
                    site_stats['weight'] = weight

                totalWeight = max(1.0, sum([site_stats['weight'] for site_stats in list(sitesStats.values())]))

                logger.debug("siteStats:\n%s" % str('\n'.join([str((k, v)) for k, v in list(sitesStats.items())])))

                # now pick a random site using the weights
                chosen_site_name = None
                cumul = 0.0
                r = random()
                for site_name,site_stats in list(sitesStats.items()):
                    ratio = site_stats['weight']/totalWeight
                    cumul += ratio

                    if r <= cumul and site_stats['queue_length'] > 0:
                        chosen_site_name = site_name
                        break

                if not chosen_site_name:
                    break

                chosen_dir_id = sitesStats[chosen_site_name]['least_recent_visited_dir_id']
                db.updateDirectoryLastVisitTime(chosen_dir_id, datetime.datetime.utcnow())

                logger.debug("chosen_site_name: %s chosen_dir_id: %s", chosen_site_name, chosen_dir_id)

                # make and start a new ResultGetterThread the location deque of the chosen site
                newGetter = ResultGetterThread(dbcreds, chosen_dir_id)
                newGetter.start()
                getters[chosen_site_name].append(newGetter)

                cleanupFinishedGetters()

                # refresh num_waiting
                num_waiting = numLocationsInQueues()
                logger.info('numLocationsInQueues=%d totalNumGetters=%d siteQueueLengths: %s load_5min: %.1f' % (num_waiting,
                                                                                                                 totalNumGetters(),
                                                                                                                 ' '.join(['%s:%d' % (name, stats['queue_length']) for name, stats in list(sitesStats.items())]),
                                                                                                                 os.getloadavg()[0]))

            # sleep before main loop next iteration
            # to wait for some results
            # and some getters to finish
            time.sleep(30 if num_waiting <= options.parallel else 0.25)
Exemple #17
0
def main():
    # make sure we run in UTC timezone
    import os
    os.environ['TZ'] = 'UTC'

    # Check the invocation arguments
    parser = OptionParser(
        '%prog [options]',
        description='run the resource assignment editor web service')
    parser.add_option(
        '--webserver_port',
        dest='webserver_port',
        type='int',
        default=7412,
        help='port number on which to host the webservice, default: %default')
    parser.add_option('-q',
                      '--broker',
                      dest='broker',
                      type='string',
                      default=DEFAULT_BROKER,
                      help='Address of the qpid broker, default: %default')
    parser.add_option(
        '--exchange',
        dest='exchange',
        type='string',
        default=DEFAULT_BUSNAME,
        help='Name of the bus exchange on the qpid broker, default: %default')
    parser.add_option('-V',
                      '--verbose',
                      dest='verbose',
                      action='store_true',
                      help='verbose logging')
    parser.add_option_group(dbcredentials.options_group(parser))
    parser.set_defaults(dbcredentials="RADB")
    (options, args) = parser.parse_args()

    logging.basicConfig(
        format='%(asctime)s %(levelname)s %(message)s',
        level=logging.DEBUG if options.verbose else logging.INFO)

    global _radb_dbcreds
    _radb_dbcreds = dbcredentials.parse_options(options)
    if _radb_dbcreds.database:
        logger.info("Using dbcreds for direct RADB access: %s" %
                    _radb_dbcreds.stringWithHiddenPassword())
    else:
        _radb_dbcreds = None

    global rarpc
    rarpc = RADBRPC.create(exchange=options.exchange, broker=options.broker)
    global otdbrpc
    otdbrpc = OTDBRPC.create(exchange=options.exchange, broker=options.broker)
    global curpc
    curpc = CleanupRPC.create(exchange=options.exchange, broker=options.broker)
    global sqrpc
    sqrpc = StorageQueryRPC.create(exchange=options.exchange,
                                   timeout=10,
                                   broker=options.broker)
    global momqueryrpc
    momqueryrpc = MoMQueryRPC.create(exchange=options.exchange,
                                     timeout=10,
                                     broker=options.broker)
    global changeshandler
    changeshandler = ChangesHandler(exchange=options.exchange,
                                    broker=options.broker,
                                    momqueryrpc=momqueryrpc,
                                    radbrpc=rarpc,
                                    sqrpc=sqrpc)

    with changeshandler, rarpc, otdbrpc, curpc, sqrpc, momqueryrpc:
        '''Start the webserver'''
        app.run(debug=options.verbose,
                threaded=True,
                host='0.0.0.0',
                port=options.webserver_port)
Exemple #18
0
    alive = False


if __name__ == "__main__":
    from optparse import OptionParser
    from lofar.common import dbcredentials
    import signal

    # Check the invocation arguments
    parser = OptionParser("%prog [options]")
    parser.add_option("-B", "--busname", dest="busname", type="string", default=DEFAULT_OTDB_NOTIFICATION_BUSNAME,
                      help="Busname or queue-name the status changes are published on. [default: %default]")
    parser.add_option_group(dbcredentials.options_group(parser))
    (options, args) = parser.parse_args()

    dbcreds = dbcredentials.parse_options(options)

    # Set signalhandler to stop the program in a neat way.
    signal.signal(signal.SIGINT, signal_handler)

    alive = True
    connected = False
    otdb_connection = None
    with ToBus(options.busname) as send_bus:
        while alive:
            while alive and not connected:
                # Connect to the database
                try:
                    otdb_connection = pg.connect(**dbcreds.pg_connect_options())
                    connected = True
                    logger.info("Connected to database %s" % (dbcreds,))
Exemple #19
0
    parser = OptionParser('%prog [options]',
	     description='Add items to the QPIDinfra database from the commandline')
    parser.add_option('-b', '--broker', dest='broker', type='string', default=None, help='Address of the qpid broker (required)')
    parser.add_option('-f', '--federation', dest='federation' , type='string', default=None, help='Address of the federated broker')
    parser.add_option('-q', '--queue', dest='queue', type='string', default=None, help='Name of the queue on the broker')
    parser.add_option('-e', '--exchange', dest='exchange', type='string', default=None, help='Name of the exchange on the broker')
    parser.add_option('-k', '--routingkey', dest='routingkey', type='string', default='#', help='Federation routing key')
    parser.add_option_group(dbcredentials.options_group(parser, "qpidinfra"))

    (options, args) = parser.parse_args()

    if (len(sys.argv)<2):
	 parser.print_help()
	 sys.exit(0)

    dbcreds = dbcredentials.parse_options(options)
    QPIDinfra = qpidinfra(dbcreds)

    if (options.broker==None):
	parser.print_help()
	sys.exit(1)

    else:
	QPIDinfra.addhost(options.broker)

    if (options.queue):
	QPIDinfra.addqueue(options.queue)
	QPIDinfra.bindqueuetohost(options.queue,options.broker)
    
    if (options.exchange):
	QPIDinfra.addexchange(options.exchange)