From b2ea14c650a5e1a476d9035ed19beb7573b2308e Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Mon, 3 Oct 2016 09:03:12 +0000 Subject: [PATCH] Task #9931: added config, and made skeleton for qpid service --- .gitattributes | 1 + LTA/LTAIngest/bin/ingestservice | 2 +- LTA/LTAIngest/lib/CMakeLists.txt | 3 ++- LTA/LTAIngest/lib/config.py | 4 ++++ LTA/LTAIngest/lib/ingestservice.py | 32 +++++++++++++++++++++++++++--- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 LTA/LTAIngest/lib/config.py diff --git a/.gitattributes b/.gitattributes index 52b07a6c089..66db0e48b4d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2946,6 +2946,7 @@ LTA/LTAIngest/bin/CMakeLists.txt -text LTA/LTAIngest/bin/ingestservice -text LTA/LTAIngest/bin/ingestservice.ini -text LTA/LTAIngest/lib/CMakeLists.txt -text +LTA/LTAIngest/lib/config.py -text LTA/LTAIngest/lib/ingestservice.py -text LTA/LTAIngest/old/ClientForm-0.1.17/ClientForm-0.1.17/PKG-INFO -text LTA/LTAIngest/old/ClientForm-0.1.17/PKG-INFO -text diff --git a/LTA/LTAIngest/bin/ingestservice b/LTA/LTAIngest/bin/ingestservice index a168b0b46f1..2a4ddf11922 100755 --- a/LTA/LTAIngest/bin/ingestservice +++ b/LTA/LTAIngest/bin/ingestservice @@ -5,5 +5,5 @@ runs the ingest service ''' if __name__ == '__main__': - from lofar.lta.ltaingest.ingestservice import main + from lofar.lta.ingest.ingestservice import main main() diff --git a/LTA/LTAIngest/lib/CMakeLists.txt b/LTA/LTAIngest/lib/CMakeLists.txt index a8cb524a8b7..f976f966c26 100644 --- a/LTA/LTAIngest/lib/CMakeLists.txt +++ b/LTA/LTAIngest/lib/CMakeLists.txt @@ -1,4 +1,5 @@ python_install(ingestservice.py - DESTINATION lofar/lta/ltaingest) + config.py + DESTINATION lofar/lta/ingest) diff --git a/LTA/LTAIngest/lib/config.py b/LTA/LTAIngest/lib/config.py new file mode 100644 index 00000000000..a0dffda1035 --- /dev/null +++ b/LTA/LTAIngest/lib/config.py @@ -0,0 +1,4 @@ +from lofar.messaging import adaptNameToEnvironment + +DEFAULT_INGEST_BUSNAME = adaptNameToEnvironment('lofar.lta.ingest.command') +DEFAULT_INGEST_SERVICENAME = 'IngestService' diff --git a/LTA/LTAIngest/lib/ingestservice.py b/LTA/LTAIngest/lib/ingestservice.py index 94cf1505454..33a09e792d1 100644 --- a/LTA/LTAIngest/lib/ingestservice.py +++ b/LTA/LTAIngest/lib/ingestservice.py @@ -26,10 +26,27 @@ import qpid.messaging import logging from datetime import datetime import time +from lofar.messaging import Service +from lofar.messaging.Service import MessageHandlerInterface +from lofar.lta.ingest.config import DEFAULT_INGEST_BUSNAME, DEFAULT_INGEST_SERVICENAME logger = logging.getLogger(__name__) -__all__ = [] +class IngestServiceMessageHandler(MessageHandlerInterface): + def __init__(self, **kwargs): + super(IngestServiceMessageHandler, self).__init__(**kwargs) + + self.service2MethodMap = {} + +def createService(busname=DEFAULT_INGEST_BUSNAME, servicename=DEFAULT_INGEST_SERVICENAME, broker=None, verbose=False): + return Service(servicename, + IngestServiceMessageHandler, + busname=busname, + broker=broker, + use_service_methods=True, + numthreads=1, + handler_args={}, + verbose=verbose) def main(): # make sure we run in UTC timezone @@ -42,10 +59,16 @@ def main(): # Check the invocation arguments parser = OptionParser("%prog [options]", - description='runs the resourceassigner service') + description='runs the ingest service') parser.add_option('-q', '--broker', dest='broker', type='string', default=None, help='Address of the qpid broker, default: localhost') + parser.add_option("--ingest_busname", dest="ingest_busname", type="string", + default=DEFAULT_INGEST_BUSNAME, + help="Name of the bus on which the ingest service listens. [default: %default]") + parser.add_option("--ingest_servicename", dest="ingest_servicename", type="string", + default=DEFAULT_INGEST_SERVICENAME, + help="Name of the ingest service. [default: %default]") parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging') (options, args) = parser.parse_args() @@ -53,7 +76,10 @@ def main(): logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG if options.verbose else logging.INFO) - waitForInterrupt() + with createService(servicename=options.ingest_servicename, busname=options.ingest_busname, broker=options.broker, verbose=options.verbose) as ingest_service: + waitForInterrupt() if __name__ == '__main__': main() + +__all__ = ['main'] -- GitLab