Skip to content

Commit

Permalink
Add allow and ignore list of processes
Browse files Browse the repository at this point in the history
to dispatcher
  • Loading branch information
gregorjerse committed Nov 19, 2023
1 parent 2156191 commit d56cefc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ This project adheres to `Semantic Versioning <http://semver.org/>`_.
Unreleased
==========

Added
-----
- Add processes allow and ignore list to dispatcher, controlled by
environmental variables ``FLOW_PROCESSES_ALLOW_LIST`` and
``FLOW_PROCESSES_IGNORE_LIST```

Fixed
-----
- Store random postfix to redis for use at cleaup time
Expand Down
11 changes: 11 additions & 0 deletions resolwe/flow/managers/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ def __init__(self, *args, **kwargs):
else:
connector_list = [flow_manager.get("NAME", DEFAULT_CONNECTOR)]

# Store the whitelist and blacklist for later use.
self._processes_allow = settings.FLOW_PROCESSES_ALLOW_LIST
self._processes_ignore = settings.FLOW_PROCESSES_IGNORE_LIST

# Pre-load all needed connectors.
self.connectors = {}
for module_name in connector_list:
Expand Down Expand Up @@ -669,6 +673,13 @@ def process_data_object(data: Data):

try:
queryset = Data.objects.filter(status=Data.STATUS_RESOLVING)
# Check if process is in the whitelist or blacklist. The blacklist has
# priority.
if self._processes_allow:
queryset = queryset.filter(process__slug__in=self._processes_allow)
if self._processes_ignore:
queryset = queryset.exclude(process__slug__in=self._processes_ignore)

if data_id is not None:
# Scan only given data object and its children.
queryset = queryset.filter(
Expand Down
39 changes: 37 additions & 2 deletions resolwe/flow/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def setUp(self):
super().setUp()

self.collection = Collection.objects.create(contributor=self.contributor)

self._register_schemas(processes_paths=[PROCESSES_DIR])
manager._processes_ignore = None
manager._processes_allow = None

def test_create_data(self):
"""Test that manager is run when new object is created."""
Expand All @@ -34,10 +35,44 @@ def test_create_data(self):
contributor=self.contributor,
process=process,
)

data.refresh_from_db()
self.assertEqual(data.status, Data.STATUS_DONE)

def test_ignore_allow_list(self):
process = Process.objects.filter(slug="test-min").latest()

# Ignored processes should not trigger processing.
manager._processes_ignore = ["test-min"]
data = Data.objects.create(
name="Test data",
contributor=self.contributor,
process=process,
)
data.refresh_from_db()
self.assertEqual(data.status, Data.STATUS_RESOLVING)

# Ignore should have precedence.
manager._processes_ignore = ["test-min"]
manager._processes_allow = ["test-min"]
data = Data.objects.create(
name="Test data",
contributor=self.contributor,
process=process,
)
data.refresh_from_db()
self.assertEqual(data.status, Data.STATUS_RESOLVING)

# Allowing some processes shoud disable others.
manager._processes_ignore = None
manager._processes_allow = ["test-something-else"]
data = Data.objects.create(
name="Test data",
contributor=self.contributor,
process=process,
)
data.refresh_from_db()
self.assertEqual(data.status, Data.STATUS_RESOLVING)

def test_spawned_process(self):
"""Test that manager is run for spawned processes and permissions are copied."""
DescriptorSchema.objects.create(
Expand Down
13 changes: 13 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
Django settings for running tests for Resolwe package.
"""
import json
import os
import sys
from distutils.util import strtobool
from pathlib import Path

from decouple import Csv, config

from resolwe.__about__ import __version__

PROJECT_ROOT = Path(__file__).parent.resolve()
Expand Down Expand Up @@ -204,6 +207,16 @@

FLOW_PROCESSES_RUNTIMES = ("resolwe.process.runtime.Process",)

# Which processes to schedule (if not set, all).
FLOW_PROCESSES_ALLOW_LIST = config(
"FLOW_PROCESSES_ALLOW_LIST", default="null", cast=json.loads
)

# Which processes to ignore (by default, none).
FLOW_PROCESSES_IGNORE_LIST = config(
"FLOW_PROCESSES_IGNORE_LIST", default="null", cast=json.loads
)

FLOW_EXECUTOR = {
"NAME": "resolwe.flow.executors.docker",
"LISTENER_CONNECTION": LISTENER_CONNECTION,
Expand Down

0 comments on commit d56cefc

Please sign in to comment.