cocluto v1.0.33 - improved the performance of quman by removing 2 unneeded ssh connection requests
work related to [https://bugzilla.ipr.univ-rennes.fr/show_bug.cgi?id=3093]
This commit is contained in:
parent
9305967d10
commit
f971cda727
|
|
@ -140,37 +140,36 @@ class Sge(IGridEngine):
|
||||||
return queues_status
|
return queues_status
|
||||||
|
|
||||||
|
|
||||||
def init_db(db_backend: ISqlDatabaseBackend):
|
def init_db(conn: ISqlConnection):
|
||||||
|
|
||||||
with db_backend.connect() as conn:
|
# a table storing the log of actions (queue activation or deactivation)
|
||||||
# a table storing the log of actions (queue activation or deactivation)
|
if not conn.table_exists('log'):
|
||||||
if not conn.table_exists('log'):
|
fields = [
|
||||||
fields = [
|
SqlTableField('id', SqlTableField.Type.FIELD_TYPE_INT, 'unique identifier of the modification', is_autoinc_index=True),
|
||||||
SqlTableField('id', SqlTableField.Type.FIELD_TYPE_INT, 'unique identifier of the modification', is_autoinc_index=True),
|
SqlTableField('timestamp', SqlTableField.Type.FIELD_TYPE_TIME, 'the time (and date) at which this modification has been made'),
|
||||||
SqlTableField('timestamp', SqlTableField.Type.FIELD_TYPE_TIME, 'the time (and date) at which this modification has been made'),
|
SqlTableField('user_id', SqlTableField.Type.FIELD_TYPE_STRING, 'the id of user performing the action (unix user id)'),
|
||||||
SqlTableField('user_id', SqlTableField.Type.FIELD_TYPE_STRING, 'the id of user performing the action (unix user id)'),
|
SqlTableField('host_fqdn', SqlTableField.Type.FIELD_TYPE_STRING, 'the fully qualified domain name of the host on which the action is performed'),
|
||||||
SqlTableField('host_fqdn', SqlTableField.Type.FIELD_TYPE_STRING, 'the fully qualified domain name of the host on which the action is performed'),
|
SqlTableField('queue_machines', SqlTableField.Type.FIELD_TYPE_STRING, 'the comma separated list of queue machines that were modified'),
|
||||||
SqlTableField('queue_machines', SqlTableField.Type.FIELD_TYPE_STRING, 'the comma separated list of queue machines that were modified'),
|
SqlTableField('action', SqlTableField.Type.FIELD_TYPE_STRING, 'the action performed: "disable" or "enable"'),
|
||||||
SqlTableField('action', SqlTableField.Type.FIELD_TYPE_STRING, 'the action performed: "disable" or "enable"'),
|
SqlTableField('disable_id', SqlTableField.Type.FIELD_TYPE_STRING, 'the tag of the disable request that led to this modification (e.g., auto.croconaus, manual.graffy, etc.)'),
|
||||||
SqlTableField('disable_id', SqlTableField.Type.FIELD_TYPE_STRING, 'the tag of the disable request that led to this modification (e.g., auto.croconaus, manual.graffy, etc.)'),
|
SqlTableField('reason', SqlTableField.Type.FIELD_TYPE_STRING, 'the reason for the modification'),
|
||||||
SqlTableField('reason', SqlTableField.Type.FIELD_TYPE_STRING, 'the reason for the modification'),
|
]
|
||||||
]
|
conn.create_table('log', fields)
|
||||||
conn.create_table('log', fields)
|
|
||||||
|
|
||||||
# a table storing the current disable requests
|
# a table storing the current disable requests
|
||||||
if not conn.table_exists('disables'):
|
if not conn.table_exists('disables'):
|
||||||
fields = [
|
fields = [
|
||||||
SqlTableField('disable_request_id', SqlTableField.Type.FIELD_TYPE_INT, 'log.id of the disable action that led to this state'),
|
SqlTableField('disable_request_id', SqlTableField.Type.FIELD_TYPE_INT, 'log.id of the disable action that led to this state'),
|
||||||
SqlTableField('queue_machine', SqlTableField.Type.FIELD_TYPE_STRING, 'the name of the queue machine that was disabled'),
|
SqlTableField('queue_machine', SqlTableField.Type.FIELD_TYPE_STRING, 'the name of the queue machine that was disabled'),
|
||||||
]
|
]
|
||||||
conn.create_table('disables', fields)
|
conn.create_table('disables', fields)
|
||||||
|
|
||||||
# a table storing the current queues
|
# a table storing the current queues
|
||||||
if not conn.table_exists('queues'):
|
if not conn.table_exists('queues'):
|
||||||
fields = [
|
fields = [
|
||||||
SqlTableField('queue_machine', SqlTableField.Type.FIELD_TYPE_STRING, 'the name of the queue'),
|
SqlTableField('queue_machine', SqlTableField.Type.FIELD_TYPE_STRING, 'the name of the queue'),
|
||||||
]
|
]
|
||||||
conn.create_table('queues', fields)
|
conn.create_table('queues', fields)
|
||||||
|
|
||||||
|
|
||||||
def create_db_backend(db_def: str) -> ISqlDatabaseBackend:
|
def create_db_backend(db_def: str) -> ISqlDatabaseBackend:
|
||||||
|
|
@ -184,18 +183,18 @@ def create_db_backend(db_def: str) -> ISqlDatabaseBackend:
|
||||||
db_name = db_params['db_name'] # the name of the database, eg 'quman'
|
db_name = db_params['db_name'] # the name of the database, eg 'quman'
|
||||||
ssh_user = db_params['ssh_user'] # the ssh user which has the privileges to access the mysql database, eg 'qumandbw'
|
ssh_user = db_params['ssh_user'] # the ssh user which has the privileges to access the mysql database, eg 'qumandbw'
|
||||||
backend = SshAccessedMysqlDb(sql_server_fqdn, db_user, db_name, ssh_user)
|
backend = SshAccessedMysqlDb(sql_server_fqdn, db_user, db_name, ssh_user)
|
||||||
command = f'ssh "{ssh_user}@{sql_server_fqdn}" "hostname"'
|
check_ssh = False
|
||||||
completed_process = subprocess.run(command, shell=True, check=False, capture_output=True)
|
if check_ssh:
|
||||||
if completed_process.returncode != 0:
|
command = f'ssh "{ssh_user}@{sql_server_fqdn}" "hostname"'
|
||||||
raise RuntimeError(f"Failed to connect to the mysql server via ssh with command '{command}'. Please check the connection parameters and make sure that the ssh user has access to the server. Error message: {completed_process.stderr.decode()}")
|
completed_process = subprocess.run(command, shell=True, check=False, capture_output=True)
|
||||||
|
if completed_process.returncode != 0:
|
||||||
|
raise RuntimeError(f"Failed to connect to the mysql server via ssh with command '{command}'. Please check the connection parameters and make sure that the ssh user has access to the server. Error message: {completed_process.stderr.decode()}")
|
||||||
elif db_type == 'sqlite':
|
elif db_type == 'sqlite':
|
||||||
db_path = Path(db_params['sqlite_file_path']) # eg./quman_test/quman.sqlite
|
db_path = Path(db_params['sqlite_file_path']) # eg./quman_test/quman.sqlite
|
||||||
backend = SqliteDb(db_path)
|
backend = SqliteDb(db_path)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unsupported database type: %s" % db_type)
|
raise ValueError("Unsupported database type: %s" % db_type)
|
||||||
|
|
||||||
init_db(backend)
|
|
||||||
|
|
||||||
return backend
|
return backend
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -478,6 +477,7 @@ def main():
|
||||||
grid_engine = Sge()
|
grid_engine = Sge()
|
||||||
db_backend = create_db_backend(args.db_def)
|
db_backend = create_db_backend(args.db_def)
|
||||||
with db_backend.connect() as conn:
|
with db_backend.connect() as conn:
|
||||||
|
init_db(conn)
|
||||||
assert isinstance(conn, ISqlConnection), f"Expected db_backend.connect() to return an ISqlConnection but got {type(conn)}"
|
assert isinstance(conn, ISqlConnection), f"Expected db_backend.connect() to return an ISqlConnection but got {type(conn)}"
|
||||||
logging.debug("Connected to database successfully with connection %s", conn)
|
logging.debug("Connected to database successfully with connection %s", conn)
|
||||||
quman = QueueManager(conn, grid_engine)
|
quman = QueueManager(conn, grid_engine)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
__version__ = '1.0.32'
|
__version__ = '1.0.33'
|
||||||
|
|
||||||
|
|
||||||
class Version(object):
|
class Version(object):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue