diff --git a/transfer_service/db_connector.py b/transfer_service/db_connector.py index 42ce88564cfa3b85507e087cc316b23d3b23686e..010d748ac65451c2a298a7f195c4b97895792bd9 100644 --- a/transfer_service/db_connector.py +++ b/transfer_service/db_connector.py @@ -44,7 +44,7 @@ class DbConnector(object): connect_timeout = 0 ) - def getConnection(self, retry = 5, timeout = 2): + def getConnection(self, retry = 10, timeout = 30): if retry < 1: retry = 1 if timeout < 1: @@ -702,6 +702,26 @@ class DbConnector(object): finally: self.connPool.putconn(conn, close = False) + def getStorageHostname(self, storageId): + """Returns the storage hostname for a given storage id, if any. Otherwise it returns 'False'.""" + conn = self.getConnection() + try: + cursor = conn.cursor(cursor_factory = RealDictCursor) + cursor.execute("SELECT hostname FROM storage WHERE storage_id = %s;", (storageId,)) + result = cursor.fetchall() + cursor.close() + except Exception: + if not conn.closed: + conn.rollback() + raise + else: + if result: + return result[0]["hostname"] + else: + return False + finally: + self.connPool.putconn(conn, close = False) + ##### Location ##### def getLocationId(self, destStorageId):