Merge pull request #517 from eeff/eeff/dev

Revert get node api changes
This commit is contained in:
fengzeroz
2022-05-30 09:51:31 +08:00
committed by GitHub
2 changed files with 10 additions and 213 deletions
+3 -125
View File
@@ -47,60 +47,14 @@ 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
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 name substring, 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
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}
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}
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}
@@ -108,44 +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 name substring, 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
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 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}
@@ -153,44 +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 name substring, 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
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 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}
+7 -88
View File
@@ -18,7 +18,6 @@
**/
#include <stdlib.h>
#include <string.h>
#include "vector.h"
@@ -66,90 +65,15 @@ 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)
{
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) ||
(NULL != node_name_substr &&
NULL == strstr(node_info.node_name, node_name_substr))) {
// `type` or `name_contains` param must comply when present
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;
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 = { 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) ||
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) {
// `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);
}
if (NEU_NODE_TYPE_MAX == node_type) {
// `type` query param is required if `id` param not present
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);
})
@@ -168,18 +92,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);
@@ -191,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);
}
@@ -283,4 +202,4 @@ void handle_get_node_state(nng_aio *aio)
free(result);
}
})
}
}