diff --git a/0003-fix-database-query-errors.patch b/0003-fix-database-query-errors.patch new file mode 100644 index 0000000000000000000000000000000000000000..60b3eb65f91ba2d610d73fdcea018f997848ec28 --- /dev/null +++ b/0003-fix-database-query-errors.patch @@ -0,0 +1,96 @@ +From e8071c4b25d6c49a3970738545a75864a52c1c3a Mon Sep 17 00:00:00 2001 +From: rabbitali +Date: Wed, 27 Dec 2023 11:09:13 +0800 +Subject: [PATCH] fix database query errors + +--- + diana/database/dao/algo_dao.py | 29 +++++++++++++++-------------- + diana/database/dao/result_dao.py | 14 ++++++-------- + 2 files changed, 21 insertions(+), 22 deletions(-) + +diff --git a/diana/database/dao/algo_dao.py b/diana/database/dao/algo_dao.py +index 4161507..c2a593c 100644 +--- a/diana/database/dao/algo_dao.py ++++ b/diana/database/dao/algo_dao.py +@@ -104,20 +104,21 @@ class AlgorithmDao(MysqlProxy): + Notes: + If you do not enter anything, query all data by default. + """ +- page = data.get('page') +- per_page = data.get('per_page') +- filters = {Algorithm.username.in_([data.get('username'), 'system'])} +- if data.get('field'): +- filters.add(Algorithm.field == data.get('field')) +- +- res = {'total_count': 0, 'total_page': 0, 'algo_list': []} +- algo_query = self._query_algo_list(filters) +- total_count = len(algo_query.all()) +- algo_info_list, total_page = sort_and_page(algo_query, None, None, per_page, page) +- res['algo_list'] = self._algo_rows_to_dict(algo_info_list) +- res['total_page'] = total_page +- res['total_count'] = total_count +- ++ res = {} ++ try: ++ filters = {Algorithm.username.in_([data.get('username'), 'system'])} ++ if data.get('field'): ++ filters.add(Algorithm.field == data.get('field')) ++ algo_query = self._query_algo_list(filters) ++ total_count = len(algo_query.all()) ++ algo_info_list, total_page = sort_and_page(algo_query, None, None, data.get('per_page'), data.get('page')) ++ res['algo_list'] = self._algo_rows_to_dict(algo_info_list) ++ res['total_page'] = total_page ++ res['total_count'] = total_count ++ except SQLAlchemyError as error: ++ LOGGER.error(error) ++ LOGGER.error("Fail to query algorithm list.") ++ return DATABASE_QUERY_ERROR, {} + return SUCCEED, res + + def _query_algo_list(self, filters): +diff --git a/diana/database/dao/result_dao.py b/diana/database/dao/result_dao.py +index 4f80079..dc8935a 100644 +--- a/diana/database/dao/result_dao.py ++++ b/diana/database/dao/result_dao.py +@@ -216,15 +216,14 @@ class ResultDao(MysqlProxy): + check_result_host_list, total_page = sort_and_page( + check_result_host_query, column, direction, per_page, page + ) ++ res['result'] = self._check_result_host_rows_to_list(check_result_host_list) ++ res['total_page'] = total_page ++ res['total_count'] = total_count + except SQLAlchemyError as error: + LOGGER.error(error) + LOGGER.error("Query check result list failed.") + return DATABASE_QUERY_ERROR, res + +- res['result'] = self._check_result_host_rows_to_list(check_result_host_list) +- res['total_page'] = total_page +- res['total_count'] = total_count +- + return SUCCEED, res + + def _query_check_result_host_list(self, filters): +@@ -390,16 +389,15 @@ class ResultDao(MysqlProxy): + domain_check_result = self._query_all_domain_check_count() + total_count = len(domain_check_result.all()) + domain_check_result_list, total_page = sort_and_page(domain_check_result, column, direction, per_page, page) ++ res['results'] = self._domain_check_result_count_rows_to_list(domain_check_result_list) ++ res['total_page'] = total_page ++ res['total_count'] = total_count + + except SQLAlchemyError as error: + LOGGER.error(error) + LOGGER.error("Get domain check result failed.") + return DATABASE_QUERY_ERROR, res + +- res['results'] = self._domain_check_result_count_rows_to_list(domain_check_result_list) +- res['total_page'] = total_page +- res['total_count'] = total_count +- + return SUCCEED, res + + def _query_all_domain_check_count(self): +-- +2.33.0 + diff --git a/aops-diana.spec b/aops-diana.spec index 90359196794c0ba771b2f3dde9085defbe75968a..3cb8071981dd8eaf2ce73f09972c36266de36aab 100644 --- a/aops-diana.spec +++ b/aops-diana.spec @@ -1,12 +1,13 @@ Name: aops-diana Version: v1.3.0 -Release: 4 +Release: 5 Summary: An intelligent abnormal detection framework of aops License: MulanPSL2 URL: https://gitee.com/openeuler/%{name} Source0: %{name}-%{version}.tar.gz Patch0001: 0001-add-diana-sql-script.patch Patch0002: 0002-fix-database-type-error.patch +Patch0003: 0003-fix-database-query-errors.patch @@ -52,6 +53,9 @@ cp -r database %{buildroot}/opt/aops/ %changelog +* Wed Dec 27 2023 wenxin - v1.3.0-5 +- fix database query errors + * Mon Sep 25 2023 gongzhengtang - v1.3.0-4 - fix database type error