diff --git a/CMake/LofarPackageList.cmake b/CMake/LofarPackageList.cmake index 10ed0938ba2b2cf57be7480a23b4a2158643d183..740c52181b38c49d3b3a57866e5423582e3d096d 100644 --- a/CMake/LofarPackageList.cmake +++ b/CMake/LofarPackageList.cmake @@ -1,7 +1,7 @@ # - Create for each LOFAR package a variable containing the absolute path to # its source directory. # -# Generated by gen_LofarPackageList_cmake.sh at ma 4 mei 2020 12:07:08 CEST +# Generated by gen_LofarPackageList_cmake.sh at do 28 mei 2020 11:22:44 CEST # # ---- DO NOT EDIT ---- # @@ -207,6 +207,7 @@ if(NOT DEFINED LOFAR_PACKAGE_LIST_INCLUDED) set(TaskPrescheduler_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/ResourceAssignment/TaskPrescheduler) set(RACommon_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/ResourceAssignment/Common) set(TMSSClient_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/TMSS/client) + set(TMSSSubtaskSchedulingService_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/TMSS/services/subtask_scheduling) set(TriggerEmailServiceCommon_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/TriggerEmailService/Common) set(TriggerEmailServiceServer_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SAS/TriggerEmailService/Server) set(CCU_MAC_SOURCE_DIR ${CMAKE_SOURCE_DIR}/SubSystems/CCU_MAC) diff --git a/SAS/TMSS/CMakeLists.txt b/SAS/TMSS/CMakeLists.txt index afc70e4bdb9d18cdc4bedface086d071fb769db6..8c0d7575c2b5ab1194e3115d8faca0debdc0586a 100644 --- a/SAS/TMSS/CMakeLists.txt +++ b/SAS/TMSS/CMakeLists.txt @@ -1,12 +1,14 @@ lofar_package(TMSS 0.1 DEPENDS PyCommon pyparameterset PyMessaging) +lofar_add_package(TMSSClient client) add_subdirectory(src) add_subdirectory(bin) add_subdirectory(test) add_subdirectory(frontend) +add_subdirectory(services) lofar_add_docker_files(docker-compose-tmss.yml) -lofar_add_package(TMSSClient client) + diff --git a/SAS/TMSS/services/CMakeLists.txt b/SAS/TMSS/services/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4520a7b4e826a8ad61f4feec3b7d1d263f10495a --- /dev/null +++ b/SAS/TMSS/services/CMakeLists.txt @@ -0,0 +1,2 @@ +lofar_add_package(TMSSSubtaskSchedulingService subtask_scheduling) + diff --git a/SAS/TMSS/services/subtask_scheduling/CMakeLists.txt b/SAS/TMSS/services/subtask_scheduling/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7d664ccd6981e1078644aac1c1d1f1deef870aab --- /dev/null +++ b/SAS/TMSS/services/subtask_scheduling/CMakeLists.txt @@ -0,0 +1,6 @@ +lofar_package(TMSSSubtaskSchedulingService 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/subtask_scheduling/bin/CMakeLists.txt b/SAS/TMSS/services/subtask_scheduling/bin/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..07e30a532f710dd1242ba026ad12e9ce014f1125 --- /dev/null +++ b/SAS/TMSS/services/subtask_scheduling/bin/CMakeLists.txt @@ -0,0 +1,4 @@ +lofar_add_bin_scripts(tmss_subtask_scheduling_service) + +# supervisord config files +lofar_add_sysconf_files(tmss_subtask_scheduling_service.ini DESTINATION supervisord.d) diff --git a/SAS/TMSS/services/subtask_scheduling/bin/tmss_subtask_scheduling_service b/SAS/TMSS/services/subtask_scheduling/bin/tmss_subtask_scheduling_service new file mode 100755 index 0000000000000000000000000000000000000000..2ecd686a25fd88e45094bf4cda143e41de1fb61d --- /dev/null +++ b/SAS/TMSS/services/subtask_scheduling/bin/tmss_subtask_scheduling_service @@ -0,0 +1,24 @@ +#!/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/>. + + +from lofar.sas.tmss.services.subtask_scheduling import main + +if __name__ == "__main__": + main() diff --git a/SAS/TMSS/services/subtask_scheduling/bin/tmss_subtask_scheduling_service.ini b/SAS/TMSS/services/subtask_scheduling/bin/tmss_subtask_scheduling_service.ini new file mode 100644 index 0000000000000000000000000000000000000000..e43c0d3e66f4534b32c6d6129397a0309a2b95e7 --- /dev/null +++ b/SAS/TMSS/services/subtask_scheduling/bin/tmss_subtask_scheduling_service.ini @@ -0,0 +1,9 @@ +[program:tmss_subtask_scheduling_service] +command=/bin/bash -c 'source $LOFARROOT/lofarinit.sh;exec tmss_subtask_scheduling_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/subtask_scheduling/lib/CMakeLists.txt b/SAS/TMSS/services/subtask_scheduling/lib/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7cf0b591612ccb75bc2a73c1a6f9d1d8a2c2d9da --- /dev/null +++ b/SAS/TMSS/services/subtask_scheduling/lib/CMakeLists.txt @@ -0,0 +1,10 @@ +lofar_find_package(PythonInterp 3.4 REQUIRED) +include(PythonInstall) + +set(_py_files + subtask_scheduling.py + ) + +python_install(${_py_files} + DESTINATION lofar/sas/tmss/services) + diff --git a/SAS/TMSS/services/subtask_scheduling/lib/subtask_scheduling.py b/SAS/TMSS/services/subtask_scheduling/lib/subtask_scheduling.py new file mode 100644 index 0000000000000000000000000000000000000000..9f2bed1b4d3fc06fd3992d18e16e92213e70c59b --- /dev/null +++ b/SAS/TMSS/services/subtask_scheduling/lib/subtask_scheduling.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python3 + +# TMSSBusListener.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/>. +# +# $Id: TMSSBusListener.py 1580 2015-09-30 14:18:57Z loose $ + +""" +TMSSBusListener listens on the lofar notification message bus and calls (empty) on<SomeMessage> methods when such a message is received. +Typical usage is to derive your own subclass from TMSSBusListener and implement the specific on<SomeMessage> methods that you are interested in. +""" + +import os +from optparse import OptionParser +import logging +logger = logging.getLogger(__name__) + +from lofar.sas.tmss.client.tmssbuslistener import * +from lofar.sas.tmss.client.tmss_http_rest_client import TMSSsession + +class TMSSSubTaskSchedulingEventMessageHandler(TMSSSubTaskEventMessageHandler): + ''' + ''' + def __init__(self, tmss_client_credentials_id: str=None): + super().__init__() + self.tmss_client = TMSSsession.create_from_dbcreds_for_ldap(tmss_client_credentials_id) + + def start_handling(self): + self.tmss_client.open() + super().start_handling() + + def stop_handling(self): + super().stop_handling() + self.tmss_client.close() + + def onSubTaskFinished(self, subtask_id: int, old_state: str, new_state:str): + '''onSubTaskFinished is called upon received a SubTaskFinished message, which is sent when a SubTasks changes state to "Finished". + :param subtask_id: the TMSS id of the SubTask + :param old_state: the previous state of the SubTask + :param new_state: the new state of the SubTask + ''' + #TODO: implement/call scheduling of defined successor subtasks + print(self.tmss_client.get_subtask(subtask_id)) + + +def main(): + # make sure we run in UTC timezone + os.environ['TZ'] = 'UTC' + + logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO) + + # Check the invocation arguments + parser = OptionParser('%prog [options]', + description='run the tmss_subtask_scheduling_service which automatically schedules the defined successor tasks for finished subtasks') + parser.add_option('-q', '--broker', dest='broker', type='string', default=DEFAULT_BROKER, help='Address of the messaging broker, default: %default') + parser.add_option('--exchange', dest='exchange', type='string', default=DEFAULT_BUSNAME, help='Name of the exchange on the messaging broker, default: %default') + parser.add_option('-t', '--tmss_client_credentials_id', dest='tmss_client_credentials_id', type='string', + default=os.environ.get("TMSS_CLIENT_DBCREDENTIALS", "TMSSClient"), + help='the credentials id for the file in ~/.lofar/dbcredentials which holds the TMSS http REST api url and credentials, default: %default') + (options, args) = parser.parse_args() + + with TMSSSubTaskBusListener(handler_type=TMSSSubTaskSchedulingEventMessageHandler, + handler_kwargs={'tmss_client_credentials_id': options.tmss_client_credentials_id}, + exchange=options.exchange, + broker=options.broker): + waitForInterrupt() + +if __name__ == '__main__': + main() diff --git a/SubSystems/RAServices/RAServices.ini b/SubSystems/RAServices/RAServices.ini index 0f013968492ce3d0a6dadfb22705bf26edf2219f..bc649306d58920185ea4e191d774735985bb638d 100644 --- a/SubSystems/RAServices/RAServices.ini +++ b/SubSystems/RAServices/RAServices.ini @@ -16,3 +16,6 @@ programs=ltastorageoverviewscraper,ltastorageoverviewwebservice [group:Messaging] programs=messagelogger + +[group:TMSS] +programs=tmss_subtask_scheduling_service