Skip to content

Commit

Permalink
Fix sequencer and validator regressions (#613)
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu authored Mar 8, 2023
1 parent 8b20e80 commit 337896b
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 12 deletions.
8 changes: 8 additions & 0 deletions tests/upgrade.trace/devices/AHU-1/002_state_system.json
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions tests/upgrade.trace/expected/devices/AHU-1/state_system.attr
Original file line number Diff line number Diff line change
@@ -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"
}
13 changes: 13 additions & 0 deletions tests/upgrade.trace/expected/devices/AHU-1/state_system.json
Original file line number Diff line number Diff line change
@@ -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" ]
}
}
26 changes: 26 additions & 0 deletions tests/upgrade.trace/expected/devices/AHU-1/state_system.out
Original file line number Diff line number Diff line change
@@ -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
} ]
}
6 changes: 3 additions & 3 deletions tests/upgrade.trace/expected/validation_report.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private void process() {
processRaw();
SequenceBase.processComplete(null);
} catch (Exception e) {
e.printStackTrace();
SequenceBase.processComplete(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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);
Expand Down

0 comments on commit 337896b

Please sign in to comment.