hat.monitor.common

Common functionality shared between clients and monitor server

 1"""Common functionality shared between clients and monitor server"""
 2
 3import importlib.resources
 4import typing
 5
 6from hat import json
 7from hat import sbs
 8
 9
10with importlib.resources.as_file(importlib.resources.files(__package__) /
11                                 'json_schema_repo.json') as _path:
12    json_schema_repo: json.SchemaRepository = json.merge_schema_repositories(
13        json.json_schema_repo,
14        json.decode_file(_path))
15
16with importlib.resources.as_file(importlib.resources.files(__package__) /
17                                 'sbs_repo.json') as _path:
18    sbs_repo: sbs.Repository = sbs.Repository.from_json(_path)
19
20
21Cid: typing.TypeAlias = int
22
23Mid: typing.TypeAlias = int
24
25
26class BlessingReq(typing.NamedTuple):
27    token: int | None
28    timestamp: float | None
29
30
31class BlessingRes(typing.NamedTuple):
32    token: int | None
33    ready: bool
34
35
36class ComponentInfo(typing.NamedTuple):
37    cid: Cid
38    mid: Mid
39    name: str | None
40    group: str | None
41    data: json.Data
42    rank: int
43    blessing_req: BlessingReq
44    blessing_res: BlessingRes
Cid: TypeAlias = int
Mid: TypeAlias = int
class BlessingReq(typing.NamedTuple):
27class BlessingReq(typing.NamedTuple):
28    token: int | None
29    timestamp: float | None

BlessingReq(token, timestamp)

BlessingReq(token: int | None, timestamp: float | None)

Create new instance of BlessingReq(token, timestamp)

token: int | None

Alias for field number 0

timestamp: float | None

Alias for field number 1

class BlessingRes(typing.NamedTuple):
32class BlessingRes(typing.NamedTuple):
33    token: int | None
34    ready: bool

BlessingRes(token, ready)

BlessingRes(token: int | None, ready: bool)

Create new instance of BlessingRes(token, ready)

token: int | None

Alias for field number 0

ready: bool

Alias for field number 1

class ComponentInfo(typing.NamedTuple):
37class ComponentInfo(typing.NamedTuple):
38    cid: Cid
39    mid: Mid
40    name: str | None
41    group: str | None
42    data: json.Data
43    rank: int
44    blessing_req: BlessingReq
45    blessing_res: BlessingRes

ComponentInfo(cid, mid, name, group, data, rank, blessing_req, blessing_res)

ComponentInfo( cid: int, mid: int, name: str | None, group: str | None, data: Union[NoneType, bool, int, float, str, List[ForwardRef('Data')], Dict[str, ForwardRef('Data')]], rank: int, blessing_req: BlessingReq, blessing_res: BlessingRes)

Create new instance of ComponentInfo(cid, mid, name, group, data, rank, blessing_req, blessing_res)

cid: int

Alias for field number 0

mid: int

Alias for field number 1

name: str | None

Alias for field number 2

group: str | None

Alias for field number 3

data: Union[NoneType, bool, int, float, str, List[ForwardRef('Data')], Dict[str, ForwardRef('Data')]]

Alias for field number 4

rank: int

Alias for field number 5

blessing_req: BlessingReq

Alias for field number 6

blessing_res: BlessingRes

Alias for field number 7

json_schema_repo: dict[str, typing.Dict[str, ForwardRef('Data')]] = {'hat-json://path.yaml': {'$schema': 'https://json-schema.org/draft/2020-12/schema', '$id': 'hat-json://path.yaml', 'title': 'JSON Path', 'oneOf': [{'type': 'string'}, {'type': 'integer'}, {'type': 'array', 'items': {'$ref': 'hat-json://path.yaml'}}]}, 'hat-json://logging.yaml': {'$schema': 'https://json-schema.org/draft/2020-12/schema', '$id': 'hat-json://logging.yaml', 'title': 'Logging', 'description': 'Logging configuration', 'type': 'object', 'required': ['version'], 'properties': {'version': {'title': 'Version', 'type': 'integer', 'default': 1}, 'formatters': {'title': 'Formatters', 'type': 'object', 'patternProperties': {'.+': {'title': 'Formatter', 'type': 'object', 'properties': {'format': {'title': 'Format', 'type': 'string', 'default': None}, 'datefmt': {'title': 'Date format', 'type': 'string', 'default': None}}}}}, 'filters': {'title': 'Filters', 'type': 'object', 'patternProperties': {'.+': {'title': 'Filter', 'type': 'object', 'properties': {'name': {'title': 'Logger name', 'type': 'string', 'default': ''}}}}}, 'handlers': {'title': 'Handlers', 'type': 'object', 'patternProperties': {'.+': {'title': 'Handler', 'type': 'object', 'description': 'Additional properties are passed as keyword arguments to\nconstructor\n', 'required': ['class'], 'properties': {'class': {'title': 'Class', 'type': 'string'}, 'level': {'title': 'Level', 'type': 'string'}, 'formatter': {'title': 'Formatter', 'type': 'string'}, 'filters': {'title': 'Filters', 'type': 'array', 'items': {'title': 'Filter id', 'type': 'string'}}}}}}, 'loggers': {'title': 'Loggers', 'type': 'object', 'patternProperties': {'.+': {'title': 'Logger', 'type': 'object', 'properties': {'level': {'title': 'Level', 'type': 'string'}, 'propagate': {'title': 'Propagate', 'type': 'boolean'}, 'filters': {'title': 'Filters', 'type': 'array', 'items': {'title': 'Filter id', 'type': 'string'}}, 'handlers': {'title': 'Handlers', 'type': 'array', 'items': {'title': 'Handler id', 'type': 'string'}}}}}}, 'root': {'title': 'Root logger', 'type': 'object', 'properties': {'level': {'title': 'Level', 'type': 'string'}, 'filters': {'title': 'Filters', 'type': 'array', 'items': {'title': 'Filter id', 'type': 'string'}}, 'handlers': {'title': 'Handlers', 'type': 'array', 'items': {'title': 'Handler id', 'type': 'string'}}}}, 'incremental': {'title': 'Incremental configuration', 'type': 'boolean', 'default': False}, 'disable_existing_loggers': {'title': 'Disable existing loggers', 'type': 'boolean', 'default': True}}}, 'hat-monitor://juggler.yaml': {'$schema': 'https://json-schema.org/draft/2020-12/schema', '$id': 'hat-monitor://juggler.yaml', '$defs': {'state': {'type': 'object', 'required': ['mid', 'local_components', 'global_components'], 'properties': {'mid': {'type': 'integer'}, 'local_components': {'type': 'array', 'items': {'type': 'object', 'required': ['cid', 'name', 'group', 'data', 'rank'], 'properties': {'cid': {'type': 'integer'}, 'name': {'type': ['string', 'null']}, 'group': {'type': ['string', 'null']}, 'rank': {'type': 'integer'}}}}, 'global_components': {'type': 'array', 'items': {'type': 'object', 'required': ['cid', 'mid', 'name', 'group', 'data', 'rank', 'blessing_req', 'blessing_res'], 'properties': {'cid': {'type': 'integer'}, 'mid': {'type': 'integer'}, 'name': {'type': ['string', 'null']}, 'group': {'type': ['string', 'null']}, 'rank': {'type': 'integer'}, 'blessing_req': {'type': 'object', 'required': ['token', 'timestamp'], 'properties': {'token': {'type': ['integer', 'null']}, 'timestamp': {'type': ['float', 'null']}}}, 'blessing_res': {'type': 'object', 'required': ['token', 'ready'], 'properties': {'token': {'type': ['integer', 'null']}, 'ready': {'type': 'boolean'}}}}}}}}, 'request': {'set_rank': {'type': 'object', 'required': ['cid', 'rank'], 'properties': {'cid': {'type': 'integer'}, 'rank': {'type': 'integer'}}}}}}, 'hat-monitor://server.yaml': {'$schema': 'https://json-schema.org/draft/2020-12/schema', '$id': 'hat-monitor://server.yaml', 'type': 'object', 'required': ['default_algorithm', 'group_algorithms', 'server', 'master', 'slave'], 'properties': {'type': {'const': 'monitor', 'description': 'configuration type identification'}, 'version': {'type': 'string', 'description': 'component version'}, 'log': {'$ref': 'hat-json://logging.yaml'}, 'default_algorithm': {'$ref': 'hat-monitor://server.yaml#/$defs/algorithm'}, 'group_algorithms': {'description': 'keys represent group names\n', 'type': 'object', 'patternProperties': {'.+': {'$ref': 'hat-monitor://server.yaml#/$defs/algorithm'}}}, 'server': {'$ref': 'hat-monitor://server.yaml#/$defs/server'}, 'master': {'$ref': 'hat-monitor://server.yaml#/$defs/master'}, 'slave': {'$ref': 'hat-monitor://server.yaml#/$defs/slave'}, 'ui': {'$ref': 'hat-monitor://server.yaml#/$defs/ui'}}, '$defs': {'server': {'title': 'Listening Orchestrator Server', 'type': 'object', 'required': ['host', 'port', 'default_rank'], 'properties': {'host': {'type': 'string', 'default': '127.0.0.1'}, 'port': {'type': 'integer', 'default': 23010}, 'default_rank': {'type': 'integer'}}}, 'master': {'title': 'Listening Orchestrator Master', 'type': 'object', 'required': ['host', 'port'], 'properties': {'host': {'type': 'string', 'default': '127.0.0.1'}, 'port': {'type': 'integer', 'default': 23011}}}, 'slave': {'type': 'object', 'required': ['parents', 'connect_timeout', 'connect_retry_count', 'connect_retry_delay'], 'properties': {'parents': {'title': 'parent addresses', 'type': 'array', 'items': {'type': 'object', 'required': ['host', 'port'], 'properties': {'host': {'type': 'string'}, 'port': {'type': 'integer', 'default': 23011}}}}, 'connect_timeout': {'type': 'number'}, 'connect_retry_count': {'type': 'integer'}, 'connect_retry_delay': {'type': 'number'}}}, 'ui': {'title': 'Listening UI Web Server', 'type': 'object', 'required': ['host', 'port'], 'properties': {'host': {'type': 'string', 'default': '127.0.0.1'}, 'port': {'type': 'integer', 'default': 23022}, 'htpasswd': {'type': 'string', 'description': 'basic authentication users\n'}}}, 'algorithm': {'enum': ['BLESS_ALL', 'BLESS_ONE']}}}}
sbs_repo: hat.sbs.repository.Repository = <hat.sbs.repository.Repository object>