Skip to content

Commit

Permalink
Merge pull request #3176 from ACE-IoT-Solutions/add-agent-name-cache
Browse files Browse the repository at this point in the history
Added a cache for agent names since platform start
  • Loading branch information
craig8 authored Apr 24, 2024
2 parents 8286369 + d131597 commit 5f60f11
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions volttron/platform/aip.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def __init__(self, env, **kwargs):
if self.message_bus == 'rmq':
self.rmq_mgmt = RabbitMQMgmt()
self.instance_name = get_platform_instance_name()
self.agent_uuid_name_map = {}

def add_agent_user_group(self):
user = pwd.getpwuid(os.getuid())
Expand Down Expand Up @@ -682,11 +683,14 @@ def remove_agent(self, agent_uuid, remove_auth=True):
self.remove_agent_user(volttron_agent_user)

def agent_name(self, agent_uuid):
if cached_name := self.agent_uuid_name_map.get(agent_uuid):
return cached_name
agent_path = os.path.join(self.install_dir, agent_uuid)
for agent_name in os.listdir(agent_path):
dist_info = os.path.join(
agent_path, agent_name, agent_name + '.dist-info')
if os.path.exists(dist_info):
self.agent_uuid_name_map[agent_uuid] = agent_name
return agent_name
raise KeyError(agent_uuid)

Expand Down

0 comments on commit 5f60f11

Please sign in to comment.