mirror of
https://github.com/emqx/neuron.git
synced 2026-10-28 14:07:20 +08:00
feat(restful): add get ndriver maps api
This commit is contained in:
@@ -442,6 +442,12 @@ static struct neu_http_handler rest_handlers[] = {
|
||||
.url = "/api/v2/ndriver/map",
|
||||
.value.handler = handle_del_ndriver_map,
|
||||
},
|
||||
{
|
||||
.method = NEU_HTTP_METHOD_GET,
|
||||
.type = NEU_HTTP_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/ndriver/map",
|
||||
.value.handler = handle_get_ndriver_maps,
|
||||
},
|
||||
};
|
||||
|
||||
void neu_rest_handler(const struct neu_http_handler **handlers, uint32_t *size)
|
||||
|
||||
@@ -84,3 +84,65 @@ void handle_del_ndriver_map(nng_aio *aio)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
void handle_get_ndriver_maps(nng_aio *aio)
|
||||
{
|
||||
int ret = 0;
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
NEU_VALIDATE_JWT(aio);
|
||||
|
||||
neu_req_get_ndriver_maps_t cmd = { 0 };
|
||||
if (neu_http_get_param_str(aio, "ndriver", cmd.ndriver,
|
||||
sizeof(cmd.ndriver)) <= 0 ||
|
||||
strlen(cmd.ndriver) >= NEU_NODE_NAME_LEN) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_PARAM_IS_WRONG, {
|
||||
neu_http_response(aio, error_code.error, result_error);
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
neu_reqresp_head_t header = {
|
||||
.ctx = aio,
|
||||
.type = NEU_REQ_GET_NDRIVER_MAPS,
|
||||
};
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
if (ret != 0) {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_IS_BUSY, {
|
||||
neu_http_response(aio, NEU_ERR_IS_BUSY, result_error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void handle_get_ndriver_maps_resp(nng_aio * aio,
|
||||
neu_resp_get_ndriver_maps_t *groups)
|
||||
{
|
||||
neu_json_ndriver_map_group_array_t group_arr = { 0 };
|
||||
|
||||
group_arr.n_group = utarray_len(groups->groups);
|
||||
group_arr.groups = calloc(group_arr.n_group, sizeof(*group_arr.groups));
|
||||
|
||||
int index = 0;
|
||||
utarray_foreach(groups->groups, neu_resp_ndriver_map_info_t *, group)
|
||||
{
|
||||
group_arr.groups[index].driver = group->driver;
|
||||
group_arr.groups[index].group = group->group;
|
||||
++index;
|
||||
}
|
||||
|
||||
char *result = NULL;
|
||||
neu_json_encode_by_fn(&group_arr, neu_json_encode_get_ndriver_maps_resp,
|
||||
&result);
|
||||
if (result) {
|
||||
neu_http_ok(aio, result);
|
||||
} else {
|
||||
NEU_JSON_RESPONSE_ERROR(NEU_ERR_EINTERNAL, {
|
||||
neu_http_response(aio, NEU_ERR_EINTERNAL, result_error);
|
||||
});
|
||||
}
|
||||
|
||||
free(result);
|
||||
free(group_arr.groups);
|
||||
utarray_free(groups->groups);
|
||||
}
|
||||
|
||||
@@ -25,5 +25,8 @@
|
||||
|
||||
void handle_add_ndriver_map(nng_aio *aio);
|
||||
void handle_del_ndriver_map(nng_aio *aio);
|
||||
void handle_get_ndriver_maps(nng_aio *aio);
|
||||
void handle_get_ndriver_maps_resp(nng_aio * aio,
|
||||
neu_resp_get_ndriver_maps_t *groups);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "global_config_handle.h"
|
||||
#include "group_config_handle.h"
|
||||
#include "handle.h"
|
||||
#include "ndriver_handle.h"
|
||||
#include "plugin_handle.h"
|
||||
#include "rest.h"
|
||||
#include "rw_handle.h"
|
||||
@@ -232,6 +233,10 @@ static int dashb_plugin_request(neu_plugin_t * plugin,
|
||||
handle_get_templates_resp(header->ctx,
|
||||
(neu_resp_get_templates_t *) data);
|
||||
break;
|
||||
case NEU_RESP_GET_NDRIVER_MAPS:
|
||||
handle_get_ndriver_maps_resp(header->ctx,
|
||||
(neu_resp_get_ndriver_maps_t *) data);
|
||||
break;
|
||||
default:
|
||||
nlog_fatal("recv unhandle msg: %s",
|
||||
neu_reqresp_type_string(header->type));
|
||||
|
||||
Reference in New Issue
Block a user