mirror of
https://github.com/ansible/awx.git
synced 2026-03-26 13:25:02 -02:30
Replace JobOrigin with ActivityStream.action_node
This commit is contained in:
@@ -35,7 +35,7 @@ from awx.main.models.ad_hoc_commands import AdHocCommand # noqa
|
||||
from awx.main.models.schedules import Schedule # noqa
|
||||
from awx.main.models.activity_stream import ActivityStream # noqa
|
||||
from awx.main.models.ha import ( # noqa
|
||||
Instance, InstanceGroup, JobOrigin, TowerScheduleState,
|
||||
Instance, InstanceGroup, TowerScheduleState,
|
||||
)
|
||||
from awx.main.models.rbac import ( # noqa
|
||||
Role, batch_role_ancestor_rebuilding, get_roles_on_resource,
|
||||
|
||||
@@ -7,6 +7,7 @@ from awx.main.fields import JSONField
|
||||
|
||||
# Django
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.utils.encoding import smart_str
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@@ -35,6 +36,13 @@ class ActivityStream(models.Model):
|
||||
timestamp = models.DateTimeField(auto_now_add=True)
|
||||
changes = models.TextField(blank=True)
|
||||
deleted_actor = JSONField(null=True)
|
||||
action_node = models.CharField(
|
||||
blank=True,
|
||||
default='',
|
||||
editable=False,
|
||||
max_length=512,
|
||||
help_text=_("The cluster node the activity took place on."),
|
||||
)
|
||||
|
||||
object_relationship_type = models.TextField(blank=True)
|
||||
object1 = models.TextField()
|
||||
@@ -78,7 +86,13 @@ class ActivityStream(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
operation = self.operation if 'operation' in self.__dict__ else '_delayed_'
|
||||
timestamp = self.timestamp.isoformat() if 'timestamp' in self.__dict__ else '_delayed_'
|
||||
if 'timestamp' in self.__dict__:
|
||||
if self.timestamp:
|
||||
timestamp = self.timestamp.isoformat()
|
||||
else:
|
||||
timestamp = self.timestamp
|
||||
else:
|
||||
timestamp = '_delayed_'
|
||||
return u'%s-%s-pk=%s' % (operation, timestamp, self.pk)
|
||||
|
||||
def get_absolute_url(self, request=None):
|
||||
@@ -97,4 +111,7 @@ class ActivityStream(models.Model):
|
||||
if 'update_fields' in kwargs and 'deleted_actor' not in kwargs['update_fields']:
|
||||
kwargs['update_fields'].append('deleted_actor')
|
||||
|
||||
hostname_char_limit = self._meta.get_field('action_node').max_length
|
||||
self.action_node = settings.CLUSTER_HOST_ID[:hostname_char_limit]
|
||||
|
||||
super(ActivityStream, self).save(*args, **kwargs)
|
||||
|
||||
@@ -19,14 +19,11 @@ from awx.api.versioning import reverse
|
||||
from awx.main.managers import InstanceManager, InstanceGroupManager
|
||||
from awx.main.fields import JSONField
|
||||
from awx.main.models.base import BaseModel, HasEditsMixin
|
||||
from awx.main.models.inventory import InventoryUpdate
|
||||
from awx.main.models.jobs import Job
|
||||
from awx.main.models.projects import ProjectUpdate
|
||||
from awx.main.models.unified_jobs import UnifiedJob
|
||||
from awx.main.utils import get_cpu_capacity, get_mem_capacity, get_system_task_capacity
|
||||
from awx.main.models.mixins import RelatedJobsMixin
|
||||
|
||||
__all__ = ('Instance', 'InstanceGroup', 'JobOrigin', 'TowerScheduleState', 'TowerAnalyticsState')
|
||||
__all__ = ('Instance', 'InstanceGroup', 'TowerScheduleState', 'TowerAnalyticsState')
|
||||
|
||||
|
||||
class HasPolicyEditsMixin(HasEditsMixin):
|
||||
@@ -266,24 +263,6 @@ class TowerAnalyticsState(SingletonModel):
|
||||
last_run = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class JobOrigin(models.Model):
|
||||
"""A model representing the relationship between a unified job and
|
||||
the instance that was responsible for starting that job.
|
||||
|
||||
It may be possible that a job has no origin (the common reason for this
|
||||
being that the job was started on Tower < 2.1 before origins were a thing).
|
||||
This is fine, and code should be able to handle it. A job with no origin
|
||||
is always assumed to *not* have the current instance as its origin.
|
||||
"""
|
||||
unified_job = models.OneToOneField(UnifiedJob, related_name='job_origin', on_delete=models.CASCADE)
|
||||
instance = models.ForeignKey(Instance, on_delete=models.CASCADE)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'main'
|
||||
|
||||
|
||||
def schedule_policy_task():
|
||||
from awx.main.tasks import apply_cluster_membership_policies
|
||||
connection.on_commit(lambda: apply_cluster_membership_policies.apply_async())
|
||||
@@ -311,31 +290,6 @@ def on_instance_deleted(sender, instance, using, **kwargs):
|
||||
schedule_policy_task()
|
||||
|
||||
|
||||
# Unfortunately, the signal can't just be connected against UnifiedJob; it
|
||||
# turns out that creating a model's subclass doesn't fire the signal for the
|
||||
# superclass model.
|
||||
@receiver(post_save, sender=InventoryUpdate)
|
||||
@receiver(post_save, sender=Job)
|
||||
@receiver(post_save, sender=ProjectUpdate)
|
||||
def on_job_create(sender, instance, created=False, raw=False, **kwargs):
|
||||
"""When a new job is created, save a record of its origin (the machine
|
||||
that started the job).
|
||||
"""
|
||||
# Sanity check: We only want to create a JobOrigin record in cases where
|
||||
# we are making a new record, and in normal situations.
|
||||
#
|
||||
# In other situations, we simply do nothing.
|
||||
if raw or not created:
|
||||
return
|
||||
|
||||
# Create the JobOrigin record, which attaches to the current instance
|
||||
# (which started the job).
|
||||
job_origin, new = JobOrigin.objects.get_or_create(
|
||||
instance=Instance.objects.me(),
|
||||
unified_job=instance,
|
||||
)
|
||||
|
||||
|
||||
class UnifiedJobTemplateInstanceGroupMembership(models.Model):
|
||||
|
||||
unifiedjobtemplate = models.ForeignKey(
|
||||
|
||||
Reference in New Issue
Block a user