diff --git a/ft/resource/error.resource b/ft/resource/error.resource index cac79f67c..03ab6c566 100644 --- a/ft/resource/error.resource +++ b/ft/resource/error.resource @@ -22,6 +22,7 @@ ${NEU_ERR_NODE_IS_RUNNING} 2007 ${NEU_ERR_NODE_NOT_RUNNING} 2008 ${NEU_ERR_NODE_IS_STOPED} 2009 ${NEU_ERR_NODE_NAME_TOO_LONG} 2010 +${NEU_ERR_NODE_NOT_ALLOW_DELETE} 2011 ${NEU_ERR_GROUP_ALREADY_SUBSCRIBED} 2101 ${NEU_ERR_GROUP_NOT_SUBSCRIBE} 2102 diff --git a/include/neuron/errcodes.h b/include/neuron/errcodes.h index dcce9c273..6355fcd88 100644 --- a/include/neuron/errcodes.h +++ b/include/neuron/errcodes.h @@ -52,6 +52,7 @@ typedef enum { NEU_ERR_NODE_NOT_RUNNING = 2008, NEU_ERR_NODE_IS_STOPED = 2009, NEU_ERR_NODE_NAME_TOO_LONG = 2010, + NEU_ERR_NODE_NOT_ALLOW_DELETE = 2011, NEU_ERR_GROUP_ALREADY_SUBSCRIBED = 2101, NEU_ERR_GROUP_NOT_SUBSCRIBE = 2102, diff --git a/plugins/restful/http.c b/plugins/restful/http.c index 9efdb48bb..1a1bbf3f7 100644 --- a/plugins/restful/http.c +++ b/plugins/restful/http.c @@ -337,6 +337,7 @@ int http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_GROUP_EXIST: case NEU_ERR_GROUP_NOT_ALLOW: case NEU_ERR_LIBRARY_NOT_ALLOW_CREATE_INSTANCE: + case NEU_ERR_NODE_NOT_ALLOW_DELETE: status = NNG_HTTP_STATUS_CONFLICT; break; case NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT: diff --git a/src/core/manager.c b/src/core/manager.c index 6656490c7..2478d4f70 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -290,34 +290,46 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data) neu_resp_error_t error = { 0 }; neu_adapter_t * adapter = neu_node_manager_find(manager->node_manager, cmd->node); + bool single = + neu_node_manager_is_single(manager->node_manager, cmd->node); strcpy(header->receiver, cmd->node); - if (adapter != NULL) { - manager_storage_del_node(manager, cmd->node); - header->type = NEU_REQ_NODE_UNINIT; - forward_msg(manager, msg, header->receiver); - if (neu_adapter_get_type(adapter) == NEU_NA_TYPE_DRIVER) { - UT_array *apps = neu_subscribe_manager_find_by_driver( - manager->subscribe_manager, cmd->node); - - utarray_foreach(apps, neu_app_subscribe_t *, app) - { - neu_reqresp_node_deleted_t resp = { 0 }; - header->type = NEU_REQRESP_NODE_DELETED; - - strcpy(resp.node, header->receiver); - strcpy(header->receiver, app->app_name); - strcpy(header->sender, "manager"); - reply(manager, header, &resp); - } - utarray_free(apps); - } - } else { + if (adapter == NULL) { error.error = NEU_ERR_NODE_NOT_EXIST; header->type = NEU_RESP_ERROR; neu_msg_exchange(header); reply(manager, header, &error); + break; + } + + if (single) { + error.error = NEU_ERR_NODE_NOT_ALLOW_DELETE; + header->type = NEU_RESP_ERROR; + neu_msg_exchange(header); + reply(manager, header, &error); + break; } + + manager_storage_del_node(manager, cmd->node); + header->type = NEU_REQ_NODE_UNINIT; + forward_msg(manager, msg, header->receiver); + if (neu_adapter_get_type(adapter) == NEU_NA_TYPE_DRIVER) { + UT_array *apps = neu_subscribe_manager_find_by_driver( + manager->subscribe_manager, cmd->node); + + utarray_foreach(apps, neu_app_subscribe_t *, app) + { + neu_reqresp_node_deleted_t resp = { 0 }; + header->type = NEU_REQRESP_NODE_DELETED; + + strcpy(resp.node, header->receiver); + strcpy(header->receiver, app->app_name); + strcpy(header->sender, "manager"); + reply(manager, header, &resp); + } + utarray_free(apps); + } + break; } case NEU_RESP_NODE_UNINIT: { diff --git a/src/core/node_manager.c b/src/core/node_manager.c index 6092e933a..fec14d0d4 100644 --- a/src/core/node_manager.c +++ b/src/core/node_manager.c @@ -222,6 +222,18 @@ neu_adapter_t *neu_node_manager_find(neu_node_manager_t *mgr, const char *name) return adapter; } +bool neu_node_manager_is_single(neu_node_manager_t *mgr, const char *name) +{ + node_entity_t *node = NULL; + + HASH_FIND_STR(mgr->nodes, name, node); + if (node != NULL) { + return node->single; + } + + return false; +} + UT_array *neu_node_manager_get_pipes(neu_node_manager_t *mgr, neu_node_type_e type) { diff --git a/src/core/node_manager.h b/src/core/node_manager.h index da06b46a7..b24ea7fcb 100644 --- a/src/core/node_manager.h +++ b/src/core/node_manager.h @@ -51,6 +51,7 @@ UT_array *neu_node_manager_get_all(neu_node_manager_t *mgr); UT_array * neu_node_manager_get_adapter(neu_node_manager_t *mgr, neu_node_type_e type); neu_adapter_t *neu_node_manager_find(neu_node_manager_t *mgr, const char *name); +bool neu_node_manager_is_single(neu_node_manager_t *mgr, const char *name); // nng_pipe array UT_array *neu_node_manager_get_pipes(neu_node_manager_t *mgr,