Skip to content

Commit

Permalink
Merge pull request #1776 from fengzeroz/v2.7
Browse files Browse the repository at this point in the history
V2.7
  • Loading branch information
fengzeroz authored Dec 22, 2023
2 parents 8930b16 + 3365638 commit 2b814b8
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 29 deletions.
4 changes: 2 additions & 2 deletions ft/tag_test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ft/template.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 4 additions & 3 deletions plugins/restful/datatag_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
7 changes: 6 additions & 1 deletion src/adapter/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/connection/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/utils/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -341,12 +340,23 @@ 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:
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:
case NEU_ERR_LICENSE_MAX_TAGS:
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:
Expand Down Expand Up @@ -382,15 +392,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) {
Expand Down
12 changes: 6 additions & 6 deletions tests/ft/driver/test_modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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']

Expand Down
4 changes: 2 additions & 2 deletions tests/ft/tag/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.0-alpha1
2.7.0

0 comments on commit 2b814b8

Please sign in to comment.