Skip to content

Commit

Permalink
Refactor validation to consolidate validation function (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu authored Nov 23, 2024
1 parent 9e9ccf8 commit 7e0f810
Show file tree
Hide file tree
Showing 21 changed files with 381 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
spelling:
name: Docs Spelling Checks
runs-on: ubuntu-latest
timeout-minutes: 1
timeout-minutes: 2
steps:
- uses: actions/checkout@v4
- name: Check Spelling
Expand Down
4 changes: 2 additions & 2 deletions bin/test_schema
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ upgrade=
schemadir=schema
testdir=tests/schemas/
outroot=out
rm -rf outroot/tests
rm -rf $outroot/tests

while getopts "d:s:fnu" opt; do
case $opt in
Expand Down Expand Up @@ -69,7 +69,7 @@ for subset in $subsets; do
reldir=$(realpath --relative-to $schemadir $testdir)
reltest=$reldir:$subset
fi
cmd="$javarun -a $schemaname $upgrade -f $reltest"
cmd="$javarun -n -a $schemaname $upgrade -f $reltest"
echo $cmd
(cd $schemadir; $cmd) || true

Expand Down
15 changes: 15 additions & 0 deletions common/src/main/java/com/google/daq/mqtt/util/ExceptionList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.google.daq.mqtt.util;

import static java.lang.String.format;

import java.util.List;

public class ExceptionList extends RuntimeException {

private final List<Exception> list;

public ExceptionList(List<Exception> list) {
super(format("List of %d exceptions", list.size()));
this.list = list;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.google.udmi.util;

import static com.google.common.base.Preconditions.checkState;
import static com.google.udmi.util.GeneralUtils.friendlyStackTrace;
import static com.google.udmi.util.GeneralUtils.ifNotNullThen;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
import static java.util.Objects.nonNull;
Expand Down Expand Up @@ -119,7 +120,7 @@ public List<String> processArgs(List<String> argList) {
}
return null;
} catch (Exception e) {
showUsage(e.getMessage());
showUsage(friendlyStackTrace(e));
return null;
}
}
Expand Down
20 changes: 10 additions & 10 deletions etc/validator.out
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ sites/udmi_site_model/out/devices/AHU-1/events_pointset.out
"sub_type" : "events",
"status" : {
"message" : "Multiple validation errors",
"detail" : "Timestamp skew REDACTED_DURATION (REDACTED_TIMESTAMP to REDACTED_TIMESTAMP) exceeds REDACTED_DURATION threshold; While converting to json node: 1 schema violations found",
"detail" : "Timestamp skew REDACTED_DURATION (REDACTED_TIMESTAMP to REDACTED_TIMESTAMP) exceeds REDACTED_DURATION threshold; 1 schema violations found",
"category" : "validation.device.multiple",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand All @@ -82,8 +82,8 @@ sites/udmi_site_model/out/devices/AHU-1/events_pointset.out
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
}, {
"message" : "While converting to json node: 1 schema violations found",
"detail" : "events_pointset: While converting to json node: 1 schema violations found REDACTED_ERROR; 1 schema violations found; object instance has properties which are not allowed by the schema: [\"extraField\"]",
"message" : "1 schema violations found",
"detail" : "events_pointset: 1 schema violations found; object instance has properties which are not allowed by the schema: [\"extraField\"]",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand Down Expand Up @@ -145,7 +145,7 @@ sites/udmi_site_model/out/devices/AHU-1/state.out
"sub_type" : "state",
"status" : {
"message" : "Multiple validation errors",
"detail" : "Timestamp skew REDACTED_DURATION (REDACTED_TIMESTAMP to REDACTED_TIMESTAMP) exceeds REDACTED_DURATION threshold; While converting to json node: 1 schema violations found",
"detail" : "Timestamp skew REDACTED_DURATION (REDACTED_TIMESTAMP to REDACTED_TIMESTAMP) exceeds REDACTED_DURATION threshold; 1 schema violations found",
"category" : "validation.device.multiple",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand All @@ -157,8 +157,8 @@ sites/udmi_site_model/out/devices/AHU-1/state.out
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
}, {
"message" : "While converting to json node: 1 schema violations found",
"detail" : "state_update: While converting to json node: 1 schema violations found REDACTED_ERROR; 1 schema violations found; /system: object instance has properties which are not allowed by the schema: [\"extraField\"]",
"message" : "1 schema violations found",
"detail" : "state_update: 1 schema violations found; /system: object instance has properties which are not allowed by the schema: [\"extraField\"]",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand Down Expand Up @@ -411,15 +411,15 @@ sites/udmi_site_model/out/devices/GAT-123/events_discovery.out
"sub_folder" : "discovery",
"sub_type" : "events",
"status" : {
"message" : "While converting to json node: 1 schema violations found",
"detail" : "events_discovery: While converting to json node: 1 schema violations found REDACTED_ERROR; 1 schema violations found; object has missing required properties ([\"scan_family\"])",
"message" : "1 schema violations found",
"detail" : "events_discovery: 1 schema violations found; object has missing required properties ([\"scan_family\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
},
"errors" : [ {
"message" : "While converting to json node: 1 schema violations found",
"detail" : "events_discovery: While converting to json node: 1 schema violations found REDACTED_ERROR; 1 schema violations found; object has missing required properties ([\"scan_family\"])",
"message" : "1 schema violations found",
"detail" : "events_discovery: 1 schema violations found; object has missing required properties ([\"scan_family\"])",
"category" : "validation.device.schema",
"timestamp" : "REDACTED_TIMESTAMP",
"level" : 500
Expand Down
245 changes: 245 additions & 0 deletions tests/schemas/events_discovery/discovery_node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
{
"timestamp": "2024-11-21T12:10:46Z",
"version": "1.5.1",
"generation": "2024-11-21T12:09:30Z",
"scan_family": "bacnet",
"scan_addr": "10117",
"event_no": 9,
"families": {
"ipv4": {
"addr": "192.168.1.131"
}
},
"refs": {
"AI:1": {
"name": "FCU_1180 Room Temp",
"possible_values": [],
"units": "degreesCelsius",
"description": "",
"ancillary": {
"present_value": 20.488115310668945
}
},
"AI:2": {
"name": "FCU_1180 Supply Air Temp",
"possible_values": [],
"units": "degreesCelsius",
"description": "",
"ancillary": {
"present_value": 20.14183235168457
}
},
"AO:1": {
"name": "FCU_1180 Heating Valve",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 0.0
}
},
"AO:2": {
"name": "FCU_1180 Cooling Valve",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 0.0
}
},
"AO:3": {
"name": "FCU_1180 Fan Speed",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 70.0
}
},
"AV:1": {
"name": "FCU_1180 Setpoint",
"possible_values": [],
"units": "degreesCelsius",
"description": "",
"ancillary": {
"present_value": 20.0
}
},
"AV:2": {
"name": "FCU_1180 Min Fan Speed",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 20.0
}
},
"AV:3": {
"name": "FCU_1180 Max Fan Speed",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 100.0
}
},
"AV:4": {
"name": "FCU_1180 Design Fan Speed",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 70.0
}
},
"AV:5": {
"name": "FCU_1180 Design Heating Valve Position",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 75.0
}
},
"AV:6": {
"name": "FCU_1180 Design Cooling Valve Position",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 67.0
}
},
"AV:7": {
"name": "FCU_1180 Mode_Mimic",
"possible_values": [],
"units": "noUnits",
"description": "",
"ancillary": {
"present_value": 1.0
}
},
"AV:9991": {
"name": "FCU_1180 Comfort KPI Score (Live)",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 69.89265441894531
}
},
"AV:9992": {
"name": "FCU_1180 Comfort KPI Score (Yesterday)",
"possible_values": [],
"units": "percent",
"description": "",
"ancillary": {
"present_value": 69.99639129638672
}
},
"BI:3": {
"name": "FCU_1180 Fan Status",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": "active"
}
},
"BI:4": {
"name": "FCU_1180 Occupancy",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": "active"
}
},
"BO:4": {
"name": "FCU_1180 Enable",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": "active"
}
},
"BV:1": {
"name": "FCU_1180 BMS Remote",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": "active"
}
},
"BV:2": {
"name": "FCU_1180 FCU Run Status",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": "active"
}
},
"BV:9991": {
"name": "FCU_1180 Within Bounds",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": "active"
}
},
"MSV:1": {
"name": "FCU_1180 Mode",
"possible_values": [
"Auto_",
"On_",
"Off_",
"Flushing_",
"Commissioning_"
],
"description": "",
"ancillary": {
"present_value": 1
}
},
"LP:1": {
"name": "FCU_101 Valve Control Loop",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": 50.0
}
},
"LP:2": {
"name": "FCU_101 Fan Control Loop",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": 50.0
}
},
"CSV:1": {
"name": "Google Cloud IoT Gateway Configuration",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": "{\n \"hostName\": \"mqtt.bos.goog\",\n \"tcpPort\": 8883,\n \"location\": \"us-central1\",\n \"project\": \"bos-platform-testing\",\n \"registry\": \"UK-LON-GLAB\",\n \"device\": \"DDC-17\"\n}"
}
},
"CSV:1000001": {
"name": "BLE PIN",
"possible_values": [],
"description": "",
"ancillary": {
"present_value": "800700"
}
}
},
"system": {
"serial_no": "141557/0009",
"ancillary": {
"name": "DDC-17"
},
"hardware": {
"make": "Delta Controls Inc.",
"model": "Red5-PLUS-1180"
}
}
}
Empty file.
2 changes: 1 addition & 1 deletion tests/schemas/events_discovery/node.out
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1 schema violations found
/system: object instance has properties which are not allowed by the schema: ["software"]
/system: object instance has properties which are not allowed by the schema: ["software"]
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"sub_folder" : "pointset",
"sub_type" : "events",
"status" : {
"message" : "While converting to json node: 2 schema violations found",
"detail" : "events_pointset: While converting to json node: 2 schema violations found @Validator.validateMessage(REDACTED); 2 schema violations found; object instance has properties which are not allowed by the schema: [\"yesvalue\"]; object has missing required properties ([\"version\"])",
"message" : "2 schema violations found",
"detail" : "events_pointset: 2 schema violations found; object instance has properties which are not allowed by the schema: [\"yesvalue\"]; object has missing required properties ([\"version\"])",
"category" : "validation.device.schema",
"timestamp" : "1999-10-20T01:02:03Z",
"level" : 500
Expand All @@ -15,8 +15,8 @@
"extra" : [ ]
},
"errors" : [ {
"message" : "While converting to json node: 2 schema violations found",
"detail" : "events_pointset: While converting to json node: 2 schema violations found @Validator.validateMessage(REDACTED); 2 schema violations found; object instance has properties which are not allowed by the schema: [\"yesvalue\"]; object has missing required properties ([\"version\"])",
"message" : "2 schema violations found",
"detail" : "events_pointset: 2 schema violations found; object instance has properties which are not allowed by the schema: [\"yesvalue\"]; object has missing required properties ([\"version\"])",
"category" : "validation.device.schema",
"timestamp" : "1999-10-20T01:02:03Z",
"level" : 500
Expand Down
Loading

0 comments on commit 7e0f810

Please sign in to comment.