From 1aed430d43c4c2d2b067c780c1329e019840ac47 Mon Sep 17 00:00:00 2001 From: jeremy Date: Fri, 3 Mar 2017 19:28:32 +0100 Subject: [PATCH] Alert handled + kill executing sequence when new alert --- simulators/alert/alertSimulator.py | 1 + simulators/config/conf1.json | 38 -------------------------------------- simulators/config/conf_simple_alert.json | 11 +++++++++++ simulators/resources/voevent_alert_01.xml | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ simulators/resources/voevent_alert_04.xml | 0 src/alert_manager/StrategyBuilder.py | 38 ++++++++++++++++++++------------------ src/alert_manager/tasks.py | 2 +- src/alert_manager/tests.py | 6 +----- src/common/RequestBuilder.py | 3 ++- src/external_modules/__init__.py | 0 src/external_modules/exposure.py | 5 +++++ src/external_modules/image_simulator.py | 5 +++++ src/external_modules/visibility_calculator.py | 12 ++++++++++++ src/majordome/tasks.py | 16 ++++++++++++++++ 14 files changed, 227 insertions(+), 63 deletions(-) delete mode 100644 simulators/config/conf1.json create mode 100644 simulators/config/conf_simple_alert.json create mode 100644 simulators/resources/voevent_alert_01.xml delete mode 100644 simulators/resources/voevent_alert_04.xml create mode 100644 src/external_modules/__init__.py create mode 100644 src/external_modules/exposure.py create mode 100644 src/external_modules/image_simulator.py create mode 100644 src/external_modules/visibility_calculator.py diff --git a/simulators/alert/alertSimulator.py b/simulators/alert/alertSimulator.py index 285db00..92cd08d 100644 --- a/simulators/alert/alertSimulator.py +++ b/simulators/alert/alertSimulator.py @@ -60,6 +60,7 @@ class AlertSimulator(): if (int(dic["time"]) == i): self.sendAlert(dic["alertSimulator"]) time.sleep(1) + self.clean_dir() return (0) if __name__ == "__main__": diff --git a/simulators/config/conf1.json b/simulators/config/conf1.json deleted file mode 100644 index afb141f..0000000 --- a/simulators/config/conf1.json +++ /dev/null @@ -1,38 +0,0 @@ -[ - { - "time" : 1, - "userSimulator" : "routine_request_01.xml" - }, - { - "time" : 23, - "userSimulator" : "routine_request_02.xml" - }, - { - "time" : 24, - "userSimulator" : "routine_request_03.xml" - }, - { - "time" : 24, - "userSimulator" : "routine_request_04.xml" - }, - { - "time" : 1, - "alertSimulator" : "voevent_alert_04.xml" - }, - { - "time" : 30, - "userSimulator" : "routine_request_05.xml" - }, - { - "time" : 35, - "plcSimulator" : {"rain" : 5, "cloud" : 3} - }, - { - "time" : 40, - "plcSimulator" : {"door1" : "open"} - }, - { - "time" : 41, - "plcSimulator" : {"light3" : "on"} - } -] diff --git a/simulators/config/conf_simple_alert.json b/simulators/config/conf_simple_alert.json new file mode 100644 index 0000000..1f70185 --- /dev/null +++ b/simulators/config/conf_simple_alert.json @@ -0,0 +1,11 @@ +[ + 30, + { + "time": 5, + "userSimulator" : "routine_request_01.xml" + }, + { + "time" : 20, + "alertSimulator" : "voevent_alert_01.xml" + } +] diff --git a/simulators/resources/voevent_alert_01.xml b/simulators/resources/voevent_alert_01.xml new file mode 100644 index 0000000..0b1ad9a --- /dev/null +++ b/simulators/resources/voevent_alert_01.xml @@ -0,0 +1,153 @@ + + + + + ivo://nasa.gsfc.tan/gcn + 2012-09-07T00:24:36 + This VOEvent message was created with GCN VOE version: 1.11 02aug12 + + VO-GCN + Scott Barthelmy + scott.barthelmy@nasa.gov + +1-301-286-3106 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The Sun and Moon values are valid at the time the VOEvent XML message was created. + + Type=61: The Swift-BAT instrument position notice. + + + + + + + + + + + RA + Dec + + 74.741200 + 25.313700 + + 0.050000 + + + + + The RA,Dec coordinates are of the type: source_object. + + + + Swift Satellite, BAT Instrument + + + + + + GRB 120907 + process.variation.burst;em.gamma + + + + + + + diff --git a/simulators/resources/voevent_alert_04.xml b/simulators/resources/voevent_alert_04.xml deleted file mode 100644 index e69de29..0000000 --- a/simulators/resources/voevent_alert_04.xml +++ /dev/null diff --git a/src/alert_manager/StrategyBuilder.py b/src/alert_manager/StrategyBuilder.py index 9b87d14..8803da1 100644 --- a/src/alert_manager/StrategyBuilder.py +++ b/src/alert_manager/StrategyBuilder.py @@ -6,24 +6,30 @@ from common.models import * JD1 = 0 JD2 = 9000000 +''' + Reads a strategy file and creates a new request with it + + ENTRY POINT : + - create_request_from_strategy +''' + + class StrategyBuilder(): + + def validate(self): + self.rb.validate_request() + return self.rb.request + ''' - Reads a strategy file and creates a new request with it - - ENTRY POINT : - - create_request_from_strategy - ''' + Reads the strategy file, and creates the request, saving everything in DB + :param : strategy_file, the name of the strategy file with .xml but without the path + :param : pyros_user, the user associated with the existing alert + :param : scientific_program, the sci prog of the existing alert + :param : name, the name of the existing request + name of the strategy + :returns : the created request + ''' def create_request_from_strategy(self, strategy_file, pyros_user, scientific_program, name): - ''' - Reads the strategy file, and creates the request, saving everything in DB - - :param : strategy_file, the name of the strategy file with .xml but without the path - :param : pyros_user, the user associated with the existing alert - :param : scientific_program, the sci prog of the existing alert - :param : name, the name of the existing request + name of the strategy - :returns : the created request - ''' tree = ET.parse(os.path.join('alert_manager', 'strategies', strategy_file)) request = tree.getroot() @@ -53,7 +59,3 @@ class StrategyBuilder(): def add_plan(self, plan, album_id, name): self.rb.add_plan(album_id, plan.get('filter'), plan.get('duration'), plan.get('nb_images'), name=name) - - def validate(self): - self.rb.validate_request() - return self.rb.request diff --git a/src/alert_manager/tasks.py b/src/alert_manager/tasks.py index e763b0a..494e12e 100644 --- a/src/alert_manager/tasks.py +++ b/src/alert_manager/tasks.py @@ -110,7 +110,7 @@ class AlertListener(Task): return alert.strat = StrategyObs.objects.filter(is_default=True)[0] - name = "GRB - " + str(alert.trig_id) + name = "GRB-" + str(alert.trig_id) Log.objects.create(agent="Alert manager", message="Creating alert from file : %s ..." % (alert.strat.xml_file,)) sb = StrategyBuilder() diff --git a/src/alert_manager/tests.py b/src/alert_manager/tests.py index 1565196..8491ad6 100644 --- a/src/alert_manager/tests.py +++ b/src/alert_manager/tests.py @@ -23,10 +23,6 @@ class TestStrategyChange(TestCase): fixtures = ['tests/alert_mgr_test.json'] def setUp(self): - ''' - Creates the base for the tests - ''' - self.alert = Alert.objects.get() self.strat1 = Alert.objects.get().strategyobs self.strat2 = StrategyObs.objects.exclude(id=self.strat1.id)[0] @@ -61,7 +57,7 @@ class TestStrategyChange(TestCase): new_alert = Alert.objects.exclude(id=self.alert.id)[0] self.assertEqual(new_alert.strategyobs.id, self.strat2.id, "The new alert should have the 'strat2' strategy") - +# OBSOLETE class AlertListenerTestsCelery(TestCase): ''' IMPORTANT : As soon as you do a DB request in a test, the test DB will no longer be synchronized with the DB used by celery diff --git a/src/common/RequestBuilder.py b/src/common/RequestBuilder.py index 6372c65..9e64480 100644 --- a/src/common/RequestBuilder.py +++ b/src/common/RequestBuilder.py @@ -19,6 +19,7 @@ class RequestBuilder(): self.sequences = {} self.albums = {} self.plans = {} + self.is_alert = is_alert def add_sequence(self, priority, jd1, jd2, t_prefered=-1, name="default", duration=0): ''' @@ -32,7 +33,7 @@ class RequestBuilder(): "start_new_request MUST be invoked before creating any sequence") sequence = Sequence(name=name, status=Sequence.TOBEPLANNED, priority=priority, - jd1=jd1, jd2=jd2, t_prefered=t_prefered, duration=duration) + jd1=jd1, jd2=jd2, t_prefered=t_prefered, duration=duration, is_alert=self.is_alert) self.sequences[self.sequence_id] = sequence self.sequence_id += 1 return self.sequence_id - 1 diff --git a/src/external_modules/__init__.py b/src/external_modules/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/external_modules/__init__.py diff --git a/src/external_modules/exposure.py b/src/external_modules/exposure.py new file mode 100644 index 0000000..b302f52 --- /dev/null +++ b/src/external_modules/exposure.py @@ -0,0 +1,5 @@ +from utils.Logger import * + + +class ExposureCalculator(Logger): + pass diff --git a/src/external_modules/image_simulator.py b/src/external_modules/image_simulator.py new file mode 100644 index 0000000..aef49ea --- /dev/null +++ b/src/external_modules/image_simulator.py @@ -0,0 +1,5 @@ +from utils.Logger import * + + +class ImageSimulator(Logger): + pass diff --git a/src/external_modules/visibility_calculator.py b/src/external_modules/visibility_calculator.py new file mode 100644 index 0000000..47dbd76 --- /dev/null +++ b/src/external_modules/visibility_calculator.py @@ -0,0 +1,12 @@ +from utils.Logger import * + +''' + Class made to manage the sequences visibility +''' + + +class VisibilityCalculator(Logger): + + # Return the visible interval + def getVisibleInterval(self, coordinates) -> tuple: + return (0, 20000) diff --git a/src/majordome/tasks.py b/src/majordome/tasks.py index 35644cc..4a2c20d 100644 --- a/src/majordome/tasks.py +++ b/src/majordome/tasks.py @@ -138,6 +138,7 @@ class Majordome(Task): self.timer_status = 5 self.tasks_timer = 5 self.timer_plc = 2 + self.alert_timer = 1 self.timer_schedule = 1 self.timer_sequence = 1 @@ -273,6 +274,7 @@ class Majordome(Task): if (schedule.created != self.schedule.created): self.next_sequence = None self.schedule = schedule + self.firstSequenceIsAlert() if (self.schedule): shs_list = self.schedule.shs.filter(Q(status=Sequence.PLANNED) | Q(status=Sequence.PENDING)).order_by('tsp') @@ -282,6 +284,20 @@ class Majordome(Task): return (0) ''' + Function called by handleScheduleTimer, the purpose is to kill the executing sequence if the + first sequence in the new planning is from an alert + ''' + @executingSequenceExist + def firstSequenceIsAlert(self): + shs_list = self.schedule.shs.filter(Q(status=Sequence.PLANNED) | + Q(status=Sequence.PENDING)).order_by('tsp') + if shs_list and shs_list[0].sequence.is_alert: + if shs_list[0].sequence.created.date() >= (datetime.datetime.now() - datetime.timedelta(seconds=10)).date(): + self.killExecutingSequence() + return 1 + return 0 + + ''' Function called by the main loop to handle the end of a night ''' def handleNightEndTimer(self): -- libgit2 0.21.2