!29 [sync] PR-26: update version to v1.0.1
From: @openeuler-sync-bot Reviewed-by: @Lostwayzxc Signed-off-by: @Lostwayzxc
This commit is contained in:
commit
90f1b4bfec
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,200 +0,0 @@
|
||||
From 7ff05329ac299727fc2be5d7f1a92a4e3b0bdd43 Mon Sep 17 00:00:00 2001
|
||||
From: fly_1997 <flylove7@outlook.com>
|
||||
Date: Mon, 29 Apr 2024 17:31:44 +0800
|
||||
Subject: [PATCH 4/4] fix auto enable error and check plugin list config
|
||||
|
||||
---
|
||||
oeaware.service | 2 +-
|
||||
src/client/arg_parse.cpp | 7 ++++---
|
||||
src/common/utils.cpp | 34 ++++++++++++++++++-------------
|
||||
src/plugin_mgr/config.cpp | 21 ++++++++++++++-----
|
||||
src/plugin_mgr/config.h | 3 +++
|
||||
src/plugin_mgr/plugin_manager.cpp | 11 +++++++++-
|
||||
6 files changed, 54 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/oeaware.service b/oeaware.service
|
||||
index 3ab4b69..b321530 100644
|
||||
--- a/oeaware.service
|
||||
+++ b/oeaware.service
|
||||
@@ -5,7 +5,7 @@ After=network.target
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/oeaware /etc/oeAware/config.yaml
|
||||
-ExecStop=kill -9 $MAINPID
|
||||
+ExecStop=kill $MAINPID && sleep 5 && kill -9 $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=1
|
||||
RemainAfterExit=yes
|
||||
diff --git a/src/client/arg_parse.cpp b/src/client/arg_parse.cpp
|
||||
index cbf0b8e..70fcd4a 100644
|
||||
--- a/src/client/arg_parse.cpp
|
||||
+++ b/src/client/arg_parse.cpp
|
||||
@@ -30,6 +30,7 @@ const struct option ArgParse::long_options[] = {
|
||||
|
||||
void ArgParse::arg_error(const std::string &msg) {
|
||||
std::cerr << "oeawarectl: " << msg << "\n";
|
||||
+ print_help();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -42,7 +43,7 @@ void ArgParse::set_arg(char *_arg) {
|
||||
}
|
||||
|
||||
void ArgParse::print_help() {
|
||||
- std::cout << "oeawarectl [options]...\n"
|
||||
+ std::cout << "usage: oeawarectl [options]...\n"
|
||||
" options\n"
|
||||
" -l|--load [plugin] load plugin and need plugin type.\n"
|
||||
" -t|--type [plugin_type] assign plugin type. there are three types:\n"
|
||||
@@ -76,12 +77,12 @@ int ArgParse::init(int argc, char *argv[]) {
|
||||
help = true;
|
||||
break;
|
||||
case '?':
|
||||
- arg_error("unknown option. See --help.");
|
||||
+ arg_error("unknown option.");
|
||||
return -1;
|
||||
default: {
|
||||
if (opt == 'l' || opt == 'r' || opt == 'q' || opt == 'Q' || opt == 'e' || opt == 'd' || opt == 'L' || opt == 'i') {
|
||||
if (cmd != -1) {
|
||||
- arg_error("invalid option. See --help.\n");
|
||||
+ arg_error("invalid option.");
|
||||
return -1;
|
||||
}
|
||||
cmd = opt;
|
||||
diff --git a/src/common/utils.cpp b/src/common/utils.cpp
|
||||
index 9435a5b..f2c277d 100644
|
||||
--- a/src/common/utils.cpp
|
||||
+++ b/src/common/utils.cpp
|
||||
@@ -23,28 +23,34 @@ static void curl_set_opt(CURL *curl, const std::string &url, FILE *file) {
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
|
||||
|
||||
}
|
||||
+static bool curl_handle(CURL *curl, const std::string &url, const std::string &path) {
|
||||
+ FILE *file = fopen(path.c_str(), "wb");
|
||||
+ if (file == nullptr) {
|
||||
+ return false;
|
||||
+ }
|
||||
+ curl_set_opt(curl, url, file);
|
||||
+ CURLcode res = curl_easy_perform(curl);
|
||||
+ long http_code = 0;
|
||||
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
|
||||
+ fclose(file);
|
||||
+ if (res == CURLE_OK && http_code >= 200 && http_code < 300) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
// Downloads file from the specified url to the path.
|
||||
bool download(const std::string &url, const std::string &path) {
|
||||
CURL *curl = nullptr;
|
||||
- CURLcode res;
|
||||
- bool ok = true;
|
||||
+ bool ret = true;
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
if (curl) {
|
||||
- FILE *file = fopen(path.c_str(), "wb");
|
||||
- if (file == nullptr) {
|
||||
- return false;
|
||||
- }
|
||||
- curl_set_opt(curl, url, file);
|
||||
- res = curl_easy_perform(curl);
|
||||
- fclose(file);
|
||||
- if (res != CURLE_OK) {
|
||||
- ok = false;
|
||||
- }
|
||||
+ if (!curl_handle(curl, url, path)) ret = false;
|
||||
} else {
|
||||
- ok = false;
|
||||
+ ret = false;
|
||||
}
|
||||
curl_global_cleanup();
|
||||
curl_easy_cleanup(curl);
|
||||
- return ok;
|
||||
+ return ret;
|
||||
}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/plugin_mgr/config.cpp b/src/plugin_mgr/config.cpp
|
||||
index 1de5a34..3c76e8e 100644
|
||||
--- a/src/plugin_mgr/config.cpp
|
||||
+++ b/src/plugin_mgr/config.cpp
|
||||
@@ -30,6 +30,18 @@ bool create_dir(const std::string &path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+bool check_plugin_list(YAML::Node plugin_list_item) {
|
||||
+ if (plugin_list_item["name"].IsNull()) {
|
||||
+ std::cerr << "Warn: null name in plugin_list.\n";
|
||||
+ return false;
|
||||
+ }
|
||||
+ if (plugin_list_item["url"].IsNull()) {
|
||||
+ std::cerr << "Warn: null url in plugin_list.\n";
|
||||
+ return false;
|
||||
+ }
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
bool Config::load(const std::string path) {
|
||||
YAML::Node node;
|
||||
struct stat buffer;
|
||||
@@ -49,16 +61,15 @@ bool Config::load(const std::string path) {
|
||||
YAML::Node plugin_list = node["plugin_list"];
|
||||
if (plugin_list.IsSequence()) {
|
||||
for (int i = 0; i < plugin_list.size(); ++i) {
|
||||
+ if (!check_plugin_list(plugin_list[i])){
|
||||
+ continue;
|
||||
+ }
|
||||
std::string name = plugin_list[i]["name"].as<std::string>();
|
||||
std::string description = plugin_list[i]["description"].as<std::string>();
|
||||
std::string url = plugin_list[i]["url"].as<std::string>();
|
||||
PluginInfo info(name, description, url);
|
||||
- if (name.empty()) {
|
||||
- std::cerr << "Warn: " << name << " url is empty.\n";
|
||||
- continue;
|
||||
- }
|
||||
if (this->plugin_list.count(name)) {
|
||||
- std::cerr << "Warn: duplicate " << name << " in plugin_list.\n";
|
||||
+ std::cerr << "Warn: duplicate \"" << name << "\" in plugin_list.\n";
|
||||
continue;
|
||||
}
|
||||
this->plugin_list.insert(std::make_pair(name, info));
|
||||
diff --git a/src/plugin_mgr/config.h b/src/plugin_mgr/config.h
|
||||
index 16c7871..5ab7672 100644
|
||||
--- a/src/plugin_mgr/config.h
|
||||
+++ b/src/plugin_mgr/config.h
|
||||
@@ -65,6 +65,9 @@ public:
|
||||
size_t get_instance_size() const {
|
||||
return this->instance.size();
|
||||
}
|
||||
+ std::string get_instance_name(int i) {
|
||||
+ return this->instance[i];
|
||||
+ }
|
||||
std::string get_name() const {
|
||||
return this->name;
|
||||
}
|
||||
diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp
|
||||
index c9981ef..0826a60 100644
|
||||
--- a/src/plugin_mgr/plugin_manager.cpp
|
||||
+++ b/src/plugin_mgr/plugin_manager.cpp
|
||||
@@ -348,7 +348,16 @@ void PluginManager::pre_enable() {
|
||||
}
|
||||
std::shared_ptr<Plugin> plugin = memory_store.get_plugin(name);
|
||||
for (int j = 0; j < plugin->get_instance_len(); ++j) {
|
||||
- instance_enabled(plugin->get_instance(i)->get_name());
|
||||
+ instance_enabled(plugin->get_instance(j)->get_name());
|
||||
+ }
|
||||
+ } else {
|
||||
+ for (int 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;
|
||||
+ }
|
||||
+ instance_enabled(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,322 +0,0 @@
|
||||
From 906d417f7a370b6b9f60069bae41ee6d00d7537e Mon Sep 17 00:00:00 2001
|
||||
From: fly_1997 <flylove7@outlook.com>
|
||||
Date: Tue, 7 May 2024 18:02:15 +0800
|
||||
Subject: [PATCH] modify logs, sock file permission and fix service file,
|
||||
repetition of dependencies
|
||||
|
||||
---
|
||||
config.yaml | 11 ++++-----
|
||||
oeaware.service | 2 +-
|
||||
src/client/cmd_handler.cpp | 22 +++++++++++++-----
|
||||
src/client/cmd_handler.h | 2 ++
|
||||
src/plugin_mgr/dep_handler.cpp | 36 +++++++++++++++++++++---------
|
||||
src/plugin_mgr/dep_handler.h | 8 +++----
|
||||
src/plugin_mgr/error_code.cpp | 2 +-
|
||||
src/plugin_mgr/message_manager.cpp | 3 +++
|
||||
src/plugin_mgr/plugin.h | 6 +++--
|
||||
src/plugin_mgr/plugin_manager.cpp | 15 ++++++++-----
|
||||
10 files changed, 73 insertions(+), 34 deletions(-)
|
||||
|
||||
diff --git a/config.yaml b/config.yaml
|
||||
index ef0b44b..99d01d7 100644
|
||||
--- a/config.yaml
|
||||
+++ b/config.yaml
|
||||
@@ -1,8 +1,9 @@
|
||||
log_path: /var/log/oeAware
|
||||
-log_level: 1
|
||||
+log_level: 2
|
||||
enable_list:
|
||||
- - name: aaa.so
|
||||
+
|
||||
plugin_list:
|
||||
- - name: test
|
||||
- description: hello world
|
||||
- url: https://gitee.com/openeuler/oeAware-manager
|
||||
\ No newline at end of file
|
||||
+ - name: numafast
|
||||
+ description: numafast is a userspace tool designed for Kunpeng Chips that aims to improve
|
||||
+ system performance by reducing cross-NUMA memory access.
|
||||
+ url: https://repo.oepkgs.net/openeuler/rpm/openEuler-22.03-LTS-SP1/extras/aarch64/Packages/n/numafast-v1.0.0-2.aarch64.rpm
|
||||
\ No newline at end of file
|
||||
diff --git a/oeaware.service b/oeaware.service
|
||||
index b321530..be13c4b 100644
|
||||
--- a/oeaware.service
|
||||
+++ b/oeaware.service
|
||||
@@ -5,7 +5,7 @@ After=network.target
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/oeaware /etc/oeAware/config.yaml
|
||||
-ExecStop=kill $MAINPID && sleep 5 && kill -9 $MAINPID
|
||||
+ExecStop=kill $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=1
|
||||
RemainAfterExit=yes
|
||||
diff --git a/src/client/cmd_handler.cpp b/src/client/cmd_handler.cpp
|
||||
index 1f2b8a5..4fec95b 100644
|
||||
--- a/src/client/cmd_handler.cpp
|
||||
+++ b/src/client/cmd_handler.cpp
|
||||
@@ -15,12 +15,22 @@
|
||||
|
||||
std::unordered_set<std::string> LoadHandler::types = {"collector", "scenario", "tune"};
|
||||
|
||||
+void LoadHandler::check(const std::string &arg, const std::string &type) {
|
||||
+ if (arg.empty()) {
|
||||
+ ArgParse::arg_error("plugin name empty.");
|
||||
+ }
|
||||
+ if (type.empty()) {
|
||||
+ ArgParse::arg_error("type empty.");
|
||||
+ }
|
||||
+ if (!types.count(type)) {
|
||||
+ ArgParse::arg_error("this type is not supported.");
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
void LoadHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
std::string arg = arg_parse.get_arg();
|
||||
std::string type = arg_parse.get_type();
|
||||
- if (arg.empty() || type.empty() || !types.count(type)) {
|
||||
- ArgParse::arg_error("args error.");
|
||||
- }
|
||||
+ check(arg, type);
|
||||
msg.add_payload(arg);
|
||||
msg.add_payload(type);
|
||||
msg.set_opt(Opt::LOAD);
|
||||
@@ -84,7 +94,7 @@ void RemoveHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
|
||||
void RemoveHandler::res_handler(Msg &msg) {
|
||||
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
||||
- std::cout << "plugin remove successful.\n";
|
||||
+ std::cout << "plugin remove successfully.\n";
|
||||
} else {
|
||||
std::cout << "plugin remove failed, because " << msg.payload(0) << ".\n";
|
||||
}
|
||||
@@ -131,7 +141,7 @@ void EnabledHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
|
||||
void EnabledHandler::res_handler(Msg &msg) {
|
||||
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
||||
- std::cout << "instance enabled.\n";
|
||||
+ std::cout << "instance enabled successfully.\n";
|
||||
} else {
|
||||
std::cout << "instance enabled failed, because "<< msg.payload(0) << ".\n";
|
||||
}
|
||||
@@ -145,7 +155,7 @@ void DisabledHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
|
||||
void DisabledHandler::res_handler(Msg &msg) {
|
||||
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
||||
- std::cout << "instance disabled.\n";
|
||||
+ std::cout << "instance disabled successfully.\n";
|
||||
} else {
|
||||
std::cout << "instance disabled failed, because "<< msg.payload(0) << ".\n";
|
||||
}
|
||||
diff --git a/src/client/cmd_handler.h b/src/client/cmd_handler.h
|
||||
index ab21944..1b6f1c1 100644
|
||||
--- a/src/client/cmd_handler.h
|
||||
+++ b/src/client/cmd_handler.h
|
||||
@@ -29,6 +29,7 @@ public:
|
||||
void handler(const ArgParse &arg_parse, Msg &msg) override;
|
||||
void res_handler(Msg &msg) override;
|
||||
private:
|
||||
+ void check(const std::string &arg, const std::string &type);
|
||||
static std::unordered_set<std::string> types;
|
||||
};
|
||||
|
||||
@@ -36,6 +37,7 @@ class QueryHandler : public CmdHandler {
|
||||
public:
|
||||
void handler(const ArgParse &arg_parse, Msg &msg) override;
|
||||
void res_handler(Msg &msg) override;
|
||||
+private:
|
||||
void print_format();
|
||||
};
|
||||
|
||||
diff --git a/src/plugin_mgr/dep_handler.cpp b/src/plugin_mgr/dep_handler.cpp
|
||||
index eff333c..652fdce 100644
|
||||
--- a/src/plugin_mgr/dep_handler.cpp
|
||||
+++ b/src/plugin_mgr/dep_handler.cpp
|
||||
@@ -11,6 +11,7 @@
|
||||
******************************************************************************/
|
||||
#include "dep_handler.h"
|
||||
#include <queue>
|
||||
+#include <unordered_set>
|
||||
#include <stdio.h>
|
||||
|
||||
void DepHandler::add_arc_node(std::shared_ptr<Node> node, const std::vector<std::string> &dep_nodes) {
|
||||
@@ -38,14 +39,14 @@ void DepHandler::add_arc_node(std::shared_ptr<Node> node, const std::vector<std:
|
||||
}
|
||||
|
||||
|
||||
-void DepHandler::add_node(std::string name, std::vector<std::string> dep_nodes) {
|
||||
+void DepHandler::add_node(const std::string &name, std::vector<std::string> dep_nodes) {
|
||||
std::shared_ptr<Node> cur_node = add_new_node(name);
|
||||
this->nodes[name] = cur_node;
|
||||
add_arc_node(cur_node, dep_nodes);
|
||||
change_arc_nodes(name, true);
|
||||
}
|
||||
|
||||
-void DepHandler::del_node(std::string name) {
|
||||
+void DepHandler::del_node(const std::string &name) {
|
||||
del_node_and_arc_nodes(get_node(name));
|
||||
this->nodes.erase(name);
|
||||
}
|
||||
@@ -119,26 +120,41 @@ void DepHandler::query_node_top(std::string name, std::vector<std::vector<std::s
|
||||
}
|
||||
}
|
||||
|
||||
-void DepHandler::query_node(std::string name, std::vector<std::vector<std::string>> &query) {
|
||||
+void DepHandler::query_node(const std::string &name, std::vector<std::vector<std::string>> &query) {
|
||||
if (!nodes.count(name)) return;
|
||||
- std::shared_ptr<Node> p = nodes[name];
|
||||
- query.emplace_back(std::vector<std::string>{name});
|
||||
- for (auto cur = p->head->next; cur != nullptr; cur = cur->next) {
|
||||
- query.emplace_back(std::vector<std::string>{name, cur->arc_name});
|
||||
- query_node(cur->arc_name, query);
|
||||
+ std::queue<std::string> q;
|
||||
+ std::unordered_set<std::string> vis;
|
||||
+ vis.insert(name);
|
||||
+ q.push(name);
|
||||
+ while (!q.empty()) {
|
||||
+ auto node = nodes[q.front()];
|
||||
+ q.pop();
|
||||
+ query.emplace_back(std::vector<std::string>{node->name});
|
||||
+ for (auto cur = node->head->next; cur != nullptr; cur = cur->next) {
|
||||
+ query.emplace_back(std::vector<std::string>{node->name, cur->arc_name});
|
||||
+ if (!vis.count(cur->arc_name)) {
|
||||
+ vis.insert(cur->arc_name);
|
||||
+ q.push(cur->arc_name);
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
-std::vector<std::string> DepHandler::get_pre_dependencies(std::string name) {
|
||||
+std::vector<std::string> DepHandler::get_pre_dependencies(const std::string &name) {
|
||||
std::vector<std::string> res;
|
||||
std::queue<std::shared_ptr<Node>> q;
|
||||
+ std::unordered_set<std::string> vis;
|
||||
+ vis.insert(name);
|
||||
q.push(nodes[name]);
|
||||
while (!q.empty()) {
|
||||
auto &node = q.front();
|
||||
q.pop();
|
||||
res.emplace_back(node->name);
|
||||
for (auto arc_node = node->head->next; arc_node != nullptr; arc_node = arc_node->next) {
|
||||
- q.push(nodes[arc_node->arc_name]);
|
||||
+ if (!vis.count(arc_node->arc_name)) {
|
||||
+ vis.insert(arc_node->arc_name);
|
||||
+ q.push(nodes[arc_node->arc_name]);
|
||||
+ }
|
||||
}
|
||||
}
|
||||
return res;
|
||||
diff --git a/src/plugin_mgr/dep_handler.h b/src/plugin_mgr/dep_handler.h
|
||||
index cc8570a..76abf49 100644
|
||||
--- a/src/plugin_mgr/dep_handler.h
|
||||
+++ b/src/plugin_mgr/dep_handler.h
|
||||
@@ -47,11 +47,11 @@ public:
|
||||
bool get_node_state(std::string name) {
|
||||
return this->nodes[name]->state;
|
||||
}
|
||||
- void add_node(std::string name, std::vector<std::string> dep_nodes = {});
|
||||
- void del_node(std::string name);
|
||||
- std::vector<std::string> get_pre_dependencies(std::string name);
|
||||
+ void add_node(const std::string &name, std::vector<std::string> dep_nodes = {});
|
||||
+ void del_node(const std::string &name);
|
||||
+ std::vector<std::string> get_pre_dependencies(const std::string &name);
|
||||
// query instance dependency
|
||||
- void query_node(std::string name, std::vector<std::vector<std::string>> &query);
|
||||
+ void query_node(const std::string &name, std::vector<std::vector<std::string>> &query);
|
||||
// query all instance dependencies
|
||||
void query_all_top(std::vector<std::vector<std::string>> &query);
|
||||
bool have_dep(const std::string &name) {
|
||||
diff --git a/src/plugin_mgr/error_code.cpp b/src/plugin_mgr/error_code.cpp
|
||||
index 6e09cb0..30cc4f8 100644
|
||||
--- a/src/plugin_mgr/error_code.cpp
|
||||
+++ b/src/plugin_mgr/error_code.cpp
|
||||
@@ -12,7 +12,7 @@ const std::unordered_map<ErrorCode, std::string> ErrorText::error_codes = {
|
||||
{ErrorCode::REMOVE_INSTANCE_HAVE_DEP, "instance with pre-dependency"},
|
||||
{ErrorCode::LOAD_PLUGIN_FILE_NOT_EXIST, "plugin file does not exist"},
|
||||
{ErrorCode::LOAD_PLUGIN_FILE_IS_NOT_SO, "file is not a plugin file"},
|
||||
- {ErrorCode::LOAD_PLUGIN_FILE_PERMISSION_DEFINED, "plugin file permission defined"},
|
||||
+ {ErrorCode::LOAD_PLUGIN_FILE_PERMISSION_DEFINED, "plugin file permission is not the specified permission"},
|
||||
{ErrorCode::LOAD_PLUGIN_EXIST, "plugin already loaded"},
|
||||
{ErrorCode::LOAD_PLUGIN_DLOPEN_FAILED, "plugin dlopen failed"},
|
||||
{ErrorCode::LOAD_PLUGIN_DLSYM_FAILED, "plugin dlsym failed"},
|
||||
diff --git a/src/plugin_mgr/message_manager.cpp b/src/plugin_mgr/message_manager.cpp
|
||||
index e2fd3b6..f081f20 100644
|
||||
--- a/src/plugin_mgr/message_manager.cpp
|
||||
+++ b/src/plugin_mgr/message_manager.cpp
|
||||
@@ -25,6 +25,9 @@ int TcpSocket::domain_listen(const char *name) {
|
||||
ERROR("[MessageManager] bind error!");
|
||||
return -1;
|
||||
}
|
||||
+ if (chmod(name, S_IRWXU | S_IRGRP | S_IXGRP) == -1) {
|
||||
+ ERROR("[MessageManager] " << name << " chmod error!");
|
||||
+ }
|
||||
if (listen(sock, 20) < 0) {
|
||||
ERROR("[MessageManager] listen error!");
|
||||
return -1;
|
||||
diff --git a/src/plugin_mgr/plugin.h b/src/plugin_mgr/plugin.h
|
||||
index 69837af..a2a1815 100644
|
||||
--- a/src/plugin_mgr/plugin.h
|
||||
+++ b/src/plugin_mgr/plugin.h
|
||||
@@ -123,8 +123,10 @@ private:
|
||||
class Plugin {
|
||||
public:
|
||||
Plugin(std::string name, PluginType type) : name(name), type(type), handler(nullptr) { }
|
||||
- ~Plugin() {
|
||||
- dlclose(handler);
|
||||
+ ~Plugin() {
|
||||
+ if (handler != nullptr) {
|
||||
+ dlclose(handler);
|
||||
+ }
|
||||
}
|
||||
int load(const std::string dl_path);
|
||||
std::string get_name() const {
|
||||
diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp
|
||||
index 0826a60..5ef395c 100644
|
||||
--- a/src/plugin_mgr/plugin_manager.cpp
|
||||
+++ b/src/plugin_mgr/plugin_manager.cpp
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "default_path.h"
|
||||
#include "utils.h"
|
||||
#include <iostream>
|
||||
+#include <unordered_set>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@@ -203,15 +204,15 @@ ErrorCode PluginManager::load_plugin(const std::string &name, PluginType type) {
|
||||
std::string generate_dot(MemoryStore &memory_store, const std::vector<std::vector<std::string>> &query) {
|
||||
std::string res;
|
||||
res += "digraph G {\n";
|
||||
- std::unordered_map<std::string, std::vector<std::string>> sub_graph;
|
||||
+ std::unordered_map<std::string, std::unordered_set<std::string>> sub_graph;
|
||||
for (auto &vec : query) {
|
||||
std::shared_ptr<Instance> instance = memory_store.get_instance(vec[0]);
|
||||
- sub_graph[instance->get_plugin_name()].emplace_back(vec[0]);
|
||||
+ sub_graph[instance->get_plugin_name()].insert(vec[0]);
|
||||
if (vec.size() == 1) {
|
||||
continue;
|
||||
}
|
||||
instance = memory_store.get_instance(vec[1]);
|
||||
- sub_graph[instance->get_plugin_name()].emplace_back(vec[1]);
|
||||
+ sub_graph[instance->get_plugin_name()].insert(vec[1]);
|
||||
res += vec[0] + "->" + vec[1] + ";";
|
||||
}
|
||||
int id = 0;
|
||||
@@ -371,8 +372,12 @@ void PluginManager::pre_load_plugin(PluginType type) {
|
||||
while ((entry = readdir(dir)) != nullptr) {
|
||||
std::string name = entry->d_name;
|
||||
if (end_with(name, ".so")) {
|
||||
- Message msg;
|
||||
- load_plugin(name, type);
|
||||
+ auto ret = load_plugin(name, type);
|
||||
+ if (ret != ErrorCode::OK) {
|
||||
+ WARN("[PluginManager] " << name << " plugin preload failed, because " << ErrorText::get_error_text(ret) << ".");
|
||||
+ } else {
|
||||
+ INFO("[PluginManager] " << name << " plugin loaded.");
|
||||
+ }
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,252 +0,0 @@
|
||||
From c35c26e51d93b0eb5b0aecdf08c338178079e02a Mon Sep 17 00:00:00 2001
|
||||
From: fly_1997 <flylove7@outlook.com>
|
||||
Date: Fri, 10 May 2024 12:01:08 +0800
|
||||
Subject: [PATCH] fix load error and args parsing error printing
|
||||
|
||||
---
|
||||
src/client/arg_parse.cpp | 28 +++++++++++++++++++++++++---
|
||||
src/client/arg_parse.h | 3 +++
|
||||
src/client/cmd_handler.cpp | 28 +++++++++++-----------------
|
||||
src/plugin_mgr/config.cpp | 11 +++++------
|
||||
src/plugin_mgr/config.h | 2 +-
|
||||
src/plugin_mgr/dep_handler.cpp | 2 +-
|
||||
src/plugin_mgr/plugin_manager.cpp | 2 +-
|
||||
7 files changed, 47 insertions(+), 29 deletions(-)
|
||||
|
||||
diff --git a/src/client/arg_parse.cpp b/src/client/arg_parse.cpp
|
||||
index 70fcd4a..805f5a7 100644
|
||||
--- a/src/client/arg_parse.cpp
|
||||
+++ b/src/client/arg_parse.cpp
|
||||
@@ -62,10 +62,23 @@ void ArgParse::print_help() {
|
||||
" --help show this help message.\n";
|
||||
}
|
||||
|
||||
+void ArgParse::init_opts() {
|
||||
+ opts.insert('l');
|
||||
+ opts.insert('r');
|
||||
+ opts.insert('q');
|
||||
+ opts.insert('Q');
|
||||
+ opts.insert('e');
|
||||
+ opts.insert('d');
|
||||
+ opts.insert('L');
|
||||
+ opts.insert('i');
|
||||
+ opts.insert('t');
|
||||
+}
|
||||
+
|
||||
int ArgParse::init(int argc, char *argv[]) {
|
||||
int cmd = -1;
|
||||
int opt;
|
||||
bool help = false;
|
||||
+ init_opts();
|
||||
opterr = 0;
|
||||
while((opt = getopt_long(argc, argv, OPT_STRING.c_str(), long_options, nullptr)) != -1) {
|
||||
std::string full_opt;
|
||||
@@ -76,9 +89,15 @@ int ArgParse::init(int argc, char *argv[]) {
|
||||
case 'h':
|
||||
help = true;
|
||||
break;
|
||||
- case '?':
|
||||
- arg_error("unknown option.");
|
||||
- return -1;
|
||||
+ case '?': {
|
||||
+ std::string err;
|
||||
+ err += optopt;
|
||||
+ if (!opts.count(optopt)) {
|
||||
+ arg_error("unknown option '-" + err + "'.");
|
||||
+ } else{
|
||||
+ arg_error("option -" + err + " requires an argument.");
|
||||
+ }
|
||||
+ }
|
||||
default: {
|
||||
if (opt == 'l' || opt == 'r' || opt == 'q' || opt == 'Q' || opt == 'e' || opt == 'd' || opt == 'L' || opt == 'i') {
|
||||
if (cmd != -1) {
|
||||
@@ -94,6 +113,9 @@ int ArgParse::init(int argc, char *argv[]) {
|
||||
|
||||
}
|
||||
}
|
||||
+ if (cmd == 'l' && type.empty()) {
|
||||
+ arg_error("option '-t' is required.");
|
||||
+ }
|
||||
if (help) {
|
||||
print_help();
|
||||
exit(EXIT_SUCCESS);
|
||||
diff --git a/src/client/arg_parse.h b/src/client/arg_parse.h
|
||||
index 8535e9c..682f0e5 100644
|
||||
--- a/src/client/arg_parse.h
|
||||
+++ b/src/client/arg_parse.h
|
||||
@@ -12,12 +12,14 @@
|
||||
#ifndef CLIENT_ARG_PARSE_H
|
||||
#define CLIENT_ARG_PARSE_H
|
||||
#include <string>
|
||||
+#include <unordered_set>
|
||||
|
||||
class ArgParse {
|
||||
public:
|
||||
static void arg_error(const std::string &msg);
|
||||
static void print_help();
|
||||
int init(int argc, char *argv[]);
|
||||
+ void init_opts();
|
||||
void set_type(char* _type);
|
||||
void set_arg(char* _arg);
|
||||
std::string get_type() const {
|
||||
@@ -29,6 +31,7 @@ public:
|
||||
private:
|
||||
std::string arg;
|
||||
std::string type;
|
||||
+ std::unordered_set<char> opts;
|
||||
static const std::string OPT_STRING;
|
||||
static const int MAX_OPT_SIZE = 20;
|
||||
static const struct option long_options[MAX_OPT_SIZE];
|
||||
diff --git a/src/client/cmd_handler.cpp b/src/client/cmd_handler.cpp
|
||||
index 4fec95b..b410968 100644
|
||||
--- a/src/client/cmd_handler.cpp
|
||||
+++ b/src/client/cmd_handler.cpp
|
||||
@@ -16,14 +16,8 @@
|
||||
std::unordered_set<std::string> LoadHandler::types = {"collector", "scenario", "tune"};
|
||||
|
||||
void LoadHandler::check(const std::string &arg, const std::string &type) {
|
||||
- if (arg.empty()) {
|
||||
- ArgParse::arg_error("plugin name empty.");
|
||||
- }
|
||||
- if (type.empty()) {
|
||||
- ArgParse::arg_error("type empty.");
|
||||
- }
|
||||
if (!types.count(type)) {
|
||||
- ArgParse::arg_error("this type is not supported.");
|
||||
+ ArgParse::arg_error("type '" + type + "' is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,9 +88,9 @@ void RemoveHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
|
||||
void RemoveHandler::res_handler(Msg &msg) {
|
||||
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
||||
- std::cout << "plugin remove successfully.\n";
|
||||
+ std::cout << "Plugin remove successfully.\n";
|
||||
} else {
|
||||
- std::cout << "plugin remove failed, because " << msg.payload(0) << ".\n";
|
||||
+ std::cout << "Plugin remove failed, because " << msg.payload(0) << ".\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,9 +135,9 @@ void EnabledHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
|
||||
void EnabledHandler::res_handler(Msg &msg) {
|
||||
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
||||
- std::cout << "instance enabled successfully.\n";
|
||||
+ std::cout << "Instance enabled successfully.\n";
|
||||
} else {
|
||||
- std::cout << "instance enabled failed, because "<< msg.payload(0) << ".\n";
|
||||
+ std::cout << "Instance enabled failed, because "<< msg.payload(0) << ".\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,9 +149,9 @@ void DisabledHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
|
||||
void DisabledHandler::res_handler(Msg &msg) {
|
||||
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
||||
- std::cout << "instance disabled successfully.\n";
|
||||
+ std::cout << "Instance disabled successfully.\n";
|
||||
} else {
|
||||
- std::cout << "instance disabled failed, because "<< msg.payload(0) << ".\n";
|
||||
+ std::cout << "Instance disabled failed, because "<< msg.payload(0) << ".\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,10 +161,10 @@ void ListHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
|
||||
void ListHandler::res_handler(Msg &msg) {
|
||||
if (msg.get_opt() == Opt::RESPONSE_ERROR) {
|
||||
- std::cerr << "query list failed, because "<< msg.payload(0) << ".\n";
|
||||
+ std::cerr << "Query list failed, because "<< msg.payload(0) << ".\n";
|
||||
return;
|
||||
}
|
||||
- std::cout << "plugin list as follows.\n";
|
||||
+ std::cout << "Plugin list as follows.\n";
|
||||
std::cout << "------------------------------------------------------------\n";
|
||||
for (int i = 0; i < msg.payload_size(); ++i) {
|
||||
std::cout << msg.payload(i);
|
||||
@@ -186,13 +180,13 @@ void InstallHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
||||
|
||||
void InstallHandler::res_handler(Msg &msg) {
|
||||
if (msg.get_opt() == Opt::RESPONSE_ERROR) {
|
||||
- std::cout << "download failed, because " << msg.payload(0) <<": " << this->arg.c_str() << '\n';
|
||||
+ std::cout << "Download failed, because " << msg.payload(0) <<": " << this->arg.c_str() << '\n';
|
||||
return;
|
||||
}
|
||||
std::string path = this->arg;
|
||||
std::string url = msg.payload(0);
|
||||
if (!download(url, path)) {
|
||||
- std::cout << "download failed, please check url or your network.\n";
|
||||
+ std::cout << "Download failed, please check url or your network.\n";
|
||||
return;
|
||||
}
|
||||
std::string command = "rpm -ivh " + path;
|
||||
diff --git a/src/plugin_mgr/config.cpp b/src/plugin_mgr/config.cpp
|
||||
index 3c76e8e..f50399b 100644
|
||||
--- a/src/plugin_mgr/config.cpp
|
||||
+++ b/src/plugin_mgr/config.cpp
|
||||
@@ -84,16 +84,15 @@ bool Config::load(const std::string path) {
|
||||
for (int i = 0; i < enable_list.size(); ++i) {
|
||||
YAML::Node plugin = enable_list[i]["name"];
|
||||
std::string name = enable_list[i]["name"].as<std::string>();
|
||||
+ YAML::Node instances = enable_list[i]["instances"];
|
||||
EnableItem enable_item(name);
|
||||
- if (plugin.IsScalar()) {
|
||||
+ if (instances.IsNull()) {
|
||||
enable_item.set_enabled(true);
|
||||
- } else if (plugin.IsSequence()) {
|
||||
- for (int j = 0; j < plugin.size(); ++j) {
|
||||
- std::string i_name = plugin[j].as<std::string>();
|
||||
+ } else {
|
||||
+ for (int j = 0; j < instances.size(); ++j) {
|
||||
+ std::string i_name = instances[j].as<std::string>();
|
||||
enable_item.add_instance(i_name);
|
||||
}
|
||||
- } else {
|
||||
- continue;
|
||||
}
|
||||
this->enable_list.emplace_back(enable_item);
|
||||
}
|
||||
diff --git a/src/plugin_mgr/config.h b/src/plugin_mgr/config.h
|
||||
index 5ab7672..6d0ee4d 100644
|
||||
--- a/src/plugin_mgr/config.h
|
||||
+++ b/src/plugin_mgr/config.h
|
||||
@@ -52,7 +52,7 @@ namespace std {
|
||||
|
||||
class EnableItem {
|
||||
public:
|
||||
- EnableItem(std::string name) : name(name) { }
|
||||
+ EnableItem(std::string name) : name(name), enabled(false) { }
|
||||
void set_enabled(bool enabled) {
|
||||
this->enabled = enabled;
|
||||
}
|
||||
diff --git a/src/plugin_mgr/dep_handler.cpp b/src/plugin_mgr/dep_handler.cpp
|
||||
index 652fdce..816056d 100644
|
||||
--- a/src/plugin_mgr/dep_handler.cpp
|
||||
+++ b/src/plugin_mgr/dep_handler.cpp
|
||||
@@ -132,7 +132,7 @@ void DepHandler::query_node(const std::string &name, std::vector<std::vector<std
|
||||
query.emplace_back(std::vector<std::string>{node->name});
|
||||
for (auto cur = node->head->next; cur != nullptr; cur = cur->next) {
|
||||
query.emplace_back(std::vector<std::string>{node->name, cur->arc_name});
|
||||
- if (!vis.count(cur->arc_name)) {
|
||||
+ if (!vis.count(cur->arc_name) && nodes.count(cur->arc_name)) {
|
||||
vis.insert(cur->arc_name);
|
||||
q.push(cur->arc_name);
|
||||
}
|
||||
diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp
|
||||
index 5ef395c..77acc40 100644
|
||||
--- a/src/plugin_mgr/plugin_manager.cpp
|
||||
+++ b/src/plugin_mgr/plugin_manager.cpp
|
||||
@@ -461,7 +461,7 @@ int PluginManager::run() {
|
||||
PluginType type = plugin_types[msg.get_payload(1)];
|
||||
ErrorCode ret_code = load_plugin(plugin_name, type);
|
||||
if(ret_code == ErrorCode::OK) {
|
||||
- INFO("[PluginManager] " << plugin_name << "plugin loaded.");
|
||||
+ INFO("[PluginManager] " << plugin_name << " plugin loaded.");
|
||||
res.set_opt(Opt::RESPONSE_OK);
|
||||
std::string lack_dep = instance_dep_check(plugin_name);
|
||||
if (!lack_dep.empty()) {
|
||||
--
|
||||
2.33.0
|
||||
|
||||
Binary file not shown.
BIN
oeAware-manager-v1.0.1.tar.gz
Normal file
BIN
oeAware-manager-v1.0.1.tar.gz
Normal file
Binary file not shown.
@ -1,16 +1,10 @@
|
||||
Name: oeAware-manager
|
||||
Version: v1.0.0
|
||||
Release: 5
|
||||
Version: v1.0.1
|
||||
Release: 1
|
||||
Summary: OeAware server and client
|
||||
License: MulanPSL2
|
||||
URL: https://gitee.com/openeuler/%{name}
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
Patch1: 0001-fix-remove-plugin-bug-and-refactor.patch
|
||||
Patch2: 0002-add-error-code-and-replace-raw-poniters-with-smart-p.patch
|
||||
Patch3: 0003-add-client-error-description-extract-class-and-fix-b.patch
|
||||
Patch4: 0004-fix-auto-enable-error-and-check-plugin-list-config.patch
|
||||
Patch5: 0005-modify-logs-sock-file-permission-and-fix-service-fil.patch
|
||||
Patch6: 0006-fix-load-error-and-args-parsing-error-printing.patch
|
||||
|
||||
BuildRequires: cmake make gcc-c++
|
||||
BuildRequires: boost-devel
|
||||
@ -19,8 +13,8 @@ BuildRequires: log4cplus-devel
|
||||
BuildRequires: yaml-cpp-devel
|
||||
BuildRequires: gtest-devel gmock-devel
|
||||
|
||||
Requires: oeAware-collector
|
||||
Requires: oeAware-scenario
|
||||
Requires: oeAware-collector >= v1.0.0
|
||||
Requires: oeAware-scenario >= v1.0.0
|
||||
Requires: graphviz
|
||||
|
||||
%description
|
||||
@ -54,6 +48,9 @@ install -D -p -m 0644 oeaware.service %{buildroot}%{_unitdir}/oeaware.service
|
||||
%attr(0644, root, root) %{_unitdir}/oeaware.service
|
||||
|
||||
%changelog
|
||||
* Sat May 11 2024 fly_1997 <flylove7@outlook.com> -v1.0.1-1
|
||||
- update version to v1.0.1
|
||||
|
||||
* Wed May 8 2024 fly_1997 <flylove7@outlook.com> -v1.0.0-5
|
||||
- fix systemd service uninstallation issue
|
||||
- fix load error and args parsing error printing
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user