diff --git a/orm/common/orm_common/hooks/transaction_id_hook.py b/orm/common/orm_common/hooks/transaction_id_hook.py index 439ac580..973311dc 100755 --- a/orm/common/orm_common/hooks/transaction_id_hook.py +++ b/orm/common/orm_common/hooks/transaction_id_hook.py @@ -7,7 +7,11 @@ class TransactionIdHook(PecanHook): def before(self, state): try: - transaction_id = utils.make_transid() + controller = str(state.controller) + if 'RootController._default' in controller: + return + else: + transaction_id = utils.make_transid() except Exception as exc: abort(500, headers={'faultstring': str(exc)}) diff --git a/orm/services/db_setup.py b/orm/services/db_setup.py index 973d0822..7f4f87f0 100644 --- a/orm/services/db_setup.py +++ b/orm/services/db_setup.py @@ -48,6 +48,21 @@ def execute_app_custom_sql(conn): conn.execute(update_regions, (customer_domain, )) +def execute_purge_uuids_record(conn): + """Execute custom SQL statements to purge records from uuids table. + + Parameters: + conn (sqlalchemy.db): connection object for the SQL database + + """ + sql = 'delete from uuids where uuid_type=\'transaction\' and ' \ + 'uuid not in (select transaction_id from transactions) and ' \ + 'uuid not in (select tracking_id from transactions) and ' \ + 'uuid not in (select resource_id from transactions);' + + conn.execute(sql) + + def main(argv=None): if argv is None: @@ -112,4 +127,5 @@ def main(argv=None): conn = engine.connect() execute_app_custom_sql(conn) + execute_purge_uuids_record(conn) conn.close() diff --git a/orm/services/flavor_manager/fms_rest/hooks/service_hooks.py b/orm/services/flavor_manager/fms_rest/hooks/service_hooks.py index 958e3d8a..723d5472 100755 --- a/orm/services/flavor_manager/fms_rest/hooks/service_hooks.py +++ b/orm/services/flavor_manager/fms_rest/hooks/service_hooks.py @@ -8,9 +8,13 @@ class TransIdHook(TransactionIdHook): def before(self, state): try: - transaction_id = utils.make_transid() + controller = str(state.controller) + if 'RootController._default' in controller: + return + else: + transaction_id = utils.make_transid() except Exception as exc: - abort(500, headers={'faultstring': exc.message}) + abort(500, headers={'faultstring': str(exc)}) tracking_id = state.request.headers['X-RANGER-Tracking-Id'] \ if 'X-RANGER-Tracking-Id' in state.request.headers else transaction_id diff --git a/orm/services/image_manager/ims/hooks/service_hooks.py b/orm/services/image_manager/ims/hooks/service_hooks.py index daac041c..fb179b11 100755 --- a/orm/services/image_manager/ims/hooks/service_hooks.py +++ b/orm/services/image_manager/ims/hooks/service_hooks.py @@ -1,11 +1,21 @@ from orm.common.orm_common.hooks.transaction_id_hook import TransactionIdHook from orm.common.orm_common.utils import utils +from pecan import abort + class TransIdHook(TransactionIdHook): def before(self, state): - transaction_id = utils.make_transid() + try: + controller = str(state.controller) + if 'RootController._default' in controller: + return + else: + transaction_id = utils.make_transid() + except Exception as exc: + abort(500, headers={'faultstring': str(exc)}) + tracking_id = state.request.headers['X-RANGER-Tracking-Id'] \ if 'X-RANGER-Tracking-Id' in state.request.headers else transaction_id setattr(state.request, 'transaction_id', transaction_id)