Skip to content

Commit

Permalink
test check
Browse files Browse the repository at this point in the history
  • Loading branch information
wayyoungboy committed Apr 25, 2024
1 parent b42efaf commit 5fa5fef
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
51 changes: 40 additions & 11 deletions handler/checker/check_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""

import os
import queue
import time

import yaml
Expand Down Expand Up @@ -111,20 +112,15 @@ def __init__(self, context, check_target_type="observer"):
self.nodes=new_node
self.version=get_version(self.nodes, self.check_target_type,self.cluster, self.stdio)

# add OBConnector
obConnector = None
# add OBConnectorPool
OBConnectorPool = None
try:
if self.cluster is not None:
obConnector=OBConnector(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)
OBConnectorPool=checkOBConnectorPool(context,2,self.cluster)

except Exception as e:
self.stdio.warn("obConnector init error. Error info is {0}".format(e))
finally:
self.context.set_variable('check_obConnector', obConnector)
self.context.set_variable('check_obConnector_pool', OBConnectorPool)


def handle(self):
Expand Down Expand Up @@ -249,4 +245,37 @@ def execute(self):
except Exception as e:
self.stdio.error("Internal error :{0}".format(e))
end_time = time.time()
print("Total cost time is {0} s".format((end_time - start_time)))
print("Total cost time is {0} s".format((end_time - start_time)))
class checkOBConnectorPool:
def __init__(self,context, max_size, cluster):
self.max_size = max_size
self.cluster=cluster
self.connections = queue.Queue(maxsize=max_size)
self.stdio=context.stdio

def get_connection(self):
try:
if self.connections.qsize() == 0:
if self.connections.qsize() < self.max_size:
conn = OBConnector(
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
)
self.connections.put(conn)
else:
conn = self.connections.get()
else:
conn = self.connections.get()
return conn
except Exception as e:
return None

def release_connection(self, conn):
if conn is not None:
self.connections.put(conn)
return

6 changes: 5 additions & 1 deletion handler/checker/step/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def __init__(self,context, step, task_variable_dict,obConnector):
self.tenant_mode = None
self.sys_database = None
self.database = None
self.ob_connector=obConnector
self.ob_connector_pool=self.context.get_variable('check_obConnector_pool',None)
if self.ob_connector_pool is not None:
self.ob_connector=self.ob_connector_pool.get_connection()
if self.ob_connector is None:
raise Exception("self.ob_connector is None.")
except Exception as e:
Expand Down Expand Up @@ -72,6 +74,8 @@ def execute(self):
except Exception as e:
self.stdio.error("StepSQLHandler execute Exception: {0}".format(e))
raise StepExecuteFailException("StepSQLHandler execute Exception: {0}".format(e))
finally:
self.ob_connector_pool.release_connection(self.ob_connector)

def update_step_variable_dict(self):
return self.task_variable_dict
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ task:
set_value: result
verify_type: between
verify: "[80,100]"
err_msg: 'memory_limit/os_memory is #{result}%,is not between 80 and 100'
err_msg: 'memory_limit: #{memory_limit}. os_memory: #{os_memory}. memory_limit/os_memory is #{result}%,is not between 80% and 100%'

# memory_size
- type: sql
Expand Down

0 comments on commit 5fa5fef

Please sign in to comment.