From e11a5fd84f808d951488a788e6285c46497695b4 Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Tue, 25 Jun 2019 12:08:01 +0000 Subject: [PATCH] SW-720: use old messagebus ToBus to send the specification xml message directly to mom.importxml at lcs023 --- SAS/SpecificationServices/lib/config.py | 2 +- .../lib/specification_service.py | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/SAS/SpecificationServices/lib/config.py b/SAS/SpecificationServices/lib/config.py index ea15b3bffc9..19760d37817 100644 --- a/SAS/SpecificationServices/lib/config.py +++ b/SAS/SpecificationServices/lib/config.py @@ -11,7 +11,7 @@ SPECIFICATIONTRANSLATION_SERVICENAME = "specificationtranslationservice" # TODO: mom.importxml does not prepend "test." on the test system? MOMIMPORTXML_BUSNAME = "mom.importxml" -MOMIMPORTXML_SUBJECT = "add specification" +MOMIMPORTXML_BROKER = "lcs023.control.lofar" # XSD paths (for validation service) TRIGGER_XSD = "$LOFARROOT/share/SAS/LofarTrigger.xsd" diff --git a/SAS/SpecificationServices/lib/specification_service.py b/SAS/SpecificationServices/lib/specification_service.py index afb8d9c516f..1f995c8d031 100644 --- a/SAS/SpecificationServices/lib/specification_service.py +++ b/SAS/SpecificationServices/lib/specification_service.py @@ -26,8 +26,7 @@ from io import BytesIO from lofar.common.util import waitForInterrupt # TODO: mom.importxml uses old messaging interface from lofar.messagebus.message import MessageContent -from lofar.messaging import RPCService, EventMessage, DEFAULT_BROKER, DEFAULT_BUSNAME, \ - ServiceMessageHandler +from lofar.messaging import RPCService, DEFAULT_BUSNAME, DEFAULT_BROKER, ServiceMessageHandler from lofar.messagebus.messagebus import ToBus as ToBusOld from lofar.messagebus.message import MessageContent as MessageContentOld from lofar.mom.momqueryservice.momqueryrpc import MoMQueryRPC @@ -35,10 +34,7 @@ from lofar.specificationservices.translation_service_rpc import TranslationRPC from lofar.specificationservices.validation_service_rpc import ValidationRPC from lofar.common.xmlparse import parse_xml_string_or_bytestring -from .config import \ - SPECIFICATION_SERVICENAME, \ - MOMIMPORTXML_BUSNAME, \ - MOMIMPORTXML_SUBJECT +from .config import SPECIFICATION_SERVICENAME, MOMIMPORTXML_BUSNAME, MOMIMPORTXML_BROKER permitted_activities = ["observation", "pipeline", "measurement"] permitted_statuses = ["opened", "approved"] @@ -253,6 +249,7 @@ class SpecificationHandler(ServiceMessageHandler): raise Exception("Invalid MoM specification: %s", response["error"]) def _add_spec_to_mom(self, mom_xml): + logger.info("about to send mom_xml: %s", mom_xml) # Construct message payload using old-style (MessageBus) message format msg = MessageContentOld() msg.protocol = "mom.importxml" @@ -260,12 +257,19 @@ class SpecificationHandler(ServiceMessageHandler): msg.summary = "Translated LOFAR specifications" msg.momid = -1 msg.sasid = -1 - msg.payload = "\n%s\n" % (mom_xml, ) # MoM needs enters around the payload to avoid "Content not allowed in prolog" error - #emsg = MessageOld(subject=MOMIMPORTXML_SUBJECT, content=content) + # prepare payload in xml to have a %s which can be filled in with plain xml in the qmsg below... + # MoM needs enters around the payload to avoid "Content not allowed in prolog" error + msg.payload = "\n%s\n" - with ToBusOld(queue=MOMIMPORTXML_BUSNAME, broker=DEFAULT_BROKER) as momimportxml_bus: - momimportxml_bus.send(msg) + # convert to qpid message (which is a proton message nowadays) + qmsg = msg.qpidMsg() + # and inject the mom_xml in the message xml + qmsg.body = qmsg.body % (mom_xml, ) + + with ToBusOld(queue=MOMIMPORTXML_BUSNAME, + broker=MOMIMPORTXML_BROKER) as momimportxml_bus: + momimportxml_bus.send(qmsg) logger.debug("Send specs to MOM: %s", mom_xml) -- GitLab