From 40183dc0078fb70d720d88f595ae2acf4f191a51 Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Thu, 18 May 2017 06:43:01 +0000 Subject: [PATCH] Task #10801: Move claim annotation to separate function --- .../ResourceAssigner/lib/assignment.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py b/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py index da923d87816..dccbbb3d8ca 100755 --- a/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py +++ b/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py @@ -348,17 +348,8 @@ class ResourceAssigner(): self._sendStateChange(task, 'error') return if claims: - # add start/endtime to claims - for claim in claims: - claim['starttime'] = task['starttime'] - claim['endtime'] = task['endtime'] - - if claim['resource_type_id'] == self.resource_types['storage']: - # FIXME: find proper way to extend storage time with a year - # 2016-09-27 scisup would like to be involved in chosing these kind of defaults - # and what to do after the claim expires - # we now choose a default period of a year, and do nothing if the claim expires - claim['endtime'] += timedelta(days=365) + # Complete the claims by annotating them with task information + self.tieClaimsToTask(claims, task) logger.info('doAssignment: inserting %d claims in the radb: %s', len(claims), claims) try: @@ -395,6 +386,21 @@ class ResourceAssigner(): # send notification that the task was scheduled self._sendStateChange(task, 'scheduled') + def tieClaimsToTask(self, claims, task): + """ Complete a set of claims by annotating them with task-related information. """ + + # add start/endtime to claims + for claim in claims: + claim['starttime'] = task['starttime'] + claim['endtime'] = task['endtime'] + + if claim['resource_type_id'] == self.resource_types['storage']: + # FIXME: find proper way to extend storage time with a year + # 2016-09-27 scisup would like to be involved in chosing these kind of defaults + # and what to do after the claim expires + # we now choose a default period of a year, and do nothing if the claim expires + claim['endtime'] += timedelta(days=365) + def _sendStateChange(self, task, status): if status == 'scheduled' or status == 'conflict' or status == 'error': content={'radb_id': task['id'], 'otdb_id':task['otdb_id'], 'mom_id': task['mom_id']} -- GitLab