Skip to content

Commit

Permalink
use context.stdio for OBConnector
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodong-ji committed Nov 28, 2024
1 parent 61bb9cf commit 26c8139
Show file tree
Hide file tree
Showing 20 changed files with 19 additions and 27 deletions.
2 changes: 1 addition & 1 deletion common/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def get_obproxy_version(context):
def get_observer_version_by_sql(context, ob_cluster, stdio=None):
stdio.verbose("start get_observer_version_by_sql . input: {0}:{1}".format(ob_cluster.get("db_host"), ob_cluster.get("db_port")))
try:
ob_connector = OBConnector(context=context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), stdio=stdio, timeout=100)
ob_connector = OBConnector(context=context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), timeout=100)
ob_version_info = ob_connector.execute_sql("select version();")
except Exception as e:
raise Exception("get_observer_version_by_sql Exception. Maybe cluster'info is error: " + e.__str__())
Expand Down
4 changes: 2 additions & 2 deletions common/config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, context):

def get_cluster_name(self):
ob_version = get_observer_version(self.context)
obConnetcor = OBConnector(context=self.context, ip=self.db_host, port=self.db_port, username=self.sys_tenant_user, password=self.sys_tenant_password, stdio=self.stdio, timeout=100)
obConnetcor = OBConnector(context=self.context, ip=self.db_host, port=self.db_port, username=self.sys_tenant_user, password=self.sys_tenant_password, timeout=100)
if ob_version.startswith("3") or ob_version.startswith("2"):
sql = "select cluster_name from oceanbase.v$ob_cluster"
res = obConnetcor.execute_sql(sql)
Expand All @@ -68,7 +68,7 @@ def get_cluster_name(self):

def get_host_info_list_by_cluster(self):
ob_version = get_observer_version(self.context)
obConnetcor = OBConnector(context=self.context, ip=self.db_host, port=self.db_port, username=self.sys_tenant_user, password=self.sys_tenant_password, stdio=self.stdio, timeout=100)
obConnetcor = OBConnector(context=self.context, ip=self.db_host, port=self.db_port, username=self.sys_tenant_user, password=self.sys_tenant_password, timeout=100)
sql = "select SVR_IP, SVR_PORT, ZONE, BUILD_VERSION from oceanbase.DBA_OB_SERVERS"
if ob_version.startswith("3") or ob_version.startswith("2") or ob_version.startswith("1"):
sql = "select SVR_IP, SVR_PORT, ZONE, BUILD_VERSION from oceanbase.__all_server"
Expand Down
3 changes: 1 addition & 2 deletions common/ob_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def __init__(
username,
password=None,
database=None,
stdio=None,
timeout=30,
):
self.context = context
Expand All @@ -44,7 +43,7 @@ def __init__(
self.password = str(password)
self.timeout = timeout
self.conn = None
self.stdio = stdio
self.stdio = context.stdio
self.database = database
self.init()

Expand Down
2 changes: 1 addition & 1 deletion core.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def update_obcluster_nodes(self, config):
return
if Util.check_none_values(ob_cluster, self.stdio):
ob_version = get_observer_version_by_sql(self.context, ob_cluster, self.stdio)
obConnetcor = OBConnector(context=self.context, ip=ob_cluster["db_host"], port=ob_cluster["db_port"], username=ob_cluster["tenant_sys"]["user"], password=ob_cluster["tenant_sys"]["password"], stdio=self.stdio, timeout=100)
obConnetcor = OBConnector(context=self.context, ip=ob_cluster["db_host"], port=ob_cluster["db_port"], username=ob_cluster["tenant_sys"]["user"], password=ob_cluster["tenant_sys"]["password"], timeout=100)
sql = "select SVR_IP, SVR_PORT, ZONE, BUILD_VERSION from oceanbase.DBA_OB_SERVERS"
if ob_version.startswith("3") or ob_version.startswith("2") or ob_version.startswith("1"):
sql = "select SVR_IP, SVR_PORT, ZONE, BUILD_VERSION from oceanbase.__all_server"
Expand Down
2 changes: 1 addition & 1 deletion handler/analyzer/analyze_index_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def init_option(self):
self.stdio.verbose('cluster config: {0}'.format(StringUtils.mask_passwords(ob_cluster)))
self.ob_cluster = ob_cluster
self.sys_connector = OBConnector(
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=100
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), timeout=100
)
tenant_name = Util.get_option(options, 'tenant_name')
table_name = Util.get_option(options, 'table_name')
Expand Down
1 change: 0 additions & 1 deletion handler/analyzer/analyze_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def __init__(self, context, analyze_type='default'):
port=self.ob_cluster.get("db_port"),
username=self.ob_cluster.get("tenant_sys").get("user"),
password=self.ob_cluster.get("tenant_sys").get("password"),
stdio=self.stdio,
timeout=10000,
database="oceanbase",
)
Expand Down
1 change: 0 additions & 1 deletion handler/analyzer/analyze_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def __init__(self, context):
port=self.ob_cluster.get("db_port"),
username=self.ob_cluster.get("tenant_sys").get("user"),
password=self.ob_cluster.get("tenant_sys").get("password"),
stdio=self.stdio,
timeout=10000,
database="oceanbase",
)
Expand Down
4 changes: 2 additions & 2 deletions handler/analyzer/analyze_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def init_config(self):
self.stdio.verbose('cluster config: {0}'.format(StringUtils.mask_passwords(ob_cluster)))
self.ob_cluster = ob_cluster
self.sys_connector = OBConnector(
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=100
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), timeout=100
)
self.ob_cluster_name = ob_cluster.get("ob_cluster_name")
self.stdio.print('init cluster config complete')
Expand All @@ -136,7 +136,7 @@ def init_ob_version(self):
def init_db_connector(self):
if self.db_user:
self.db_connector_provided = True
self.db_connector = OBConnector(context=self.context, ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=self.db_user, password=self.db_password, stdio=self.stdio, timeout=100)
self.db_connector = OBConnector(context=self.context, ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=self.db_user, password=self.db_password, timeout=100)
else:
self.db_connector = self.sys_connector

Expand Down
4 changes: 2 additions & 2 deletions handler/analyzer/analyze_sql_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def init_config(self):
self.stdio.verbose('cluster config: {0}'.format(StringUtils.mask_passwords(ob_cluster)))
self.ob_cluster = ob_cluster
self.sys_connector = OBConnector(
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=100
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), timeout=100
)
self.ob_cluster_name = ob_cluster.get("ob_cluster_name")
self.stdio.print('init cluster config complete')
Expand All @@ -69,7 +69,7 @@ def init_db_connector(self):
if self.db_user:
self.stdio.verbose("init db connector start")
self.db_connector_provided = True
self.db_connector = OBConnector(context=self.context, ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=self.db_user, password=self.db_password, stdio=self.stdio, timeout=100)
self.db_connector = OBConnector(context=self.context, ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=self.db_user, password=self.db_password, timeout=100)
self.stdio.verbose("init db connector complete")
else:
self.db_connector = self.sys_connector
Expand Down
1 change: 0 additions & 1 deletion handler/analyzer/analyze_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(self, context, analyze_type='diff'):
port=self.ob_cluster.get("db_port"),
username=self.ob_cluster.get("tenant_sys").get("user"),
password=self.ob_cluster.get("tenant_sys").get("password"),
stdio=self.stdio,
timeout=10000,
database="oceanbase",
)
Expand Down
2 changes: 1 addition & 1 deletion handler/checker/check_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def __init__(self, context, max_size, cluster):
try:
for i in range(max_size):
conn = OBConnector(
context=context, ip=self.cluster.get("db_host"), port=self.cluster.get("db_port"), username=self.cluster.get("tenant_sys").get("user"), password=self.cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=10000
context=context, ip=self.cluster.get("db_host"), port=self.cluster.get("db_port"), username=self.cluster.get("tenant_sys").get("user"), password=self.cluster.get("tenant_sys").get("password"), timeout=10000
)
self.connections.put(conn)
self.stdio.verbose("obConnectorPool init success!")
Expand Down
4 changes: 2 additions & 2 deletions handler/display/display_scenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, context, display_pack_dir='./', tasks_base_path="~/.obdiag/di
def init_config(self):
self.cluster = self.context.cluster_config
self.sys_connector = OBConnector(
context=self.context, ip=self.cluster.get("db_host"), port=self.cluster.get("db_port"), username=self.cluster.get("tenant_sys").get("user"), password=self.cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=100
context=self.context, ip=self.cluster.get("db_host"), port=self.cluster.get("db_port"), username=self.cluster.get("tenant_sys").get("user"), password=self.cluster.get("tenant_sys").get("password"), timeout=100
)
self.obproxy_nodes = self.context.obproxy_config['servers']
self.ob_nodes = self.context.cluster_config['servers']
Expand Down Expand Up @@ -92,7 +92,7 @@ def execute(self):

def __init_db_connector(self):
self.db_connector = OBConnector(
context=self.context, ip=self.db_conn.get("host"), port=self.db_conn.get("port"), username=self.db_conn.get("user"), password=self.db_conn.get("password"), database=self.db_conn.get("database"), stdio=self.stdio, timeout=100
context=self.context, ip=self.db_conn.get("host"), port=self.db_conn.get("port"), username=self.db_conn.get("user"), password=self.db_conn.get("password"), database=self.db_conn.get("database"), timeout=100
)

def __init_db_conn(self, cli_connection_string):
Expand Down
1 change: 0 additions & 1 deletion handler/gather/gather_ash_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def __init__(self, context, gather_pack_dir='./'):
port=self.cluster.get("db_port"),
username=self.cluster.get("tenant_sys").get("user"),
password=self.cluster.get("tenant_sys").get("password"),
stdio=self.stdio,
timeout=10000,
database="oceanbase",
)
Expand Down
1 change: 0 additions & 1 deletion handler/gather/gather_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __init__(self, context, gather_pack_dir='./'):
port=self.ob_cluster.get("db_port"),
username=self.ob_cluster.get("tenant_sys").get("user"),
password=self.ob_cluster.get("tenant_sys").get("password"),
stdio=self.stdio,
timeout=10000,
database="oceanbase",
)
Expand Down
4 changes: 2 additions & 2 deletions handler/gather/gather_plan_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def init_config(self):
ob_cluster = self.context.cluster_config
self.ob_cluster = ob_cluster
self.sys_connector = OBConnector(
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=100
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), timeout=100
)
self.ob_cluster_name = ob_cluster.get("ob_cluster_name")
return True
Expand Down Expand Up @@ -95,7 +95,7 @@ def init_option(self):

def __init_db_connector(self):
self.db_connector = OBConnector(
context=self.context, ip=self.db_conn.get("host"), port=self.db_conn.get("port"), username=self.db_conn.get("user"), password=self.db_conn.get("password"), database=self.db_conn.get("database"), stdio=self.stdio, timeout=100
context=self.context, ip=self.db_conn.get("host"), port=self.db_conn.get("port"), username=self.db_conn.get("user"), password=self.db_conn.get("password"), database=self.db_conn.get("database"), timeout=100
)

def handle(self):
Expand Down
4 changes: 2 additions & 2 deletions handler/gather/gather_tabledump.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def init(self):
else:
self.tenant_name = self.__extract_string(user)
self.ob_connector = OBConnector(
context=self.context, ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=self.ob_cluster.get("tenant_sys").get("user"), password=self.ob_cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=100
context=self.context, ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=self.ob_cluster.get("tenant_sys").get("user"), password=self.ob_cluster.get("tenant_sys").get("password"), timeout=100
)
self.tenant_connector = OBConnector(context=self.context, ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=user, password=password, stdio=self.stdio, timeout=100)
self.tenant_connector = OBConnector(context=self.context, ip=self.ob_cluster.get("db_host"), port=self.ob_cluster.get("db_port"), username=user, password=password, timeout=100)
self.file_name = "{0}/obdiag_tabledump_result_{1}.txt".format(self.store_dir, TimeUtils.timestamp_to_filename_time(self.gather_timestamp))
return True
except Exception as e:
Expand Down
1 change: 0 additions & 1 deletion handler/gather/gather_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(self, context, gather_pack_dir='./'):
port=self.ob_cluster.get("db_port"),
username=self.ob_cluster.get("tenant_sys").get("user"),
password=self.ob_cluster.get("tenant_sys").get("password"),
stdio=self.stdio,
timeout=10000,
database="oceanbase",
)
Expand Down
2 changes: 1 addition & 1 deletion handler/gather/step/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, context, step, ob_cluster, report_path, task_variable_dict):
self.sys_database = None
self.database = None
self.ob_connector = OBConnector(
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=10000
context=self.context, ip=ob_cluster.get("db_host"), port=ob_cluster.get("db_port"), username=ob_cluster.get("tenant_sys").get("user"), password=ob_cluster.get("tenant_sys").get("password"), timeout=10000
)
except Exception as e:
self.stdio.error("StepSQLHandler init fail. Please check the OBCLUSTER conf. OBCLUSTER: {0} Exception : {1} .".format(ob_cluster, e))
Expand Down
1 change: 0 additions & 1 deletion handler/rca/rca_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def __init__(self, context):
port=self.ob_cluster.get("db_port"),
username=self.ob_cluster.get("tenant_sys").get("user"),
password=self.ob_cluster.get("tenant_sys").get("password"),
stdio=self.stdio,
timeout=10000,
)
self.context.set_variable("ob_connector", ob_connector)
Expand Down
2 changes: 1 addition & 1 deletion telemetry/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def set_cluster_conn(self, context, obcluster):
try:

self.cluster_conn = OBConnector(
context=context, ip=obcluster.get("db_host"), port=obcluster.get("db_port"), username=obcluster.get("tenant_sys").get("user"), password=obcluster.get("tenant_sys").get("password"), stdio=self.stdio, timeout=10000
context=context, ip=obcluster.get("db_host"), port=obcluster.get("db_port"), username=obcluster.get("tenant_sys").get("user"), password=obcluster.get("tenant_sys").get("password"), timeout=10000
)
self.threads.append(threading.Thread(None, self.get_cluster_info()))
# self.threads.append(threading.Thread(None, self.get_tenant_info()))
Expand Down

0 comments on commit 26c8139

Please sign in to comment.