diff --git a/SAS/TMSS/services/workflow_service/CMakeLists.txt b/SAS/TMSS/services/workflow_service/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5c5d502c21bb7b28fb93be9f02f0498a44fda702 --- /dev/null +++ b/SAS/TMSS/services/workflow_service/CMakeLists.txt @@ -0,0 +1,7 @@ +lofar_package(TMSSWorkflowService 0.1 DEPENDS TMSSClient PyCommon pyparameterset PyMessaging) + +lofar_find_package(PythonInterp 3.4 REQUIRED) + +add_subdirectory(lib) +add_subdirectory(bin) + diff --git a/SAS/TMSS/services/workflow_service/bin/CMakeLists.txt b/SAS/TMSS/services/workflow_service/bin/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2e7ec964e60e2c8a2becb4db91c456e8b201a015 --- /dev/null +++ b/SAS/TMSS/services/workflow_service/bin/CMakeLists.txt @@ -0,0 +1,4 @@ +lofar_add_bin_scripts(tmss_workflow_service) + +# supervisord config files +lofar_add_sysconf_files(tmss_workflow_service.ini DESTINATION supervisord.d) diff --git a/SAS/TMSS/services/workflow_service/bin/tmss_workflow_service b/SAS/TMSS/services/workflow_service/bin/tmss_workflow_service new file mode 100755 index 0000000000000000000000000000000000000000..51dd037a08aaa765c994f5aed0df7ca1f2d296e2 --- /dev/null +++ b/SAS/TMSS/services/workflow_service/bin/tmss_workflow_service @@ -0,0 +1,22 @@ +#!/usr/bin/python3 + +# Copyright (C) 2012-2015 ASTRON (Netherlands Institute for Radio Astronomy) +# P.O. Box 2, 7990 AA Dwingeloo, The Netherlands +# +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# The LOFAR software suite is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. + +if __name__ == '__main__': + from lofar.sas.tmss.services.workflow_service import main + main() diff --git a/SAS/TMSS/services/workflow_service/bin/tmss_workflow_service.ini b/SAS/TMSS/services/workflow_service/bin/tmss_workflow_service.ini new file mode 100644 index 0000000000000000000000000000000000000000..0f80770faf3c580ff8a0558e62399adb66e2fa76 --- /dev/null +++ b/SAS/TMSS/services/workflow_service/bin/tmss_workflow_service.ini @@ -0,0 +1,9 @@ +[program:tmss_workflow_service] +command=/bin/bash -c 'source $LOFARROOT/lofarinit.sh;exec tmss_workflow_service' +user=lofarsys +stopsignal=INT ; KeyboardInterrupt +stopasgroup=true ; bash does not propagate signals +stdout_logfile=%(program_name)s.log +redirect_stderr=true +stderr_logfile=NONE +stdout_logfile_maxbytes=0 diff --git a/SAS/TMSS/services/workflow_service/lib/CMakeLists.txt b/SAS/TMSS/services/workflow_service/lib/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f18bbb8b7ccbc3554a0f0e1c5fb32a44145fab22 --- /dev/null +++ b/SAS/TMSS/services/workflow_service/lib/CMakeLists.txt @@ -0,0 +1,10 @@ +lofar_find_package(PythonInterp 3.4 REQUIRED) +include(PythonInstall) + +set(_py_files + workflow_service.py + ) + +python_install(${_py_files} + DESTINATION lofar/sas/tmss/services) + diff --git a/SAS/TMSS/services/workflow_service/lib/workflow_service.py b/SAS/TMSS/services/workflow_service/lib/workflow_service.py new file mode 100644 index 0000000000000000000000000000000000000000..c38bde688e87903f9b66a4c9f2d6234814a4c808 --- /dev/null +++ b/SAS/TMSS/services/workflow_service/lib/workflow_service.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 + +# subtask_scheduling.py +# +# Copyright (C) 2015 +# ASTRON (Netherlands Institute for Radio Astronomy) +# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands +# +# This file is part of the LOFAR software suite. +# The LOFAR software suite is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# The LOFAR software suite is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. +# + +import os +import logging +logger = logging.getLogger(__name__) + +from lofar.sas.tmss.client.tmssbuslistener import * + +class SchedulingUnitEventMessageHandler(TMSSEventMessageHandler): + + def onSchedulingUnitBlueprintStatusChanged(self, id: int, status: str): + try: + # import here and not at top of module because we need the django.setup() to be run first, either from this module's main, or from the TMSSTestEnvironment + from lofar.sas.tmss.tmss.workflowapp.signals import scheduling_unit_blueprint_signal + from lofar.sas.tmss.tmss.tmssapp.models import SchedulingUnitBlueprint + + logger.info("SchedulingUnitBlueprint id=%s status changed to '%s', signalling workflow...", id, status) + scheduling_unit_blueprint = SchedulingUnitBlueprint.objects.get(pk=id) + scheduling_unit_blueprint_signal.send(sender=self.__class__, instance=scheduling_unit_blueprint, status=status) + except Exception as e: + logger.error(e) + + +def create_workflow_service(exchange: str=DEFAULT_BUSNAME, broker: str=DEFAULT_BROKER): + return TMSSBusListener(handler_type=SchedulingUnitEventMessageHandler, + handler_kwargs={}, + exchange=exchange, broker=broker) + +def main(): + # make sure we run in UTC timezone + os.environ['TZ'] = 'UTC' + + from optparse import OptionParser, OptionGroup + from lofar.common import dbcredentials + + logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) + + # Check the invocation arguments + parser = OptionParser('%prog [options]', + description='run the tmss_workflow_service which forwards TMSS events to the workflow engine.') + + group = OptionGroup(parser, 'Messaging options') + group.add_option('-b', '--broker', dest='broker', type='string', default=DEFAULT_BROKER, + help='Address of the message broker, default: %default') + group.add_option('-e', "--exchange", dest="exchange", type="string", default=DEFAULT_BUSNAME, + help="Bus or queue where the TMSS messages are published. [default: %default]") + parser.add_option_group(group) + + parser.add_option_group(dbcredentials.options_group(parser)) + parser.set_defaults(dbcredentials=os.environ.get('TMSS_DBCREDENTIALS', 'TMSS')) + (options, args) = parser.parse_args() + + dbcreds = dbcredentials.parse_options(options) + logger.info("Using TMSS dbcreds: %s" % dbcreds.stringWithHiddenPassword()) + + # setup django + os.environ["TMSS_DBCREDENTIALS"] = options.dbcredentials + os.environ["DJANGO_SETTINGS_MODULE"] = "lofar.sas.tmss.tmss.settings" + os.environ['TMSS_ENABLE_VIEWFLOW'] = 'True' + import django + django.setup() + + with create_workflow_service(options.exchange, options.broker): + waitForInterrupt() + +if __name__ == '__main__': + main()