Skip to content

Commit c9bae5e

Browse files
author
fengzero
committed
fix: import apps crash
1 parent 4533901 commit c9bae5e

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

plugins/restful/global_config_handle.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ typedef enum {
6060
STATE_DEL_APP,
6161
STATE_DEL_DRIVER,
6262
STATE_ADD_NODE,
63+
STATE_UPDATE_DEFAULT_APP_TAGS,
6364
STATE_ADD_GROUP,
6465
STATE_ADD_TAG,
6566
STATE_GET_APP_SUBS,
@@ -745,6 +746,28 @@ static void put_apps_context_next(context_t *ctx, neu_reqresp_type_e type,
745746
}
746747

747748
// After adding nodes, get subscriptions for default apps to unsub
749+
ctx->idx = 0;
750+
ctx->unsub_idx = 0;
751+
ctx->state = STATE_UPDATE_DEFAULT_APP_TAGS;
752+
}
753+
// fall through
754+
case STATE_UPDATE_DEFAULT_APP_TAGS: {
755+
neu_resp_error_t * err = data;
756+
neu_json_apps_req_t *apps = ctx->apps_req;
757+
758+
if (ctx->idx > 0 && 0 != err->error) {
759+
ctx->error = err->error;
760+
ctx->state = STATE_END;
761+
break;
762+
}
763+
764+
for (; ctx->idx < (size_t) apps->n_app; ++ctx->idx) {
765+
neu_json_app_t *app = &apps->apps[ctx->idx];
766+
NEXT(ctx, add_app_tags, app);
767+
++ctx->idx;
768+
goto done;
769+
}
770+
748771
ctx->idx = 0;
749772
ctx->unsub_idx = 0;
750773
ctx->state = STATE_GET_APP_SUBS;
@@ -1789,12 +1812,12 @@ static int add_app_node(context_t *ctx, neu_json_app_t *app)
17891812

17901813
static int add_app_tags(context_t *ctx, neu_json_app_t *app)
17911814
{
1792-
int ret = 0;
17931815
neu_plugin_t *plugin = neu_rest_get_plugin();
17941816

17951817
neu_reqresp_head_t header = {
1796-
.type = NEU_REQ_UPDATE_NODE_TAG,
1797-
.ctx = ctx->aio,
1818+
.otel_trace_type = NEU_OTEL_TRACE_TYPE_REST_COMM,
1819+
.type = NEU_REQ_UPDATE_NODE_TAG,
1820+
.ctx = ctx->aio,
17981821
};
17991822

18001823
neu_req_update_node_tag_t cmd = { 0 };
@@ -1807,7 +1830,7 @@ static int add_app_tags(context_t *ctx, neu_json_app_t *app)
18071830
return NEU_ERR_IS_BUSY;
18081831
}
18091832

1810-
return ret;
1833+
return 0;
18111834
}
18121835

18131836
static int add_app_setting(context_t *ctx, neu_json_app_t *app)

tests/ft/app/test_apps_export_import.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def test_import_new_app_node(self):
7575
"port": 1883,
7676
"ssl": False
7777
},
78-
"groups": []
78+
"groups": [],
79+
"tags": ""
7980
}]
8081

8182
response = api.put_apps(apps)
@@ -114,7 +115,8 @@ def test_import_existing_app_node_overwrite(self):
114115
"port": 1883,
115116
"ssl": False
116117
},
117-
"groups": []
118+
"groups": [],
119+
"tags": ""
118120
}]
119121

120122
response = api.put_apps(apps)
@@ -157,6 +159,7 @@ def test_import_app_subscription_driver_not_exist(self):
157159
"port": 1883,
158160
"ssl": False
159161
},
162+
"tags": "",
160163
"groups": [{
161164
"driver": non_exist_driver,
162165
"group": "group1"

0 commit comments

Comments
 (0)