From 75b37f891d0326cbe0fa6618d24c4ea73e99c777 Mon Sep 17 00:00:00 2001 From: "xiang.zhou" Date: Mon, 9 Feb 2026 13:34:40 +0800 Subject: [PATCH 1/2] update disconnect error status code and update scan node api --- plugins/restful/scan_handle.c | 2 +- src/utils/http.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/restful/scan_handle.c b/plugins/restful/scan_handle.c index 2d89315d..063a3903 100644 --- a/plugins/restful/scan_handle.c +++ b/plugins/restful/scan_handle.c @@ -73,6 +73,6 @@ void handle_scan_tags_resp(nng_aio *aio, neu_resp_scan_tags_t *resp) { char *result = NULL; neu_json_encode_by_fn(resp, neu_json_encode_scan_tags_resp, &result); - neu_http_ok(aio, result); + neu_http_response(aio, resp->error, result); free(result); } diff --git a/src/utils/http.c b/src/utils/http.c index 02edae23..88970968 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -248,7 +248,6 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_NODE_SETTING_NOT_FOUND: case NEU_ERR_PLUGIN_READ_FAILURE: case NEU_ERR_PLUGIN_WRITE_FAILURE: - case NEU_ERR_PLUGIN_DISCONNECTED: case NEU_ERR_PLUGIN_TAG_NOT_ALLOW_READ: case NEU_ERR_PLUGIN_TAG_NOT_ALLOW_WRITE: case NEU_ERR_LICENSE_EXPIRED: @@ -343,6 +342,7 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_NODE_TAGS_TOO_MANY: case NEU_ERR_NODE_TAGS_INVALID: case NEU_ERR_NODE_TAGS_TOO_LONG: + case NEU_ERR_PLUGIN_DISCONNECTED: status = NNG_HTTP_STATUS_BAD_REQUEST; break; case NEU_ERR_FILE_NOT_EXIST: From 3dc21e9248a6337c39954cea03bd02c2c282f93f Mon Sep 17 00:00:00 2001 From: "xiang.zhou" Date: Wed, 11 Feb 2026 15:03:50 +0800 Subject: [PATCH 2/2] update scan tags api --- include/neuron/json/neu_json_scan.h | 1 + include/neuron/msg.h | 3 +++ include/neuron/plugin.h | 2 +- plugins/restful/scan_handle.c | 2 ++ src/adapter/driver/driver.c | 4 ++-- src/parser/neu_json_scan.c | 29 +++++++++++++++++++++++++---- tests/ft/neuron/api.py | 6 +++--- 7 files changed, 37 insertions(+), 10 deletions(-) diff --git a/include/neuron/json/neu_json_scan.h b/include/neuron/json/neu_json_scan.h index ab65f6e8..e7a048fc 100644 --- a/include/neuron/json/neu_json_scan.h +++ b/include/neuron/json/neu_json_scan.h @@ -37,6 +37,7 @@ typedef struct { char *node; char *id; char *ctx; + int load_index; } neu_json_scan_tags_req_t; int neu_json_decode_scan_tags_req(char *buf, neu_json_scan_tags_req_t **result); diff --git a/include/neuron/msg.h b/include/neuron/msg.h index eb106647..9e677ace 100644 --- a/include/neuron/msg.h +++ b/include/neuron/msg.h @@ -1706,6 +1706,7 @@ typedef struct neu_req_scan_tags { char driver[NEU_NODE_NAME_LEN]; char id[NEU_TAG_ADDRESS_LEN]; char ctx[NEU_VALUE_SIZE]; + int load_index; } neu_req_scan_tags_t; typedef struct { @@ -1722,6 +1723,8 @@ typedef struct { neu_type_e type; bool is_array; char ctx[NEU_VALUE_SIZE]; + int load_index; + int c_flag; } neu_resp_scan_tags_t; typedef struct { diff --git a/include/neuron/plugin.h b/include/neuron/plugin.h index 96773d3b..f1b5ec1a 100644 --- a/include/neuron/plugin.h +++ b/include/neuron/plugin.h @@ -112,7 +112,7 @@ typedef struct neu_plugin_intf_funs { int n_tag); // create tags by API int (*del_tags)(neu_plugin_t *plugin, int n_tag); int (*scan_tags)(neu_plugin_t *plugin, void *req, char *id, - char *ctx); + char *ctx, int load_index); int (*test_read_tag)(neu_plugin_t *plugin, void *req, neu_datatag_t tag); int (*action)(neu_plugin_t *plugin, const char *action); diff --git a/plugins/restful/scan_handle.c b/plugins/restful/scan_handle.c index 063a3903..4c5907a8 100644 --- a/plugins/restful/scan_handle.c +++ b/plugins/restful/scan_handle.c @@ -54,6 +54,8 @@ void handle_scan_tags(nng_aio *aio) strcpy(cmd.ctx, req->ctx); } + cmd.load_index = req->load_index; + if (0 != neu_plugin_op(plugin, header, &cmd)) { NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, { neu_http_response(aio, NEU_ERR_IS_BUSY, result_error); diff --git a/src/adapter/driver/driver.c b/src/adapter/driver/driver.c index 672e49ee..eb1bc840 100644 --- a/src/adapter/driver/driver.c +++ b/src/adapter/driver/driver.c @@ -3394,8 +3394,8 @@ void neu_adapter_driver_scan_tags(neu_adapter_driver_t *driver, } neu_req_scan_tags_t *cmd = (neu_req_scan_tags_t *) &req[1]; - driver->adapter.module->intf_funs->driver.scan_tags(driver->adapter.plugin, - req, cmd->id, cmd->ctx); + driver->adapter.module->intf_funs->driver.scan_tags( + driver->adapter.plugin, req, cmd->id, cmd->ctx, cmd->load_index); } void neu_adapter_driver_test_read_tag(neu_adapter_driver_t *driver, diff --git a/src/parser/neu_json_scan.c b/src/parser/neu_json_scan.c index b0d2b11a..73e871ba 100644 --- a/src/parser/neu_json_scan.c +++ b/src/parser/neu_json_scan.c @@ -64,6 +64,13 @@ int neu_json_decode_scan_tags_req(char *buf, neu_json_scan_tags_req_t **result) }, }; + neu_json_elem_t req_load_index_elems[] = { + { + .name = "load_index", + .t = NEU_JSON_INT, + }, + }; + if (0 != neu_json_decode_by_json(json_obj, NEU_JSON_ELEM_SIZE(req_node_elems), req_node_elems)) { @@ -78,10 +85,14 @@ int neu_json_decode_scan_tags_req(char *buf, neu_json_scan_tags_req_t **result) neu_json_decode_by_json(json_obj, NEU_JSON_ELEM_SIZE(req_ctx_elems), req_ctx_elems); - req->node = req_node_elems[0].v.val_str; - req->id = req_id_elems[0].v.val_str; - req->ctx = req_ctx_elems[0].v.val_str; - *result = req; + neu_json_decode_by_json(json_obj, NEU_JSON_ELEM_SIZE(req_load_index_elems), + req_load_index_elems); + + req->node = req_node_elems[0].v.val_str; + req->id = req_id_elems[0].v.val_str; + req->ctx = req_ctx_elems[0].v.val_str; + req->load_index = req_load_index_elems[0].v.val_int; + *result = req; neu_json_decode_free(json_obj); return 0; @@ -164,6 +175,16 @@ int neu_json_encode_scan_tags_resp(void *json_object, void *param) .t = NEU_JSON_STR, .v.val_str = resp->ctx, }, + { + .name = "load_index", + .t = NEU_JSON_INT, + .v.val_int = resp->load_index, + }, + { + .name = "completed", + .t = NEU_JSON_INT, + .v.val_int = resp->c_flag, + }, { .name = "tags", .t = NEU_JSON_OBJECT, diff --git a/tests/ft/neuron/api.py b/tests/ft/neuron/api.py index 690d6b34..dc51f62d 100644 --- a/tests/ft/neuron/api.py +++ b/tests/ft/neuron/api.py @@ -411,8 +411,8 @@ def get_nodes_disable_auth(type): @gen_check -def scan_tags(node, id, ctx=""): - return requests.post(url=config.BASE_URL + "/api/v2/scan/tags", headers={"Authorization": config.default_jwt}, json={"node": node, "id": id, "ctx": ctx}) +def scan_tags(node, id, ctx="", load_index=0): + return requests.post(url=config.BASE_URL + "/api/v2/scan/tags", headers={"Authorization": config.default_jwt}, json={"node": node, "id": id, "ctx": ctx, "load_index": load_index}) def otel_start(host, port): @@ -587,4 +587,4 @@ def simulator_export(jwt=config.default_jwt): def simulator_list_tags(jwt=config.default_jwt): return requests.get(url=config.BASE_URL + "/api/v2/simulator/tags", - headers={"Authorization": jwt}) \ No newline at end of file + headers={"Authorization": jwt})