Skip to content

Commit 7b977aa

Browse files
authored
Fix Provisional Cluster Warning Bugs (#1523)
* fix bugs in provisional cluster warning
1 parent 3212a73 commit 7b977aa

File tree

3 files changed

+167
-103
lines changed

3 files changed

+167
-103
lines changed

src-electron/db/zap-schema.sql

Lines changed: 133 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,12 +2997,10 @@ BEGIN
29972997
END;
29982998

29992999
/*
3000-
SQL Trigger that adds a warning to the notification table when enabling a provisional cluster.
3001-
Triggers are needed for both AFTER INSERT and AFTER UPDATE,
3002-
as initial enabling inserts a row into ENDPOINT_TYPE_CLUSTER, while subsequent enabling updates the table.
3000+
SQL UPDATE Trigger that adds a warning to the notification table when re-enabling a provisional cluster.
30033001
*/
30043002
CREATE TRIGGER
3005-
UPDATE_TRIGGER_ENABLE_PROVISIONAL_CLUSTER_WARNING
3003+
UPDATE_TRIGGER_PROVISIONAL_CLUSTER_WARNING
30063004
AFTER
30073005
UPDATE ON ENDPOINT_TYPE_CLUSTER
30083006
WHEN
@@ -3127,95 +3125,153 @@ BEGIN
31273125
);
31283126
END;
31293127

3128+
/*
3129+
SQL INSERT Trigger that adds a warning to the notification table when first-time enabling a provisional cluster.
3130+
*/
31303131
CREATE TRIGGER
3131-
INSERT_TRIGGER_ENABLE_PROVISIONAL_CLUSTER_WARNING
3132+
INSERT_TRIGGER_PROVISIONAL_CLUSTER_WARNING_PER_CLUSTER
31323133
AFTER
31333134
INSERT ON ENDPOINT_TYPE_CLUSTER
31343135
WHEN
3135-
(
3136+
new.ENABLED = 1
3137+
AND EXISTS (
31363138
SELECT
3137-
COUNT()
3139+
1
31383140
FROM
3139-
ENDPOINT_TYPE_CLUSTER
3140-
INNER JOIN
31413141
CLUSTER
3142-
ON
3143-
ENDPOINT_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID
31443142
WHERE
3145-
ENDPOINT_TYPE_CLUSTER.CLUSTER_REF = new.CLUSTER_REF
3143+
CLUSTER.CLUSTER_ID = new.CLUSTER_REF
31463144
AND
3147-
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF = new.ENDPOINT_TYPE_REF
3148-
AND
3149-
ENDPOINT_TYPE_CLUSTER.SIDE = new.SIDE
3150-
AND
3151-
new.ENABLED = 1
3152-
AND
3153-
CLUSTER.API_MATURITY = "provisional"
3154-
) > 0
3145+
CLUSTER.API_MATURITY = "provisional"
3146+
)
3147+
AND EXISTS (
3148+
SELECT
3149+
1
3150+
FROM
3151+
SESSION_PARTITION
3152+
INNER JOIN
3153+
ENDPOINT_TYPE
3154+
ON
3155+
SESSION_PARTITION.SESSION_PARTITION_ID = ENDPOINT_TYPE.SESSION_PARTITION_REF
3156+
WHERE
3157+
ENDPOINT_TYPE.ENDPOINT_TYPE_ID = new.ENDPOINT_TYPE_REF
3158+
)
31553159
BEGIN
31563160
INSERT INTO
3157-
SESSION_NOTICE(SESSION_REF, NOTICE_TYPE, NOTICE_MESSAGE, NOTICE_SEVERITY, DISPLAY, SEEN)
3158-
VALUES
3159-
(
3160-
(
3161-
SELECT
3162-
SESSION_PARTITION.SESSION_REF
3163-
FROM
3164-
ENDPOINT_TYPE_CLUSTER
3165-
INNER JOIN
3166-
ENDPOINT_TYPE
3167-
ON
3168-
ENDPOINT_TYPE.ENDPOINT_TYPE_ID = ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF
3169-
INNER JOIN
3170-
SESSION_PARTITION
3171-
ON
3172-
SESSION_PARTITION.SESSION_PARTITION_ID = ENDPOINT_TYPE.SESSION_PARTITION_REF
3173-
WHERE
3174-
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID = new.ENDPOINT_TYPE_CLUSTER_ID
3175-
),
3176-
"WARNING",
3177-
"On endpoint "
3178-
||
3179-
(
3180-
SELECT
3181-
ENDPOINT.ENDPOINT_IDENTIFIER
3182-
FROM
3183-
ENDPOINT
3184-
INNER JOIN
3185-
ENDPOINT_TYPE
3186-
ON
3187-
ENDPOINT.ENDPOINT_TYPE_REF = ENDPOINT_TYPE.ENDPOINT_TYPE_ID
3188-
INNER JOIN
3189-
ENDPOINT_TYPE_CLUSTER
3190-
ON
3191-
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_REF = ENDPOINT_TYPE.ENDPOINT_TYPE_ID
3192-
WHERE
3193-
ENDPOINT_TYPE_CLUSTER.ENDPOINT_TYPE_CLUSTER_ID = new.ENDPOINT_TYPE_CLUSTER_ID
3194-
)
3195-
||
3196-
", support for cluster: "
3197-
||
3198-
(
3199-
SELECT
3200-
CLUSTER.NAME || " " || new.SIDE
3201-
FROM
3202-
CLUSTER
3203-
WHERE
3204-
CLUSTER.CLUSTER_ID = new.CLUSTER_REF
3205-
)
3206-
||
3207-
" is provisional.",
3208-
1,
3209-
1,
3210-
0
3211-
);
3161+
SESSION_NOTICE (SESSION_REF, NOTICE_TYPE, NOTICE_MESSAGE, NOTICE_SEVERITY, DISPLAY, SEEN)
3162+
SELECT
3163+
SP.SESSION_REF,
3164+
"WARNING",
3165+
"On endpoint " || E.ENDPOINT_IDENTIFIER || ", support for cluster: " || C.NAME || " " || new.SIDE || " is provisional.",
3166+
1,
3167+
1,
3168+
0
3169+
FROM
3170+
ENDPOINT E
3171+
INNER JOIN
3172+
ENDPOINT_TYPE ET
3173+
ON
3174+
E.ENDPOINT_TYPE_REF = ET.ENDPOINT_TYPE_ID
3175+
INNER JOIN
3176+
SESSION_PARTITION SP
3177+
ON
3178+
ET.SESSION_PARTITION_REF = SP.SESSION_PARTITION_ID
3179+
INNER JOIN
3180+
CLUSTER C
3181+
ON
3182+
C.CLUSTER_ID = new.CLUSTER_REF
3183+
WHERE
3184+
ET.ENDPOINT_TYPE_ID = new.ENDPOINT_TYPE_REF;
3185+
END;
3186+
3187+
/*
3188+
SQL INSERT Trigger that adds warnings for provisional clusters to the notification table when creating an endpoint.
3189+
The triggered is placed on ENDPOINT table since ENDPOINT data is required in the warning and is loaded after ENDPOINT_TYPE and ENDPOINT_TYPE_CLUSTER.
3190+
*/
3191+
CREATE TRIGGER
3192+
INSERT_TRIGGER_PROVISIONAL_CLUSTER_WARNING_PER_ENDPOINT
3193+
AFTER
3194+
INSERT ON ENDPOINT
3195+
BEGIN
3196+
INSERT INTO
3197+
SESSION_NOTICE (SESSION_REF, NOTICE_TYPE, NOTICE_MESSAGE, NOTICE_SEVERITY, DISPLAY, SEEN)
3198+
SELECT
3199+
SP.SESSION_REF,
3200+
"WARNING",
3201+
"On endpoint " || E.ENDPOINT_IDENTIFIER || ", support for cluster: " || C.NAME || " " || ETC.SIDE || " is provisional.",
3202+
1,
3203+
1,
3204+
0
3205+
FROM
3206+
ENDPOINT E
3207+
INNER JOIN
3208+
ENDPOINT_TYPE ET
3209+
ON
3210+
E.ENDPOINT_TYPE_REF = ET.ENDPOINT_TYPE_ID
3211+
INNER JOIN
3212+
SESSION_PARTITION SP
3213+
ON
3214+
SP.SESSION_PARTITION_ID = ET.SESSION_PARTITION_REF
3215+
INNER JOIN
3216+
ENDPOINT_TYPE_CLUSTER ETC
3217+
ON
3218+
ETC.ENDPOINT_TYPE_REF = ET.ENDPOINT_TYPE_ID
3219+
INNER JOIN
3220+
CLUSTER C
3221+
ON
3222+
ETC.CLUSTER_REF = C.CLUSTER_ID
3223+
WHERE
3224+
E.ENDPOINT_ID = NEW.ENDPOINT_ID
3225+
AND
3226+
ETC.ENABLED = 1
3227+
AND
3228+
C.API_MATURITY = "provisional";
3229+
END;
3230+
3231+
/*
3232+
SQL DELETE Trigger that removes provisional cluster warnings from the notification table when deleting an endpoint.
3233+
*/
3234+
CREATE TRIGGER
3235+
DELETE_TRIGGER_PROVISIONAL_CLUSTER_WARNING_REMOVAL
3236+
AFTER
3237+
DELETE ON ENDPOINT
3238+
BEGIN
3239+
DELETE FROM
3240+
SESSION_NOTICE
3241+
WHERE
3242+
SESSION_REF = (
3243+
SELECT
3244+
SESSION_REF
3245+
FROM
3246+
SESSION_PARTITION
3247+
WHERE
3248+
SESSION_PARTITION.SESSION_PARTITION_ID = (
3249+
SELECT
3250+
SESSION_PARTITION_REF
3251+
FROM
3252+
ENDPOINT_TYPE
3253+
WHERE
3254+
ENDPOINT_TYPE.ENDPOINT_TYPE_ID = old.ENDPOINT_TYPE_REF
3255+
)
3256+
)
3257+
AND
3258+
NOTICE_TYPE="WARNING"
3259+
AND
3260+
NOTICE_MESSAGE LIKE
3261+
(
3262+
"On endpoint "
3263+
||
3264+
old.ENDPOINT_IDENTIFIER
3265+
||
3266+
", support for cluster: % is provisional."
3267+
);
32123268
END;
32133269

32143270
/*
3215-
SQL Trigger that removes a warning from the notification table when disabling a provisional cluster.
3271+
SQL UPDATE Trigger that removes a warning from the notification table when disabling a provisional cluster.
32163272
*/
32173273
CREATE TRIGGER
3218-
UPDATE_TRIGGER_DISABLE_PROVISIONAL_CLUSTER_WARNING_REMOVAL
3274+
UPDATE_TRIGGER_PROVISIONAL_CLUSTER_WARNING_REMOVAL
32193275
AFTER
32203276
UPDATE ON ENDPOINT_TYPE_CLUSTER
32213277
WHEN

src-electron/importexport/import-json.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,9 +1766,7 @@ async function importEndpointTypes(
17661766
}
17671767
}
17681768

1769-
await setAndPrintProvisionalClusterWarnings(
1770-
db,
1771-
sessionId,
1769+
await printProvisionalClusterWarnings(
17721770
provisionalClusterWarnings,
17731771
provisionalClusterWarningTitle,
17741772
specMessageIndent,
@@ -2266,36 +2264,21 @@ function generateProvisionalClusterWarnings(clusters, endpointId) {
22662264
}
22672265

22682266
/**
2269-
* Set provisional cluster warnings in the notification table,
2270-
* and print the concatenated warning message to the console.
2267+
* Print the concatenated provisional cluster warning message to the console.
22712268
*
2272-
* @param {*} db
2273-
* @param {*} sessionId
22742269
* @param {*} warnings
22752270
* @param {*} provisionalClusterWarningTitle
22762271
* @param {*} specMessageIndent
22772272
* @param {*} dottedLine
22782273
*/
2279-
async function setAndPrintProvisionalClusterWarnings(
2280-
db,
2281-
sessionId,
2274+
async function printProvisionalClusterWarnings(
22822275
warnings,
22832276
provisionalClusterWarningTitle,
22842277
specMessageIndent,
22852278
dottedLine
22862279
) {
22872280
let warningMessage = ''
22882281
if (warnings.length > 0) {
2289-
for (let warning of warnings) {
2290-
await querySessionNotice.setNotification(
2291-
db,
2292-
'WARNING',
2293-
warning,
2294-
sessionId,
2295-
1,
2296-
0
2297-
)
2298-
}
22992282
warningMessage = dottedLine.concat(
23002283
provisionalClusterWarningTitle,
23012284
specMessageIndent,

test/provisional-cluster.test.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ let sid
3737
let pkgId
3838
let eptTypeId
3939
let clusterId
40+
let eptId
4041

4142
beforeAll(async () => {
4243
env.setDevelopmentEnv()
@@ -61,7 +62,7 @@ beforeAll(async () => {
6162
afterAll(() => dbApi.closeDatabase(db), testUtil.timeout.short())
6263

6364
test(
64-
'Initialize a provisional cluster',
65+
'Initialize a provisional cluster and test triggers for enabling an endpoint',
6566
async () => {
6667
// insert a cluster with provisional apiMaturity
6768
let provisionalClusterCode = 0x1111
@@ -110,7 +111,21 @@ test(
110111
)
111112
expect(eptTypeId).not.toBeNull()
112113

113-
await queryEndpoint.insertEndpoint(db, sid, 0, eptTypeId, null, null)
114+
/* insert an endpoint should trigger a warning for the provisional cluster Scenes enabled
115+
according to requirement of On/Off Light Device Type */
116+
eptId = await queryEndpoint.insertEndpoint(
117+
db,
118+
sid,
119+
0,
120+
eptTypeId,
121+
null,
122+
null
123+
)
124+
let notifications = await querySessionNotification.getNotification(db, sid)
125+
expect(notifications.length).toBe(1)
126+
expect(notifications[0].message).toBe(
127+
'On endpoint 0, support for cluster: Scenes server is provisional.'
128+
)
114129
},
115130
testUtil.timeout.long()
116131
)
@@ -138,7 +153,8 @@ test(
138153
false
139154
)
140155
let notifications = await querySessionNotification.getNotification(db, sid)
141-
expect(notifications.length).toBe(0)
156+
expect(listContainsClientWarning(notifications)).toBe(false)
157+
expect(listContainsServerWarning(notifications)).toBe(false)
142158

143159
// test update trigger on enable a cluster
144160
// update provisional client cluster to enabled should trigger a warning
@@ -150,11 +166,12 @@ test(
150166
true
151167
)
152168
notifications = await querySessionNotification.getNotification(db, sid)
153-
expect(notifications.length).toBe(1)
154169
expect(listContainsClientWarning(notifications)).toBe(true)
170+
expect(listContainsServerWarning(notifications)).toBe(false)
155171

156172
// test insert trigger
157173
// insert an enabled provisional server cluster should trigger a warning
174+
// 3 notifications should be present: Scenes server, Provisional client, Provisional server
158175
await queryConfig.insertOrReplaceClusterState(
159176
db,
160177
eptTypeId,
@@ -163,7 +180,7 @@ test(
163180
true
164181
)
165182
notifications = await querySessionNotification.getNotification(db, sid)
166-
expect(notifications.length).toBe(2)
183+
expect(notifications.length).toBe(3)
167184
expect(listContainsClientWarning(notifications)).toBe(true)
168185
expect(listContainsServerWarning(notifications)).toBe(true)
169186

@@ -177,8 +194,8 @@ test(
177194
false
178195
)
179196
notifications = await querySessionNotification.getNotification(db, sid)
180-
expect(notifications.length).toBe(1)
181197
expect(listContainsClientWarning(notifications)).toBe(true)
198+
expect(listContainsServerWarning(notifications)).toBe(false)
182199

183200
// disable the provisional client cluster should remove the client warning
184201
await queryConfig.insertOrReplaceClusterState(
@@ -189,6 +206,14 @@ test(
189206
false
190207
)
191208
notifications = await querySessionNotification.getNotification(db, sid)
209+
expect(listContainsClientWarning(notifications)).toBe(false)
210+
expect(listContainsServerWarning(notifications)).toBe(false)
211+
212+
expect(notifications.length).toBe(1)
213+
214+
// test delete trigger: delete the endpoint should remove the remaining warning
215+
await queryEndpoint.deleteEndpoint(db, eptId)
216+
notifications = await querySessionNotification.getNotification(db, sid)
192217
expect(notifications.length).toBe(0)
193218
},
194219
testUtil.timeout.medium()

0 commit comments

Comments
 (0)