From 47acdd6d138d1b9ec6fd388df41a6085941c10e9 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Mon, 30 May 2022 00:31:06 +0800 Subject: [PATCH 1/4] revert: "test(restful): add new get node api functionality tests" This reverts commit 4cf8dd6b788b33e56ef3de50c4563ba564973ed7. --- ft/node_api_test.robot | 62 ++++-------------------------------------- 1 file changed, 6 insertions(+), 56 deletions(-) diff --git a/ft/node_api_test.robot b/ft/node_api_test.robot index 7683c309..2c465491 100644 --- a/ft/node_api_test.robot +++ b/ft/node_api_test.robot @@ -47,10 +47,6 @@ Get node with wrong parameters, it will return failure Integer response status 400 Integer response body error ${ERR_REQUEST_PARAM_INVALID} - GET /api/v2/node?name_contains=test-node - Integer response status 400 - Integer response body error ${ERR_REQUEST_PARAM_INVALID} - Get node by nonexistent id, it should failure GET /api/v2/node?id=123456 @@ -72,18 +68,10 @@ Get DRIVER node by id, it should return the DRIVER node Integer response body nodes 0 id ${id} String response body nodes 0 name test-node -Get DRIVER node by name substring, it should return the DRIVER node +Get DRIVER node by id with correct type, it should return the DRIVER node ${id} = Get Node ID ${NODE_DRIVER} test-node - GET /api/v2/node?type=${NODE_DRIVER}&name_contains=test-node - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name test-node - -Get DRIVER node by id with correct type and name substring, it should return the DRIVER node - ${id} = Get Node ID ${NODE_DRIVER} test-node - - GET /api/v2/node?type=${NODE_DRIVER}&id=${id}&name_contains=test-node + GET /api/v2/node?type=${NODE_DRIVER}&id=${id} Integer response status 200 Integer response body nodes 0 id ${id} String response body nodes 0 name test-node @@ -95,13 +83,6 @@ Get DRIVER node by id with wrong type, it should return failure Integer response status 404 Integer response body error ${ERR_NODE_NOT_EXIST} -Get DRIVER node by id with wrong name substring, it should return failure - ${id} = Get Node ID ${NODE_DRIVER} test-node - - GET /api/v2/node?id=${id}&name_contains=xxx - Integer response status 404 - Integer response body error ${ERR_NODE_NOT_EXIST} - Get WEB node, it should return all WEB node ${res} = Get Nodes ${NODE_WEB} @@ -116,18 +97,10 @@ Get WEB node by id, it should return the WEB node Integer response body nodes 0 id ${id} String response body nodes 0 name default-dashboard-adapter -Get WEB node by name substring, it should return the WEB node +Get WEB node by id with correct type, it should return the WEB node ${id} = Get Node ID ${NODE_WEB} default-dashboard-adapter - GET /api/v2/node?type=${NODE_WEB}&name_contains=dashboard - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name default-dashboard-adapter - -Get WEB node by id with correct type and name substring, it should return the WEB node - ${id} = Get Node ID ${NODE_WEB} default-dashboard-adapter - - GET /api/v2/node?type=${NODE_WEB}&id=${id}&name_contains=dashboard + GET /api/v2/node?type=${NODE_WEB}&id=${id} Integer response status 200 Integer response body nodes 0 id ${id} String response body nodes 0 name default-dashboard-adapter @@ -139,13 +112,6 @@ Get WEB node by id with wrong type, it should return failure Integer response status 404 Integer response body error ${ERR_NODE_NOT_EXIST} -Get WEB node by id with wrong name substring, it should return failure - ${id} = Get Node ID ${NODE_WEB} default-dashboard-adapter - - GET /api/v2/node?id=${id}&name_contains=xxx - Integer response status 404 - Integer response body error ${ERR_NODE_NOT_EXIST} - Get MQTT node, it should return all mqtt node ${res} = Add Node type=${${NODE_MQTT}} name=mqtt-adapter plugin_name=mqtt ${res} = Get Nodes ${NODE_MQTT} @@ -161,18 +127,10 @@ Get MQTT node by id, it should return the MQTT node Integer response body nodes 0 id ${id} String response body nodes 0 name mqtt-adapter -Get MQTT node by name substring, it should return the MQTT node +Get MQTT node by id with correct type, it should return the MQTT node ${id} = Get Node ID ${NODE_MQTT} mqtt-adapter - GET /api/v2/node?type=${NODE_MQTT}&name_contains=mqtt - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name mqtt-adapter - -Get MQTT node by id with correct type and name substring, it should return the MQTT node - ${id} = Get Node ID ${NODE_MQTT} mqtt-adapter - - GET /api/v2/node?type=${NODE_MQTT}&id=${id}&name_contains=mqtt + GET /api/v2/node?type=${NODE_MQTT}&id=${id} Integer response status 200 Integer response body nodes 0 id ${id} String response body nodes 0 name mqtt-adapter @@ -184,14 +142,6 @@ Get MQTT node by id with wrong type, it should return failure Integer response status 404 Integer response body error ${ERR_NODE_NOT_EXIST} -Get MQTT node by id with wrong name substring, it should return failure - ${id} = Get Node ID ${NODE_MQTT} mqtt-adapter - - GET /api/v2/node?id=${id}&name_contains=xxx - Integer response status 404 - Integer response body error ${ERR_NODE_NOT_EXIST} - - Get UNKNOWN type node, it should return empty node ${res} = Get Nodes ${NODE_UNKNOWN} From 48db0323822191cd93d806ea1da8b127d7826c42 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Mon, 30 May 2022 00:31:35 +0800 Subject: [PATCH 2/4] revert: "feat(restful): update get nodes api with `name_contains` param" This reverts commit e1b67cf41c09980cb6c8b7a33bca303981179f22. --- plugins/restful/adapter_handle.c | 40 +++++++------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/plugins/restful/adapter_handle.c b/plugins/restful/adapter_handle.c index 225b9031..54f9bafa 100644 --- a/plugins/restful/adapter_handle.c +++ b/plugins/restful/adapter_handle.c @@ -18,7 +18,6 @@ **/ #include -#include #include "vector.h" @@ -66,9 +65,8 @@ void handle_del_adapter(nng_aio *aio) }) } -static void handle_get_adapter_by_id(nng_aio *aio, neu_node_id_t node_id, - neu_node_type_e node_type, - const char * node_name_substr) +static void handle_get_adapter_by_id(nng_aio *aio, neu_node_type_e node_type, + neu_node_id_t node_id) { int rv = 0; neu_plugin_t * plugin = neu_rest_get_plugin(); @@ -81,10 +79,7 @@ static void handle_get_adapter_by_id(nng_aio *aio, neu_node_id_t node_id, return; } - if ((NEU_NODE_TYPE_MAX != node_type && node_type != node_info.node_type) || - (NULL != node_name_substr && - NULL == strstr(node_info.node_name, node_name_substr))) { - // `type` or `name_contains` param must comply when present + if (NEU_NODE_TYPE_MAX != node_type && node_type != node_info.node_type) { NEU_JSON_RESPONSE_ERROR(NEU_ERR_NODE_NOT_EXIST, { http_response(aio, error_code.error, result_error); }) @@ -120,20 +115,14 @@ static void handle_get_adapter_by_id(nng_aio *aio, neu_node_id_t node_id, void handle_get_adapter(nng_aio *aio) { - neu_plugin_t * plugin = neu_rest_get_plugin(); - char * result = NULL; - neu_node_type_e node_type = NEU_NODE_TYPE_MAX; - neu_node_id_t node_id = 0; - char name_substr[64] = {}; - ssize_t name_substr_len = 0; + neu_plugin_t * plugin = neu_rest_get_plugin(); + char * result = NULL; + neu_node_type_e node_type = NEU_NODE_TYPE_MAX; + neu_node_id_t node_id = 0; VALIDATE_JWT(aio); - name_substr_len = http_get_param_str(aio, "name_contains", name_substr, - sizeof(name_substr)); - - if (-1 == name_substr_len || sizeof(name_substr) == name_substr_len || - NEU_ERR_EINVAL == http_get_param_node_type(aio, "type", &node_type) || + if (NEU_ERR_EINVAL == http_get_param_node_type(aio, "type", &node_type) || NEU_ERR_EINVAL == http_get_param_node_id(aio, "id", &node_id)) { NEU_JSON_RESPONSE_ERROR(NEU_ERR_PARAM_IS_WRONG, { http_response(aio, error_code.error, result_error); @@ -142,14 +131,10 @@ void handle_get_adapter(nng_aio *aio) } if (0 != node_id) { - // `id` param presents, then filter by id - return handle_get_adapter_by_id(aio, node_id, node_type, - (-2 != name_substr_len) ? name_substr - : NULL); + return handle_get_adapter_by_id(aio, node_type, node_id); } if (NEU_NODE_TYPE_MAX == node_type) { - // `type` query param is required if `id` param not present NEU_JSON_RESPONSE_ERROR(NEU_ERR_PARAM_IS_WRONG, { http_response(aio, error_code.error, result_error); }) @@ -168,18 +153,11 @@ void handle_get_adapter(nng_aio *aio) { neu_node_info_t *info = (neu_node_info_t *) iterator_get(&iter); - if (-2 != name_substr_len && - NULL == strstr(info->node_name, name_substr)) { - // `name_contains` param presents, then filter by name sub string - continue; - } - nodes_res.nodes[index].id = info->node_id; nodes_res.nodes[index].name = info->node_name; nodes_res.nodes[index].plugin_id = info->plugin_id.id_val; index += 1; } - nodes_res.n_node = index; neu_json_encode_by_fn(&nodes_res, neu_json_encode_get_nodes_resp, &result); From b484e541a2e52aa74ba306a7ee49b1717050549e Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Mon, 30 May 2022 00:34:30 +0800 Subject: [PATCH 3/4] revert: "test(restful): add new get node api functionality tests" This reverts commit 47f20e17bf18f5a4707a6f333e580a27eb871d99. --- ft/node_api_test.robot | 78 ++---------------------------------------- 1 file changed, 3 insertions(+), 75 deletions(-) diff --git a/ft/node_api_test.robot b/ft/node_api_test.robot index 2c465491..0bfc3744 100644 --- a/ft/node_api_test.robot +++ b/ft/node_api_test.robot @@ -47,41 +47,14 @@ Get node with wrong parameters, it will return failure Integer response status 400 Integer response body error ${ERR_REQUEST_PARAM_INVALID} -Get node by nonexistent id, it should failure - GET /api/v2/node?id=123456 - - Integer response status 404 - Integer response body error ${ERR_NODE_NOT_EXIST} - Get DRIVER node, it should return all DRIVER node ${res} = Get Nodes ${NODE_DRIVER} Check Response Status ${res} 200 - Node With Name Should Exist ${res}[nodes] test-node - -Get DRIVER node by id, it should return the DRIVER node - ${id} = Get Node ID ${NODE_DRIVER} test-node - - GET /api/v2/node?id=${id} - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name test-node - -Get DRIVER node by id with correct type, it should return the DRIVER node - ${id} = Get Node ID ${NODE_DRIVER} test-node - - GET /api/v2/node?type=${NODE_DRIVER}&id=${id} - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name test-node - -Get DRIVER node by id with wrong type, it should return failure - ${id} = Get Node ID ${NODE_DRIVER} test-node - - GET /api/v2/node?type=${NODE_WEB}&id=${id} - Integer response status 404 - Integer response body error ${ERR_NODE_NOT_EXIST} + FOR ${name} IN test-node + Node With Name Should Exist ${res}[nodes] ${name} + END Get WEB node, it should return all WEB node ${res} = Get Nodes ${NODE_WEB} @@ -89,29 +62,6 @@ Get WEB node, it should return all WEB node Check Response Status ${res} 200 Node With Name Should Exist ${res}[nodes] default-dashboard-adapter -Get WEB node by id, it should return the WEB node - ${id} = Get Node ID ${NODE_WEB} default-dashboard-adapter - - GET /api/v2/node?id=${id} - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name default-dashboard-adapter - -Get WEB node by id with correct type, it should return the WEB node - ${id} = Get Node ID ${NODE_WEB} default-dashboard-adapter - - GET /api/v2/node?type=${NODE_WEB}&id=${id} - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name default-dashboard-adapter - -Get WEB node by id with wrong type, it should return failure - ${id} = Get Node ID ${NODE_WEB} default-dashboard-adapter - - GET /api/v2/node?type=${NODE_DRIVER}&id=${id} - Integer response status 404 - Integer response body error ${ERR_NODE_NOT_EXIST} - Get MQTT node, it should return all mqtt node ${res} = Add Node type=${${NODE_MQTT}} name=mqtt-adapter plugin_name=mqtt ${res} = Get Nodes ${NODE_MQTT} @@ -119,28 +69,6 @@ Get MQTT node, it should return all mqtt node Check Response Status ${res} 200 Node With Name Should Exist ${res}[nodes] mqtt-adapter -Get MQTT node by id, it should return the MQTT node - ${id} = Get Node ID ${NODE_MQTT} mqtt-adapter - - GET /api/v2/node?id=${id} - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name mqtt-adapter - -Get MQTT node by id with correct type, it should return the MQTT node - ${id} = Get Node ID ${NODE_MQTT} mqtt-adapter - - GET /api/v2/node?type=${NODE_MQTT}&id=${id} - Integer response status 200 - Integer response body nodes 0 id ${id} - String response body nodes 0 name mqtt-adapter - -Get MQTT node by id with wrong type, it should return failure - ${id} = Get Node ID ${NODE_MQTT} mqtt-adapter - - GET /api/v2/node?type=${NODE_WEB}&id=${id} - Integer response status 404 - Integer response body error ${ERR_NODE_NOT_EXIST} Get UNKNOWN type node, it should return empty node ${res} = Get Nodes ${NODE_UNKNOWN} From 2a55d6785bbbe5203569d4514a167ae4b8a61866 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Mon, 30 May 2022 00:36:50 +0800 Subject: [PATCH 4/4] revert: "feat(restful): update get node api with filtering by node id param" This reverts commit d66ac56847294030c5a441d34c988f81be1c9679. --- plugins/restful/adapter_handle.c | 69 +++----------------------------- 1 file changed, 5 insertions(+), 64 deletions(-) diff --git a/plugins/restful/adapter_handle.c b/plugins/restful/adapter_handle.c index 54f9bafa..f99cc84f 100644 --- a/plugins/restful/adapter_handle.c +++ b/plugins/restful/adapter_handle.c @@ -65,76 +65,15 @@ void handle_del_adapter(nng_aio *aio) }) } -static void handle_get_adapter_by_id(nng_aio *aio, neu_node_type_e node_type, - neu_node_id_t node_id) -{ - int rv = 0; - neu_plugin_t * plugin = neu_rest_get_plugin(); - neu_node_info_t node_info = { 0 }; - - rv = neu_system_get_node_by_id(plugin, node_id, &node_info); - if (0 != rv) { - NEU_JSON_RESPONSE_ERROR( - rv, { http_response(aio, error_code.error, result_error); }) - return; - } - - if (NEU_NODE_TYPE_MAX != node_type && node_type != node_info.node_type) { - NEU_JSON_RESPONSE_ERROR(NEU_ERR_NODE_NOT_EXIST, { - http_response(aio, error_code.error, result_error); - }) - return; - } - - neu_json_get_nodes_resp_node_t node_resp = { 0 }; - node_resp.id = node_info.node_id; - node_resp.name = node_info.node_name; - node_resp.plugin_id = node_info.plugin_id.id_val; - - neu_json_get_nodes_resp_t nodes_resp = { 0 }; - nodes_resp.n_node = 1; - nodes_resp.nodes = &node_resp; - - char *result = NULL; - rv = neu_json_encode_by_fn(&nodes_resp, neu_json_encode_get_nodes_resp, - &result); - if (0 == rv) { - http_ok(aio, result); - } else { - nlog_error("encode node info json response fail"); - NEU_JSON_RESPONSE_ERROR(NEU_ERR_EINTERNAL, { - http_response(aio, error_code.error, result_error); - }) - } - - free(result); - free(node_info.node_name); - - return; -} - void handle_get_adapter(nng_aio *aio) { neu_plugin_t * plugin = neu_rest_get_plugin(); char * result = NULL; - neu_node_type_e node_type = NEU_NODE_TYPE_MAX; - neu_node_id_t node_id = 0; + neu_node_type_e node_type = { 0 }; VALIDATE_JWT(aio); - if (NEU_ERR_EINVAL == http_get_param_node_type(aio, "type", &node_type) || - NEU_ERR_EINVAL == http_get_param_node_id(aio, "id", &node_id)) { - NEU_JSON_RESPONSE_ERROR(NEU_ERR_PARAM_IS_WRONG, { - http_response(aio, error_code.error, result_error); - }) - return; - } - - if (0 != node_id) { - return handle_get_adapter_by_id(aio, node_type, node_id); - } - - if (NEU_NODE_TYPE_MAX == node_type) { + if (http_get_param_node_type(aio, "type", &node_type) != 0) { NEU_JSON_RESPONSE_ERROR(NEU_ERR_PARAM_IS_WRONG, { http_response(aio, error_code.error, result_error); }) @@ -169,7 +108,9 @@ void handle_get_adapter(nng_aio *aio) VECTOR_FOR_EACH(&nodes, iter) { neu_node_info_t *info = (neu_node_info_t *) iterator_get(&iter); + free(info->node_name); + index += 1; } vector_uninit(&nodes); } @@ -261,4 +202,4 @@ void handle_get_node_state(nng_aio *aio) free(result); } }) -} \ No newline at end of file +}