oeAware-manager/0008-fix-dependency-error-and-add-enable-failed-logs.patch
fly_1997 52431a838a fix dependency disabled failed, dependency error and pre-enable illegal plugin
(cherry picked from commit 7050336b5637ec8c058c19506da0ef128a6771ad)
2024-06-14 19:06:49 +08:00

139 lines
5.8 KiB
Diff

From 918ef95a2e5f9de71efa55beee35eaa083c31b7d Mon Sep 17 00:00:00 2001
From: fly_1997 <flylove7@outlook.com>
Date: Thu, 13 Jun 2024 16:28:19 +0800
Subject: [PATCH 2/2] fix dependency error and add enable failed logs
---
src/plugin_mgr/dep_handler.cpp | 22 +++++++++++++---------
src/plugin_mgr/instance_run_handler.h | 2 ++
src/plugin_mgr/plugin_manager.cpp | 17 ++++++++++++-----
3 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/src/plugin_mgr/dep_handler.cpp b/src/plugin_mgr/dep_handler.cpp
index 227ee2f..2b20e7e 100644
--- a/src/plugin_mgr/dep_handler.cpp
+++ b/src/plugin_mgr/dep_handler.cpp
@@ -28,22 +28,26 @@ void DepHandler::add_arc_node(std::shared_ptr<Node> node, const std::vector<std:
std::shared_ptr<ArcNode> arc_head = node->head;
node->cnt = dep_nodes.size();
int real_cnt = 0;
+ bool state = true;
for (auto name : dep_nodes) {
std::string from = node->instance->get_name();
std::shared_ptr<ArcNode> tmp = std::make_shared<ArcNode>(from, name);
tmp->next = arc_head->next;
arc_head->next = tmp;
-
+ tmp->init = true;
if (nodes.count(name)) {
tmp->is_exist = true;
- tmp->init = true;
real_cnt++;
+ if (!nodes[name]->instance->get_state()) {
+ state = false;
+ }
}
in_edges[name].insert(from);
arc_nodes[std::make_pair(from, name)] = tmp;
}
+ /* node->instance->state = true, only all dependencies meet the conditions. */
if (real_cnt == node->cnt) {
- node->instance->set_state(true);
+ node->instance->set_state(state);
}
node->real_cnt = real_cnt;
}
@@ -115,18 +119,17 @@ void DepHandler::del_node_and_arc_nodes(std::shared_ptr<Node> node) {
}
void DepHandler::update_instance_state(const std::string &name) {
- if (!nodes[name]->instance->get_state() || !in_edges.count(name)) return;
+ if (!in_edges.count(name)) return;
std::unordered_set<std::string> &arcs = in_edges[name];
for (auto &from : arcs) {
auto arc_node = arc_nodes[std::make_pair(from, name)];
if (nodes.count(from)) {
auto tmp = nodes[from];
tmp->real_cnt++;
- if (tmp->real_cnt == tmp->cnt) {
+ if (tmp->real_cnt == tmp->cnt && nodes[name]->instance->get_state()) {
tmp->instance->set_state(true);
}
arc_node->is_exist = true;
- arc_node->init = true;
update_instance_state(tmp->instance->get_name());
}
}
@@ -144,8 +147,9 @@ void DepHandler::query_node_top(const std::string &name, std::vector<std::vector
query.emplace_back(std::vector<std::string>{name});
return;
}
- while (arc_node->next != nullptr) {
- if (arc_node->next->is_exist) {
+ while (arc_node->next != nullptr) {
+ /* Display the edges that exist and the points that do not. */
+ if (arc_node->next->is_exist || !nodes.count(arc_node->next->to)) {
query.emplace_back(std::vector<std::string>{name, arc_node->next->to});
}
arc_node = arc_node->next;
@@ -164,7 +168,7 @@ void DepHandler::query_node_dependency(const std::string &name, std::vector<std:
std::string node_name = node->instance->get_name();
query.emplace_back(std::vector<std::string>{node_name});
for (auto cur = node->head->next; cur != nullptr; cur = cur->next) {
- if (cur->is_exist) {
+ if (cur->is_exist || !nodes.count(cur->to)) {
query.emplace_back(std::vector<std::string>{node_name, cur->to});
}
if (!vis.count(cur->to) && nodes.count(cur->to)) {
diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h
index 682510b..3804a49 100644
--- a/src/plugin_mgr/instance_run_handler.h
+++ b/src/plugin_mgr/instance_run_handler.h
@@ -19,8 +19,10 @@
#include <queue>
enum class RunType {
+ /* Message from PluginManager. */
ENABLED,
DISABLED,
+ /* Message from internal. */
INTERNAL_ENABLED,
INTERNAL_DISABLED,
};
diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp
index 7220f48..c3ff8bf 100644
--- a/src/plugin_mgr/plugin_manager.cpp
+++ b/src/plugin_mgr/plugin_manager.cpp
@@ -290,16 +290,23 @@ void PluginManager::pre_enable() {
if (item.get_enabled()) {
std::shared_ptr<Plugin> plugin = memory_store.get_plugin(plugin_name);
for (size_t j = 0; j < plugin->get_instance_len(); ++j) {
- instance_enabled(plugin->get_instance(j)->get_name());
+ std::string name = plugin->get_instance(j)->get_name();
+ auto ret = instance_enabled(name);
+ if (ret != ErrorCode::OK) {
+ WARN("[PluginManager] " << name << " instance pre-enabled failed, because " << ErrorText::get_error_text(ret) << ".");
+ } else {
+ INFO("[PluginManager] " << name << " instance pre-enabled.");
+ }
}
} else {
for (size_t j = 0; j < item.get_instance_size(); ++j) {
std::string name = item.get_instance_name(j);
- if (!memory_store.is_instance_exist(name)) {
- WARN("[PluginManager] instance " << name << " cannot be enabled, because it does not exist.");
- continue;
+ auto ret = instance_enabled(name);
+ if (ret != ErrorCode::OK) {
+ WARN("[PluginManager] " << name << " instance pre-enabled failed, because " << ErrorText::get_error_text(ret) << ".");
+ } else {
+ INFO("[PluginManager] " << name << " instance pre-enabled.");
}
- instance_enabled(name);
}
}
}
--
2.33.0