diff --git a/tests/upgrade.trace/devices/AHU-1/002_state_system.json b/tests/upgrade.trace/devices/AHU-1/002_state_system.json new file mode 100644 index 0000000000..34631cc15e --- /dev/null +++ b/tests/upgrade.trace/devices/AHU-1/002_state_system.json @@ -0,0 +1,8 @@ +{ + "firmware" : { + "version" : [ "D_IP_BW6_V35_6_S14" ] + }, + "last_config" : "2021-05-14T15:53:26Z", + "make_model" : "Delmatic IP_BW6", + "operational" : true +} diff --git a/tests/upgrade.trace/expected/devices/AHU-1/state_system.attr b/tests/upgrade.trace/expected/devices/AHU-1/state_system.attr new file mode 100644 index 0000000000..f509edfbf2 --- /dev/null +++ b/tests/upgrade.trace/expected/devices/AHU-1/state_system.attr @@ -0,0 +1,9 @@ +{ + "deviceNumId" : "00000062256946", + "subFolder" : "system", + "deviceRegistryId" : "ZZ-TRI-FECTA", + "subType" : "state", + "msgSource" : "002_state_system.json", + "deviceId" : "AHU-1", + "projectId" : "playback-project" +} \ No newline at end of file diff --git a/tests/upgrade.trace/expected/devices/AHU-1/state_system.json b/tests/upgrade.trace/expected/devices/AHU-1/state_system.json new file mode 100644 index 0000000000..1517520a18 --- /dev/null +++ b/tests/upgrade.trace/expected/devices/AHU-1/state_system.json @@ -0,0 +1,13 @@ +{ + "hardware" : { + "model" : "Delmatic IP_BW6", + "make" : "unknown" + }, + "last_config" : "1999-10-20T01:02:03Z", + "operation" : { + "operational" : true + }, + "software" : { + "firmware" : [ "D_IP_BW6_V35_6_S14" ] + } +} \ No newline at end of file diff --git a/tests/upgrade.trace/expected/devices/AHU-1/state_system.out b/tests/upgrade.trace/expected/devices/AHU-1/state_system.out new file mode 100644 index 0000000000..3062256e3b --- /dev/null +++ b/tests/upgrade.trace/expected/devices/AHU-1/state_system.out @@ -0,0 +1,26 @@ +{ + "timestamp" : "1999-10-20T01:02:03Z", + "version" : "1.4.0", + "sub_folder" : "system", + "sub_type" : "state", + "status" : { + "message" : "While converting to json node: 2 schema violations found", + "detail" : "state_system: While converting to json node: 2 schema violations found @Validator.validateMessage(redacted); 2 schema violations found; object has missing required properties ([\"serial_no\"]); /software/firmware: instance type (array) does not match any allowed primitive type (allowed: [\"string\"])", + "category" : "validation.device.schema", + "timestamp" : "1999-10-20T01:02:03Z", + "level" : 500 + }, + "errors" : [ { + "message" : "While converting to json node: 2 schema violations found", + "detail" : "state_update: While converting to json node: 2 schema violations found @Validator.validateMessage(redacted); 2 schema violations found; /system: object has missing required properties ([\"serial_no\"]); /system/software/firmware: instance type (array) does not match any allowed primitive type (allowed: [\"string\"])", + "category" : "validation.device.schema", + "timestamp" : "1999-10-20T01:02:03Z", + "level" : 500 + }, { + "message" : "While converting to json node: 2 schema violations found", + "detail" : "state_system: While converting to json node: 2 schema violations found @Validator.validateMessage(redacted); 2 schema violations found; object has missing required properties ([\"serial_no\"]); /software/firmware: instance type (array) does not match any allowed primitive type (allowed: [\"string\"])", + "category" : "validation.device.schema", + "timestamp" : "1999-10-20T01:02:03Z", + "level" : 500 + } ] +} diff --git a/tests/upgrade.trace/expected/validation_report.json b/tests/upgrade.trace/expected/validation_report.json index 123482ac01..69c083d6fc 100644 --- a/tests/upgrade.trace/expected/validation_report.json +++ b/tests/upgrade.trace/expected/validation_report.json @@ -13,9 +13,9 @@ "AHU-1" : { "last_seen" : "1999-10-20T01:02:03Z", "status" : { - "message" : "While converting to json node: 2 schema violations found", - "detail" : "state_update: While converting to json node: 2 schema violations found @Validator.validateMessage(redacted); 2 schema violations found; /system: object has missing required properties ([\"serial_no\"]); /system/software/firmware: instance type (array) does not match any allowed primitive type (allowed: [\"string\"])", - "category" : "validation.device.schema", + "message" : "Multiple validation errors", + "detail" : "While converting to json node: 2 schema violations found; While converting to json node: 2 schema violations found", + "category" : "validation.device.multiple", "timestamp" : "1999-10-20T01:02:03Z", "level" : 500 } 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 e4aefcd4d6..53fbb4c497 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 @@ -20,6 +20,7 @@ import com.google.bos.iot.core.proxy.IotReflectorClient; import com.google.bos.iot.core.proxy.MockPublisher; import com.google.common.base.Joiner; +import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -227,7 +228,10 @@ static void ensureValidatorConfig() { } private static void reportLoadingErrors(SiteModel model) { - Exception exception = model.getMetadata(validatorConfig.device_id).exception; + String deviceId = validatorConfig.device_id; + checkState(model.allDeviceIds().contains(deviceId), + String.format("device_id %s not found in site model", deviceId)); + Exception exception = model.getMetadata(deviceId).exception; if (exception != null) { System.err.println("Device loading error: " + exception.getMessage()); } @@ -1482,7 +1486,9 @@ static void processComplete(Exception e) { statusEntry.timestamp = new Date(); statusEntry.message = wasError ? Common.getExceptionMessage(e) : "Run completed"; statusEntry.category = SEQUENCER_CATEGORY; - validationState.status = statusEntry; - updateValidationState(); + if (validationState != null) { + validationState.status = statusEntry; + updateValidationState(); + } } } diff --git a/validator/src/main/java/com/google/daq/mqtt/sequencer/SequenceRunner.java b/validator/src/main/java/com/google/daq/mqtt/sequencer/SequenceRunner.java index f29dcc7f0a..5caced59d3 100644 --- a/validator/src/main/java/com/google/daq/mqtt/sequencer/SequenceRunner.java +++ b/validator/src/main/java/com/google/daq/mqtt/sequencer/SequenceRunner.java @@ -129,6 +129,7 @@ private void process() { processRaw(); SequenceBase.processComplete(null); } catch (Exception e) { + e.printStackTrace(); SequenceBase.processComplete(e); } } diff --git a/validator/src/main/java/com/google/daq/mqtt/util/MessageUpgrader.java b/validator/src/main/java/com/google/daq/mqtt/util/MessageUpgrader.java index a2803aead3..7dd6c7336c 100644 --- a/validator/src/main/java/com/google/daq/mqtt/util/MessageUpgrader.java +++ b/validator/src/main/java/com/google/daq/mqtt/util/MessageUpgrader.java @@ -13,9 +13,10 @@ public class MessageUpgrader { public static final JsonNodeFactory NODE_FACTORY = JsonNodeFactory.instance; public static final String STATE_SCHEMA = "state"; + public static final String STATE_SCHEMA_PREFIX = "state_"; public static final String METADATA_SCHEMA = "metadata"; private static final String TARGET_FORMAT = "%d.%d.%d"; - private final JsonNode message; + private final ObjectNode message; private final String schemaName; private final int major; private int patch; @@ -28,7 +29,7 @@ public class MessageUpgrader { * @param message message to be upgraded */ public MessageUpgrader(String schemaName, JsonNode message) { - this.message = message; + this.message = (ObjectNode) message; this.schemaName = schemaName; JsonNode version = message.get(VERSION_KEY); @@ -99,7 +100,7 @@ public boolean upgrade(boolean forceUpgrade) { } private void upgrade_1_3_14() { - if (STATE_SCHEMA.equals(schemaName)) { + if (STATE_SCHEMA.equals(schemaName) || schemaName.startsWith(STATE_SCHEMA_PREFIX)) { upgrade_1_3_14_state(); } if (METADATA_SCHEMA.equals(schemaName)) { @@ -108,7 +109,7 @@ private void upgrade_1_3_14() { } private void upgrade_1_3_14_state() { - ObjectNode system = (ObjectNode) message.get("system"); + ObjectNode system = getStateSystemNode(); if (system != null) { upgradeMakeModel(system); upgradeFirmware(system); @@ -128,13 +129,13 @@ private void upgrade_1_3_14_metadata() { } private void upgrade_1_4_1() { - if (STATE_SCHEMA.equals(schemaName)) { + if (STATE_SCHEMA.equals(schemaName) || schemaName.startsWith(STATE_SCHEMA_PREFIX)) { upgrade_1_4_1_state(); } } private void upgrade_1_4_1_state() { - ObjectNode system = (ObjectNode) message.get("system"); + ObjectNode system = getStateSystemNode(); if (system != null) { assertFalse("operation key in older version", system.has("operation")); JsonNode operational = system.remove("operational"); @@ -146,6 +147,10 @@ private void upgrade_1_4_1_state() { } } + private ObjectNode getStateSystemNode() { + return schemaName.equals(STATE_SCHEMA) ? ((ObjectNode) message.get("system")) : message; + } + private void assertFalse(String message, boolean value) { if (value) { throw new RuntimeException(message);