Skip to content

Commit

Permalink
update0717
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyd66 committed Jul 17, 2024
1 parent 4a4ba37 commit e63fcac
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
73 changes: 73 additions & 0 deletions common/ssh_client/local_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*
# Copyright (c) 2022 OceanBase
# OceanBase Diagnostic Tool is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.

"""
@time: 2024/6/24
@file: local_client.py
@desc:
"""

from common.ssh_client.base import SsherClient
import subprocess32 as subprocess
import shutil


class LocalClient(SsherClient):
def __init__(self, context=None, node=None):
super().__init__(context, node)

def exec_cmd(self, cmd):
try:
self.stdio.verbose("[local host] run cmd = [{0}] on localhost".format(cmd))
#if tag:
#cmd="sudo {0}".format(cmd)
out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable='/bin/bash')
stdout, stderr = out.communicate()
if stderr:
return stderr.decode('utf-8')
return stdout.decode('utf-8')
except Exception as e:
self.stdio.error("run cmd = [{0}] on localhost, Exception = [{1}]".format(cmd, e))
raise Exception("[localhost] Execute Shell command failed, command=[{0}] Exception = [{1}]".format(cmd, e))

def download(self, remote_path, local_path):
try:
shutil.copy(remote_path, local_path)
except Exception as e:
self.stdio.error("download file from localhost, remote_path=[{0}], local_path=[{1}], error=[{2}]".format(remote_path, local_path, str(e)))
raise Exception("download file from localhost, remote_path=[{0}], local_path=[{1}], error=[{2}]".format(remote_path, local_path, str(e)))

def upload(self, remote_path, local_path):
try:
shutil.copy(local_path, remote_path)
except Exception as e:
self.stdio.error("upload file to localhost, remote _path =[{0}], local _path=[{1}], error=[{2}]".format(remote_path, local_path, str(e)))
raise Exception("[local] upload file to localhost, remote _path =[{0}], local _path=[{1}], error=[{2}]".format(remote_path, local_path, str(e)))

def ssh_invoke_shell_switch_user(self, new_user, cmd, time_out):
try:
cmd = "su - {0} -c '{1}'".format(new_user, cmd)
self.stdio.verbose("[local host] ssh_invoke_shell_switch_user cmd = [{0}] on localhost".format(cmd))
out = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True, executable='/bin/bash')
stdout, stderr = out.communicate()
if stderr:
return stderr.decode('utf-8')
return stdout.decode('utf-8')
except:
self.stdio.error("run cmd = [{0}] on localhost".format(cmd))
raise Exception("the client type is not support ssh invoke shell switch user")

def get_name(self):
return "local"

def get_ip(self):
return self.client.get_ip()
12 changes: 12 additions & 0 deletions handler/rca/scene/index_ddl_error_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def execute(self):
self.verbose("gather rootservice.log by {0}".format(self.trace_id))
work_path_rs = self.store_dir + "/{0}_on_rs/".format(self.trace_id)
self.gather_log.set_parameters("scope", "rootservice")
if self.input_parameters.get("since") is not None:
since = self.input_parameters.get("since")
self.gather_log.set_parameters("since", since)
self.gather_log.grep("{0}".format(self.trace_id))
logs_name = self.gather_log.execute(save_path=work_path_rs)
if logs_name is None or len(logs_name) <= 0:
Expand All @@ -161,6 +164,9 @@ def execute(self):
self.verbose("gather observer.log by {0}".format(self.trace_id))
work_path_ddl_wait_trans_end_ctx_try_wait = self.store_dir + "/{0}_on_obs/".format(self.trace_id)
self.gather_log.set_parameters("scope", "observer")
if self.input_parameters.get("since") is not None:
since = self.input_parameters.get("since")
self.gather_log.set_parameters("since", since)
self.gather_log.grep("{0}".format(self.trace_id))
logs_name = self.gather_log.execute(save_path=work_path_ddl_wait_trans_end_ctx_try_wait)
if logs_name is None or len(logs_name) <= 0:
Expand All @@ -176,6 +182,9 @@ def execute(self):
# index_sstable_build_task_finish
work_path_index_sstable_build_task_finish = self.store_dir + "/{0}_on_obs/".format(self.trace_id)
self.gather_log.set_parameters("scope", "observer")
if self.input_parameters.get("since") is not None:
since = self.input_parameters.get("since")
self.gather_log.set_parameters("since", since)
self.gather_log.grep("{0}".format(self.trace_id))
logs_name = self.gather_log.execute(save_path=work_path_index_sstable_build_task_finish)
if logs_name is None or len(logs_name) <= 0:
Expand All @@ -191,6 +200,9 @@ def execute(self):
self.verbose("gather rootservice.log by {0}".format(self.trace_id))
work_path_rs = self.store_dir + "/{0}_on_rs/".format(self.trace_id)
self.gather_log.set_parameters("scope", "rootservice")
if self.input_parameters.get("since") is not None:
since = self.input_parameters.get("since")
self.gather_log.set_parameters("since", since)
self.gather_log.grep("{0}".format(self.trace_id))
logs_name = self.gather_log.execute(save_path=work_path_rs)
if logs_name is None or len(logs_name) <= 0:
Expand Down
9 changes: 8 additions & 1 deletion handler/rca/scene/lock_conflict_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def __init__(self):

def init(self, context):
try:
if self.input_parameters is not None:
tenant_name = self.input_parameters.get("tenant_name")
tenant_data = self.ob_connector.execute_sql("select tenant_id from oceanbase.__all_tenant where tenant_name = '{0}';".format(tenant_name))
if len(tenant_data) == 0:
raise RCAInitException("can not find tenant id by tenant name: {0}. Please check the tenant name.".format(tenant_name))
self.tenant_id = tenant_data[0][0]
self.verbose("tenant_id is {0}".format(self.tenant_id))
super().init(context)
self.local_path = context.get_variable("store_dir")
if self.observer_version is None or len(self.observer_version.strip()) == 0 or self.observer_version == "":
Expand Down Expand Up @@ -83,7 +90,7 @@ def __execute_4_2(self):
wait_lock_trans_id = OB_LOCKS_data["TRANS_ID"]
trans_record.add_record("wait_lock_trans_id is {0}".format(wait_lock_trans_id))
cursor_by_trans_id = self.ob_connector.execute_sql_return_cursor_dictionary('select * from oceanbase.GV$OB_TRANSACTION_PARTICIPANTS where TX_ID="{0}";'.format(wait_lock_trans_id))

wait_lock_session_datas = cursor_by_trans_id.fetchall()
self.stdio.verbose("get sql_info by holding_lock_session_id:{0}".format(holding_lock_session_id))
wait_lock_session_id = "not get"
Expand Down

0 comments on commit e63fcac

Please sign in to comment.