From 5562e636ead2cc7f59d574267290934b8ada8119 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Thu, 1 Nov 2018 15:14:39 -0400 Subject: [PATCH] Coalesce host and group A.S. deletion entries --- awx/main/conf.py | 11 +++++++++++ awx/main/signals.py | 16 +++++++++++++--- awx/settings/defaults.py | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/awx/main/conf.py b/awx/main/conf.py index 5008d72dc2..265b1ef739 100644 --- a/awx/main/conf.py +++ b/awx/main/conf.py @@ -24,6 +24,17 @@ register( feature_required='activity_streams', ) +register( + 'ACTIVITY_STREAM_COALESCE_ENTRIES', + field_class=fields.BooleanField, + label=_('Coalesce Select Activity Stream Entries'), + help_text=_('For certain processes, combine multiple entries into one. ' + 'This replaces many similar entries with a single summary entry.'), + category=_('System'), + category_slug='system', + feature_required='activity_streams', +) + register( 'ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC', field_class=fields.BooleanField, diff --git a/awx/main/signals.py b/awx/main/signals.py index 1cd56a5697..b2b9ed8f3d 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -487,12 +487,22 @@ def activity_stream_delete(sender, instance, **kwargs): # If we trigger this handler there we may fall into db-integrity-related race conditions. # So we add flag verification to prevent normal signal handling. This funciton will be # explicitly called with flag on in Inventory.schedule_deletion. - if isinstance(instance, Inventory) and not kwargs.get('inventory_delete_flag', False): - return + changes = {} + if isinstance(instance, Inventory): + if not kwargs.get('inventory_delete_flag', False): + return + if settings.ACTIVITY_STREAM_COALESCE_ENTRIES: + # Add additional data about child hosts / groups that will be deleted + changes['coalesce_data'] = { + 'hosts_deleted': instance.hosts.count(), + 'groups_deleted': instance.groups.count() + } + elif isinstance(instance, (Host, Group)) and instance.inventory.pending_deletion and settings.ACTIVITY_STREAM_COALESCE_ENTRIES: + return # accounted for by inventory entry, above _type = type(instance) if getattr(_type, '_deferred', False): return - changes = model_to_dict(instance) + changes.update(model_to_dict(instance)) object1 = camelcase_to_underscore(instance.__class__.__name__) if type(instance) == OAuth2AccessToken: changes['token'] = CENSOR_VALUE diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 62a4c2cbcc..b102b83c86 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -919,6 +919,7 @@ SCM_EXCLUDE_EMPTY_GROUPS = True # Defaults for enabling/disabling activity stream. # Note: These settings may be overridden by database settings. ACTIVITY_STREAM_ENABLED = True +ACTIVITY_STREAM_COALESCE_ENTRIES = True ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = False # Internal API URL for use by inventory scripts and callback plugin.