From 0a7a4931d96665babf97b7bb1a8bb3024908c4d9 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 4 Apr 2019 13:35:37 +0000
Subject: [PATCH] SW-516: datetimes are now automagically converted

---
 .../ResourceAssignmentService/rpc.py          | 55 +++----------------
 1 file changed, 8 insertions(+), 47 deletions(-)

diff --git a/SAS/ResourceAssignment/ResourceAssignmentService/rpc.py b/SAS/ResourceAssignment/ResourceAssignmentService/rpc.py
index cb637e730ca..aecb16ead96 100644
--- a/SAS/ResourceAssignment/ResourceAssignmentService/rpc.py
+++ b/SAS/ResourceAssignment/ResourceAssignmentService/rpc.py
@@ -60,7 +60,7 @@ class RARPC(RPCWrapper):
 
     def getResourceClaims(self, claim_ids=None, lower_bound=None, upper_bound=None, resource_ids=None, task_ids=None,
                           status=None, resource_type=None, extended=False, include_properties=False):
-        claims = self.rpc('GetResourceClaims', claim_ids=claim_ids,
+        return self.rpc('GetResourceClaims', claim_ids=claim_ids,
                                                lower_bound=lower_bound,
                                                upper_bound=upper_bound,
                                                resource_ids=resource_ids,
@@ -70,21 +70,8 @@ class RARPC(RPCWrapper):
                                                extended=extended,
                                                include_properties=include_properties)
 
-        logger.debug("found %s claims for claim_ids=%s, lower_bound=%s, upper_bound=%s, task_ids=%s, status=%s, resource_type=%s",
-                     len(claims), claim_ids, lower_bound, upper_bound, task_ids, status, resource_type)
-        
-        for claim in claims:
-            claim['starttime'] = claim['starttime'].datetime()
-            claim['endtime'] = claim['endtime'].datetime()
-        return claims
-
     def getResourceClaim(self, id):
-        resource_claim = self.rpc('GetResourceClaim', id=id)
-        if resource_claim:
-            resource_claim['starttime'] = resource_claim['starttime'].datetime()
-            resource_claim['endtime'] = resource_claim['endtime'].datetime()
-        return resource_claim
-
+        return self.rpc('GetResourceClaim', id=id)
 
     def insertResourceClaim(self, resource_id, task_id, starttime, endtime, status, claim_size, username,
                             user_id, used_rcus=None, properties=None):
@@ -158,11 +145,6 @@ class RARPC(RPCWrapper):
 
         all_usages = convertStringDigitKeysToInt(all_usages)
 
-        for resource_id, resource_usages_per_status in list(all_usages.items()):
-            for status, usages in list(resource_usages_per_status.items()):
-                for usage in usages:
-                    usage['as_of_timestamp'] = usage['as_of_timestamp'].datetime()
-
         return all_usages
 
     def getResourceGroupTypes(self):
@@ -196,11 +178,7 @@ class RARPC(RPCWrapper):
 
     def getTask(self, id=None, mom_id=None, otdb_id=None, specification_id=None):
         '''get a task for either the given (task)id, or for the given mom_id, or for the given otdb_id, or for the given specification_id'''
-        task = self.rpc('GetTask', id=id, mom_id=mom_id, otdb_id=otdb_id, specification_id=specification_id)
-        if task:
-            task['starttime'] = task['starttime'].datetime()
-            task['endtime'] = task['endtime'].datetime()
-        return task
+        return self.rpc('GetTask', id=id, mom_id=mom_id, otdb_id=otdb_id, specification_id=specification_id)
 
     def insertTask(self, mom_id, otdb_id, task_status, task_type, specification_id):
         return self.rpc('InsertTask', mom_id=mom_id,
@@ -227,10 +205,7 @@ class RARPC(RPCWrapper):
                          task_status=task_status)
 
     def getTasksTimeWindow(self, task_ids=None, mom_ids=None, otdb_ids=None):
-        result = self.rpc('GetTasksTimeWindow', task_ids=task_ids, mom_ids=mom_ids, otdb_ids=otdb_ids)
-        result['min_starttime'] = result['min_starttime'].datetime()
-        result['max_endtime'] = result['max_endtime'].datetime()
-        return result
+        return self.rpc('GetTasksTimeWindow', task_ids=task_ids, mom_ids=mom_ids, otdb_ids=otdb_ids)
 
     def getTasks(self, lower_bound=None, upper_bound=None, task_ids=None, task_status=None, task_type=None, mom_ids=None, otdb_ids=None, cluster=None):
         '''getTasks let's you query tasks from the radb with many optional filters.
@@ -243,11 +218,7 @@ class RARPC(RPCWrapper):
         :param otdb_ids: int/list/tuple specifies one or more otdb_ids to select
         :param cluster: string specifies the cluster to select
         '''
-        tasks = self.rpc('GetTasks', lower_bound=lower_bound, upper_bound=upper_bound, task_ids=task_ids, task_status=task_status, task_type=task_type, mom_ids=mom_ids, otdb_ids=otdb_ids, cluster=cluster)
-        for task in tasks:
-            task['starttime'] = task['starttime'].datetime()
-            task['endtime'] = task['endtime'].datetime()
-        return tasks
+        return self.rpc('GetTasks', lower_bound=lower_bound, upper_bound=upper_bound, task_ids=task_ids, task_status=task_status, task_type=task_type, mom_ids=mom_ids, otdb_ids=otdb_ids, cluster=cluster)
 
     def getTaskPredecessorIds(self, id=None):
         return self.rpc('GetTaskPredecessorIds', id=id)
@@ -268,11 +239,7 @@ class RARPC(RPCWrapper):
         return self.rpc('GetTaskStatuses')
 
     def getSpecification(self, id):
-        specification = self.rpc('GetSpecification', id=id)
-        if specification:
-            specification['starttime'] = specification['starttime'].datetime()
-            specification['endtime'] = specification['endtime'].datetime()
-        return specification
+        return self.rpc('GetSpecification', id=id)
 
     def insertSpecificationAndTask(self, mom_id, otdb_id, task_status, task_type, starttime, endtime, content, cluster):
         return self.rpc('InsertSpecificationAndTask',
@@ -304,11 +271,7 @@ class RARPC(RPCWrapper):
                          cluster=cluster)
 
     def getSpecifications(self):
-        specifications = self.rpc('GetSpecifications')
-        for specification in specifications:
-            specification['starttime'] = specification['starttime'].datetime()
-            specification['endtime'] = specification['endtime'].datetime()
-        return specifications
+        return self.rpc('GetSpecifications')
 
     def getUnits(self):
         return self.rpc('GetUnits')
@@ -328,13 +291,11 @@ class RARPC(RPCWrapper):
                         claim_id=claim_id)
 
     def get_max_resource_usage_between(self, resource_id, lower_bound, upper_bound, claim_status='claimed'):
-        result = self.rpc('get_max_resource_usage_between',
+        return self.rpc('get_max_resource_usage_between',
                           resource_id=resource_id,
                           lower_bound=lower_bound,
                           upper_bound=upper_bound,
                           claim_status=claim_status)
-        result['as_of_timestamp'] = result['as_of_timestamp'].datetime()
-        return result
 
     def get_resource_claimable_capacity(self, resource_id, lower_bound, upper_bound):
         '''get the claimable capacity for the given resource within the timewindow given by lower_bound and upper_bound.
-- 
GitLab