From ebfca09a5fb8f5345e3bc2a1b9ef978507e3a88c Mon Sep 17 00:00:00 2001 From: Ryan Slominski Date: Tue, 27 Aug 2024 16:29:03 -0400 Subject: [PATCH] Updated Schemas to match libp v5.0.0 (#5) https://github.com/JeffersonLab/jaws-libp/releases/tag/v5.0.0 --- deps.yaml | 2 +- .../org/jlab/jaws/clients/ClientTest.java | 43 ++++++++++--------- .../avro/{AlarmInstance.avsc => Alarm.avsc} | 19 ++++++-- .../{AlarmClass.avsc => AlarmAction.avsc} | 8 ++-- .../{AlarmCategory.avsc => AlarmSystem.avsc} | 4 +- src/main/avro/EffectiveRegistration.avsc | 12 +++--- ...tanceConsumer.java => ActionConsumer.java} | 10 ++--- ...tanceProducer.java => ActionProducer.java} | 12 +++--- ...{ClassConsumer.java => AlarmConsumer.java} | 10 ++--- ...{ClassProducer.java => AlarmProducer.java} | 12 +++--- ...egoryConsumer.java => SystemConsumer.java} | 10 ++--- ...egoryProducer.java => SystemProducer.java} | 12 +++--- 12 files changed, 83 insertions(+), 71 deletions(-) rename src/main/avro/{AlarmInstance.avsc => Alarm.avsc} (87%) rename src/main/avro/{AlarmClass.avsc => AlarmAction.avsc} (93%) rename src/main/avro/{AlarmCategory.avsc => AlarmSystem.avsc} (81%) rename src/main/java/org/jlab/jaws/clients/{InstanceConsumer.java => ActionConsumer.java} (73%) rename src/main/java/org/jlab/jaws/clients/{InstanceProducer.java => ActionProducer.java} (79%) rename src/main/java/org/jlab/jaws/clients/{ClassConsumer.java => AlarmConsumer.java} (79%) rename src/main/java/org/jlab/jaws/clients/{ClassProducer.java => AlarmProducer.java} (83%) rename src/main/java/org/jlab/jaws/clients/{CategoryConsumer.java => SystemConsumer.java} (73%) rename src/main/java/org/jlab/jaws/clients/{CategoryProducer.java => SystemProducer.java} (79%) diff --git a/deps.yaml b/deps.yaml index 5940b07..aa41a44 100644 --- a/deps.yaml +++ b/deps.yaml @@ -37,7 +37,7 @@ services: - SCHEMA_REGISTRY_KAFKA_BROKERS=PLAINTEXT://kafka:9092 jaws-libp: - image: jeffersonlab/jaws-libp:4.9.2 + image: jeffersonlab/jaws-libp:5.0.0 tty: true stdin_open: true hostname: jaws-libp diff --git a/src/integration/java/org/jlab/jaws/clients/ClientTest.java b/src/integration/java/org/jlab/jaws/clients/ClientTest.java index 30bf3fb..beb3e0c 100644 --- a/src/integration/java/org/jlab/jaws/clients/ClientTest.java +++ b/src/integration/java/org/jlab/jaws/clients/ClientTest.java @@ -42,20 +42,20 @@ public void setup(){ @Test - public void categoryTest() throws InterruptedException, ExecutionException, TimeoutException { - LinkedHashMap> results = new LinkedHashMap<>(); + public void systemTest() throws InterruptedException, ExecutionException, TimeoutException { + LinkedHashMap> results = new LinkedHashMap<>(); - try(CategoryConsumer consumer = new CategoryConsumer(clientOverrides)) { + try(SystemConsumer consumer = new SystemConsumer(clientOverrides)) { consumer.addListener(new EventSourceListener<>() { @Override - public void highWaterOffset(LinkedHashMap> records) { + public void highWaterOffset(LinkedHashMap> records) { results.putAll(records); } }); - AlarmCategory expected = new AlarmCategory("team1"); + AlarmSystem expected = new AlarmSystem("team1"); - try(CategoryProducer producer = new CategoryProducer(clientOverrides)) { + try(SystemProducer producer = new SystemProducer(clientOverrides)) { Future future = producer.send("TESTING", expected); // Block until sent or an exception is thrown @@ -75,7 +75,7 @@ public void highWaterOffset(LinkedHashMap future = producer.send("TESTING", null); // Block until sent or an exception is thrown @@ -85,18 +85,18 @@ public void highWaterOffset(LinkedHashMap> results = new LinkedHashMap<>(); + public void actionTest() throws InterruptedException, ExecutionException, TimeoutException { + LinkedHashMap> results = new LinkedHashMap<>(); - try(ClassConsumer consumer = new ClassConsumer(clientOverrides)) { + try(ActionConsumer consumer = new ActionConsumer(clientOverrides)) { consumer.addListener(new EventSourceListener<>() { @Override - public void highWaterOffset(LinkedHashMap> records) { + public void highWaterOffset(LinkedHashMap> records) { results.putAll(records); } }); - AlarmClass expected = new AlarmClass("category", + AlarmAction expected = new AlarmAction("system", AlarmPriority.P1_CRITICAL, "rationale", "correctiveaction", @@ -105,7 +105,7 @@ public void highWaterOffset(LinkedHashMap future = producer.send("TESTING", expected); // Block until sent or an exception is thrown @@ -125,7 +125,7 @@ public void highWaterOffset(LinkedHashMap future = producer.send("TESTING", null); // Block until sent or an exception is thrown @@ -135,24 +135,25 @@ public void highWaterOffset(LinkedHashMap> results = new LinkedHashMap<>(); + public void alarmTest() throws InterruptedException, ExecutionException, TimeoutException { + LinkedHashMap> results = new LinkedHashMap<>(); - try(InstanceConsumer consumer = new InstanceConsumer(clientOverrides)) { + try(AlarmConsumer consumer = new AlarmConsumer(clientOverrides)) { consumer.addListener(new EventSourceListener<>() { @Override - public void highWaterOffset(LinkedHashMap> records) { + public void highWaterOffset(LinkedHashMap> records) { results.putAll(records); } }); - AlarmInstance expected = new AlarmInstance("class", "device", + Alarm expected = new Alarm("action", "device", new Source(), Arrays.asList(new String[]{"location1"}), + "managedby", "maskedby", "screencommand"); - try(InstanceProducer producer = new InstanceProducer(clientOverrides)) { + try(AlarmProducer producer = new AlarmProducer(clientOverrides)) { Future future = producer.send("TESTING", expected); // Block until sent or an exception is thrown @@ -172,7 +173,7 @@ public void highWaterOffset(LinkedHashMap future = producer.send("TESTING", null); // Block until sent or an exception is thrown diff --git a/src/main/avro/AlarmInstance.avsc b/src/main/avro/Alarm.avsc similarity index 87% rename from src/main/avro/AlarmInstance.avsc rename to src/main/avro/Alarm.avsc index 8ef46a0..7b06894 100644 --- a/src/main/avro/AlarmInstance.avsc +++ b/src/main/avro/Alarm.avsc @@ -1,16 +1,16 @@ { "type": "record", - "name": "AlarmInstance", + "name": "Alarm", "namespace": "org.jlab.jaws.entity", - "doc": "Instance of an alarm class", + "doc": "An alarm instance", "fields": [ { - "name": "alarmclass", + "name": "action", "type": { "type": "string", "avro.java.string": "String" }, - "doc": "The alarm class; provides inheritable shared values", + "doc": "The alarm action; provides inheritable shared class values", "default": "base" }, { @@ -75,6 +75,17 @@ }, "doc": "The locations associated with the alarm" }, + { + "name": "managedby", + "type": [ + "null", + { + "type": "string", + "avro.java.string": "String" + } + ], + "doc": "Whom manages this alarm" + }, { "name": "maskedby", "type": [ diff --git a/src/main/avro/AlarmClass.avsc b/src/main/avro/AlarmAction.avsc similarity index 93% rename from src/main/avro/AlarmClass.avsc rename to src/main/avro/AlarmAction.avsc index fa57776..bc5fe1c 100644 --- a/src/main/avro/AlarmClass.avsc +++ b/src/main/avro/AlarmAction.avsc @@ -1,16 +1,16 @@ { "type": "record", - "name": "AlarmClass", + "name": "AlarmAction", "namespace": "org.jlab.jaws.entity", - "doc": "An alarm class", + "doc": "An alarm action (class of alarm)", "fields": [ { - "name": "category", + "name": "system", "type": { "type": "string", "avro.java.string": "String" }, - "doc": "The alarm category name" + "doc": "The alarm system name" }, { "name": "priority", diff --git a/src/main/avro/AlarmCategory.avsc b/src/main/avro/AlarmSystem.avsc similarity index 81% rename from src/main/avro/AlarmCategory.avsc rename to src/main/avro/AlarmSystem.avsc index 2ad7597..f79834a 100644 --- a/src/main/avro/AlarmCategory.avsc +++ b/src/main/avro/AlarmSystem.avsc @@ -1,8 +1,8 @@ { "type": "record", - "name": "AlarmCategory", + "name": "AlarmSystem", "namespace": "org.jlab.jaws.entity", - "doc": "Value of a named category", + "doc": "Value of a named system", "fields": [ { "name": "team", diff --git a/src/main/avro/EffectiveRegistration.avsc b/src/main/avro/EffectiveRegistration.avsc index b5f5f95..0375968 100644 --- a/src/main/avro/EffectiveRegistration.avsc +++ b/src/main/avro/EffectiveRegistration.avsc @@ -5,21 +5,21 @@ "doc": "Processed registration (instance + class)", "fields": [ { - "name": "instance", + "name": "alarm", "type": [ "null", - "AlarmInstance" + "Alarm" ], - "doc": "The alarm instance", + "doc": "The alarm registration instance", "default": null }, { - "name": "class", + "name": "action", "type": [ "null", - "AlarmClass" + "AlarmAction" ], - "doc": "The alarm class", + "doc": "The alarm action (class of alarm)", "default": null } ] diff --git a/src/main/java/org/jlab/jaws/clients/InstanceConsumer.java b/src/main/java/org/jlab/jaws/clients/ActionConsumer.java similarity index 73% rename from src/main/java/org/jlab/jaws/clients/InstanceConsumer.java rename to src/main/java/org/jlab/jaws/clients/ActionConsumer.java index dbb3a95..d516076 100644 --- a/src/main/java/org/jlab/jaws/clients/InstanceConsumer.java +++ b/src/main/java/org/jlab/jaws/clients/ActionConsumer.java @@ -1,6 +1,6 @@ package org.jlab.jaws.clients; -import org.jlab.jaws.entity.AlarmInstance; +import org.jlab.jaws.entity.AlarmAction; import org.jlab.kafka.eventsource.EventSourceConfig; import java.time.Instant; @@ -9,13 +9,13 @@ /** * A Consumer provides default properties values for GROUP, TOPIC, KEY_DESERIALIZER, and VALUE_DESERIALIZER. */ -public class InstanceConsumer extends JAWSConsumer { +public class ActionConsumer extends JAWSConsumer { /** * Create a new Consumer with the provided property overrides. * * @param props The properties, which will override any defaults set by this class */ - public InstanceConsumer(Properties props) { + public ActionConsumer(Properties props) { super(setDefaults(props)); } @@ -26,8 +26,8 @@ private static Properties setDefaults(Properties overrides) { overrides = new Properties(); } - defaults.put(EventSourceConfig.GROUP_ID_CONFIG, "instance-consumer" + Instant.now().toString() + "-" + Math.random()); - defaults.put(EventSourceConfig.TOPIC_CONFIG, InstanceProducer.TOPIC); + defaults.put(EventSourceConfig.GROUP_ID_CONFIG, "action-consumer" + Instant.now().toString() + "-" + Math.random()); + defaults.put(EventSourceConfig.TOPIC_CONFIG, ActionProducer.TOPIC); defaults.put(EventSourceConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); defaults.put(EventSourceConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.KafkaAvroDeserializer"); diff --git a/src/main/java/org/jlab/jaws/clients/InstanceProducer.java b/src/main/java/org/jlab/jaws/clients/ActionProducer.java similarity index 79% rename from src/main/java/org/jlab/jaws/clients/InstanceProducer.java rename to src/main/java/org/jlab/jaws/clients/ActionProducer.java index ea15a21..19a5be1 100644 --- a/src/main/java/org/jlab/jaws/clients/InstanceProducer.java +++ b/src/main/java/org/jlab/jaws/clients/ActionProducer.java @@ -4,7 +4,7 @@ import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; import org.apache.kafka.common.header.Header; -import org.jlab.jaws.entity.AlarmInstance; +import org.jlab.jaws.entity.AlarmAction; import java.time.Instant; import java.util.Properties; @@ -14,18 +14,18 @@ * A Producer provides default properties values for CLIENT_ID, TOPIC, KEY_DESERIALIZER, and VALUE_DESERIALIZER. * A default send method is also provided. */ -public class InstanceProducer extends JAWSProducer { +public class ActionProducer extends JAWSProducer { /** * The topic name */ - public static final String TOPIC = "alarm-instances"; + public static final String TOPIC = "alarm-actions"; /** * Create a new Producer with the provided property overrides. * * @param props The properties, which will override any defaults set by this class */ - public InstanceProducer(Properties props) { + public ActionProducer(Properties props) { super(setDefaults(props)); } @@ -36,7 +36,7 @@ private static Properties setDefaults(Properties overrides) { overrides = new Properties(); } - defaults.put(ProducerConfig.CLIENT_ID_CONFIG, "instance-producer" + Instant.now().toString() + "-" + Math.random()); + defaults.put(ProducerConfig.CLIENT_ID_CONFIG, "action-producer" + Instant.now().toString() + "-" + Math.random()); defaults.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer"); defaults.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.KafkaAvroSerializer"); @@ -52,7 +52,7 @@ private static Properties setDefaults(Properties overrides) { * @param value The message value * @return An asynchronous call Future reference */ - public Future send(String key, AlarmInstance value) { + public Future send(String key, AlarmAction value) { Iterable
headers = getDefaultHeaders(); diff --git a/src/main/java/org/jlab/jaws/clients/ClassConsumer.java b/src/main/java/org/jlab/jaws/clients/AlarmConsumer.java similarity index 79% rename from src/main/java/org/jlab/jaws/clients/ClassConsumer.java rename to src/main/java/org/jlab/jaws/clients/AlarmConsumer.java index 5a75d37..8c85585 100644 --- a/src/main/java/org/jlab/jaws/clients/ClassConsumer.java +++ b/src/main/java/org/jlab/jaws/clients/AlarmConsumer.java @@ -1,6 +1,6 @@ package org.jlab.jaws.clients; -import org.jlab.jaws.entity.AlarmClass; +import org.jlab.jaws.entity.Alarm; import org.jlab.kafka.eventsource.EventSourceConfig; import java.time.Instant; @@ -9,13 +9,13 @@ /** * A Consumer provides default properties values for GROUP, TOPIC, KEY_DESERIALIZER, and VALUE_DESERIALIZER. */ -public class ClassConsumer extends JAWSConsumer { +public class AlarmConsumer extends JAWSConsumer { /** * Create a new Consumer with the provided property overrides. * * @param props The properties, which will override any defaults set by this class */ - public ClassConsumer(Properties props) { + public AlarmConsumer(Properties props) { super(setDefaults(props)); } @@ -26,8 +26,8 @@ private static Properties setDefaults(Properties overrides) { overrides = new Properties(); } - defaults.put(EventSourceConfig.GROUP_ID_CONFIG, "class-consumer" + Instant.now().toString() + "-" + Math.random()); - defaults.put(EventSourceConfig.TOPIC_CONFIG, ClassProducer.TOPIC); + defaults.put(EventSourceConfig.GROUP_ID_CONFIG, "alarm-consumer" + Instant.now().toString() + "-" + Math.random()); + defaults.put(EventSourceConfig.TOPIC_CONFIG, AlarmProducer.TOPIC); defaults.put(EventSourceConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); defaults.put(EventSourceConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.KafkaAvroDeserializer"); diff --git a/src/main/java/org/jlab/jaws/clients/ClassProducer.java b/src/main/java/org/jlab/jaws/clients/AlarmProducer.java similarity index 83% rename from src/main/java/org/jlab/jaws/clients/ClassProducer.java rename to src/main/java/org/jlab/jaws/clients/AlarmProducer.java index b3e1d91..ac356dc 100644 --- a/src/main/java/org/jlab/jaws/clients/ClassProducer.java +++ b/src/main/java/org/jlab/jaws/clients/AlarmProducer.java @@ -4,7 +4,7 @@ import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; import org.apache.kafka.common.header.Header; -import org.jlab.jaws.entity.AlarmClass; +import org.jlab.jaws.entity.Alarm; import java.time.Instant; import java.util.Properties; @@ -14,18 +14,18 @@ * A Producer provides default properties values for CLIENT_ID, TOPIC, KEY_DESERIALIZER, and VALUE_DESERIALIZER. * A default send method is also provided. */ -public class ClassProducer extends JAWSProducer { +public class AlarmProducer extends JAWSProducer { /** * The topic name */ - public static final String TOPIC = "alarm-classes"; + public static final String TOPIC = "alarms"; /** * Create a new Producer with the provided property overrides. * * @param props The properties, which will override any defaults set by this class */ - public ClassProducer(Properties props) { + public AlarmProducer(Properties props) { super(setDefaults(props)); } @@ -36,7 +36,7 @@ private static Properties setDefaults(Properties overrides) { overrides = new Properties(); } - defaults.put(ProducerConfig.CLIENT_ID_CONFIG, "class-producer" + Instant.now().toString() + "-" + Math.random()); + defaults.put(ProducerConfig.CLIENT_ID_CONFIG, "alarm-producer" + Instant.now().toString() + "-" + Math.random()); defaults.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer"); defaults.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.KafkaAvroSerializer"); @@ -52,7 +52,7 @@ private static Properties setDefaults(Properties overrides) { * @param value The message value * @return An asynchronous call Future reference */ - public Future send(String key, AlarmClass value) { + public Future send(String key, Alarm value) { Iterable
headers = getDefaultHeaders(); diff --git a/src/main/java/org/jlab/jaws/clients/CategoryConsumer.java b/src/main/java/org/jlab/jaws/clients/SystemConsumer.java similarity index 73% rename from src/main/java/org/jlab/jaws/clients/CategoryConsumer.java rename to src/main/java/org/jlab/jaws/clients/SystemConsumer.java index 12b8184..07e05c0 100644 --- a/src/main/java/org/jlab/jaws/clients/CategoryConsumer.java +++ b/src/main/java/org/jlab/jaws/clients/SystemConsumer.java @@ -1,6 +1,6 @@ package org.jlab.jaws.clients; -import org.jlab.jaws.entity.AlarmCategory; +import org.jlab.jaws.entity.AlarmSystem; import org.jlab.kafka.eventsource.EventSourceConfig; import java.time.Instant; @@ -9,13 +9,13 @@ /** * A Consumer provides default properties values for GROUP, TOPIC, KEY_DESERIALIZER, and VALUE_DESERIALIZER. */ -public class CategoryConsumer extends JAWSConsumer { +public class SystemConsumer extends JAWSConsumer { /** * Create a new Consumer with the provided property overrides. * * @param props The properties, which will override any defaults set by this class */ - public CategoryConsumer(Properties props) { + public SystemConsumer(Properties props) { super(setDefaults(props)); } @@ -26,8 +26,8 @@ private static Properties setDefaults(Properties overrides) { overrides = new Properties(); } - defaults.put(EventSourceConfig.GROUP_ID_CONFIG, "category-consumer" + Instant.now().toString() + "-" + Math.random()); - defaults.put(EventSourceConfig.TOPIC_CONFIG, CategoryProducer.TOPIC); + defaults.put(EventSourceConfig.GROUP_ID_CONFIG, "system-consumer" + Instant.now().toString() + "-" + Math.random()); + defaults.put(EventSourceConfig.TOPIC_CONFIG, SystemProducer.TOPIC); defaults.put(EventSourceConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); defaults.put(EventSourceConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.KafkaAvroDeserializer"); diff --git a/src/main/java/org/jlab/jaws/clients/CategoryProducer.java b/src/main/java/org/jlab/jaws/clients/SystemProducer.java similarity index 79% rename from src/main/java/org/jlab/jaws/clients/CategoryProducer.java rename to src/main/java/org/jlab/jaws/clients/SystemProducer.java index 0d4377b..1da2950 100644 --- a/src/main/java/org/jlab/jaws/clients/CategoryProducer.java +++ b/src/main/java/org/jlab/jaws/clients/SystemProducer.java @@ -4,7 +4,7 @@ import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; import org.apache.kafka.common.header.Header; -import org.jlab.jaws.entity.AlarmCategory; +import org.jlab.jaws.entity.AlarmSystem; import java.time.Instant; import java.util.Properties; @@ -14,18 +14,18 @@ * A Producer provides default properties values for CLIENT_ID, TOPIC, KEY_DESERIALIZER, and VALUE_DESERIALIZER. * A default send method is also provided. */ -public class CategoryProducer extends JAWSProducer { +public class SystemProducer extends JAWSProducer { /** * The topic name */ - public static final String TOPIC = "alarm-categories"; + public static final String TOPIC = "alarm-systems"; /** * Create a new Producer with the provided property overrides. * * @param props The properties, which will override any defaults set by this class */ - public CategoryProducer(Properties props) { + public SystemProducer(Properties props) { super(setDefaults(props)); } @@ -36,7 +36,7 @@ private static Properties setDefaults(Properties overrides) { overrides = new Properties(); } - defaults.put(ProducerConfig.CLIENT_ID_CONFIG, "category-producer" + Instant.now().toString() + "-" + Math.random()); + defaults.put(ProducerConfig.CLIENT_ID_CONFIG, "system-producer" + Instant.now().toString() + "-" + Math.random()); defaults.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer"); defaults.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.KafkaAvroSerializer"); @@ -52,7 +52,7 @@ private static Properties setDefaults(Properties overrides) { * @param value The message value * @return An asynchronous call Future reference */ - public Future send(String key, AlarmCategory value) { + public Future send(String key, AlarmSystem value) { Iterable
headers = getDefaultHeaders();