Skip to content

Commit

Permalink
fix upgrader for state.gateway.devices property (#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
noursaidi authored Jun 26, 2024
1 parent 359a7e3 commit 7170f43
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 14 deletions.
21 changes: 21 additions & 0 deletions common/src/main/java/com/google/udmi/util/MessageUpgrader.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ private Object upgradeRaw(boolean forceUpgrade) {
patch = 1;
}

if (minor < 5) {
JsonNode before = message.deepCopy();
upgradeTo_1_5_0();
upgraded |= !before.equals(message);
patch = 0;
minor = 5;
}

if (upgraded && message.get(VERSION_KEY) != null) {
message.put(UPGRADED_FROM, originalVersion);
message.put(VERSION_KEY, String.format(TARGET_FORMAT, major, minor, patch));
Expand Down Expand Up @@ -198,6 +206,19 @@ private void upgradeTo_1_4_1() {
}
}

private void upgradeTo_1_5_0() {
if (STATE_SCHEMA.equals(schemaName)) {
upgradeTo_1_5_0_state();
}
}

private void upgradeTo_1_5_0_state() {
ObjectNode gateway = (ObjectNode) message.get("gateway");
if (gateway != null && gateway.has("devices")) {
gateway.remove("devices");
}
}

private void upgradeTo_1_4_1_metadata() {
JsonNode localnet = message.get("localnet");
if (localnet == null || !localnet.has("families")) {
Expand Down
32 changes: 32 additions & 0 deletions tests/schemas/state/upgrade_gateway_devices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"timestamp": "2024-06-26T09:23:53Z",
"version": "1.4.2",
"system": {
"last_config": "2024-06-07T03:27:41Z",
"operation": {
"operational": true
},
"serial_no": "RT644001PQ",
"hardware": {
"make": "ACME",
"model": "Device"
},
"software": {
"firmware": "108.04.20053"
},
"status": {
"message": "Applied a config message",
"category": "system.config.apply",
"timestamp": "2024-06-26T09:23:53Z",
"level": 300
}
},
"gateway": {
"devices": {
"AHU-101": null
}
},
"pointset": {
"points": {}
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"timestamp": "2024-06-11T08:31:26Z",
"version": "1.4.1",
"version": "1.5.0",
"upgraded_from": "1.4.0",
"hash": "c621e305",
"hash": "fb9a66c5",
"system": {
"tags": [ ],
"location": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"timestamp": "2024-06-11T08:31:32Z",
"version": "1.4.1",
"version": "1.5.0",
"upgraded_from": "1.4.0",
"hash": "2359ef26",
"hash": "773f9366",
"cloud": {
"auth_type": "RS256"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"timestamp": "2018-08-26T21:39:29Z",
"version": "1.4.1",
"version": "1.5.0",
"upgraded_from": "1.3.14",
"hash": "8c32e186",
"hash": "d3901546",
"cloud": {
"auth_type": "RS256"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"timestamp": "2018-08-26T21:39:29Z",
"version": "1.4.1",
"version": "1.5.0",
"upgraded_from": "1.3.13",
"hash": "5ba64b5a",
"hash": "58124f9a",
"cloud": {
"auth_type": "RS256"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"timestamp": "2020-05-01T13:39:07Z",
"version": "1.4.1",
"version": "1.5.0",
"upgraded_from": "1",
"hash": "591b1971",
"hash": "98f3ddb1",
"cloud": {
"auth_type": "RS256"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"timestamp": "2020-05-01T13:39:07Z",
"version": "1.4.1",
"version": "1.5.0",
"upgraded_from": "1",
"hash": "84855bb1",
"hash": "55944f71",
"cloud": {
"auth_type": "RS256"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"timestamp": "2021-02-25T09:56:39Z",
"version": "1.4.1",
"version": "1.5.0",
"upgraded_from": "1.3.14",
"hash": "43f89cdd",
"hash": "b79ff09d",
"system": {
"tags": [ ],
"location": {
Expand Down

0 comments on commit 7170f43

Please sign in to comment.