116 lines
5.1 KiB
Diff
116 lines
5.1 KiB
Diff
From 2a6837386db74d59e35f2ff54499d79904ae1501 Mon Sep 17 00:00:00 2001
|
|
From: fly_1997 <flylove7@outlook.com>
|
|
Date: Thu, 13 Jun 2024 10:06:04 +0800
|
|
Subject: [PATCH 1/2] fix dependency disabled failed and pre-enable illegal
|
|
plugin
|
|
|
|
---
|
|
src/plugin_mgr/instance_run_handler.cpp | 17 ++++++++++-------
|
|
src/plugin_mgr/instance_run_handler.h | 4 +++-
|
|
src/plugin_mgr/plugin_manager.cpp | 12 ++++++------
|
|
3 files changed, 19 insertions(+), 14 deletions(-)
|
|
|
|
diff --git a/src/plugin_mgr/instance_run_handler.cpp b/src/plugin_mgr/instance_run_handler.cpp
|
|
index 496166b..928b555 100644
|
|
--- a/src/plugin_mgr/instance_run_handler.cpp
|
|
+++ b/src/plugin_mgr/instance_run_handler.cpp
|
|
@@ -79,10 +79,11 @@ void InstanceRunHandler::enable_instance(const std::string &name) {
|
|
}
|
|
}
|
|
|
|
-void InstanceRunHandler::disable_instance(const std::string &name) {
|
|
- if (in_degree[name] != 0) {
|
|
+void InstanceRunHandler::disable_instance(const std::string &name, RunType type) {
|
|
+ if (type == RunType::INTERNAL_DISABLED && in_degree[name] != 0) {
|
|
return;
|
|
}
|
|
+ in_degree[name] = 0;
|
|
std::queue<std::shared_ptr<Node>> instance_node_queue;
|
|
auto dep_handler = memory_store.get_dep_handler();
|
|
instance_node_queue.push(dep_handler.get_node(name));
|
|
@@ -111,12 +112,14 @@ void InstanceRunHandler::handle_instance() {
|
|
while(this->recv_queue_try_pop(msg)){
|
|
std::shared_ptr<Instance> instance = msg->get_instance();
|
|
switch (msg->get_type()){
|
|
- case RunType::ENABLED: {
|
|
+ case RunType::ENABLED:
|
|
+ case RunType::INTERNAL_ENABLED: {
|
|
enable_instance(instance->get_name());
|
|
break;
|
|
}
|
|
- case RunType::DISABLED: {
|
|
- disable_instance(instance->get_name());
|
|
+ case RunType::DISABLED:
|
|
+ case RunType::INTERNAL_DISABLED: {
|
|
+ disable_instance(instance->get_name(), msg->get_type());
|
|
break;
|
|
}
|
|
}
|
|
@@ -139,7 +142,7 @@ void InstanceRunHandler::change_instance_state(const std::string &name, std::vec
|
|
if (instance->get_enabled()) {
|
|
memory_store.delete_edge(name, instance->get_name());
|
|
in_degree[instance->get_name()]--;
|
|
- auto msg = std::make_shared<InstanceRunMessage>(RunType::DISABLED, instance);
|
|
+ auto msg = std::make_shared<InstanceRunMessage>(RunType::INTERNAL_DISABLED, instance);
|
|
recv_queue_push(std::move(msg));
|
|
}
|
|
}
|
|
@@ -156,7 +159,7 @@ void InstanceRunHandler::change_instance_state(const std::string &name, std::vec
|
|
if (!instance->get_enabled()) {
|
|
in_degree[instance->get_name()]++;
|
|
memory_store.add_edge(name, instance->get_name());
|
|
- auto msg = std::make_shared<InstanceRunMessage>(RunType::ENABLED, instance);
|
|
+ auto msg = std::make_shared<InstanceRunMessage>(RunType::INTERNAL_ENABLED, instance);
|
|
recv_queue_push(std::move(msg));
|
|
}
|
|
}
|
|
diff --git a/src/plugin_mgr/instance_run_handler.h b/src/plugin_mgr/instance_run_handler.h
|
|
index 980fd98..682510b 100644
|
|
--- a/src/plugin_mgr/instance_run_handler.h
|
|
+++ b/src/plugin_mgr/instance_run_handler.h
|
|
@@ -21,6 +21,8 @@
|
|
enum class RunType {
|
|
ENABLED,
|
|
DISABLED,
|
|
+ INTERNAL_ENABLED,
|
|
+ INTERNAL_DISABLED,
|
|
};
|
|
|
|
/* Message for communication between plugin manager and instance scheduling */
|
|
@@ -89,7 +91,7 @@ private:
|
|
void run_instance(std::vector<std::string> &deps, InstanceRun run);
|
|
void change_instance_state(const std::string &name, std::vector<std::string> &deps, std::vector<std::string> &after_deps);
|
|
void enable_instance(const std::string &name);
|
|
- void disable_instance(const std::string &name);
|
|
+ void disable_instance(const std::string &name, RunType type);
|
|
private:
|
|
/* Instance execution queue. */
|
|
std::priority_queue<ScheduleInstance> schedule_queue;
|
|
diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp
|
|
index 9ecaa6d..7220f48 100644
|
|
--- a/src/plugin_mgr/plugin_manager.cpp
|
|
+++ b/src/plugin_mgr/plugin_manager.cpp
|
|
@@ -282,13 +282,13 @@ ErrorCode PluginManager::download(const std::string &name, std::string &res) {
|
|
void PluginManager::pre_enable() {
|
|
for (size_t i = 0; i < config->get_enable_list_size(); ++i) {
|
|
EnableItem item = config->get_enable_list(i);
|
|
+ std::string plugin_name = item.get_name();
|
|
+ if (!memory_store.is_plugin_exist(plugin_name)) {
|
|
+ WARN("[PluginManager] plugin " << plugin_name << " cannot be enabled, because it does not exist.");
|
|
+ continue;
|
|
+ }
|
|
if (item.get_enabled()) {
|
|
- std::string name = item.get_name();
|
|
- if (!memory_store.is_plugin_exist(name)) {
|
|
- WARN("[PluginManager] plugin " << name << " cannot be enabled, because it does not exist.");
|
|
- continue;
|
|
- }
|
|
- std::shared_ptr<Plugin> plugin = memory_store.get_plugin(name);
|
|
+ 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());
|
|
}
|
|
--
|
|
2.33.0
|
|
|