Skip to content

Commit

Permalink
wip: add per-entity restart parameters [AAP-20053]
Browse files Browse the repository at this point in the history
  • Loading branch information
jshimkus-rh committed Mar 21, 2024
1 parent 4c1bb7b commit ee17619
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 14 deletions.
22 changes: 22 additions & 0 deletions src/aap_eda/api/serializers/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ class Meta:
"project_id",
"rulebook_id",
"extra_var_id",
"restart_completion_interval",
"restart_failure_interval",
"restart_failure_limit",
"restart_policy",
"restart_count",
"rulebook_name",
Expand Down Expand Up @@ -250,6 +253,9 @@ class Meta:
"project_id",
"rulebook_id",
"extra_var_id",
"restart_completion_interval",
"restart_failure_interval",
"restart_failure_limit",
"restart_policy",
"restart_count",
"rulebook_name",
Expand Down Expand Up @@ -294,6 +300,11 @@ def to_representation(self, activation):
"project_id": activation.project_id,
"rulebook_id": activation.rulebook_id,
"extra_var_id": activation.extra_var_id,
"restart_completion_interval": (
activation.restart_completion_interval
),
"restart_failure_interval": activation.restart_failure_interval,
"restart_failure_limit": activation.restart_failure_limit,
"restart_policy": activation.restart_policy,
"restart_count": activation.restart_count,
"rulebook_name": activation.rulebook_name,
Expand Down Expand Up @@ -324,6 +335,9 @@ class Meta:
"rulebook_id",
"extra_var_id",
"user",
"restart_completion_interval",
"restart_failure_interval",
"restart_failure_limit",
"restart_policy",
"awx_token_id",
"credentials",
Expand Down Expand Up @@ -489,6 +503,9 @@ class Meta:
"rulebook",
"extra_var",
"instances",
"restart_completion_interval",
"restart_failure_interval",
"restart_failure_limit",
"restart_policy",
"restart_count",
"rulebook_name",
Expand Down Expand Up @@ -573,6 +590,11 @@ def to_representation(self, activation):
"instances": ActivationInstanceSerializer(
activation_instances, many=True
).data,
"restart_completion_interval": (
activation.restart_completion_interval
),
"restart_failure_interval": activation.restart_failure_interval,
"restart_failure_limit": activation.restart_failure_limit,
"restart_policy": activation.restart_policy,
"restart_count": activation.restart_count,
"rulebook_name": activation.rulebook_name,
Expand Down
3 changes: 3 additions & 0 deletions src/aap_eda/api/serializers/event_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class Meta:
"rulebook_id",
"extra_var_id",
"user",
"restart_completion_interval",
"restart_failure_interval",
"restart_failure_limit",
"restart_policy",
"credentials",
"log_level",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Generated by Django 4.2.7 on 2024-03-21 18:43

import django.core.validators
from django.db import migrations, models

import aap_eda.core.models.activation
import aap_eda.core.models.event_stream


class Migration(migrations.Migration):
dependencies = [
(
"core",
"0027_credentialtype_alter_permission_resource_type_and_more",
),
]

operations = [
migrations.AddField(
model_name="activation",
name="restart_completion_interval",
field=models.IntegerField(
default=aap_eda.core.models.activation.RestartCompletionInterval[
"MINIMUM"
],
validators=[
django.core.validators.MinValueValidator(
limit_value=aap_eda.core.models.activation.RestartCompletionInterval[
"MINIMUM"
],
message="The restart interval for completions specifies the delay, in seconds, between restarts; it must be an integer greater than or equal to 0 indicating the delay, in seconds, between restarts; system settings = 0, default = 0",
)
],
),
),
migrations.AddField(
model_name="activation",
name="restart_failure_interval",
field=models.IntegerField(
default=aap_eda.core.models.activation.RestartFailureInterval[
"MINIMUM"
],
validators=[
django.core.validators.MinValueValidator(
limit_value=aap_eda.core.models.activation.RestartFailureInterval[
"MINIMUM"
],
message="The restart interval for failures specifies the delay, in seconds, between restarts; it must be an integer greater than or equal to 0 indicating the delay, in seconds, between restarts; system settings = 0, default = 0",
)
],
),
),
migrations.AddField(
model_name="activation",
name="restart_failure_limit",
field=models.IntegerField(
default=aap_eda.core.models.activation.RestartFailureLimit[
"SETTINGS"
],
validators=[
django.core.validators.MinValueValidator(
limit_value=aap_eda.core.models.activation.RestartFailureLimit[
"MINIMUM"
],
message="The restart limit for failiures specifies the limit on repeated attempts to start an activation in the face of failures to do so; it must be an integer greater than or equal to -1; system settings = 0, unlimited restarts = -1, default = 0",
)
],
),
),
migrations.AddField(
model_name="eventstream",
name="restart_completion_interval",
field=models.IntegerField(
default=aap_eda.core.models.event_stream.RestartCompletionInterval[
"MINIMUM"
],
validators=[
django.core.validators.MinValueValidator(
limit_value=aap_eda.core.models.event_stream.RestartCompletionInterval[
"MINIMUM"
],
message="The restart interval for completions specifies the delay, in seconds, between restarts; it must be an integer greater than or equal to 0 indicating the delay, in seconds, between restarts; system settings = 0, default = 0",
)
],
),
),
migrations.AddField(
model_name="eventstream",
name="restart_failure_interval",
field=models.IntegerField(
default=aap_eda.core.models.event_stream.RestartFailureInterval[
"MINIMUM"
],
validators=[
django.core.validators.MinValueValidator(
limit_value=aap_eda.core.models.event_stream.RestartFailureInterval[
"MINIMUM"
],
message="The restart interval for failures specifies the delay, in seconds, between restarts; it must be an integer greater than or equal to 0 indicating the delay, in seconds, between restarts; system settings = 0, default = 0",
)
],
),
),
migrations.AddField(
model_name="eventstream",
name="restart_failure_limit",
field=models.IntegerField(
default=aap_eda.core.models.event_stream.RestartFailureLimit[
"SETTINGS"
],
validators=[
django.core.validators.MinValueValidator(
limit_value=aap_eda.core.models.event_stream.RestartFailureLimit[
"MINIMUM"
],
message="The restart limit for failiures specifies the limit on repeated attempts to start an activation in the face of failures to do so; it must be an integer greater than or equal to -1; system settings = 0, unlimited restarts = -1, default = 0",
)
],
),
),
]
94 changes: 94 additions & 0 deletions src/aap_eda/core/models/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import enum

from django.conf import settings
from django.core import validators
from django.db import models

from aap_eda.core.enums import (
Expand All @@ -28,6 +32,25 @@
__all__ = ("Activation",)


class RestartCompletionInterval(enum.IntEnum):
MINIMUM = 0
SETTINGS = MINIMUM
DEFAULT = SETTINGS


class RestartFailureInterval(enum.IntEnum):
MINIMUM = 0
SETTINGS = MINIMUM
DEFAULT = SETTINGS


class RestartFailureLimit(enum.IntEnum):
MINIMUM = -1
SETTINGS = 0
DEFAULT = SETTINGS
UNLIMITED = MINIMUM


class Activation(StatusHandlerModelMixin, ContainerableMixin, models.Model):
class Meta:
db_table = "core_activation"
Expand All @@ -52,6 +75,52 @@ class Meta:
extra_var = models.ForeignKey(
"ExtraVar", on_delete=models.CASCADE, null=True
)
restart_completion_interval = models.IntegerField(
validators=[
validators.MinValueValidator(
limit_value=RestartCompletionInterval.MINIMUM,
message="The restart interval for completions specifies"
" the delay, in seconds, between restarts"
"; it must be an integer greater than or equal to"
f" {RestartCompletionInterval.MINIMUM}"
" indicating the delay, in seconds, between restarts"
f"; system settings = {RestartCompletionInterval.SETTINGS}"
f", default = {RestartCompletionInterval.DEFAULT}",
),
],
default=RestartCompletionInterval.DEFAULT,
)
restart_failure_interval = models.IntegerField(
validators=[
validators.MinValueValidator(
limit_value=RestartFailureInterval.MINIMUM,
message="The restart interval for failures specifies"
" the delay, in seconds, between restarts"
"; it must be an integer greater than or equal to "
f" {RestartFailureInterval.MINIMUM}"
" indicating the delay, in seconds, between restarts"
f"; system settings = {RestartFailureInterval.SETTINGS}"
f", default = {RestartFailureInterval.DEFAULT}",
),
],
default=RestartFailureInterval.DEFAULT,
)
restart_failure_limit = models.IntegerField(
validators=[
validators.MinValueValidator(
limit_value=RestartFailureLimit.MINIMUM,
message="The restart limit for failiures specifies"
" the limit on repeated attempts to start an activation"
" in the face of failures to do so"
"; it must be an integer greater than or equal to"
f" {RestartFailureLimit.MINIMUM}"
f"; system settings = {RestartFailureLimit.SETTINGS}"
f", unlimited restarts = {RestartFailureLimit.UNLIMITED}"
f", default = {RestartFailureLimit.DEFAULT}",
),
],
default=RestartFailureLimit.DEFAULT,
)
restart_policy = models.TextField(
choices=RestartPolicy.choices(),
default=RestartPolicy.ON_FAILURE,
Expand Down Expand Up @@ -122,3 +191,28 @@ class Meta:
on_delete=models.CASCADE,
related_name="+",
)

@property
def effective_restart_completion_interval(self):
effective = self.restart_completion_interval
if effective == RestartCompletionInterval.SETTINGS:
effective = settings.ACTIVATION_RESTART_SECONDS_ON_COMPLETE
return effective

@property
def effective_restart_failure_interval(self):
effective = self.restart_failure_interval
if effective == RestartFailureInterval.SETTINGS:
effective = settings.ACTIVATION_RESTART_SECONDS_ON_FAILURE
return effective

@property
def effective_restart_failure_limit(self):
effective = self.restart_failure_limit
if effective == RestartFailureLimit.SETTINGS:
effective = settings.ACTIVATION_MAX_RESTARTS_ON_FAILURE
return effective

@property
def unlimited_restart_failures(self):
return self.restart_failure_limit == RestartFailureLimit.UNLIMITED
Loading

0 comments on commit ee17619

Please sign in to comment.