Skip to content

Commit

Permalink
Rename AlarmInstance to Alarm (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
slominskir authored Aug 27, 2024
1 parent e857cc1 commit 694ee61
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 194 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions container/app/container-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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='|'
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/jaws_libp/avro/schema-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/jaws_libp/avro/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* :download:`AlarmOverrideKey.avsc </../../src/jaws_libp/avro/schemas/AlarmOverrideKey.avsc>`
* :download:`AlarmOverrideSet.avsc </../../src/jaws_libp/avro/schemas/AlarmOverrideSet.avsc>`
* :download:`AlarmOverrideUnion.avsc </../../src/jaws_libp/avro/schemas/AlarmOverrideUnion.avsc>`
* :download:`AlarmInstance.avsc </../../src/jaws_libp/avro/schemas/AlarmInstance.avsc>`
* :download:`Alarm.avsc </../../src/jaws_libp/avro/schemas/Alarm.avsc>`
* :download:`AlarmState.avsc </../../src/jaws_libp/avro/schemas/AlarmState.avsc>`
* :download:`DisabledOverride.avsc </../../src/jaws_libp/avro/schemas/DisabledOverride.avsc>`
* :download:`EffectiveNotification.avsc </../../src/jaws_libp/avro/schemas/EffectiveNotification.avsc>`
Expand Down
54 changes: 27 additions & 27 deletions src/jaws_libp/avro/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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):
Expand All @@ -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']

Expand All @@ -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):
Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/jaws_libp/avro/topics.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alarm-activations",
"alarm-categories",
"alarm-actions",
"alarm-instances",
"alarms",
"alarm-locations",
"alarm-overrides",
"intermediate-registration",
Expand Down
Loading

0 comments on commit 694ee61

Please sign in to comment.