Coverage for /Users/buh/.pyenv/versions/3.12.9/envs/es-testbed/lib/python3.12/site-packages/es_testbed/entities/entity.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-17 19:30 -0600

1"""Entity Parent Class""" 

2 

3import typing as t 

4from es_testbed.helpers.es_api import find_write_index, get_ds_current, resolver 

5 

6if t.TYPE_CHECKING: 

7 from elasticsearch8 import Elasticsearch 

8 

9# pylint: disable=R0903 

10 

11 

12class Entity: 

13 """Entity Parent Class""" 

14 

15 def __init__( 

16 self, 

17 client: 'Elasticsearch', 

18 name: t.Union[str, None] = None, 

19 ): 

20 self.client = client 

21 self.name = name # This will change with entity name changes 

22 

23 @property 

24 def am_i_write_idx(self) -> bool: 

25 """ 

26 Determine if self.name is the write index for either a rollover alias or a 

27 data_stream 

28 """ 

29 if self.name.startswith('.ds-'): # Datastream 

30 ds = resolver(self.client, self.name)['indices'][0]['data_stream'] 

31 return bool(self.name == get_ds_current(self.client, ds)) 

32 return bool(self.name == find_write_index(self.client, self.name))