diff --git a/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py b/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py index a61d53628d3dcff55792943bb05427e52d01cf48..d0269013145b961e58d7d30525557844d03e0d09 100755 --- a/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py +++ b/SAS/ResourceAssignment/ResourceAssigner/lib/assignment.py @@ -311,7 +311,7 @@ class ResourceAssigner(): claims = [] for resource_type_name, needed_claim_for_resource_type in needed_resources_for_task_type.items(): if resource_type_name in resource_types: - logger.info('claimResources: processing resource_type: %s' % resource_type_name) + logger.info('claimResources: processing resource_type: %s contents: %s' % (resource_type_name, needed_claim_for_resource_type)) db_resource_type_id = resource_types[resource_type_name] db_resources_for_type = [r for r in resources if r['type_id'] == db_resource_type_id] @@ -335,28 +335,33 @@ class ResourceAssigner(): claim['endtime'] += timedelta(days=31) # if the needed_claim_for_resource_type dict contains more kvp's, - # then the subdict contains groups of properties for the claim + # then the subdicts contains groups of properties for the claim if len(needed_claim_for_resource_type) > 1: claim['properties'] = [] - needed_prop_groups = next((v for k,v in needed_claim_for_resource_type.items() if isinstance(v, collections.Iterable))) - def processProperties(propertiesDict, sap_nr=None): + def processProperties(propertiesDict, sap_nr=None, is_input=False): for prop_type_name, prop_value in propertiesDict.items(): if prop_type_name in rc_property_types: rc_property_type_id = rc_property_types[prop_type_name] - property = {'type':rc_property_type_id, 'value':prop_value} + property = {'type':rc_property_type_id, + 'value':prop_value, + 'io_type': 'input' if is_input else 'output'} if sap_nr is not None: property['sap_nr'] = sap_nr claim['properties'].append(property) else: logger.error('claimResources: unknown prop_type:%s' % prop_type_name) - for group_name, needed_prop_group in needed_prop_groups.items(): - if group_name == 'saps': - for sap_dict in needed_prop_group: - processProperties(sap_dict['properties'], sap_dict['sap_nr']) - else: - processProperties(needed_prop_group) + subdicts = (k:v for k,v in needed_claim_for_resource_type.items() if isinstance(v, dict)) + for subdict_name, subdict in subdicts.items(): + logger.info('claimResources: processing resource_type: %s subdict_name: \'%s\' subdict_contents: %s' % (resource_type_name, subdict_name, subdict)) + is_input = 'input' in subdict_name.lower() + for group_name, needed_prop_group in subdict.items(): + if group_name == 'saps': + for sap_dict in needed_prop_group: + processProperties(sap_dict['properties'], sap_dict['sap_nr'], is_input) + else: + processProperties(needed_prop_group, is_input) logger.info('claimResources: created claim:%s' % claim) claims.append(claim)