Skip to content

Commit

Permalink
Unique discovery keys (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu committed Aug 2, 2022
1 parent e414f10 commit 8007b0e
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 201 deletions.
10 changes: 5 additions & 5 deletions .gencode_hash.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
3cd595a2ef2e148e6b1a4e7e12a52c4da8b6ecf1222826ca5656ace77be82d05 gencode/docs/config.html
e2944b13db5ff06be9caea51d03bca48f2cb093a8bb583dca14051255d34ea6b gencode/docs/envelope.html
04b55d0e207495a1c471423a5e89347342241bbd3c845de3e8355209692eb70a gencode/docs/event_discovery.html
368f12b9b695b31d97e65509c461f56c12762ec50b9baff89fd7fd85713e8fce gencode/docs/event_discovery.html
8133e380e40f27c56accbffc665b2eeb56ec84a4da3b52ba7aa5e439c9c40572 gencode/docs/event_pointset.html
076eb51e75281ed065a9f0236a1e19b6bf3c277b51ceca84f6aa3f76d5bb6022 gencode/docs/event_system.html
465a940ab96c32e040ae14b62f384ae9c472f646f3de1ea96288fd4c11de1409 gencode/docs/event_validation.html
Expand All @@ -21,7 +21,7 @@ ff79de9390aa25bb45fb3e2ebb682c865ccab764f56d9644377d9d28c0ab10e4 gencode/java/u
d4a82e132b2d223c4a82384d22455283c0b64aba3100fc210e72f9700b9df2d0 gencode/java/udmi/schema/DeviceValidationEvent.java
587d67a67431349939dffd37b880c44e798a1eb607d54bd6d8a077bbac668067 gencode/java/udmi/schema/DiscoveryCommand.java
d8a80ab3180d33bfa17564c969018e1d4350a47dbc70c4ae8a5abbfb25cfedc9 gencode/java/udmi/schema/DiscoveryConfig.java
d51debc0dd93d1a5139f95bf417fc59e8afbbf36ae7e47c80fd7bc39638fc0ce gencode/java/udmi/schema/DiscoveryEvent.java
4793b2370b1f3b8fd89941586b779dffdde83d321a2621907f67d4d297d19b17 gencode/java/udmi/schema/DiscoveryEvent.java
04112dd47b0f761131c276c67d3cd8b789d25e6716b5732be9fef14fc6831f1d gencode/java/udmi/schema/DiscoveryModel.java
9962b0eb7d5adf52af6160e9f3131f8eeb52ae9e518954dbb6aead1bcad0245e gencode/java/udmi/schema/DiscoveryState.java
090bbaf1508aa6ca8380af936af990673f300eb5a940c9e8ab94deb64efa2b7b gencode/java/udmi/schema/Entry.java
Expand All @@ -42,7 +42,7 @@ a5e5adfc187709e8646a11c92e804acfb67743f9d72149008aaca954df3177f6 gencode/java/u
304164da05dc722b6e94cfa68659f0120e2425c94bfb5f5a4c6d796fe13da885 gencode/java/udmi/schema/Metadata.java
a4e8f69100ab678a8236f481c558d677bbaea3e76c853bbd9262113d2a9c031d gencode/java/udmi/schema/Metrics.java
5e1c5411fae4d7c47391ceb5d19ae864fcd484df75ac6b6db39fd2d12647dec8 gencode/java/udmi/schema/Physical_tag.java
052139f222b9585dcc1dd4c5de197e107cf6264783917af4b62c84d66548e3cc gencode/java/udmi/schema/PointEnumerationEvent.java
d808259db6bbcd26ecf438844ce286d15d4750906be24588d97acfbe8a4ae315 gencode/java/udmi/schema/PointEnumerationEvent.java
9855400da64cb7c9501294b72d0190caa646fab043b39a6c7c5e4b0250515f20 gencode/java/udmi/schema/PointPointsetConfig.java
8f3fc1cdc2dcd3e524863f4675aebabc450a35f5fd1cdc3fd37289b5cab7f2ec gencode/java/udmi/schema/PointPointsetEvent.java
65337109653a93d873dae40eb517857149bae1b20c7b479f41b35c0822d94ba0 gencode/java/udmi/schema/PointPointsetModel.java
Expand Down Expand Up @@ -85,9 +85,9 @@ b461bdc24310ef972faf579b5be577b5af67fb0977d6afb4c42955211b26e3d5 gencode/python
1c178f298884d66c72b295319f3e29b4178b0eaf5201aebd93ba80699e7466d5 gencode/python/udmi/schema/config_system.py
631371489cb1275517bebcc4040cbc655d18ca147ab540701b3fd9cedba138c5 gencode/python/udmi/schema/envelope.py
1eb9019b9d0b4ff7de2df8beb625a4f89292d636ece0c02f160495c537bd6c2c gencode/python/udmi/schema/event.py
00a05eaa2f478620511fe1f95c9200b6b8719c5b753263cc0d9296118915d509 gencode/python/udmi/schema/event_discovery.py
82182e3f569ad80dc0751027959c7db9135d10072fbe79f896d63a4cd2f4771f gencode/python/udmi/schema/event_discovery.py
ad33b91a7fabb4eed7e49c30a983a2106c96330facbe0f376f94d06e2263d6d0 gencode/python/udmi/schema/event_discovery_family.py
06c416a6ffcb96f84c1cf7419a31f996b2028094af6351ae77e958124bf501c5 gencode/python/udmi/schema/event_discovery_point.py
42e6fb6edda2b6aeae5e5b48ae66f87a5daf336bca1e746b1157e8f1ce31d5d5 gencode/python/udmi/schema/event_discovery_point.py
abe4044d2e3be6693ed39edc8ccaed4eee4eb8acad991e820b21d6ecf3812dd9 gencode/python/udmi/schema/event_mapping.py
ddf849bfeb2b87d071cefd5e6feacabc57375a7fff6d72b6d42ffb89f33c859b gencode/python/udmi/schema/event_pointset.py
44aff1bc930dbdbadd51ac3fe0e7d9c83ad84a6a9f9d1c809b3fce66cbcd5e00 gencode/python/udmi/schema/event_pointset_point.py
Expand Down
376 changes: 212 additions & 164 deletions gencode/docs/event_discovery.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions gencode/java/udmi/schema/DiscoveryEvent.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion gencode/java/udmi/schema/PointEnumerationEvent.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions gencode/python/udmi/schema/event_discovery.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions gencode/python/udmi/schema/event_discovery_point.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pubber/pubber.iml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
<orderEntry type="library" name="Gradle: io.moquette:moquette-broker:0.15" level="project" />
<orderEntry type="library" name="Gradle: com.librato.metrics:metrics-librato:5.1.0" level="project" />
<orderEntry type="library" name="Gradle: com.librato.metrics:librato-java:2.1.0" level="project" />
<orderEntry type="library" name="Gradle: com.bugsnag:bugsnag:3.6.3" level="project" />
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.12.5" level="project" />
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-core:2.12.5" level="project" />
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.12.5" level="project" />
<orderEntry type="library" name="Gradle: com.bugsnag:bugsnag:3.6.4" level="project" />
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-annotations:2.13.3" level="project" />
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-core:2.13.3" level="project" />
<orderEntry type="library" name="Gradle: com.fasterxml.jackson.core:jackson-databind:2.13.3" level="project" />
<orderEntry type="library" name="Gradle: joda-time:joda-time:2.10.10" level="project" />
<orderEntry type="library" name="Gradle: org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5" level="project" />
<orderEntry type="library" name="Gradle: org.slf4j:slf4j-simple:1.7.30" level="project" />
Expand Down
14 changes: 9 additions & 5 deletions pubber/src/main/java/daq/pubber/Pubber.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ public class Pubber {
private final State deviceState = new State();
private final ExtraPointsetEvent devicePoints = new ExtraPointsetEvent();
private final Set<AbstractPoint> allPoints = new HashSet<>();
private final AtomicInteger logMessageCount = new AtomicInteger(0);
private final AtomicBoolean stateDirty = new AtomicBoolean();
private Config deviceConfig = new Config();
private int deviceMessageCount = -1;
Expand Down Expand Up @@ -308,7 +307,7 @@ private void processDeviceMetadata(Metadata metadata) {
} else {
throw new RuntimeException("missingPoint not in pointset");
}
}
}

points.forEach((name, point) -> addPoint(makePoint(name, point)));
}
Expand Down Expand Up @@ -756,13 +755,17 @@ private void updateDiscoveryEnumeration(FamilyDiscoveryConfig enumeration) {
info("Discovery enumeration at " + isoConvert(enumerationGeneration));
DiscoveryEvent discoveryEvent = new DiscoveryEvent();
discoveryEvent.generation = enumerationGeneration;
discoveryEvent.points = enumeratePoints(configuration.deviceId);
discoveryEvent.uniqs = enumeratePoints(configuration.deviceId);
publishDeviceMessage(discoveryEvent);
}

private Map<String, PointEnumerationEvent> enumeratePoints(String deviceId) {
return allMetadata.get(deviceId).pointset.points.entrySet().stream().collect(
Collectors.toMap(Map.Entry::getKey, this::getPointEnumerationEvent));
Collectors.toMap(this::getPointUniqKey, this::getPointEnumerationEvent));
}

private String getPointUniqKey(Map.Entry<String, PointPointsetModel> entry) {
return String.format("%08x", entry.getKey().hashCode());
}

private PointEnumerationEvent getPointEnumerationEvent(
Expand All @@ -772,6 +775,7 @@ private PointEnumerationEvent getPointEnumerationEvent(
pointEnumerationEvent.writable = model.writable;
pointEnumerationEvent.units = model.units;
pointEnumerationEvent.ref = model.ref;
pointEnumerationEvent.name = entry.getKey();
return pointEnumerationEvent;
}

Expand Down Expand Up @@ -878,7 +882,7 @@ private void sendDiscoveryEvent(String family, Date scanGeneration) {
discoveryEvent.families.computeIfAbsent("iot",
key -> new FamilyDiscoveryEvent()).id = deviceId;
if (isTrue(() -> deviceConfig.discovery.families.get(family).enumerate)) {
discoveryEvent.points = enumeratePoints(deviceId);
discoveryEvent.uniqs = enumeratePoints(deviceId);
}
publishDeviceMessage(discoveryEvent);
sentEvents.incrementAndGet();
Expand Down
4 changes: 2 additions & 2 deletions schema/event_discovery.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
}
}
},
"points": {
"uniqs": {
"description": "Collection of data points available for this device.",
"additionalProperties": false,
"existingJavaType": "java.util.Map<String, PointEnumerationEvent>",
"patternProperties": {
"^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$": {
"^[-_.:/a-zA-Z0-9]+$": {
"$ref": "file:event_discovery_point.json#"
}
}
Expand Down
4 changes: 4 additions & 0 deletions schema/event_discovery_point.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"name": {
"description": "Friendly name for the point, if known",
"type": "string"
},
"possible_values": {
"description": "List of possible enumerated values for the point",
"type": "array",
Expand Down
5 changes: 3 additions & 2 deletions tests/event_discovery.tests/enumeration.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"version": "1.3.14",
"timestamp": "2018-08-26T21:42:12.237Z",
"generation": "2018-08-26T21:37:12Z",
"points": {
"uniqs": {
// Numerical value with an articulated unit
"sup_flow_actual_avo_1": {
"units": "percent", // with units, type typically defaults to 'number'
Expand All @@ -15,7 +15,8 @@
"description": "Basic value reading"
},
// Multi-state enumerated value
"zone_mode_msv_1": {
"978A87C5": {
"name": "zone_mode_msv_1",
"possible_values": [ "Deadband Mode", "Heating Mode", "Cooling Mode" ],
"type": "multistate" // enumerated values defining the multistate
},
Expand Down
5 changes: 5 additions & 0 deletions tests/event_discovery.tests/errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"id": "0E:93:32:11:04:82"
}
},
"uniqs": {
"bad_entity_name_": {
"present_value": 21.30108642578125
}
},
"points": {
"bad_entity_name_": {
"present_value": 21.30108642578125
Expand Down
4 changes: 2 additions & 2 deletions tests/event_discovery.tests/errors.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
5 schema violations found
ECMA 262 regex "^[-_.:0-9A-Z]+$" does not match input string "92E*A09"
object has missing required properties (["generation"])
object instance has properties which are not allowed by the schema: ["bad_entity_name_"]
object instance has properties which are not allowed by the schema: ["id"]
object instance has properties which are not allowed by the schema: ["id","points"]
object instance has properties which are not allowed by the schema: ["ip_v4","mac"]
object instance has properties which are not allowed by the schema: ["present_value"]
5 changes: 3 additions & 2 deletions tests/event_discovery.tests/from_bacnet.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"generation": "2022-06-21T17:19:49.191023+00:00",
"points": {
"org_building_5005_analogInput_1094": {
"uniqs": {
"5005/1094": {
"ref": "org/building/5005/analogInput/1094",
"name": "discharge_air_velocity_pressure",
"units": "inchesOfWater",
"description": "Discharge Air Velocity Pressure",
"ancillary": {
Expand Down
2 changes: 1 addition & 1 deletion tests/event_discovery.tests/implicit.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"id": "0E:93:32:11:04:82"
}
},
"points": {
"uniqs": {
"sup_flow_actual_avo_1": {
"units": "percent",
"ref": "analog-value_29",
Expand Down
2 changes: 1 addition & 1 deletion tests/event_discovery.tests/point_error.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"id": "872849"
}
},
"points": {
"uniqs": {
"sup_flow_actual_avo_1": {
"status": {
"message": "Timeout during point communication",
Expand Down
Loading

0 comments on commit 8007b0e

Please sign in to comment.