mlog = logging.getLogger(__name__) start_delay = 0.5 """float: process start delay in seconds""" create_timeout = 2 """float: create process timeout in seconds""" sigint_timeout = 5 """float: SIGINT timeout in seconds""" sigkill_timeout = 2 """float: SIGKILL timeout in seconds""" Status = util.extend_enum_doc( enum.Enum('Status', ['STOPPED', 'DELAYED', 'STARTING', 'RUNNING', 'STOPPING'])) class Component: """Component Args: conf (hat.json.Data): configuration defined by ``hat://orchestrator.yaml#/definitions/component`` """ def __init__(self, conf): self._conf = conf self._status = Status.DELAYED if conf['delay'] else Status.STOPPED self._revive = conf['revive']
from hat import chatter from hat import sbs from hat import util from hat.util import json import hat.monitor.common package_path = Path(__file__).parent json_schema_repo = json.SchemaRepository( json.json_schema_repo, hat.monitor.common.json_schema_repo, json.SchemaRepository.from_json(package_path / 'json_schema_repo.json')) sbs_repo = sbs.Repository( chatter.sbs_repo, sbs.Repository.from_json(package_path / 'sbs_repo.json')) Order = util.extend_enum_doc(enum.Enum('Order', ['DESCENDING', 'ASCENDING'])) OrderBy = util.extend_enum_doc( enum.Enum('OrderBy', ['TIMESTAMP', 'SOURCE_TIMESTAMP'])) EventPayloadType = util.extend_enum_doc( enum.Enum('EventPayloadType', ['BINARY', 'JSON', 'SBS'])) EventId = util.namedtuple('EventId', ['server', 'int: server identifier'], ['instance', 'int: event instance identifier']) EventType = typing.List[str] EventPayload = util.namedtuple( 'EventPayload', ['type', 'EventPayloadType: payload type'], ['data', 'Union[bytes,json.Data,SbsData]: data'])
import itertools import json import pathlib import typing import urllib.parse import jsonpatch import jsonschema.validators import yaml from hat import util Data = typing.Union[None, bool, int, float, str, typing.List['Data'], typing.Dict[str, 'Data']] Format = util.extend_enum_doc(enum.Enum('Format', ['JSON', 'YAML'])) def equals(a, b): """Equality comparison of json serializable data. Tests for equality of data according to JSON format. Notably, ``bool`` values are not considered equal to numeric values in any case. This is different from default equality comparison, which considers `False` equal to `0` and `0.0`; and `True` equal to `1` and `1.0`. Args: a (Data): data b (Data): data Returns:
"""Implementation of blessing calculation algorithms""" import enum from hat import util Algorithm = util.extend_enum_doc( enum.Enum('Algorithm', ['BLESS_ALL', 'BLESS_ONE'])) _last_token_id = 0 def calculate_blessing(group_algorithms, components, default_algorithm=Algorithm.BLESS_ONE): """Calculate blessing Args: group_algorithms (Dict[str,Algorithm]): association of algorith to group components (List[common.ComponentInfo]): components state with previous blessing tokens Returns: List[common.ComponentInfo]: components state with updated blessing """ if not components: return components group_components = {} for c in components:
BackendQueryData = util.namedtuple( 'BackendQueryData', ['event_ids', 'Optional[List[EventId]]: event identifiers', None], ['event_type_ids', 'Optional[List[int]]: event types', None], ['t_from', 'Optional[Timestamp]: timestamp from', None], ['t_to', 'Optional[Timestamp]: timestamp to', None], ['source_t_from', 'Optional[Timestamp]', None], ['source_t_to', 'Optional[Timestamp]', None], ['payload', 'Optional[EventPayload]: payload', None], ['order', 'Order: order', Order.DESCENDING], # NOQA ['order_by', 'OrderBy: order by', OrderBy.TIMESTAMP], # NOQA ['unique_type', 'bool: unique type flag', False], ['max_results', 'Optional[int]: maximum results', None]) SourceType = util.extend_enum_doc( enum.Enum('SourceType', ['COMMUNICATION', 'MODULE'])) Source = util.namedtuple('Source', ['type', 'SourceType: source type'], ['id', 'int: identifier']) ProcessEvent = util.namedtuple( 'ProcessEvent', ['event_id', 'EventId: event identifier'], ['source', 'Source: source'], ['event_type', 'EventType: event type'], ['source_timestamp', 'Optional[Timestamp]: source timestamp'], ['payload', 'Optional[EventPayload]: payload']) SessionChanges = util.namedtuple( 'SessionChanges', ['new', 'List[ProcessEvent]: new register events'], ['deleted', 'List[ProcessEvent]: deleted register events']) BackendConf = json.Data