diff --git a/plugins/restful/handle.c b/plugins/restful/handle.c index 003e701a..eecf66f0 100644 --- a/plugins/restful/handle.c +++ b/plugins/restful/handle.c @@ -366,6 +366,12 @@ static struct neu_http_handler rest_handlers[] = { .url = "/api/v2/template/tag", .value.handler = handle_add_template_tags, }, + { + .method = NEU_HTTP_METHOD_PUT, + .type = NEU_HTTP_HANDLER_FUNCTION, + .url = "/api/v2/template/tag", + .value.handler = handle_update_template_tags, + }, }; void neu_rest_handler(const struct neu_http_handler **handlers, uint32_t *size) diff --git a/plugins/restful/rest.c b/plugins/restful/rest.c index c0c1cc4a..11fe3afd 100644 --- a/plugins/restful/rest.c +++ b/plugins/restful/rest.c @@ -201,6 +201,7 @@ static int dashb_plugin_request(neu_plugin_t * plugin, handle_add_tags_resp(header->ctx, (neu_resp_add_tag_t *) data); break; case NEU_RESP_UPDATE_TAG: + case NEU_RESP_UPDATE_TEMPLATE_TAG: handle_update_tags_resp(header->ctx, (neu_resp_update_tag_t *) data); break; case NEU_RESP_GET_TAG: diff --git a/plugins/restful/template_handle.c b/plugins/restful/template_handle.c index 6230c5c9..30d77eb5 100644 --- a/plugins/restful/template_handle.c +++ b/plugins/restful/template_handle.c @@ -372,3 +372,17 @@ void handle_add_template_tags(nng_aio *aio) } }) } + +void handle_update_template_tags(nng_aio *aio) +{ + NEU_PROCESS_HTTP_REQUEST_VALIDATE_JWT( + aio, neu_json_template_mod_tags_req_t, + neu_json_decode_template_mod_tags_req, { + int ret = + send_template_tags_req(aio, NEU_REQ_UPDATE_TEMPLATE_TAG, req); + if (0 != ret) { + NEU_JSON_RESPONSE_ERROR( + ret, { neu_http_response(aio, ret, result_error); }); + } + }) +} diff --git a/plugins/restful/template_handle.h b/plugins/restful/template_handle.h index a7c72717..3a24268a 100644 --- a/plugins/restful/template_handle.h +++ b/plugins/restful/template_handle.h @@ -31,5 +31,6 @@ void handle_get_template_resp(nng_aio *aio, neu_resp_get_template_t *resp); void handle_get_templates_resp(nng_aio *aio, neu_resp_get_templates_t *resp); void handle_add_template_tags(nng_aio *aio); +void handle_update_template_tags(nng_aio *aio); #endif diff --git a/src/core/manager.c b/src/core/manager.c index 5598daef..5a8c3b43 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -397,6 +397,24 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data) reply(manager, header, &resp); break; } + case NEU_REQ_UPDATE_TEMPLATE_TAG: { + neu_req_update_template_tag_t *cmd = + (neu_req_update_template_tag_t *) &header[1]; + neu_resp_update_tag_t resp = { 0 }; + + resp.error = + neu_manager_update_template_tags(manager, cmd, &resp.index); + if (resp.index > 0) { + // TODO: storage + } + + neu_req_update_template_tag_fini(cmd); + + header->type = NEU_RESP_UPDATE_TEMPLATE_TAG; + strcpy(header->receiver, header->sender); + reply(manager, header, &resp); + break; + } case NEU_REQ_ADD_NODE: { neu_req_add_node_t *cmd = (neu_req_add_node_t *) &header[1]; int error = @@ -704,6 +722,7 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data) case NEU_RESP_ADD_TAG: case NEU_RESP_ADD_TEMPLATE_TAG: case NEU_RESP_UPDATE_TAG: + case NEU_RESP_UPDATE_TEMPLATE_TAG: case NEU_RESP_GET_TAG: case NEU_RESP_GET_GROUP: case NEU_RESP_GET_NODE_SETTING: diff --git a/src/core/manager_internal.c b/src/core/manager_internal.c index 138ddec6..e356fe9b 100644 --- a/src/core/manager_internal.c +++ b/src/core/manager_internal.c @@ -260,6 +260,37 @@ int neu_manager_add_template_tags(neu_manager_t * manager, return ret; } +int neu_manager_update_template_tags(neu_manager_t * manager, + neu_req_update_template_tag_t *req, + uint16_t * index_p) +{ + int ret = 0; + + neu_template_t *tmpl = + neu_template_manager_find(manager->template_manager, req->tmpl); + if (NULL == tmpl) { + return NEU_ERR_TEMPLATE_NOT_FOUND; + } + + neu_group_t *grp = neu_template_get_group(tmpl, req->group); + if (NULL == grp) { + return NEU_ERR_GROUP_NOT_EXIST; + } + + int i = 0; + for (; i < req->n_tag; ++i) { + if (0 != (ret = neu_group_update_tag(grp, &req->tags[i]))) { + break; + } + } + + if (index_p) { + *index_p = i; + } + + return ret; +} + UT_array *neu_manager_get_driver_group(neu_manager_t *manager) { UT_array *drivers = diff --git a/src/core/manager_internal.h b/src/core/manager_internal.h index 99d58fc7..2680ab1d 100644 --- a/src/core/manager_internal.h +++ b/src/core/manager_internal.h @@ -68,6 +68,9 @@ int neu_manager_get_templates(neu_manager_t * manager, int neu_manager_add_template_tags(neu_manager_t * manager, neu_req_add_template_tag_t *req, uint16_t * index_p); +int neu_manager_update_template_tags(neu_manager_t * manager, + neu_req_add_template_tag_t *req, + uint16_t * index_p); UT_array *neu_manager_get_driver_group(neu_manager_t *manager);