mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
Merge pull request #2718 from hxy7yx/main-1
feat(tag):supports renaming tags
This commit is contained in:
@@ -398,6 +398,72 @@ void handle_update_tags_resp(nng_aio *aio, neu_resp_update_tag_t *resp)
|
||||
handle_add_tags_resp(aio, resp);
|
||||
}
|
||||
|
||||
void handle_rename_tag(nng_aio *aio)
|
||||
{
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
|
||||
aio, neu_json_rename_tag_req_t, neu_json_decode_rename_tag_req, {
|
||||
int ret = 0;
|
||||
neu_reqresp_head_t header = { 0 };
|
||||
neu_req_rename_tag_t cmd = { 0 };
|
||||
int err_type;
|
||||
|
||||
header.ctx = aio;
|
||||
header.type = NEU_REQ_RENAME_TAG;
|
||||
header.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM;
|
||||
|
||||
if (strlen(req->node) >= NEU_NODE_NAME_LEN) {
|
||||
err_type = NEU_ERR_NODE_NAME_TOO_LONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (strlen(req->group) >= NEU_GROUP_NAME_LEN) {
|
||||
err_type = NEU_ERR_GROUP_NAME_TOO_LONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (strlen(req->old_name) == 0 || strlen(req->new_name) == 0) {
|
||||
err_type = NEU_ERR_PARAM_IS_WRONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (strlen(req->old_name) >= NEU_TAG_NAME_LEN) {
|
||||
err_type = NEU_ERR_TAG_NAME_TOO_LONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (strlen(req->new_name) >= NEU_TAG_NAME_LEN) {
|
||||
err_type = NEU_ERR_TAG_NAME_TOO_LONG;
|
||||
goto error;
|
||||
}
|
||||
|
||||
strcpy(cmd.driver, req->node);
|
||||
strcpy(cmd.group, req->group);
|
||||
strcpy(cmd.old_name, req->old_name);
|
||||
strcpy(cmd.new_name, req->new_name);
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
goto success;
|
||||
|
||||
error:
|
||||
NEU_JSON_RESPONSE_ERROR(
|
||||
err_type, { neu_http_response(aio, err_type, result_error); });
|
||||
success:;
|
||||
})
|
||||
}
|
||||
|
||||
void handle_rename_tag_resp(nng_aio *aio, neu_resp_rename_tag_t *resp)
|
||||
{
|
||||
NEU_JSON_RESPONSE_ERROR(
|
||||
resp->error, { neu_http_response(aio, resp->error, result_error); });
|
||||
}
|
||||
|
||||
void handle_get_tags(nng_aio *aio)
|
||||
{
|
||||
neu_plugin_t * plugin = neu_rest_get_plugin();
|
||||
|
||||
@@ -33,6 +33,8 @@ void handle_import_tags_resp(nng_aio *aio, neu_resp_add_tag_t *resp);
|
||||
void handle_del_tags(nng_aio *aio);
|
||||
void handle_update_tags(nng_aio *aio);
|
||||
void handle_update_tags_resp(nng_aio *aio, neu_resp_update_tag_t *resp);
|
||||
void handle_rename_tag(nng_aio *aio);
|
||||
void handle_rename_tag_resp(nng_aio *aio, neu_resp_rename_tag_t *resp);
|
||||
void handle_get_tags(nng_aio *aio);
|
||||
void handle_get_tags_resp(nng_aio *aio, neu_resp_get_tag_t *tags);
|
||||
|
||||
|
||||
@@ -212,6 +212,9 @@ static struct neu_http_handler cors_handler[] = {
|
||||
{
|
||||
.url = "/api/v2/simulator/export",
|
||||
},
|
||||
{
|
||||
.url = "/api/v2/tag/rename",
|
||||
},
|
||||
};
|
||||
|
||||
static struct neu_http_handler rest_handlers[] = {
|
||||
@@ -294,6 +297,12 @@ static struct neu_http_handler rest_handlers[] = {
|
||||
.url = "/api/v2/tags",
|
||||
.value.handler = handle_del_tags,
|
||||
},
|
||||
{
|
||||
.method = NEU_HTTP_METHOD_PUT,
|
||||
.type = NEU_HTTP_HANDLER_FUNCTION,
|
||||
.url = "/api/v2/tag/rename",
|
||||
.value.handler = handle_rename_tag,
|
||||
},
|
||||
{
|
||||
.method = NEU_HTTP_METHOD_POST,
|
||||
.type = NEU_HTTP_HANDLER_FUNCTION,
|
||||
|
||||
@@ -280,6 +280,13 @@ static int dashb_plugin_request(neu_plugin_t * plugin,
|
||||
scope, "error", ((neu_resp_update_tag_t *) data)->error);
|
||||
}
|
||||
break;
|
||||
case NEU_RESP_RENAME_TAG:
|
||||
handle_rename_tag_resp(header->ctx, (neu_resp_rename_tag_t *) data);
|
||||
if (neu_otel_control_is_started() && trace) {
|
||||
neu_otel_scope_add_span_attr_int(
|
||||
scope, "error", ((neu_resp_rename_tag_t *) data)->error);
|
||||
}
|
||||
break;
|
||||
case NEU_RESP_GET_TAG:
|
||||
handle_get_tags_resp(header->ctx, (neu_resp_get_tag_t *) data);
|
||||
if (neu_otel_control_is_started() && trace) {
|
||||
|
||||
Reference in New Issue
Block a user