From 4949867a2d40ff61393210c1db6f4e55e39e3777 Mon Sep 17 00:00:00 2001 From: Fabrice Le Goff <fabrice.le.goff@cern.ch> Date: Tue, 12 Dec 2023 17:58:15 +0100 Subject: [PATCH] cx_Oracle -> oracledb --- DeploymentTest/add_files_to_sfotz_intr.py | 5 ++-- ProductionTools/ddm.test.py | 2 +- ProductionTools/ddmtiming.test.py | 2 +- .../installed/castor.sfotzdb_intr_writer.sh | 5 ++-- .../installed/castor.sfotzdb_reader.sh | 12 ++++++---- .../installed/castor.sfotzdb_writer.sh | 10 +++++--- .../oracle_create_missing_and_close_opened.py | 5 ++-- .../oracle_run_status.py | 7 +++--- Script/cs/Threads/DdmMonitoringThread.py | 2 +- Script/cs/Threads/InfoServiceThread.py | 4 ++-- Script/cs/Tools/Libraries/Database.py | 23 ++++++++++--------- 11 files changed, 45 insertions(+), 32 deletions(-) diff --git a/DeploymentTest/add_files_to_sfotz_intr.py b/DeploymentTest/add_files_to_sfotz_intr.py index df7d0a8..b98822d 100644 --- a/DeploymentTest/add_files_to_sfotz_intr.py +++ b/DeploymentTest/add_files_to_sfotz_intr.py @@ -1,9 +1,10 @@ -import cx_Oracle import coral_auth +import oracledb +oracledb.init_oracle_client() user, pwd, dbn = coral_auth.get_connection_parameters_from_connection_string( 'oracle://int8r/ATLAS_SFO_T0') -orcl = cx_Oracle.connect(user, pwd, dbn) +orcl = oracledb.connect(user=user, password=pwd, dsn=dbn) curs = orcl.cursor() try: diff --git a/ProductionTools/ddm.test.py b/ProductionTools/ddm.test.py index ed9ffb5..97cf5d3 100755 --- a/ProductionTools/ddm.test.py +++ b/ProductionTools/ddm.test.py @@ -4,7 +4,7 @@ from __future__ import print_function from future import standard_library standard_library.install_aliases() from builtins import str -import urllib.request, urllib.error, urllib.parse #pylint: disable=import-error +import urllib.request, urllib.error, urllib.parse import json import uuid from time import time diff --git a/ProductionTools/ddmtiming.test.py b/ProductionTools/ddmtiming.test.py index 7efe3a4..2e61b8b 100755 --- a/ProductionTools/ddmtiming.test.py +++ b/ProductionTools/ddmtiming.test.py @@ -7,7 +7,7 @@ standard_library.install_aliases() from builtins import str from builtins import range from past.utils import old_div -import urllib.request, urllib.error, urllib.parse #pylint: disable=import-error +import urllib.request, urllib.error, urllib.parse import json import uuid from time import time diff --git a/ProductionTools/installed/castor.sfotzdb_intr_writer.sh b/ProductionTools/installed/castor.sfotzdb_intr_writer.sh index b974717..8bc73b9 100755 --- a/ProductionTools/installed/castor.sfotzdb_intr_writer.sh +++ b/ProductionTools/installed/castor.sfotzdb_intr_writer.sh @@ -15,10 +15,11 @@ else fi python -i -c " -import cx_Oracle import coral_auth +import oracledb +oracledb.init_oracle_client() user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://int8r/ATLAS_SFO_T0') -orcl = cx_Oracle.connect(user, pwd, dbn) +orcl = oracledb.connect(user=user, password=pwd, dsn=dbn) curs = orcl.cursor() print('orcl: connection to db object, curs: cursor on the connection') " diff --git a/ProductionTools/installed/castor.sfotzdb_reader.sh b/ProductionTools/installed/castor.sfotzdb_reader.sh index c9ec8a5..5c389c8 100755 --- a/ProductionTools/installed/castor.sfotzdb_reader.sh +++ b/ProductionTools/installed/castor.sfotzdb_reader.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +DBN=atonr_conf + if [ "x$CMTRELEASE" != x ]; then # TDAQ environment already loaded echo "using $CMTRELEASE" @@ -8,17 +10,19 @@ elif [ -r /sw/castor/script_setup.sh ]; then source /sw/castor/script_setup.sh elif [ -r /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh ]; then #testbed - source /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh + source /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh tdaq-11-02-00 + DBN=atonr_adg else echo "error: cannot setup environment" exit fi python -i -c " -import cx_Oracle import coral_auth -user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://atonr_conf/ATLAS_SFO_T0_R') -orcl = cx_Oracle.connect(user, pwd, dbn) +import oracledb +oracledb.init_oracle_client() +user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://${DBN}/ATLAS_SFO_T0_R') +orcl = oracledb.connect(user=user, password=pwd, dsn=dbn) curs = orcl.cursor() print('orcl: connection to db object, curs: cursor on the connection') " diff --git a/ProductionTools/installed/castor.sfotzdb_writer.sh b/ProductionTools/installed/castor.sfotzdb_writer.sh index 6e2dc76..6a23ddb 100755 --- a/ProductionTools/installed/castor.sfotzdb_writer.sh +++ b/ProductionTools/installed/castor.sfotzdb_writer.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +DBN=atonr_conf + if [ "x$CMTRELEASE" != x ]; then # TDAQ environment already loaded echo "using $CMTRELEASE" @@ -9,16 +11,18 @@ elif [ -r /sw/castor/script_setup.sh ]; then elif [ -r /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh ]; then #testbed source /cvmfs/atlas.cern.ch/repo/sw/tdaq/tools/cmake_tdaq/bin/cm_setup.sh + DBN=atonr_adg else echo "error: cannot setup environment" exit fi python -i -c " -import cx_Oracle import coral_auth -user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://atonr_conf/ATLAS_SFO_T0') -orcl = cx_Oracle.connect(user, pwd, dbn) +import oracledb +oracledb.init_oracle_client() +user,pwd,dbn = coral_auth.get_connection_parameters_from_connection_string('oracle://${DBN}/ATLAS_SFO_T0') +orcl = oracledb.connect(user=user, password=pwd, dsn=dbn) curs = orcl.cursor() print('orcl: connection to db object, curs: cursor on the connection') " diff --git a/ProductionTools/oracle_db_disaster_recovery/oracle_create_missing_and_close_opened.py b/ProductionTools/oracle_db_disaster_recovery/oracle_create_missing_and_close_opened.py index 5c7d862..5009213 100755 --- a/ProductionTools/oracle_db_disaster_recovery/oracle_create_missing_and_close_opened.py +++ b/ProductionTools/oracle_db_disaster_recovery/oracle_create_missing_and_close_opened.py @@ -1,9 +1,10 @@ #!/usr/bin/env python -import cx_Oracle import sqlite3 import coral_auth import argparse import datetime +import oracledb +oracledb.init_oracle_client() def get_next_index(orac, seqname): @@ -236,7 +237,7 @@ def oracle_create_missing_and_close_opened(oradb_url, sqlite_file, try: user, pwd, dbn = coral_auth.get_connection_parameters_from_connection_string( oradb_url) - oradb = cx_Oracle.connect(user, pwd, dbn) + oradb = oracledb.connect(user=user, password=pwd, dsn=dbn) orac = oradb.cursor() except Exception: print(f'error connecing to {oradb_url}') diff --git a/ProductionTools/oracle_db_disaster_recovery/oracle_run_status.py b/ProductionTools/oracle_db_disaster_recovery/oracle_run_status.py index 9e03b7e..5c83ddf 100755 --- a/ProductionTools/oracle_db_disaster_recovery/oracle_run_status.py +++ b/ProductionTools/oracle_db_disaster_recovery/oracle_run_status.py @@ -1,7 +1,8 @@ #!/usr/bin/env python -import cx_Oracle import coral_auth import argparse +import oracledb +oracledb.init_oracle_client() def _stream_status_fast(orac, run_number, sfoids): @@ -76,7 +77,7 @@ def oracle_run_status_fast(oradb_url, run_number, sfos): print('run status:') user, pwd, dbn = coral_auth.get_connection_parameters_from_connection_string( oradb_url) - oradb = cx_Oracle.connect(user, pwd, dbn) + oradb = oracledb.connect(user=user, password=pwd, dsn=dbn) orac = oradb.cursor() sfoids = [f'SFO-{i}' for i in sfos] @@ -92,7 +93,7 @@ def oracle_run_status_report(oradb_url, run_number, sfos, report): print('run status:') user, pwd, dbn = coral_auth.get_connection_parameters_from_connection_string( oradb_url) - oradb = cx_Oracle.connect(user, pwd, dbn) + oradb = oracledb.connect(user=user, password=pwd, dsn=dbn) orac = oradb.cursor() sfoids = [f'SFO-{i}' for i in sfos] diff --git a/Script/cs/Threads/DdmMonitoringThread.py b/Script/cs/Threads/DdmMonitoringThread.py index fb099b8..e41c57e 100644 --- a/Script/cs/Threads/DdmMonitoringThread.py +++ b/Script/cs/Threads/DdmMonitoringThread.py @@ -1,6 +1,6 @@ #!/bin/env python import threading -import urllib.request, urllib.error, urllib.parse #pylint: disable=import-error +import urllib.request, urllib.error, urllib.parse import json import queue import time diff --git a/Script/cs/Threads/InfoServiceThread.py b/Script/cs/Threads/InfoServiceThread.py index 2a81687..42fa3f1 100644 --- a/Script/cs/Threads/InfoServiceThread.py +++ b/Script/cs/Threads/InfoServiceThread.py @@ -47,7 +47,7 @@ class InfoServiceThread(threading.Thread): if self.ipc_partition.isValid(): self.logger.info('partition %s is valid: IS publication enabled', self.ipc_partition.name()) - + # variable to handle the period between the partition becomes valid # and the first publication attempt # None means that there is nothing to do @@ -211,7 +211,7 @@ class InfoServiceThread(threading.Thread): stats.write_count, stats.read_bytes, stats.write_bytes, stats.busy_time) return - + d = psutil.disk_io_counters(perdisk=True, nowrap=True) for sd in d: if not sd in self.conf.ISStorageIoStatsDevices: diff --git a/Script/cs/Tools/Libraries/Database.py b/Script/cs/Tools/Libraries/Database.py index 59c6e67..9638a52 100644 --- a/Script/cs/Tools/Libraries/Database.py +++ b/Script/cs/Tools/Libraries/Database.py @@ -1,9 +1,10 @@ #!/bin/env python -import cx_Oracle import sys import datetime import time import coral_auth +import oracledb +oracledb.init_oracle_client() # Errors for Oracle Database # StandardError: @@ -22,8 +23,8 @@ class OraDB(object): def __init__(self, url): self.connstring = url - self.conn_params = coral_auth.get_connection_parameters_from_connection_string(self.connstring) #pylint: disable=no-member - self.orcl = cx_Oracle.connect(*self.conn_params) #pylint: disable=no-member + self.conn_user, self.conn_pwd, self.conn_dbn = coral_auth.get_connection_parameters_from_connection_string(self.connstring) + self.orcl = oracledb.connect(user=self.conn_user, password=self.conn_pwd, dsn=self.conn_dbn) self.curs = self.orcl.cursor() self.lastKeys = {} @@ -37,7 +38,7 @@ class OraDB(object): return self.curs.fetchone() def getDateVar(self): - return self.curs.var(cx_Oracle.DATETIME) #pylint: disable=no-member + return self.curs.var(oracledb.DATETIME) def lastOp(self): return self.curs.statement @@ -48,7 +49,7 @@ class OraDB(object): def refresh(self): self.orcl.commit() self.orcl.close() - self.orcl = cx_Oracle.connect(*self.conn_params) #pylint: disable=no-member + self.orcl = oracledb.connect(user=self.conn_user, password=self.conn_pwd, dsn=self.conn_dbn) self.curs = self.orcl.cursor() class Database(): @@ -84,7 +85,7 @@ class Database(): return (True, True) else: return (True, False) - except (cx_Oracle.InterfaceError,cx_Oracle.DatabaseError) as ex: #pylint: disable=no-member + except (oracledb.InterfaceError,oracledb.DatabaseError) as ex: errstr = 'database error: {}, request: "{}", request keys:"{}"'.format( str(ex), str(self.db.lastOp()), str(self.db.getLastKeys())) self.logger.error(errstr) @@ -112,7 +113,7 @@ class Database(): # cannot find the file in the DB return (None, None, None) result = row[:3] - except (cx_Oracle.InterfaceError,cx_Oracle.DatabaseError) as ex: #pylint: disable=no-member + except (oracledb.InterfaceError,oracledb.DatabaseError) as ex: errstr = 'database error: {}, request: "{}", request keys:"{}"'.format( str(ex), str(self.db.lastOp()), str(self.db.getLastKeys())) self.logger.error(errstr) @@ -127,7 +128,7 @@ class Database(): try: self.filedeletion(sfofile) return True - except (cx_Oracle.InterfaceError,cx_Oracle.DatabaseError) as ex: #pylint: disable=no-member + except (oracledb.InterfaceError,oracledb.DatabaseError) as ex: errstr = 'database error: {}, request: "{}", request keys:"{}"'.format( str(ex), str(self.db.lastOp()), str(self.db.getLastKeys())) self.logger.error(errstr) @@ -145,7 +146,7 @@ class Database(): retry = False try: self.filetransfer(sfofile, remotefile) - except (cx_Oracle.InterfaceError, cx_Oracle.DatabaseError) as ex: #pylint: disable=no-member + except (oracledb.InterfaceError, oracledb.DatabaseError) as ex: ex_info = str(ex) errstr = 'database error: {}, request: "{}", request keys:"{}"'.format( str(ex), str(self.db.lastOp()), str(self.db.getLastKeys())) @@ -177,7 +178,7 @@ class Database(): return True - except (cx_Oracle.InterfaceError, cx_Oracle.DatabaseError) as ex: #pylint: disable=no-member + except (oracledb.InterfaceError, oracledb.DatabaseError) as ex: errstr = 'database error: {}, request: "{}", request keys:"{}"'.format( str(ex), str(self.db.lastOp()), str(self.db.getLastKeys())) self.logger.error(errstr) @@ -205,7 +206,7 @@ class Database(): try: self.db.execute(args,keys) return True - except (cx_Oracle.InterfaceError,cx_Oracle.DatabaseError) as ex: #pylint: disable=no-member + except (oracledb.InterfaceError,oracledb.DatabaseError) as ex: errstr = 'database error: {}, request: "{}", request keys:"{}"'.format( str(ex), str(self.db.lastOp()), str(self.db.getLastKeys()) ) -- GitLab