Skip to content

Commit

Permalink
fix: remove PENDING_NO_WORKERS status
Browse files Browse the repository at this point in the history
  • Loading branch information
jshimkus-rh committed May 8, 2024
1 parent 5a9b4d1 commit c1c8c9e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 125 deletions.
4 changes: 0 additions & 4 deletions src/aap_eda/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class ActivationStatus(DjangoStrEnum):
STARTING = "starting"
RUNNING = "running"
PENDING = "pending"
PENDING_WORKERS_OFFLINE = "pending (workers offline)"
FAILED = "failed"
STOPPING = "stopping"
STOPPED = "stopped"
Expand Down Expand Up @@ -104,9 +103,6 @@ class DefaultCredentialType(DjangoStrEnum):
# TODO: rename to "RulebookProcessStatus" or "ParentProcessStatus"
ACTIVATION_STATUS_MESSAGE_MAP = {
ActivationStatus.PENDING: "Wait for a worker to be available to start activation", # noqa: E501
ActivationStatus.PENDING_WORKERS_OFFLINE: "Wait for a worker to be available to" # noqa: E501
" start activation (all workers in the" # noqa: E501
" node are offline)", # noqa: E501
ActivationStatus.STARTING: "Worker is starting activation",
ActivationStatus.RUNNING: "Container running activation",
ActivationStatus.STOPPING: "Activation is being disabled",
Expand Down

This file was deleted.

74 changes: 34 additions & 40 deletions src/aap_eda/tasks/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,48 +153,47 @@ def _run_request(

def _set_request_cannot_be_run_status(
request_type: ActivationRequest,
process_parent_type: ProcessParentType,
process_parent_id: int,
process_parent: Union[Activation, EventStream],
status_text: str,
) -> None:
"""Set the request status to indicate it cannot be run on this node.
The request cannot be run on this node due to detected functional issues.
While it cannot be run on this node anothter functional node can run it.
This method sets the request's state such that other nodes can identify
it as something to be run, if possible. This identification is performed
as part of monitor_rulebook_processes.
While it cannot be run on this node anothter functional node may be able
to.
"""
status_manager = StatusManager(
get_process_parent(process_parent_type, process_parent_id),
)

status = ActivationStatus.WORKERS_OFFLINE
# If the request is start/auto-start we know the request isn't
# running.
# running and can be put into the appropriate pending state.
# If a restart it can also be put in the appropriate pending
# state.
#
# If the request is in one of the pending states that also
# indicates it's not running; this check is for previous
# failures to start that got dispatched from the monitor
# task.
if (
request_type
in [
ActivationRequest.START,
ActivationRequest.AUTO_START,
]
) or (
status_manager.db_instance.status
in [
ActivationStatus.PENDING,
ActivationStatus.PENDING_WORKERS_OFFLINE,
]
if request_type in [
ActivationRequest.START,
ActivationRequest.AUTO_START,
ActivationRequest.RESTART,
]:
status = ActivationStatus.PENDING

# If the target status is WORKERS_OFFLINE and the process already has that
# status there's nothing to do. For any other situation we need to be
# certain to set the status text.
if (status != ActivationStatus.WORKERS_OFFLINE) or (
process_parent.status != ActivationStatus.WORKERS_OFFLINE
):
status = ActivationStatus.PENDING_WORKERS_OFFLINE
status_manager = StatusManager(process_parent)
status_manager.set_status(status, status_text)

status_manager.set_status(status, status_text)
# There may not be a latest instance.
if status_manager.latest_instance:
status_manager.set_latest_instance_status(status, status_text)
# Set the latest instance's status only if there is a latest instance
# and only if the status is WORKERS_OFFLINE.
if status_manager.latest_instance and (
status == ActivationStatus.WORKERS_OFFLINE
):
status_manager.set_latest_instance_status(status, status_text)


def dispatch(
Expand Down Expand Up @@ -289,17 +288,13 @@ def dispatch(
)

if not enqueable:
# The request is not enqueable. If not a restart set the request
# status to "workers offline".
if request_type != ActivationRequest.RESTART:
# Set the request status such that, if possible, a functional
# node can pick it up and run it.
_set_request_cannot_be_run_status(
request_type,
process_parent_type,
process_parent_id,
status_msg,
)
# The request is not enqueable. Set the request status such that, if
# possible, a functional node can pick it up and run it.
_set_request_cannot_be_run_status(
request_type,
get_process_parent(process_parent_type, process_parent_id),
status_msg,
)
else:
unique_enqueue(
queue_name,
Expand Down Expand Up @@ -480,7 +475,6 @@ def monitor_rulebook_processes() -> None:
for process in models.RulebookProcess.objects.filter(
status__in=[
ActivationStatus.RUNNING,
ActivationStatus.PENDING_WORKERS_OFFLINE,
ActivationStatus.WORKERS_OFFLINE,
]
):
Expand Down
1 change: 0 additions & 1 deletion tests/integration/api/test_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ def test_enable_activation(
for state in [
enums.ActivationStatus.COMPLETED,
enums.ActivationStatus.PENDING,
enums.ActivationStatus.PENDING_WORKERS_OFFLINE,
enums.ActivationStatus.STOPPED,
enums.ActivationStatus.FAILED,
]:
Expand Down
1 change: 0 additions & 1 deletion tests/integration/core/test_rulebook_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def test_rulebook_process_save(init_data):
enums.ActivationStatus.UNRESPONSIVE,
enums.ActivationStatus.ERROR,
enums.ActivationStatus.PENDING,
enums.ActivationStatus.PENDING_WORKERS_OFFLINE,
]:
instance.status = status
instance.save(update_fields=["status"])
Expand Down
4 changes: 2 additions & 2 deletions tools/docker/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ x-environment: &common-env
EDA_SECRET_KEY: ${EDA_SECRET_KEY:-'insecure'}
EDA_DEBUG: ${EDA_DEBUG:-True}
EDA_DB_PASSWORD: ${EDA_DB_PASSWORD:-'secret'}
EDA_RULEBOOK_WORKER_QUEUES: "activation-node1,activation-node2"
EDA_RULEBOOK_WORKER_QUEUES: "jbs-node1,jbs-node2"
EDA_ANSIBLE_BASE_JWT_VALIDATE_CERT: ${EDA_ANSIBLE_BASE_JWT_VALIDATE_CERT:-False}
EDA_ANSIBLE_BASE_JWT_KEY: ${EDA_ANSIBLE_BASE_JWT_KEY:-'https://localhost'}

Expand Down Expand Up @@ -197,7 +197,7 @@ services:
image: "${EDA_IMAGE:-localhost/aap-eda}"
environment:
<<: *common-env
EDA_RULEBOOK_QUEUE_NAME: 'activation-node2'
EDA_RULEBOOK_QUEUE_NAME: 'jbs-node2'
EDA_PODMAN_SOCKET_URL: tcp://podman-node2:8888
command:
- aap-eda-manage
Expand Down

0 comments on commit c1c8c9e

Please sign in to comment.