Skip to content

Commit

Permalink
launch: include validation warnings in returned message
Browse files Browse the repository at this point in the history
In case some warnings are issued when launching a workflow, the `launch`
endpoint will now include them in a new `validation_warnings` key.

Closes reanahub/reana-client#660.
  • Loading branch information
giuseppe-steduto committed Aug 24, 2023
1 parent b72bc72 commit 9a78d6b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes
Version 0.9.1 (UNRELEASED)
--------------------------

- Changes OpenAPI specification to include the optional ``validation_warnings`` key in the response of the ``launch`` endpoint.
- Changes OpenAPI specification with respect to return the maximum inactivity time before automatic closure of interactive sessions in ``info`` endpoint.
- Adds the timestamp of when the workflow was stopped (``run_stopped_at``) to the workflow list and the workflow status endpoints.
- Adds the content of the ``REANA_GITLAB_HOST`` environment variable to the list of GitLab instances from which it is possible to launch a workflow.
Expand Down
9 changes: 9 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,22 @@
"message": {
"type": "string"
},
"validation_warnings": {
"description": "Dictionary of validation warnings, if any. Each key is a property that was not correctly validated.",
"type": "object"
},
"workflow_id": {
"type": "string"
},
"workflow_name": {
"type": "string"
}
},
"required": [
"workflow_id",
"workflow_name",
"message"
],
"type": "object"
}
},
Expand Down
14 changes: 13 additions & 1 deletion reana_server/rest/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,22 @@ def launch(user, url, name="", parameters="{}", specification=None):
Request succeeded. Information of the workflow launched.
schema:
type: object
required:
- workflow_id
- workflow_name
- message
properties:
workflow_id:
type: string
workflow_name:
type: string
message:
type: string
validation_warnings:
description: >-
Dictionary of validation warnings, if any. Each
key is a property that was not correctly validated.
type: object
examples:
application/json:
{
Expand Down Expand Up @@ -180,7 +189,7 @@ def launch(user, url, name="", parameters="{}", specification=None):
with load_reana_spec_lock:
reana_yaml = load_reana_spec(spec_path, workspace_path=tmpdir)
input_parameters = json.loads(parameters)
validate_workflow(reana_yaml, input_parameters)
validation_warnings = validate_workflow(reana_yaml, input_parameters)

Check warning on line 192 in reana_server/rest/launch.py

View check run for this annotation

Codecov / codecov/patch

reana_server/rest/launch.py#L192

Added line #L192 was not covered by tests

# Keep only files and directories listed as workflow's inputs
filter_input_files(tmpdir, reana_yaml)
Expand Down Expand Up @@ -223,6 +232,8 @@ def launch(user, url, name="", parameters="{}", specification=None):
"workflow_name": workflow.name,
"message": "The workflow has been successfully submitted.",
}
if validation_warnings:
response_data["validation_warnings"] = validation_warnings

Check warning on line 236 in reana_server/rest/launch.py

View check run for this annotation

Codecov / codecov/patch

reana_server/rest/launch.py#L235-L236

Added lines #L235 - L236 were not covered by tests
return LaunchSchema().dump(response_data)
except HTTPError as e:
logging.error(traceback.format_exc())
Expand Down Expand Up @@ -271,3 +282,4 @@ class LaunchSchema(Schema):
workflow_id = fields.UUID()
workflow_name = fields.Str()
message = fields.Str()
validation_warnings = fields.Dict()
7 changes: 4 additions & 3 deletions reana_server/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import itertools
import pathlib
from typing import Dict
from typing import Dict, List

from reana_commons.config import WORKSPACE_PATHS
from reana_commons.errors import REANAValidationError
Expand Down Expand Up @@ -107,7 +107,7 @@ def validate_inputs(reana_yaml: Dict) -> None:
)


def validate_workflow(reana_yaml: Dict, input_parameters: Dict) -> None:
def validate_workflow(reana_yaml: Dict, input_parameters: Dict) -> List[Exception]:
"""Validate REANA workflow specification by calling all the validation utilities.
:param reana_yaml: dictionary which represents REANA specification file.
Expand All @@ -119,12 +119,13 @@ def validate_workflow(reana_yaml: Dict, input_parameters: Dict) -> None:
operational_options = reana_yaml.get("inputs", {}).get("options", {})
original_parameters = reana_yaml.get("inputs", {}).get("parameters", {})

validate_reana_yaml(reana_yaml)
reana_yaml_warnings = validate_reana_yaml(reana_yaml)
validate_operational_options(workflow_type, operational_options)
validate_input_parameters(input_parameters, original_parameters)
validate_compute_backends(reana_yaml)
validate_workspace_path(reana_yaml)
validate_inputs(reana_yaml)
return reana_yaml_warnings

Check warning on line 128 in reana_server/validation.py

View check run for this annotation

Codecov / codecov/patch

reana_server/validation.py#L128

Added line #L128 was not covered by tests


def validate_retention_rule(rule: str, days: int) -> None:
Expand Down

0 comments on commit 9a78d6b

Please sign in to comment.