From 83674e97d41e19103dcdb2614a90c4b9413ca710 Mon Sep 17 00:00:00 2001 From: Trevor Pering Date: Wed, 6 Nov 2024 00:51:58 -0800 Subject: [PATCH] Fix error handling for received state with no-state --- bin/augment_metadata | 6 +++--- .../java/com/google/daq/mqtt/sequencer/SequenceBase.java | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/augment_metadata b/bin/augment_metadata index d48f6ddf71..1cc4cb3d3c 100755 --- a/bin/augment_metadata +++ b/bin/augment_metadata @@ -6,17 +6,17 @@ # if [[ $# -lt 2 ]]; then - echo Usage: $0 SITE_DIR DEVICE_ID [PUBBER_OPTS...] + echo Usage: $0 SITE_DIR DEVICE_ID [METADATA_OPTS...] false fi site_dir=$(realpath $1) device_id=$2 shift 2 -pubber_opts=$* +metadata_opts=$* nostate=false -if [[ $pubber_opts =~ noState ]]; then +if [[ $metadata_opts =~ noState ]]; then nostate=true fi diff --git a/validator/src/main/java/com/google/daq/mqtt/sequencer/SequenceBase.java b/validator/src/main/java/com/google/daq/mqtt/sequencer/SequenceBase.java index 8b03c72326..b103f012c2 100644 --- a/validator/src/main/java/com/google/daq/mqtt/sequencer/SequenceBase.java +++ b/validator/src/main/java/com/google/daq/mqtt/sequencer/SequenceBase.java @@ -179,6 +179,7 @@ public class SequenceBase { public static final int SCHEMA_SCORE_TOTAL = 10; public static final int CAPABILITY_SCORE = 1; public static final String STATUS_LEVEL_VIOLATION = "STATUS_LEVEL"; + public static final String RECEIVED_STATE_VIOLATION = "RECEIVED_STATE"; public static final String DEVICE_STATE_SCHEMA = "device_state"; private static final String ALL_CHANGES = ""; private static final int SEQUENCER_FUNCTIONS_VERSION = Validator.TOOLS_FUNCTIONS_VERSION; @@ -1880,7 +1881,12 @@ private synchronized void handleUpdateMessage(String subTypeRaw, isoConvert(stateCutoffThreshold), lastStart, txnId)); return; } - checkState(deviceSupportsState(), "Received state update with no-state device"); + if (!deviceSupportsState()) { + String violation = "Received state update with no-state device"; + warning(violation); + deviceStateViolations.put(RECEIVED_STATE_VIOLATION, violation); + return; + } boolean deltaState = RECV_STATE_DIFFERNATOR.isInitialized(); List stateChanges = RECV_STATE_DIFFERNATOR.computeChanges(converted); Instant start = ofNullable(convertedState.timestamp).orElseGet(Date::new).toInstant();