Skip to content

Commit

Permalink
Merge branch 'hhyo:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
taijiyouxia authored Jul 24, 2023
2 parents 9e80ece + cedc1f3 commit 6e84f59
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 271 deletions.
198 changes: 0 additions & 198 deletions sql/aliyun_rds.py

This file was deleted.

40 changes: 8 additions & 32 deletions sql/db_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@
from sql.engines import get_engine
from common.utils.extend_json_encoder import ExtendJSONEncoder, ExtendJSONEncoderBytes
from sql.utils.resource_group import user_instances
from .models import AliyunRdsConfig, Instance
from .models import Instance

from .aliyun_rds import (
process_status as aliyun_process_status,
create_kill_session as aliyun_create_kill_session,
kill_session as aliyun_kill_session,
sapce_status as aliyun_sapce_status,
)

logger = logging.getLogger("default")

Expand All @@ -38,11 +32,7 @@ def process(request):
query_engine = get_engine(instance=instance)
query_result = None
if instance.db_type == "mysql":
# 判断是RDS还是其他实例
if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
result = aliyun_process_status(request)
else:
query_result = query_engine.processlist(command_type)
query_result = query_engine.processlist(command_type)

elif instance.db_type == "mongo":
query_result = query_engine.current_op(command_type)
Expand Down Expand Up @@ -85,11 +75,7 @@ def create_kill_session(request):
result = {"status": 0, "msg": "ok", "data": []}
query_engine = get_engine(instance=instance)
if instance.db_type == "mysql":
# 判断是RDS还是其他实例
if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
result = aliyun_create_kill_session(request)
else:
result["data"] = query_engine.get_kill_command(json.loads(thread_ids))
result["data"] = query_engine.get_kill_command(json.loads(thread_ids))
elif instance.db_type == "mongo":
kill_command = query_engine.get_kill_command(json.loads(thread_ids))
result["data"] = kill_command
Expand Down Expand Up @@ -125,11 +111,7 @@ def kill_session(request):
engine = get_engine(instance=instance)
r = None
if instance.db_type == "mysql":
# 判断是RDS还是其他实例
if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
result = aliyun_kill_session(request)
else:
r = engine.kill(json.loads(thread_ids))
r = engine.kill(json.loads(thread_ids))
elif instance.db_type == "mongo":
r = engine.kill_op(json.loads(thread_ids))
elif instance.db_type == "oracle":
Expand All @@ -153,7 +135,7 @@ def kill_session(request):

# 问题诊断--表空间信息
@permission_required("sql.tablespace_view", raise_exception=True)
def tablesapce(request):
def tablespace(request):
instance_name = request.POST.get("instance_name")
offset = int(request.POST.get("offset", 0))
limit = int(request.POST.get("limit", 14))
Expand All @@ -165,17 +147,9 @@ def tablesapce(request):

query_engine = get_engine(instance=instance)
if instance.db_type == "mysql":
# 判断是RDS还是其他实例
if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
result = aliyun_sapce_status(request)
else:
query_result = query_engine.tablesapce(offset, limit)
r = query_engine.tablesapce_num()
total = r.rows[0][0]
query_result = query_engine.tablespace(offset, limit)
elif instance.db_type == "oracle":
query_result = query_engine.tablespace(offset, limit)
r = query_engine.tablespace_count()
total = r.rows[0][0]
else:
result = {
"status": 1,
Expand All @@ -187,6 +161,8 @@ def tablesapce(request):
if query_result:
if not query_result.error:
table_space = query_result.to_dict()
r = query_engine.tablespace_count()
total = r.rows[0][0]
result = {"status": 0, "msg": "ok", "rows": table_space, "total": total}
else:
result = {"status": 1, "msg": query_result.error}
Expand Down
7 changes: 7 additions & 0 deletions sql/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, instance=None):
self.password = instance.password
self.db_name = instance.db_name
self.mode = instance.mode
self.is_ssl = instance.is_ssl

# 判断如果配置了隧道则连接隧道,只测试了MySQL
if self.instance.tunnel:
Expand Down Expand Up @@ -215,6 +216,12 @@ def set_variable(self, variable_name, variable_value):
def get_engine(instance=None): # pragma: no cover
"""获取数据库操作engine"""
if instance.db_type == "mysql":
from sql.models import AliyunRdsConfig

if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
from .cloud.aliyun_rds import AliyunRDS

return AliyunRDS(instance=instance)
from .mysql import MysqlEngine

return MysqlEngine(instance=instance)
Expand Down
Empty file added sql/engines/cloud/__init__.py
Empty file.
Loading

0 comments on commit 6e84f59

Please sign in to comment.