Skip to content

Commit 46aec00

Browse files
committed
pull out handle channel old and new
1 parent c292d1b commit 46aec00

File tree

1 file changed

+79
-55
lines changed

1 file changed

+79
-55
lines changed

server/recceiver/cfstore.py

Lines changed: 79 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,76 @@ def orphan_channel(
621621
_log.debug("Add orphaned alias %s with no IOC: %s", alias_channel, ioc_info)
622622

623623

624+
def handle_channel_old_and_new(
625+
cf_channel: CFChannel,
626+
iocid: str,
627+
ioc_info: IocInfo,
628+
processor: CFProcessor,
629+
channels: List[CFChannel],
630+
new_channels: Set[str],
631+
cf_config: CFConfig,
632+
recordInfoByName: Dict[str, RecordInfo],
633+
old_channels: List[CFChannel],
634+
):
635+
"""
636+
Channel exists in Channelfinder with same iocid.
637+
Update the status to ensure it is marked active and update the time.
638+
"""
639+
_log.debug("Channel %s exists in Channelfinder with same iocid %s", cf_channel.name, iocid)
640+
cf_channel.properties = __merge_property_lists(
641+
[
642+
CFProperty.active(ioc_info.owner),
643+
CFProperty.time(ioc_info.owner, ioc_info.time),
644+
],
645+
cf_channel,
646+
processor.managed_properties,
647+
)
648+
channels.append(cf_channel)
649+
_log.debug("Add existing channel with same IOC: %s", cf_channel)
650+
new_channels.remove(cf_channel.name)
651+
652+
"""In case, alias exist"""
653+
if cf_config.alias_enabled:
654+
if cf_channel.name in recordInfoByName:
655+
for alias_name in recordInfoByName[cf_channel.name].aliases:
656+
if alias_name in old_channels:
657+
"""alias exists in old list"""
658+
alias_channel = CFChannel(alias_name, "", [])
659+
alias_channel.properties = __merge_property_lists(
660+
[
661+
CFProperty.active(ioc_info.owner),
662+
CFProperty.time(ioc_info.owner, ioc_info.time),
663+
],
664+
alias_channel,
665+
processor.managed_properties,
666+
)
667+
channels.append(alias_channel)
668+
new_channels.remove(alias_name)
669+
else:
670+
"""alias exists but not part of old list"""
671+
aprops = __merge_property_lists(
672+
[
673+
CFProperty.active(ioc_info.owner),
674+
CFProperty.time(ioc_info.owner, ioc_info.time),
675+
CFProperty.alias(
676+
ioc_info.owner,
677+
cf_channel.name,
678+
),
679+
],
680+
cf_channel,
681+
processor.managed_properties,
682+
)
683+
channels.append(
684+
CFChannel(
685+
alias_name,
686+
ioc_info.owner,
687+
aprops,
688+
)
689+
)
690+
new_channels.remove(alias_name)
691+
_log.debug("Add existing alias with same IOC: %s", cf_channel)
692+
693+
624694
def __updateCF__(processor: CFProcessor, recordInfoByName: Dict[str, RecordInfo], records_to_delete, ioc_info: IocInfo):
625695
_log.info("CF Update IOC: %s", ioc_info)
626696
_log.debug("CF Update IOC: %s recordInfoByName %s", ioc_info, recordInfoByName)
@@ -673,63 +743,17 @@ def __updateCF__(processor: CFProcessor, recordInfoByName: Dict[str, RecordInfo]
673743
orphan_channel(cf_channel, ioc_info, channels, cf_config, recordInfoByName)
674744
else:
675745
if cf_channel.name in new_channels: # case: channel in old and new
676-
"""
677-
Channel exists in Channelfinder with same iocid.
678-
Update the status to ensure it is marked active and update the time.
679-
"""
680-
_log.debug("Channel %s exists in Channelfinder with same iocid %s", cf_channel.name, iocid)
681-
cf_channel.properties = __merge_property_lists(
682-
[
683-
CFProperty.active(ioc_info.owner),
684-
CFProperty.time(ioc_info.owner, ioc_info.time),
685-
],
746+
handle_channel_old_and_new(
686747
cf_channel,
687-
processor.managed_properties,
748+
iocid,
749+
ioc_info,
750+
processor,
751+
channels,
752+
new_channels,
753+
cf_config,
754+
recordInfoByName,
755+
old_channels,
688756
)
689-
channels.append(cf_channel)
690-
_log.debug("Add existing channel with same IOC: %s", cf_channel)
691-
new_channels.remove(cf_channel.name)
692-
693-
"""In case, alias exist"""
694-
if cf_config.alias_enabled:
695-
if cf_channel.name in recordInfoByName:
696-
for alias_name in recordInfoByName[cf_channel.name].aliases:
697-
if alias_name in old_channels:
698-
"""alias exists in old list"""
699-
alias_channel = CFChannel(alias_name, "", [])
700-
alias_channel.properties = __merge_property_lists(
701-
[
702-
CFProperty.active(ioc_info.owner),
703-
CFProperty.time(ioc_info.owner, ioc_info.time),
704-
],
705-
alias_channel,
706-
processor.managed_properties,
707-
)
708-
channels.append(alias_channel)
709-
new_channels.remove(alias_name)
710-
else:
711-
"""alias exists but not part of old list"""
712-
aprops = __merge_property_lists(
713-
[
714-
CFProperty.active(ioc_info.owner),
715-
CFProperty.time(ioc_info.owner, ioc_info.time),
716-
CFProperty.alias(
717-
ioc_info.owner,
718-
cf_channel.name,
719-
),
720-
],
721-
cf_channel,
722-
processor.managed_properties,
723-
)
724-
channels.append(
725-
CFChannel(
726-
alias_name,
727-
ioc_info.owner,
728-
aprops,
729-
)
730-
)
731-
new_channels.remove(alias_name)
732-
_log.debug("Add existing alias with same IOC: %s", cf_channel)
733757
# now pvNames contains a list of pv's new on this host/ioc
734758
"""A dictionary representing the current channelfinder information associated with the pvNames"""
735759
existingChannels: Dict[str, CFChannel] = {}

0 commit comments

Comments
 (0)