@@ -348,52 +348,17 @@ def chainResult(_ignored):
348348 t .addCallbacks (chainResult , chainError )
349349 return d
350350
351- def _commitWithThread (self , transaction : CommitTransaction ):
352- if not self .running :
353- host = transaction .source_address .host
354- port = transaction .source_address .port
355- raise defer .CancelledError (f"CF Processor is not running (transaction: { host } :{ port } )" )
356-
357- _log .info ("CF_COMMIT: {transaction}" .format (transaction = transaction ))
358- _log .debug ("CF_COMMIT: transaction: {s}" .format (s = repr (transaction )))
359- """
360- a dictionary with a list of records with their associated property info
361- pvInfo
362- {record_id: { "pvName":"recordName",
363- "infoProperties":{propName:value, ...}}}
364- """
365- ioc_info = IocInfo (
366- host = transaction .source_address .host ,
367- hostname = transaction .client_infos .get ("HOSTNAME" ) or transaction .source_address .host ,
368- ioc_name = transaction .client_infos .get ("IOCNAME" ) or str (transaction .source_address .port ),
369- ioc_IP = transaction .source_address .host ,
370- owner = (
371- transaction .client_infos .get ("ENGINEER" )
372- or transaction .client_infos .get ("CF_USERNAME" )
373- or self .cf_config .username
374- ),
375- time = self .currentTime (timezone = self .cf_config .timezone ),
376- port = transaction .source_address .port ,
377- channelcount = 0 ,
378- )
379-
380- """The unique identifier for a particular IOC"""
381- iocid = ioc_info .ioc_id
382- _log .debug ("transaction: {s}" .format (s = repr (transaction )))
383-
351+ def transaction_to_recordInfo (self , ioc_info : IocInfo , transaction : CommitTransaction ) -> Dict [str , RecordInfo ]:
384352 recordInfo : Dict [str , RecordInfo ] = {}
385353 for record_id , (record_name , record_type ) in transaction .records_to_add .items ():
386354 recordInfo [record_id ] = RecordInfo (pvName = record_name , recordType = None , infoProperties = [], aliases = [])
387355 if self .cf_config .record_type_enabled :
388356 recordInfo [record_id ].recordType = record_type
357+
389358 for record_id , (record_infos_to_add ) in transaction .record_infos_to_add .items ():
390359 # find intersection of these sets
391360 if record_id not in recordInfo :
392- _log .warning (
393- "IOC: {iocid}: PV not found for recinfo with RID: {record_id}" .format (
394- iocid = iocid , record_id = record_id
395- )
396- )
361+ _log .warning ("IOC: %s: PV not found for recinfo with RID: {record_id}" , ioc_info , record_id )
397362 continue
398363 recinfo_wl = [p for p in self .record_property_names_list if p in record_infos_to_add .keys ()]
399364 if recinfo_wl :
@@ -402,15 +367,11 @@ def _commitWithThread(self, transaction: CommitTransaction):
402367 CFProperty (infotag , ioc_info .owner , record_infos_to_add [infotag ])
403368 )
404369
405- for record_id , alias in transaction .aliases .items ():
370+ for record_id , record_aliases in transaction .aliases .items ():
406371 if record_id not in recordInfo :
407- _log .warning (
408- "IOC: {iocid}: PV not found for alias with RID: {record_id}" .format (
409- iocid = iocid , record_id = record_id
410- )
411- )
372+ _log .warning ("IOC: %s: PV not found for alias with RID: %s" , ioc_info , record_id )
412373 continue
413- recordInfo [record_id ].aliases = alias
374+ recordInfo [record_id ].aliases = record_aliases
414375
415376 for record_id in recordInfo :
416377 for epics_env_var_name , cf_prop_name in self .env_vars .items ():
@@ -422,21 +383,27 @@ def _commitWithThread(self, transaction: CommitTransaction):
422383 _log .debug (
423384 "EPICS environment var %s listed in environment_vars setting list not found in this IOC: %s" ,
424385 epics_env_var_name ,
425- ioc_info . ioc_name ,
386+ ioc_info ,
426387 )
388+ return recordInfo
427389
428- records_to_delete = list (transaction .records_to_delete )
429- _log .debug ("Delete records: {s}" .format (s = records_to_delete ))
430-
390+ def record_info_by_name (self , recordInfo , ioc_info ) -> Dict [str , RecordInfo ]:
431391 recordInfoByName = {}
432392 for record_id , (info ) in recordInfo .items ():
433393 if info .pvName in recordInfoByName :
434- _log .warning (
435- "Commit contains multiple records with PV name: {pv} ({iocid})" .format (pv = info .pvName , iocid = iocid )
436- )
394+ _log .warning ("Commit contains multiple records with PV name: %s (%s)" , info .pvName , ioc_info )
437395 continue
438396 recordInfoByName [info .pvName ] = info
439-
397+ return recordInfoByName
398+
399+ def update_ioc_infos (
400+ self ,
401+ transaction : CommitTransaction ,
402+ ioc_info : IocInfo ,
403+ records_to_delete : List [str ],
404+ recordInfoByName : Dict [str , RecordInfo ],
405+ ):
406+ iocid = ioc_info .ioc_id
440407 if transaction .initial :
441408 """Add IOC to source list """
442409 self .iocs [iocid ] = ioc_info
@@ -448,27 +415,59 @@ def _commitWithThread(self, transaction: CommitTransaction):
448415 """In case, alias exists"""
449416 if self .cf_config .alias_enabled :
450417 if record_name in recordInfoByName :
451- for alias in recordInfoByName [record_name ].aliases :
452- self .channel_ioc_ids [alias ].append (iocid ) # add iocname to pvName in dict
418+ for record_aliases in recordInfoByName [record_name ].aliases :
419+ self .channel_ioc_ids [record_aliases ].append (iocid ) # add iocname to pvName in dict
453420 self .iocs [iocid ].channelcount += 1
454421 for record_name in records_to_delete :
455422 if iocid in self .channel_ioc_ids [record_name ]:
456423 self .remove_channel (record_name , iocid )
457424 """In case, alias exists"""
458425 if self .cf_config .alias_enabled :
459426 if record_name in recordInfoByName :
460- for alias in recordInfoByName [record_name ].aliases :
461- self .remove_channel (alias , iocid )
427+ for record_aliases in recordInfoByName [record_name ].aliases :
428+ self .remove_channel (record_aliases , iocid )
429+
430+ def _commitWithThread (self , transaction : CommitTransaction ):
431+ if not self .running :
432+ host = transaction .source_address .host
433+ port = transaction .source_address .port
434+ raise defer .CancelledError (f"CF Processor is not running (transaction: { host } :{ port } )" )
435+
436+ _log .info ("CF_COMMIT: %s" , transaction )
437+ _log .debug ("CF_COMMIT: transaction: %s" , repr (transaction ))
438+
439+ ioc_info = IocInfo (
440+ host = transaction .source_address .host ,
441+ hostname = transaction .client_infos .get ("HOSTNAME" ) or transaction .source_address .host ,
442+ ioc_name = transaction .client_infos .get ("IOCNAME" ) or str (transaction .source_address .port ),
443+ ioc_IP = transaction .source_address .host ,
444+ owner = (
445+ transaction .client_infos .get ("ENGINEER" )
446+ or transaction .client_infos .get ("CF_USERNAME" )
447+ or self .cf_config .username
448+ ),
449+ time = self .currentTime (timezone = self .cf_config .timezone ),
450+ port = transaction .source_address .port ,
451+ channelcount = 0 ,
452+ )
453+
454+ recordInfo = self .transaction_to_recordInfo (ioc_info , transaction )
455+
456+ records_to_delete = list (transaction .records_to_delete )
457+ _log .debug ("Delete records: {s}" .format (s = records_to_delete ))
458+
459+ recordInfoByName = self .record_info_by_name (recordInfo , ioc_info )
460+ self .update_ioc_infos (transaction , ioc_info , records_to_delete , recordInfoByName )
462461 poll (__updateCF__ , self , recordInfoByName , records_to_delete , ioc_info )
463462
464- def remove_channel (self , recordName , iocid ):
463+ def remove_channel (self , recordName : str , iocid : str ):
465464 self .channel_ioc_ids [recordName ].remove (iocid )
466465 if iocid in self .iocs :
467466 self .iocs [iocid ].channelcount -= 1
468467 if self .iocs [iocid ].channelcount == 0 :
469468 self .iocs .pop (iocid , None )
470469 elif self .iocs [iocid ].channelcount < 0 :
471- _log .error ("Channel count negative: {s} " , s = iocid )
470+ _log .error ("Channel count negative: %s " , iocid )
472471 if len (self .channel_ioc_ids [recordName ]) <= 0 : # case: channel has no more iocs
473472 del self .channel_ioc_ids [recordName ]
474473
0 commit comments