mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
Merge pull request #2695 from ZhouBox/v2.14
[v2.14]update scan tags api && update disconnect error status code and update scan node api
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
@@ -73,6 +75,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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -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:
|
||||
|
||||
@@ -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})
|
||||
headers={"Authorization": jwt})
|
||||
|
||||
Reference in New Issue
Block a user