From d6e94f7009449cb094f574d92493cfe12935ff5e Mon Sep 17 00:00:00 2001 From: "xiang.zhou" Date: Mon, 18 Dec 2023 14:58:10 +0800 Subject: [PATCH 1/6] fix:add library update fail error code --- src/utils/http.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/http.c b/src/utils/http.c index 6d82e2383..7775ead13 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -341,6 +341,7 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_PLUGIN_NAME_TOO_LONG: case NEU_ERR_PLUGIN_NOT_SUPPORT_TEMPLATE: case NEU_ERR_LIBRARY_ADD_FAIL: + case NEU_ERR_LIBRARY_UPDATE_FAIL: case NEU_ERR_LIBRARY_MODULE_NOT_EXISTS: case NEU_ERR_LIBRARY_MODULE_KIND_NOT_SUPPORT: case NEU_ERR_LIBRARY_MODULE_VERSION_NOT_MATCH: From 74dc6b94899f5e9ca9da726b671a4c690b43a1cf Mon Sep 17 00:00:00 2001 From: fengzero Date: Mon, 18 Dec 2023 07:30:21 +0000 Subject: [PATCH 2/6] fix(conn): lock conn buf --- src/connection/connection.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/connection/connection.c b/src/connection/connection.c index 4a2b87fbd..9084f927f 100644 --- a/src/connection/connection.c +++ b/src/connection/connection.c @@ -1289,10 +1289,12 @@ int neu_conn_stream_consume(neu_conn_t *conn, void *context, neu_conn_disconnect(conn); break; } else { + pthread_mutex_lock(&conn->mtx); conn->offset -= used; memmove(conn->buf, conn->buf + used, conn->offset); neu_protocol_unpack_buf_init(&protocol_buf, conn->buf, conn->offset); + pthread_mutex_unlock(&conn->mtx); } } } From 3e4489d2c2c07b4535a18ab7d54c3b261747b64a Mon Sep 17 00:00:00 2001 From: hxy7yx <1595670487@qq.com> Date: Mon, 18 Dec 2023 15:40:56 +0800 Subject: [PATCH 3/6] fix:add_tags and add_gtags http resp code --- ft/tag_test.robot | 4 ++-- ft/template.robot | 8 ++++---- plugins/restful/datatag_handle.c | 7 ++++--- src/utils/http.c | 16 +++++++--------- tests/ft/driver/test_modbus.py | 12 ++++++------ tests/ft/tag/test_tag.py | 4 ++-- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/ft/tag_test.robot b/ft/tag_test.robot index 0442ca0e5..7a0649b9b 100644 --- a/ft/tag_test.robot +++ b/ft/tag_test.robot @@ -59,7 +59,7 @@ Add different types of tags to the group, it should return success Add a list of tags with errors, it should return the number of successful additions. ${res}= Add Tags modbus-node group ${tag1},${tag2},${tag3},${tag4} - Check Response Status ${res} 200 + Check Response Status ${res} 409 Check Error Code ${res} ${NEU_ERR_TAG_NAME_CONFLICT} Should Be Equal As Integers ${res}[index] 0 @@ -139,7 +139,7 @@ Delete tag from non-existent group, it should return success Update non-existent tag, it should return failure. ${res}= Update Tags modbus-node group ${tag4} - Check Response Status ${res} 200 + Check Response Status ${res} 404 Check Error Code ${res} ${NEU_ERR_TAG_NOT_EXIST} ${res}= Get Tags modbus-node group diff --git a/ft/template.robot b/ft/template.robot index 8b3a4e3f2..185fd3546 100644 --- a/ft/template.robot +++ b/ft/template.robot @@ -96,7 +96,7 @@ Create a template with invalid tag type, it should fail. ${groups} = Create List ${group} ${res} = Add Template ${g_template} ${g_plugin} ${groups} - Check Response Status ${res} 206 + Check Response Status ${res} 400 Check Error Code ${res} ${NEU_ERR_TAG_TYPE_NOT_SUPPORT} [Teardown] Del Template ${g_template} @@ -108,7 +108,7 @@ Create a template with invalid tag address, it should fail. ${groups} = Create List ${group} ${res} = Add Template ${g_template} ${g_plugin} ${groups} - Check Response Status ${res} 206 + Check Response Status ${res} 400 Check Error Code ${res} ${NEU_ERR_TAG_ADDRESS_FORMAT_INVALID} [Teardown] Del Template ${g_template} @@ -802,7 +802,7 @@ Add tag with too long name to existing template group, it should fail. &{tag} = New Tag From ${g_tag1} name=${g_long_str} ${res} = Add Template Tags ${g_template} ${g_group1}[name] ${tag} - Check Response Status ${res} 206 + Check Response Status ${res} 400 Check Error Code ${res} ${NEU_ERR_TAG_NAME_TOO_LONG} [Teardown] Del Template ${g_template} @@ -1026,7 +1026,7 @@ Update tag name to invalid value, it should fail. &{tag} = New Tag From ${g_tag1} name=${g_long_str} ${res} = Put Template Tags ${g_template} ${g_group1}[name] ${tag} - Check Response Status ${res} 206 + Check Response Status ${res} 400 Check Error Code ${res} ${NEU_ERR_TAG_NAME_TOO_LONG} [Teardown] Del Template ${g_template} diff --git a/plugins/restful/datatag_handle.c b/plugins/restful/datatag_handle.c index bc5f14ee7..ccbb74193 100644 --- a/plugins/restful/datatag_handle.c +++ b/plugins/restful/datatag_handle.c @@ -92,7 +92,8 @@ void handle_add_tags_resp(nng_aio *aio, neu_resp_add_tag_t *resp) neu_json_encode_by_fn(&res, neu_json_encode_au_tags_resp, &result); - neu_http_ok(aio, result); + NEU_JSON_RESPONSE_ERROR(resp->error, + { neu_http_response(aio, resp->error, result); }); free(result); } @@ -183,8 +184,8 @@ void handle_add_gtags_resp(nng_aio *aio, neu_resp_add_tag_t *resp) res.index = resp->index; neu_json_encode_by_fn(&res, neu_json_encode_au_gtags_resp, &result); - - neu_http_ok(aio, result); + NEU_JSON_RESPONSE_ERROR(resp->error, + { neu_http_response(aio, resp->error, result); }); free(result); } diff --git a/src/utils/http.c b/src/utils/http.c index 7775ead13..0bebf11c4 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -348,6 +348,13 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_LIBRARY_NAME_NOT_CONFORM: case NEU_ERR_LIBRARY_CLIB_NOT_MATCH: case NEU_ERR_LIBRARY_ARCH_NOT_SUPPORT: + case NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT: + case NEU_ERR_TAG_TYPE_NOT_SUPPORT: + case NEU_ERR_TAG_ADDRESS_FORMAT_INVALID: + case NEU_ERR_TAG_DESCRIPTION_TOO_LONG: + case NEU_ERR_TAG_PRECISION_INVALID: + case NEU_ERR_TAG_NAME_TOO_LONG: + case NEU_ERR_TAG_ADDRESS_TOO_LONG: status = NNG_HTTP_STATUS_BAD_REQUEST; break; case NEU_ERR_FILE_NOT_EXIST: @@ -383,15 +390,6 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_LIBRARY_SYSTEM_NOT_ALLOW_DEL: status = NNG_HTTP_STATUS_CONFLICT; break; - case NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT: - case NEU_ERR_TAG_TYPE_NOT_SUPPORT: - case NEU_ERR_TAG_ADDRESS_FORMAT_INVALID: - case NEU_ERR_TAG_DESCRIPTION_TOO_LONG: - case NEU_ERR_TAG_PRECISION_INVALID: - case NEU_ERR_TAG_NAME_TOO_LONG: - case NEU_ERR_TAG_ADDRESS_TOO_LONG: - status = NNG_HTTP_STATUS_PARTIAL_CONTENT; - break; default: if (code >= NEU_ERR_PLUGIN_ERROR_START && code <= NEU_ERR_PLUGIN_ERROR_END) { diff --git a/tests/ft/driver/test_modbus.py b/tests/ft/driver/test_modbus.py index c97388d75..8685f9d3a 100644 --- a/tests/ft/driver/test_modbus.py +++ b/tests/ft/driver/test_modbus.py @@ -382,27 +382,27 @@ def test_add_wrong_tags(self, param): "attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_BYTES}] response = api.add_tags(node=param[0], group='group', tags=wrong_tag1) - assert 200 == response.status_code + assert 400 == response.status_code assert error.NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT == response.json()[ 'error'] response = api.add_tags(node=param[0], group='group', tags=wrong_tag2) - assert 200 == response.status_code + assert 400 == response.status_code assert error.NEU_ERR_TAG_TYPE_NOT_SUPPORT == response.json()[ 'error'] response = api.add_tags(node=param[0], group='group', tags=wrong_tag3) - assert 200 == response.status_code + assert 400 == response.status_code assert error.NEU_ERR_TAG_ADDRESS_FORMAT_INVALID == response.json()[ 'error'] response = api.add_tags(node=param[0], group='group', tags=wrong_tag4) - assert 200 == response.status_code + assert 400 == response.status_code assert error.NEU_ERR_TAG_ADDRESS_FORMAT_INVALID == response.json()[ 'error'] response = api.add_tags(node=param[0], group='group', tags=wrong_tag5) - assert 200 == response.status_code + assert 400 == response.status_code assert error.NEU_ERR_TAG_ADDRESS_FORMAT_INVALID == response.json()[ 'error'] @@ -571,7 +571,7 @@ def test_update_wrong_tag(self, param): up_tag[0]['type'] = config.NEU_TYPE_BIT response = api.update_tags( node=param[0], group='group', tags=up_tag) - assert 200 == response.status_code + assert 400 == response.status_code assert error.NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT == response.json()[ 'error'] diff --git a/tests/ft/tag/test_tag.py b/tests/ft/tag/test_tag.py index b430bbcc2..ed51e64bf 100644 --- a/tests/ft/tag/test_tag.py +++ b/tests/ft/tag/test_tag.py @@ -279,7 +279,7 @@ def test_adding_gtags_type_err(self): ] ) - assert 200 == response.status_code + assert 400 == response.status_code assert NEU_ERR_TAG_TYPE_NOT_SUPPORT == response.json()['error'] response = api.get_group() @@ -342,7 +342,7 @@ def test_adding_gtags_name_err(self): ] ) - assert 200 == response.status_code + assert 409 == response.status_code assert NEU_ERR_TAG_NAME_CONFLICT == response.json()['error'] response = api.get_group() From b14522058555e128ae4288562974f31c1cab950c Mon Sep 17 00:00:00 2001 From: hxy7yx <1595670487@qq.com> Date: Mon, 18 Dec 2023 18:10:38 +0800 Subject: [PATCH 4/6] fix http status --- src/utils/http.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/utils/http.c b/src/utils/http.c index 0bebf11c4..e9a6aa8c0 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -355,6 +355,8 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_TAG_PRECISION_INVALID: case NEU_ERR_TAG_NAME_TOO_LONG: case NEU_ERR_TAG_ADDRESS_TOO_LONG: + case NEU_ERR_LICENSE_BAD_CLOCK: + case NEU_ERR_LICENSE_MODULE_INVALID: status = NNG_HTTP_STATUS_BAD_REQUEST; break; case NEU_ERR_FILE_NOT_EXIST: From 59e7ff3e60e208f631df9cffbe493cad0d4e2c7f Mon Sep 17 00:00:00 2001 From: hxy7yx <1595670487@qq.com> Date: Tue, 19 Dec 2023 14:07:59 +0800 Subject: [PATCH 5/6] fix(add_gtags):license tag count --- src/adapter/adapter.c | 7 ++++++- src/utils/http.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/adapter/adapter.c b/src/adapter/adapter.c index 82fa9bb8f..fa5a96357 100644 --- a/src/adapter/adapter.c +++ b/src/adapter/adapter.c @@ -1286,7 +1286,6 @@ int add_gtags(neu_adapter_t *adapter, neu_req_add_gtag_t *cmd, cmd->groups[group_index].group, &cmd->groups[group_index].tags[tag_index], cmd->groups[group_index].interval); - if (add_tag_result != 0) { for (int added_group_index = 0; added_group_index < group_index; added_group_index++) { @@ -1308,6 +1307,12 @@ int add_gtags(neu_adapter_t *adapter, neu_req_add_gtag_t *cmd, cmd->groups[group_index].group, cmd->groups[group_index].tags[added_tag_index].name); } + for (int groups_count = 0; groups_count < cmd->n_group; + groups_count++) { + neu_adapter_driver_try_del_tag( + (neu_adapter_driver_t *) adapter, + cmd->groups[groups_count].n_tag); + } resp->index = 0; resp->error = add_tag_result; return add_tag_result; diff --git a/src/utils/http.c b/src/utils/http.c index e9a6aa8c0..8a7b1ab3b 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -287,7 +287,6 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_LICENSE_EXPIRED: case NEU_ERR_LICENSE_DISABLED: case NEU_ERR_LICENSE_MAX_NODES: - case NEU_ERR_LICENSE_MAX_TAGS: case NEU_ERR_LICENSE_TOKEN_NOT_MATCH: case NEU_ERR_GROUP_ALREADY_SUBSCRIBED: case NEU_ERR_PLUGIN_TAG_TYPE_MISMATCH: @@ -355,6 +354,7 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_TAG_PRECISION_INVALID: case NEU_ERR_TAG_NAME_TOO_LONG: case NEU_ERR_TAG_ADDRESS_TOO_LONG: + case NEU_ERR_LICENSE_MAX_TAGS: case NEU_ERR_LICENSE_BAD_CLOCK: case NEU_ERR_LICENSE_MODULE_INVALID: status = NNG_HTTP_STATUS_BAD_REQUEST; From 336563834b3fcc54021f2fca216dc1f32ab35b21 Mon Sep 17 00:00:00 2001 From: fengzero Date: Thu, 21 Dec 2023 03:31:34 +0000 Subject: [PATCH 6/6] version: 2.7.0 --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 83ec0ffea..9aa34646d 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.7.0-alpha1 \ No newline at end of file +2.7.0 \ No newline at end of file