Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将阿里云RDS的功能抽到单独engine #2087

Merged
merged 8 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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[0][0]
result = {"status": 0, "msg": "ok", "rows": table_space, "total": total}
else:
result = {"status": 1, "msg": query_result.error}
Expand Down
6 changes: 6 additions & 0 deletions sql/engines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,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