Skip to content
Snippets Groups Projects
Commit d60ad2bc authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

Task #8887: added create_add_notifications.sql.py to create...

Task #8887: added create_add_notifications.sql.py to create add_notifications.sql. Added two update notifications for resource availability and capacity
parent fb0f9b61
Branches
Tags
No related merge requests found
......@@ -5042,6 +5042,7 @@ SAS/ResourceAssignment/ResourceAssignmentDatabase/sql/add_notifications.sql -tex
SAS/ResourceAssignment/ResourceAssignmentDatabase/sql/add_resource_allocation_statics.sql -text
SAS/ResourceAssignment/ResourceAssignmentDatabase/sql/add_triggers.sql -text
SAS/ResourceAssignment/ResourceAssignmentDatabase/sql/add_virtual_instrument.sql -text
SAS/ResourceAssignment/ResourceAssignmentDatabase/sql/create_add_notifications.sql.py -text
SAS/ResourceAssignment/ResourceAssignmentDatabase/sql/create_add_virtual_instrument.sql.py -text
SAS/ResourceAssignment/ResourceAssignmentDatabase/sql/create_and_populate_database.sql -text
SAS/ResourceAssignment/ResourceAssignmentDatabase/sql/create_database.sql -text
......
--this file was generated by make_radb_postgres_notification_queries() in python module lofar.sas.resourceassignment.database.radbpglistener
--this file was generated by create_add_notifications.sql.py
--it creates triggers and functions which fire postgres notify events upon the given table actions
--these notify events can be listened to implenting a subclass of the PostgresListener in the lofar.common.postgres python module
--for the radb such a subclass has been made, which listens specifically to the notifications defined below
--RADBPGListener in module lofar.sas.resourceassignment.database.radbpglistener
--this RADBPGListener then broadcasts the event on the lofar bus.
DROP TRIGGER IF EXISTS TRIGGER_NOTIFY_NOTIFY_task_INSERT_with_task_view ON resource_allocation.task CASCADE;
DROP FUNCTION IF EXISTS resource_allocation.NOTIFY_task_INSERT_with_task_view();
......@@ -153,3 +159,44 @@ CREATE TRIGGER TRIGGER_NOTIFY_NOTIFY_resource_claim_DELETE
AFTER DELETE ON resource_allocation.resource_claim
FOR EACH ROW
EXECUTE PROCEDURE resource_allocation.NOTIFY_resource_claim_DELETE();
DROP TRIGGER IF EXISTS TRIGGER_NOTIFY_NOTIFY_resource_availability_UPDATE ON resource_monitoring.resource_availability CASCADE;
DROP FUNCTION IF EXISTS resource_monitoring.NOTIFY_resource_availability_UPDATE();
CREATE OR REPLACE FUNCTION resource_monitoring.NOTIFY_resource_availability_UPDATE()
RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify(CAST('resource_availability_update' AS text),
'{"old":' || row_to_json(OLD)::text || ',"new":' || row_to_json(NEW)::text || '}');
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER TRIGGER_NOTIFY_NOTIFY_resource_availability_UPDATE
AFTER UPDATE ON resource_monitoring.resource_availability
FOR EACH ROW
EXECUTE PROCEDURE resource_monitoring.NOTIFY_resource_availability_UPDATE();
DROP TRIGGER IF EXISTS TRIGGER_NOTIFY_NOTIFY_resource_capacity_UPDATE ON resource_monitoring.resource_capacity CASCADE;
DROP FUNCTION IF EXISTS resource_monitoring.NOTIFY_resource_capacity_UPDATE();
CREATE OR REPLACE FUNCTION resource_monitoring.NOTIFY_resource_capacity_UPDATE()
RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify(CAST('resource_capacity_update' AS text),
'{"old":' || row_to_json(OLD)::text || ',"new":' || row_to_json(NEW)::text || '}');
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER TRIGGER_NOTIFY_NOTIFY_resource_capacity_UPDATE
AFTER UPDATE ON resource_monitoring.resource_capacity
FOR EACH ROW
EXECUTE PROCEDURE resource_monitoring.NOTIFY_resource_capacity_UPDATE();
#!/usr/bin/python
# 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/>.
# $Id: radb.py 33394 2016-01-25 15:53:55Z schaap $
'''
TODO: documentation
'''
import logging
import psycopg2
import psycopg2.extras
from lofar.common.postgres import makePostgresNotificationQueries
logger = logging.getLogger(__name__)
if __name__ == '__main__':
with open('add_notifications.sql', 'wt') as f:
f.write('--this file was generated by create_add_notifications.sql.py\n')
f.write('--it creates triggers and functions which fire postgres notify events upon the given table actions\n')
f.write('--these notify events can be listened to implenting a subclass of the PostgresListener in the lofar.common.postgres python module\n')
f.write('--for the radb such a subclass has been made, which listens specifically to the notifications defined below\n')
f.write('--RADBPGListener in module lofar.sas.resourceassignment.database.radbpglistener\n')
f.write('--this RADBPGListener then broadcasts the event on the lofar bus.\n')
f.write('\n')
f.writelines(makePostgresNotificationQueries('resource_allocation', 'task', 'INSERT', view_for_row='task_view'))
f.writelines(makePostgresNotificationQueries('resource_allocation', 'task', 'UPDATE', view_for_row='task_view'))
f.writelines(makePostgresNotificationQueries('resource_allocation', 'task', 'DELETE'))
f.writelines(makePostgresNotificationQueries('resource_allocation', 'specification', 'UPDATE', view_for_row='task_view', view_selection_id='specification_id'))
f.writelines(makePostgresNotificationQueries('resource_allocation', 'resource_claim', 'INSERT', view_for_row='resource_claim_view'))
f.writelines(makePostgresNotificationQueries('resource_allocation', 'resource_claim', 'UPDATE', view_for_row='resource_claim_view'))
f.writelines(makePostgresNotificationQueries('resource_allocation', 'resource_claim', 'DELETE'))
f.writelines(makePostgresNotificationQueries('resource_monitoring', 'resource_availability', 'UPDATE'))
f.writelines(makePostgresNotificationQueries('resource_monitoring', 'resource_capacity', 'UPDATE'))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment