@@ -31,7 +31,6 @@ def get_output_from_file(self, file_path):
31
31
except IOError as e :
32
32
print (f"An error occurred: { e } " )
33
33
34
-
35
34
def add_arguments (self , parser ):
36
35
parser .add_argument ("-e" , "--environment" , help = "Environment, use dev to simulate output" )
37
36
parser .add_argument ('--profile' , action = 'store_true' , default = False )
@@ -48,7 +47,7 @@ def _handle(self, *args, **options):
48
47
def calculate_gpu_count (gres_value ):
49
48
if 'null' in gres_value :
50
49
return 0
51
- gpu_list = gres_value .split (',' )
50
+ gpu_list = gres_value .split (') ,' )
52
51
return reduce (lambda x , y : x + y ,[int (gpu_info .split (':' )[2 ].replace ('(S' ,'' )) for gpu_info in gpu_list ])
53
52
54
53
def calculate_cpu_count (row ):
@@ -77,13 +76,11 @@ def calculate_owner_value(project_list, row):
77
76
project_list = Project .objects .all ()
78
77
compute_node , compute_node_created = ResourceType .objects .get_or_create (name = 'Compute Node' , description = 'Compute Node' )
79
78
partition_resource_type , partition_created = ResourceType .objects .get_or_create (name = 'Cluster Partition' , description = 'Cluster Partition' )
80
- int_attribute_type = AttributeType .objects .get (name = 'Int' )
81
- text_attribute_type = AttributeType .objects .get (name = 'Text' )
82
- gpu_count_attribute_type , gpu_count_created = ResourceAttributeType .objects .get_or_create (name = 'GPU Count' , defaults = {'attribute_type' : int_attribute_type })
83
- core_count_attribute_type , core_count_created = ResourceAttributeType .objects .get_or_create (name = 'Core Count' , defaults = {'attribute_type' : int_attribute_type })
84
- features_attribute_type , features_created = ResourceAttributeType .objects .get_or_create (name = 'Features' , defaults = {'attribute_type' : text_attribute_type })
85
- owner_attribute_type , owner_created = ResourceAttributeType .objects .get_or_create (name = 'Owner' , defaults = {'attribute_type' : text_attribute_type })
86
- service_end_attribute_type , service_end_created = ResourceAttributeType .objects .get_or_create (name = 'ServiceEnd' , defaults = {'attribute_type' : text_attribute_type })
79
+ gpu_count_attribute_type = ResourceAttributeType .objects .get (name = 'GPU Count' )
80
+ core_count_attribute_type = ResourceAttributeType .objects .get (name = 'Core Count' )
81
+ features_attribute_type = ResourceAttributeType .objects .get (name = 'Features' )
82
+ owner_attribute_type = ResourceAttributeType .objects .get (name = 'Owner' )
83
+ service_end_attribute_type = ResourceAttributeType .objects .get (name = 'ServiceEnd' )
87
84
processed_resources = set ()
88
85
bulk_process_resource_attribute = []
89
86
bulk_update_resource = []
@@ -95,15 +92,24 @@ def calculate_owner_value(project_list, row):
95
92
bulk_process_resource_attribute .append (ResourceAttribute (resource_attribute_type = features_attribute_type , resource = new_resource , value = row .get ('avail_features' , '(null)' )))
96
93
bulk_process_resource_attribute .append (ResourceAttribute (resource_attribute_type = owner_attribute_type , resource = new_resource , value = calculate_owner_value (project_list , row )))
97
94
if new_resource .is_available is False :
98
- bulk_update_resource .append (Resource (name = row ['nodelist' ], is_available = True ))
99
- bulk_process_resource_attribute .append (ResourceAttribute (resource = new_resource , value = ' ' , resource_attribute_type = service_end_attribute_type ))
95
+ bulk_update_resource .append (Resource (name = row ['nodelist' ], is_available = True , resource_type = compute_node ))
96
+ bulk_process_resource_attribute .append (ResourceAttribute (resource = new_resource , value = None , resource_attribute_type = service_end_attribute_type ))
100
97
processed_resources .add (new_resource .name )
101
- ResourceAttribute .objects .bulk_create (bulk_process_resource_attribute , update_conflicts = True , unique_fields = [], update_fields = ['value' ])
102
- Resource .objects .bulk_create (bulk_update_resource , update_conflicts = True , unique_fields = [], update_fields = ['is_available' ])
98
+ try :
99
+ ResourceAttribute .objects .bulk_create (bulk_process_resource_attribute , update_conflicts = True , unique_fields = [], update_fields = ['value' ])
100
+ Resource .objects .bulk_create (bulk_update_resource , update_conflicts = True , unique_fields = [], update_fields = ['is_available' ])
101
+ except Exception as e :
102
+ logger .error (f'Error processing resources info: { str (e )} ' )
103
+ raise
103
104
bulk_process_resource_attribute = []
104
105
bulk_update_resource = []
105
106
for resource_to_delete in Resource .objects .exclude (name__in = list (processed_resources )).filter (is_available = True , resource_type = compute_node ):
106
- bulk_update_resource .append (Resource (name = resource_to_delete .name , is_available = False ))
107
+ resource_to_delete .is_available = False
108
+ bulk_update_resource .append (resource_to_delete )
107
109
bulk_process_resource_attribute .append (ResourceAttribute (resource = resource_to_delete , value = str (datetime .now ()), resource_attribute_type = service_end_attribute_type ))
108
- ResourceAttribute .objects .bulk_create (bulk_process_resource_attribute , update_conflicts = True , unique_fields = [], update_fields = ['value' ])
109
- Resource .objects .bulk_create (bulk_update_resource , update_conflicts = True , unique_fields = [], update_fields = ['is_available' ])
110
+ try :
111
+ ResourceAttribute .objects .bulk_create (bulk_process_resource_attribute , update_conflicts = True , unique_fields = [], update_fields = ['value' ])
112
+ Resource .objects .bulk_create (bulk_update_resource , update_conflicts = True , unique_fields = [], update_fields = ['is_available' ])
113
+ except Exception as e :
114
+ logger .error (f'Error cleaning up resources: { str (e )} ' )
115
+ raise
0 commit comments