From 694ee6180547703aa6d496da68ecaafd1b0deccc Mon Sep 17 00:00:00 2001 From: Ryan Slominski Date: Tue, 27 Aug 2024 13:41:51 -0400 Subject: [PATCH] Rename AlarmInstance to Alarm (#13) --- README.md | 16 ++-- build.yaml | 2 +- container/app/container-entrypoint.sh | 36 ++++----- .../app/example-data/{instances => alarms} | 0 src/jaws_libp/avro/schema-registry.json | 4 +- .../{AlarmInstance.avsc => Alarm.avsc} | 4 +- src/jaws_libp/avro/schemas/__init__.py | 2 +- src/jaws_libp/avro/serde.py | 54 ++++++------- src/jaws_libp/avro/topics.json | 2 +- src/jaws_libp/clients.py | 18 ++--- src/jaws_libp/console.py | 8 +- src/jaws_libp/entities.py | 10 +-- .../{list_instances.py => list_alarms.py} | 12 +-- .../client/{set_instance.py => set_alarm.py} | 30 ++++---- .../scripts/client/set_effective_alarm.py | 14 ++-- .../client/set_effective_registration.py | 20 ++--- tests/integration/test_alarm.py | 75 +++++++++++++++++++ tests/integration/test_instance.py | 75 ------------------- tests/integration/test_serde.py | 6 +- 19 files changed, 194 insertions(+), 194 deletions(-) rename container/app/example-data/{instances => alarms} (100%) rename src/jaws_libp/avro/schemas/{AlarmInstance.avsc => Alarm.avsc} (98%) rename src/jaws_libp/scripts/client/{list_instances.py => list_alarms.py} (75%) rename src/jaws_libp/scripts/client/{set_instance.py => set_alarm.py} (75%) create mode 100644 tests/integration/test_alarm.py delete mode 100644 tests/integration/test_instance.py diff --git a/README.md b/README.md index 512a136f..94e1c0e3 100644 --- a/README.md +++ b/README.md @@ -57,14 +57,14 @@ Environment variables are used to configure jaws-libp: The Docker container can optionally handle the following environment variables as well: -| Name | Description | -|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| ALARM_LOCATIONS | Path to an alarm locations file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/locations)), else an https URL to a file, else a comma separated list of location definitions with fields separated by the pipe symbol. Example Inline CSV: `name\|parent` | -| ALARM_CATEGORIES | Path to an alarm categories file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/categories)), else an https URL to a file, else a comma separated list of catgory definitions with fields. Example Inline CSV: `name` | -| ALARM_ACTIONS | Path to an alarm classes file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/actions)), else an https URL to a file, else a comma separated list of class definitions with fields separated by the pipe symbol. Example Inline CSV: `name\|category\|priority\|rationale\|correctiveaction\|latching\|filterable\|ondelayseconds\|offdelayseconds` | -| ALARM_INSTANCES | Path to an alarm instances file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/instances)), else an https URL to a file, else a comma separated list of instance definitions with fields separated by the pipe symbol. Leave epicspv field empty for SimpleProducer. Example Inline CSV: `name\|action\|epicspv\|location\|maskedby\|screencommand` | -| ALARM_INSTANCES_URL_CSV | If provided, is a comma separated list of file names to append to ALARM_INSTANCES; ignored if ALARM_INSTANCES doesn't start with `https`; [Example](https://github.com/JeffersonLab/jaws-libp/blob/cc56789a68009f71988ba98f5f55d822c240cd9d/build.yml#L25-L26). | -| ALARM_OVERRIDES | Path to an alarm overrides file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/overrides)), else an https URL to a file. | +| Name | Description | +|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| ALARM_LOCATIONS | Path to an alarm locations file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/locations)), else an https URL to a file, else a comma separated list of location definitions with fields separated by the pipe symbol. Example Inline CSV: `name\|parent` | +| ALARM_CATEGORIES | Path to an alarm categories file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/categories)), else an https URL to a file, else a comma separated list of catgory definitions with fields. Example Inline CSV: `name` | +| ALARM_ACTIONS | Path to an alarm classes file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/actions)), else an https URL to a file, else a comma separated list of class definitions with fields separated by the pipe symbol. Example Inline CSV: `name\|category\|priority\|rationale\|correctiveaction\|latching\|filterable\|ondelayseconds\|offdelayseconds` | +| ALARMS | Path to an alarm registration instances file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/alarms)), else an https URL to a file, else a comma separated list of instance definitions with fields separated by the pipe symbol. Leave epicspv field empty for SimpleProducer. Example Inline CSV: `name\|action\|epicspv\|location\|maskedby\|screencommand` | +| ALARMS_URL_CSV | If provided, is a comma separated list of file names to append to ALARMS; ignored if ALARMS doesn't start with `https`; [Example](https://github.com/JeffersonLab/jaws-libp/blob/cc56789a68009f71988ba98f5f55d822c240cd9d/build.yml#L25-L26). | +| ALARM_OVERRIDES | Path to an alarm overrides file to import ([example file](https://github.com/JeffersonLab/jaws-libp/blob/main/container/app/example-data/overrides)), else an https URL to a file. | ## Build This [Python 3.9+](https://www.python.org/) project is built with [setuptools](https://setuptools.pypa.io/en/latest/setuptools.html) and may be run using the Python [virtual environment](https://docs.python.org/3/tutorial/venv.html) feature to isolate dependencies. The [pip](https://pypi.org/project/pip/) tool can be used to download dependencies. diff --git a/build.yaml b/build.yaml index b965a529..ecef249b 100644 --- a/build.yaml +++ b/build.yaml @@ -21,7 +21,7 @@ services: - ALARM_LOCATIONS=/data/locations - ALARM_CATEGORIES=/data/categories - ALARM_ACTIONS=/data/actions - - ALARM_INSTANCES=/data/instances + - ALARM_INSTANCES=/data/alarms #- ALARM_INSTANCES=https://raw.githubusercontent.com/JeffersonLab/alarms/main/instances #- ALARM_INSTANCES_URL_CSV=aperture,bcm,beamdump,bels,blm,box,bpm,camac,crates,cryo,dempow,gun,harp,helicity,ioc,ion,laser,lcw,misc,mo,odh,radcon,rf,rfsep,trim,vacuum - ALARM_OVERRIDES=/data/overrides diff --git a/container/app/container-entrypoint.sh b/container/app/container-entrypoint.sh index 0d0b5c2d..98e747d0 100755 --- a/container/app/container-entrypoint.sh +++ b/container/app/container-entrypoint.sh @@ -152,36 +152,36 @@ else fi -echo "-------------------------" -echo "Step 7: Adding instances " -echo "-------------------------" -if [[ -z "${ALARM_INSTANCES}" ]]; then +echo "--------------------------------------------" +echo "Step 7: Adding alarm registration instances " +echo "--------------------------------------------" +if [[ -z "${ALARMS}" ]]; then echo "No alarm definitions specified" -elif beginswith 'https://' "${ALARM_INSTANCES}"; then - echo "HTTPS URL specified: $ALARM_INSTANCES" +elif beginswith 'https://' "${ALARMS}"; then + echo "HTTPS URL specified: $ALARMS" - if [[ -n "${ALARM_INSTANCES_URL_CSV}" ]]; then - echo "Using URL_CSV: $ALARM_INSTANCES_URL_CSV" + if [[ -n "${ALARMS_URL_CSV}" ]]; then + echo "Using URL_CSV: $ALARMS_URL_CSV" IFS=',' - read -a definitions <<< "$ALARM_INSTANCES_URL_CSV" + read -a definitions <<< "$ALARMS_URL_CSV" for defStr in "${definitions[@]}"; do - echo "Loading URL: ${ALARM_INSTANCES}/${defStr}" - wget -O /tmp/instances "${ALARM_INSTANCES}/${defStr}" - set_instance --file /tmp/instances + echo "Loading URL: ${ALARMS}/${defStr}" + wget -O /tmp/alarms "${ALARMS}/${defStr}" + set_instance --file /tmp/alarms done else echo "Grabbing single URL" - wget -O /tmp/instances "$ALARM_INSTANCES" - set_instance --file /tmp/instances + wget -O /tmp/alarms "$ALARMS" + set_instance --file /tmp/alarms fi -elif [[ -f "$ALARM_INSTANCES" ]]; then - echo "Attempting to setup alarm definitions from file $ALARM_INSTANCES" - set_instance --file "$ALARM_INSTANCES" +elif [[ -f "$ALARMS" ]]; then + echo "Attempting to setup alarm definitions from file $ALARMS" + set_instance --file "$ALARMS" else echo "Attempting to setup instances" IFS=',' - read -a definitions <<< "$ALARM_INSTANCES" + read -a definitions <<< "$ALARMS" for defStr in "${definitions[@]}"; do IFS='|' diff --git a/container/app/example-data/instances b/container/app/example-data/alarms similarity index 100% rename from container/app/example-data/instances rename to container/app/example-data/alarms diff --git a/src/jaws_libp/avro/schema-registry.json b/src/jaws_libp/avro/schema-registry.json index 6edf8848..8679c091 100644 --- a/src/jaws_libp/avro/schema-registry.json +++ b/src/jaws_libp/avro/schema-registry.json @@ -10,7 +10,7 @@ {"file": "avro/schemas/ShelvedOverride.avsc", "subject": "shelved-override", "references": []}, {"file": "avro/schemas/AlarmActivationUnion.avsc", "subject": "alarm-activations-value", "references": []}, {"file": "avro/schemas/AlarmAction.avsc", "subject": "alarm-actions-value", "references": []}, - {"file": "avro/schemas/AlarmInstance.avsc", "subject": "alarm-instances-value", "references": []}, + {"file": "avro/schemas/Alarm.avsc", "subject": "alarms-value", "references": []}, {"file": "avro/schemas/AlarmOverrideUnion.avsc", "subject": "alarm-overrides-value", "references": [ {"name": "org.jlab.jaws.entity.DisabledOverride", "subject": "disabled-override", "version": "1"}, {"name": "org.jlab.jaws.entity.FilteredOverride", "subject": "filtered-override", "version": "1"}, @@ -33,7 +33,7 @@ {"file": "avro/schemas/ProcessorTransitions.avsc", "subject": "processor-transitions", "references": []}, {"file": "avro/schemas/AlarmState.avsc", "subject": "alarm-state", "references": []}, {"file": "avro/schemas/EffectiveRegistration.avsc", "subject": "effective-registrations-value", "references": [ - {"name": "org.jlab.jaws.entity.AlarmInstance", "subject": "alarm-instances-value", "version": "1"}, + {"name": "org.jlab.jaws.entity.Alarm", "subject": "alarms-value", "version": "1"}, {"name": "org.jlab.jaws.entity.AlarmAction", "subject": "alarm-actions-value", "version": "1"} ]}, {"file": "avro/schemas/EffectiveNotification.avsc", "subject": "effective-notifications-value", "references": [ diff --git a/src/jaws_libp/avro/schemas/AlarmInstance.avsc b/src/jaws_libp/avro/schemas/Alarm.avsc similarity index 98% rename from src/jaws_libp/avro/schemas/AlarmInstance.avsc rename to src/jaws_libp/avro/schemas/Alarm.avsc index b6d3eda3..7b06894b 100644 --- a/src/jaws_libp/avro/schemas/AlarmInstance.avsc +++ b/src/jaws_libp/avro/schemas/Alarm.avsc @@ -1,8 +1,8 @@ { "type": "record", - "name": "AlarmInstance", + "name": "Alarm", "namespace": "org.jlab.jaws.entity", - "doc": "Instance of an alarm class", + "doc": "An alarm instance", "fields": [ { "name": "action", diff --git a/src/jaws_libp/avro/schemas/__init__.py b/src/jaws_libp/avro/schemas/__init__.py index 90a95923..5ef62de5 100644 --- a/src/jaws_libp/avro/schemas/__init__.py +++ b/src/jaws_libp/avro/schemas/__init__.py @@ -9,7 +9,7 @@ * :download:`AlarmOverrideKey.avsc ` * :download:`AlarmOverrideSet.avsc ` * :download:`AlarmOverrideUnion.avsc ` - * :download:`AlarmInstance.avsc ` + * :download:`Alarm.avsc ` * :download:`AlarmState.avsc ` * :download:`DisabledOverride.avsc ` * :download:`EffectiveNotification.avsc ` diff --git a/src/jaws_libp/avro/serde.py b/src/jaws_libp/avro/serde.py index 1db01957..80406370 100644 --- a/src/jaws_libp/avro/serde.py +++ b/src/jaws_libp/avro/serde.py @@ -14,7 +14,7 @@ SerializationContext from ..entities import AlarmCategory, AlarmLocation, AlarmPriority, ChannelErrorActivation, NoActivation, \ - Source, AlarmInstance, AlarmActivationUnion, Activation, \ + Source, Alarm, AlarmActivationUnion, Activation, \ EPICSActivation, NoteActivation, DisabledOverride, FilteredOverride, LatchedOverride, MaskedOverride, \ OnDelayedOverride, OffDelayedOverride, ShelvedOverride, AlarmOverrideUnion, OverriddenAlarmType, AlarmOverrideKey, \ ShelvedReason, EPICSSEVR, EPICSSTAT, UnionEncoding, CALCSource, EPICSSource, AlarmAction, \ @@ -495,32 +495,32 @@ def from_dict(self, data: Dict[str, Union[Tuple[str, Dict[str, str]], return AlarmActivationUnion(obj) -class InstanceSerde(RegistryAvroSerde): +class AlarmSerde(RegistryAvroSerde): """ - Provides AlarmInstance serde utilities + Provides Alarm serde utilities """ def __init__(self, schema_registry_client: SchemaRegistryClient, union_encoding: UnionEncoding = UnionEncoding.TUPLE, avro_conf: Dict = None): """ - Create a new InstanceSerde. + Create a new AlarmSerde. :param schema_registry_client: The SchemaRegistryClient :param union_encoding: The union encoding to use :param avro_conf: configuration for avro serde """ - schema_bytes = pkgutil.get_data("jaws_libp", "avro/schemas/AlarmInstance.avsc") + schema_bytes = pkgutil.get_data("jaws_libp", "avro/schemas/Alarm.avsc") schema_str = schema_bytes.decode('utf-8') schema = Schema(schema_str, "AVRO", []) super().__init__(schema_registry_client, schema, union_encoding, avro_conf) - def to_dict(self, data: AlarmInstance) -> Dict[str, Union[str, Dict[str, Any]]]: + def to_dict(self, data: Alarm) -> Dict[str, Union[str, Dict[str, Any]]]: """ - Converts an AlarmInstance to a dict. + Converts an Alarm to a dict. - :param data: The AlarmInstance + :param data: The Alarm :return: A dict """ if isinstance(data.source, Source): @@ -546,14 +546,14 @@ def to_dict(self, data: AlarmInstance) -> Dict[str, Union[str, Dict[str, Any]]]: "screencommand": data.screen_command } - def from_dict(self, data: Dict[str, Union[str, Any]]) -> AlarmInstance: + def from_dict(self, data: Dict[str, Union[str, Any]]) -> Alarm: """ - Converts a dict to an AlarmInstance. + Converts a dict to an Alarm. Note: UnionEncoding.POSSIBLY_AMBIGUOUS_DICT is not supported. :param data: The dict - :return: The AlarmInstance + :return: The Alarm """ unionobj = data['source'] @@ -566,12 +566,12 @@ def from_dict(self, data: Dict[str, Union[str, Any]]) -> AlarmInstance: else: source = Source() - return AlarmInstance(data.get('action'), - source, - data.get('location'), - data.get('managedby'), - data.get('maskedby'), - data.get('screencommand')) + return Alarm(data.get('action'), + source, + data.get('location'), + data.get('managedby'), + data.get('maskedby'), + data.get('screencommand')) class OverrideSetSerde(RegistryAvroWithReferencesSerde): @@ -708,25 +708,25 @@ def __init__(self, schema_registry_client: SchemaRegistryClient, avro_conf: Dict :param avro_conf: configuration for avro serde """ self._action_serde = ActionSerde(schema_registry_client) - self._instance_serde = InstanceSerde(schema_registry_client) + self._alarm_serde = AlarmSerde(schema_registry_client) action_schema_ref = SchemaReference("org.jlab.jaws.entity.AlarmAction", "alarm-actions-value", 1) - registration_schema_ref = SchemaReference("org.jlab.jaws.entity.AlarmInstance", - "alarm-instances-value", 1) + alarm_schema_ref = SchemaReference("org.jlab.jaws.entity.Alarm", + "alarms-value", 1) - references = [action_schema_ref, registration_schema_ref] + references = [action_schema_ref, alarm_schema_ref] action_bytes = pkgutil.get_data("jaws_libp", "avro/schemas/AlarmAction.avsc") action_schema_str = action_bytes.decode('utf-8') - instance_bytes = pkgutil.get_data("jaws_libp", "avro/schemas/AlarmInstance.avsc") - instance_schema_str = instance_bytes.decode('utf-8') + alarm_bytes = pkgutil.get_data("jaws_libp", "avro/schemas/Alarm.avsc") + alarm_schema_str = alarm_bytes.decode('utf-8') named_schemas = {} ref_dict = json.loads(action_schema_str) fastavro.parse_schema(ref_dict, named_schemas=named_schemas) - ref_dict = json.loads(instance_schema_str) + ref_dict = json.loads(alarm_schema_str) fastavro.parse_schema(ref_dict, named_schemas=named_schemas) schema_bytes = pkgutil.get_data("jaws_libp", "avro/schemas/EffectiveRegistration.avsc") @@ -746,7 +746,7 @@ def to_dict(self, data: EffectiveRegistration) -> Dict[str, Any]: """ return { "action": self._action_serde.to_dict(data.action) if data.action is not None else None, - "instance": self._instance_serde.to_dict(data.instance) if data.instance is not None else None + "alarm": self._alarm_serde.to_dict(data.alarm) if data.alarm is not None else None } def from_dict(self, data: Dict[str, Any]) -> EffectiveRegistration: @@ -758,8 +758,8 @@ def from_dict(self, data: Dict[str, Any]) -> EffectiveRegistration: """ return EffectiveRegistration( self._action_serde.from_dict(data['action'][1]) if data.get('action') is not None else None, - self._instance_serde.from_dict(data['instance'][1]) - if data.get('instance') is not None else None) + self._alarm_serde.from_dict(data['alarm'][1]) + if data.get('alarm') is not None else None) class EffectiveNotificationSerde(RegistryAvroWithReferencesSerde): diff --git a/src/jaws_libp/avro/topics.json b/src/jaws_libp/avro/topics.json index 396ef460..9490a3fb 100644 --- a/src/jaws_libp/avro/topics.json +++ b/src/jaws_libp/avro/topics.json @@ -2,7 +2,7 @@ "alarm-activations", "alarm-categories", "alarm-actions", - "alarm-instances", + "alarms", "alarm-locations", "alarm-overrides", "intermediate-registration", diff --git a/src/jaws_libp/clients.py b/src/jaws_libp/clients.py index 67fead2c..5f4c9675 100644 --- a/src/jaws_libp/clients.py +++ b/src/jaws_libp/clients.py @@ -16,7 +16,7 @@ from psutil import Process from .avro.serde import CategorySerde, LocationSerde, OverrideKeySerde, OverrideSerde, EffectiveRegistrationSerde, \ - StringSerde, Serde, EffectiveAlarmSerde, EffectiveNotificationSerde, ActionSerde, ActivationSerde, InstanceSerde + StringSerde, Serde, EffectiveAlarmSerde, EffectiveNotificationSerde, ActionSerde, ActivationSerde, AlarmSerde from .entities import UnionEncoding from .eventsource import EventSourceListener, EventSourceTable from .scripts import DEFAULT_BOOTSTRAP_SERVERS @@ -457,9 +457,9 @@ def __init__(self, client_name: str): super().__init__(config) -class InstanceConsumer(JAWSConsumer): +class AlarmConsumer(JAWSConsumer): """ - Consumer for JAWS Instance messages. + Consumer for JAWS Alarm registration instance messages. """ def __init__(self, client_name: str): """ @@ -469,10 +469,10 @@ def __init__(self, client_name: str): """ schema_registry_client = get_registry_client() key_serde = StringSerde() - value_serde = InstanceSerde(schema_registry_client, UnionEncoding.DICT_WITH_TYPE) + value_serde = AlarmSerde(schema_registry_client, UnionEncoding.DICT_WITH_TYPE) config = { - 'topic': 'alarm-instances', + 'topic': 'alarms', 'client.name': client_name, 'key.serde': key_serde, 'value.serde': value_serde @@ -631,9 +631,9 @@ def __init__(self, client_name: str): super().__init__('effective-registrations', client_name, key_serde, value_serde) -class InstanceProducer(JAWSProducer): +class AlarmProducer(JAWSProducer): """ - Producer for JAWS Instance messages. + Producer for JAWS alarm registration instance messages. """ def __init__(self, client_name: str): """ @@ -643,9 +643,9 @@ def __init__(self, client_name: str): """ schema_registry_client = get_registry_client() key_serde = StringSerde() - value_serde = InstanceSerde(schema_registry_client) + value_serde = AlarmSerde(schema_registry_client) - super().__init__('alarm-instances', client_name, key_serde, value_serde) + super().__init__('alarms', client_name, key_serde, value_serde) class LocationProducer(JAWSProducer): diff --git a/src/jaws_libp/console.py b/src/jaws_libp/console.py index 4102905e..32aa2d82 100644 --- a/src/jaws_libp/console.py +++ b/src/jaws_libp/console.py @@ -10,7 +10,7 @@ from confluent_kafka import Message from tabulate import tabulate from .clients import JAWSConsumer, CategoryConsumer, ActivationConsumer, LocationConsumer, OverrideConsumer, \ - InstanceConsumer, EffectiveRegistrationConsumer, EffectiveAlarmConsumer, EffectiveNotificationConsumer, \ + AlarmConsumer, EffectiveRegistrationConsumer, EffectiveAlarmConsumer, EffectiveNotificationConsumer, \ ActionConsumer from .eventsource import EventSourceListener @@ -271,9 +271,9 @@ def __init__(self, client_name: str): msg.value().alarm_class]) -class InstanceConsoleConsumer(ConsoleConsumer): +class AlarmConsoleConsumer(ConsoleConsumer): """ - ConsoleConsumer for JAWS AlarmInstance messages. + ConsoleConsumer for JAWS Alarm registration instance messages. """ def __init__(self, client_name: str): """ @@ -281,7 +281,7 @@ def __init__(self, client_name: str): :param client_name: The name of the client application """ - consumer = InstanceConsumer(client_name) + consumer = AlarmConsumer(client_name) super().__init__(consumer, ["Alarm Name", "Action", "Source", "Location", "Managed By", "Masked By", "Screen Command"], diff --git a/src/jaws_libp/entities.py b/src/jaws_libp/entities.py index a77770dc..6b6984b0 100644 --- a/src/jaws_libp/entities.py +++ b/src/jaws_libp/entities.py @@ -315,9 +315,9 @@ class AlarmAction: @dataclass -class AlarmInstance: +class Alarm: """ - Alarm Instance. An instance inherits action class attributes, but also brings instance-specific + Alarm Instance. An instance associates with action class attributes, but also brings instance-specific attributes. """ action: str @@ -419,13 +419,13 @@ class ProcessorTransitions: @dataclass class EffectiveRegistration: """ - Effective Registration (action class + instance) + Effective Registration (action class + alarm instance) """ action: AlarmAction """The Alarm Action (class of alarm)""" - instance: AlarmInstance - """The actual alarm registration instance""" + alarm: Alarm + """The registered alarm instance""" @dataclass diff --git a/src/jaws_libp/scripts/client/list_instances.py b/src/jaws_libp/scripts/client/list_alarms.py similarity index 75% rename from src/jaws_libp/scripts/client/list_instances.py rename to src/jaws_libp/scripts/client/list_alarms.py index 5bbf4ced..9f21e9fd 100644 --- a/src/jaws_libp/scripts/client/list_instances.py +++ b/src/jaws_libp/scripts/client/list_alarms.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 """ - Lists the alarm registration instances. + Lists the alarm registration alarms. """ import click -from ...console import InstanceConsoleConsumer +from ...console import AlarmConsoleConsumer # pylint: disable=too-few-public-methods @@ -30,9 +30,9 @@ def filter_if(self, key, value): @click.option('--monitor', is_flag=True, help="Monitor indefinitely") @click.option('--nometa', is_flag=True, help="Exclude audit headers and timestamp") @click.option('--export', is_flag=True, help="Dump records in AVRO JSON format") -@click.option('--action', help="Only show instances with the specified action (class of alarm)") -def list_instances(monitor, nometa, export, action) -> None: - consumer = InstanceConsoleConsumer('list_instances.py') +@click.option('--action', help="Only show alarms with the specified action (class of alarm)") +def list_alarms(monitor, nometa, export, action) -> None: + consumer = AlarmConsoleConsumer('list_alarms.py') filter_obj = ActionFilter(action) @@ -40,7 +40,7 @@ def list_instances(monitor, nometa, export, action) -> None: def click_main() -> None: - list_instances() + list_alarms() if __name__ == "__main__": diff --git a/src/jaws_libp/scripts/client/set_instance.py b/src/jaws_libp/scripts/client/set_alarm.py similarity index 75% rename from src/jaws_libp/scripts/client/set_instance.py rename to src/jaws_libp/scripts/client/set_alarm.py index 35b7eee1..cfc12478 100644 --- a/src/jaws_libp/scripts/client/set_instance.py +++ b/src/jaws_libp/scripts/client/set_alarm.py @@ -5,15 +5,15 @@ **Note**: bulk imports with ``--file`` expect alarm instance records formatted in `AVRO JSON Encoding `_. - See `Example file `_. + See `Example file `_. """ import click from click import Choice -from ...clients import InstanceProducer +from ...clients import AlarmProducer from ...console import LocationConsoleConsumer -from ...entities import AlarmInstance, \ +from ...entities import Alarm, \ Source, EPICSSource, CALCSource @@ -21,7 +21,7 @@ @click.command() @click.option('--file', is_flag=True, help="Imports a file of key=value pairs (one per line) where the key is alarm name and value is JSON " - "encoded AVRO formatted per the alarm-instances-value schema") + "encoded AVRO formatted per the alarms-value schema") @click.option('--unset', is_flag=True, help="Remove the alarm") @click.option('--action', help="The alarm action (class of alarm)") @click.option('--pv', help="The name of the EPICS CA PV that directly powers this alarm") @@ -33,9 +33,9 @@ @click.option('--managedby', help="Whom manages this alarm (optional)") @click.option('--maskedby', help="The optional parent alarm that masks this one") @click.argument('name') -def set_instance(file, unset, action, pv, expression, location, +def set_alarm(file, unset, action, pv, expression, location, screencommand, managedby, maskedby, name) -> None: - producer = InstanceProducer('set_instance.py') + producer = AlarmProducer('set_alarm.py') key = name @@ -55,23 +55,23 @@ def set_instance(file, unset, action, pv, expression, location, if action is None: action = "base" - value = AlarmInstance(action, - source, - location, - managedby, - maskedby, - screencommand) + value = Alarm(action, + source, + location, + managedby, + maskedby, + screencommand) producer.send(key, value) def click_main() -> None: - consumer = LocationConsoleConsumer('set_instance.py') + consumer = LocationConsoleConsumer('set_alarm.py') locations = consumer.get_keys_then_done() - set_instance.params[5].type = Choice(locations) + set_alarm.params[5].type = Choice(locations) - set_instance() + set_alarm() if __name__ == "__main__": diff --git a/src/jaws_libp/scripts/client/set_effective_alarm.py b/src/jaws_libp/scripts/client/set_effective_alarm.py index b4e7e987..81b68ff2 100644 --- a/src/jaws_libp/scripts/client/set_effective_alarm.py +++ b/src/jaws_libp/scripts/client/set_effective_alarm.py @@ -14,7 +14,7 @@ from ...entities import EffectiveAlarm, AlarmState, AlarmOverrideSet, \ OverriddenAlarmType, EffectiveRegistration, EffectiveNotification, \ DisabledOverride, FilteredOverride, LatchedOverride, MaskedOverride, OnDelayedOverride, OffDelayedOverride, \ - ShelvedOverride, ShelvedReason, Source, AlarmInstance + ShelvedOverride, ShelvedReason, Source, Alarm # pylint: disable=duplicate-code @@ -43,12 +43,12 @@ def __get_overrides(override): def __get_instance(): - return AlarmInstance("base", - Source(), - ["INJ"], - None, - "alarm1", - "command1") + return Alarm("base", + Source(), + ["INJ"], + None, + "alarm1", + "command1") # pylint: disable=duplicate-code,missing-function-docstring,no-value-for-parameter diff --git a/src/jaws_libp/scripts/client/set_effective_registration.py b/src/jaws_libp/scripts/client/set_effective_registration.py index e5b00126..642401c7 100644 --- a/src/jaws_libp/scripts/client/set_effective_registration.py +++ b/src/jaws_libp/scripts/client/set_effective_registration.py @@ -10,17 +10,17 @@ import click from ...clients import EffectiveRegistrationProducer from ...entities import EffectiveRegistration, \ - AlarmInstance, Source + Alarm, Source # pylint: disable=duplicate-code def __get_instance(): - return AlarmInstance("base", - Source(), - ["INJ"], - None, - "alarm1", - "command1") + return Alarm("base", + Source(), + ["INJ"], + None, + "alarm1", + "command1") # pylint: disable=missing-function-docstring,no-value-for-parameter @@ -35,10 +35,10 @@ def set_effective_registration(unset, name): if unset: value = None else: - alarm_class = None - alarm_instance = __get_instance() + action = None + alarm = __get_instance() - value = EffectiveRegistration(alarm_class, alarm_instance) + value = EffectiveRegistration(action, alarm) producer.send(key, value) diff --git a/tests/integration/test_alarm.py b/tests/integration/test_alarm.py new file mode 100644 index 00000000..08d3c093 --- /dev/null +++ b/tests/integration/test_alarm.py @@ -0,0 +1,75 @@ +from click import Choice +from click.testing import CliRunner +from jaws_libp.avro.serde import AlarmSerde +from jaws_libp.entities import Alarm, Source, UnionEncoding, EPICSSource +from jaws_libp.scripts.client.list_alarms import list_alarms +from jaws_libp.scripts.client.set_alarm import set_alarm + + +def test_simple_alarm(): + alarm_name = "alarm1" + action_name = "TESTING_ACTION" + location = ["LOCATION1"] + source = Source() + managed_by = None + masked_by = None + screen_command = None + alarm = Alarm(action_name, source, location, managed_by, masked_by, screen_command) + + runner = CliRunner() + + set_alarm.params[5].type = Choice(location) + + try: + # Set + result = runner.invoke(set_alarm, [alarm_name, + '--action', action_name, + '--location', location[0]]) + assert result.exit_code == 0 + + # Get + result = runner.invoke(list_alarms, ['--export']) + assert result.exit_code == 0 + + alarm_serde = AlarmSerde(None, union_encoding=UnionEncoding.DICT_WITH_TYPE) + assert result.output == alarm_name + '=' + alarm_serde.to_json(alarm) + '\n' + + finally: + # Clear + result = runner.invoke(set_alarm, [alarm_name, '--unset']) + assert result.exit_code == 0 + + +def test_epics_alarm(): + alarm_name = "alarm1" + action_name = "TESTING_ACTION" + location = ["LOCATION1"] + source = EPICSSource("channel1") + managed_by = None + masked_by = None + screen_command = None + alarm = Alarm(action_name, source, location, managed_by, masked_by, screen_command) + + runner = CliRunner() + + set_alarm.params[5].type = Choice(location) + + try: + # Set + result = runner.invoke(set_alarm, [alarm_name, + '--pv', source.pv, + '--action', action_name, + '--location', location[0]]) + assert result.exit_code == 0 + + # Get + result = runner.invoke(list_alarms, ['--export']) + assert result.exit_code == 0 + + instance_serde = AlarmSerde(None, union_encoding=UnionEncoding.DICT_WITH_TYPE) + assert result.output == alarm_name + '=' + instance_serde.to_json(alarm) + '\n' + + finally: + # Clear + result = runner.invoke(set_alarm, [alarm_name, '--unset']) + assert result.exit_code == 0 diff --git a/tests/integration/test_instance.py b/tests/integration/test_instance.py deleted file mode 100644 index 16397d6a..00000000 --- a/tests/integration/test_instance.py +++ /dev/null @@ -1,75 +0,0 @@ -from click import Choice -from click.testing import CliRunner -from jaws_libp.avro.serde import InstanceSerde -from jaws_libp.entities import AlarmInstance, Source, UnionEncoding, EPICSSource -from jaws_libp.scripts.client.list_instances import list_instances -from jaws_libp.scripts.client.set_instance import set_instance - - -def test_simple_instance(): - alarm_name = "alarm1" - action_name = "TESTING_ACTION" - location = ["LOCATION1"] - source = Source() - managed_by = None - masked_by = None - screen_command = None - instance = AlarmInstance(action_name, source, location, managed_by, masked_by, screen_command) - - runner = CliRunner() - - set_instance.params[5].type = Choice(location) - - try: - # Set - result = runner.invoke(set_instance, [alarm_name, - '--action', action_name, - '--location', location[0]]) - assert result.exit_code == 0 - - # Get - result = runner.invoke(list_instances, ['--export']) - assert result.exit_code == 0 - - instance_serde = InstanceSerde(None, union_encoding=UnionEncoding.DICT_WITH_TYPE) - assert result.output == alarm_name + '=' + instance_serde.to_json(instance) + '\n' - - finally: - # Clear - result = runner.invoke(set_instance, [alarm_name, '--unset']) - assert result.exit_code == 0 - - -def test_epics_instance(): - alarm_name = "alarm1" - action_name = "TESTING_ACTION" - location = ["LOCATION1"] - source = EPICSSource("channel1") - managed_by = None - masked_by = None - screen_command = None - instance = AlarmInstance(action_name, source, location, managed_by, masked_by, screen_command) - - runner = CliRunner() - - set_instance.params[5].type = Choice(location) - - try: - # Set - result = runner.invoke(set_instance, [alarm_name, - '--pv', source.pv, - '--action', action_name, - '--location', location[0]]) - assert result.exit_code == 0 - - # Get - result = runner.invoke(list_instances, ['--export']) - assert result.exit_code == 0 - - instance_serde = InstanceSerde(None, union_encoding=UnionEncoding.DICT_WITH_TYPE) - assert result.output == alarm_name + '=' + instance_serde.to_json(instance) + '\n' - - finally: - # Clear - result = runner.invoke(set_instance, [alarm_name, '--unset']) - assert result.exit_code == 0 diff --git a/tests/integration/test_serde.py b/tests/integration/test_serde.py index c68e23bc..c92811a2 100644 --- a/tests/integration/test_serde.py +++ b/tests/integration/test_serde.py @@ -1,10 +1,10 @@ -from jaws_libp.avro.serde import InstanceSerde +from jaws_libp.avro.serde import AlarmSerde from jaws_libp.entities import UnionEncoding -def test_instance_serde(): +def test_alarm_serde(): - serde = InstanceSerde(None, union_encoding=UnionEncoding.DICT_WITH_TYPE) + serde = AlarmSerde(None, union_encoding=UnionEncoding.DICT_WITH_TYPE) expected_json = '{"action": "base", "location": ["INJ"], "managedby": null, "maskedby": null, "screencommand": "/", "source": {' \ '"org.jlab.jaws.entity.EPICSSource": {"pv": "channel1"}}}'