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 30, 2023
1 parent 6cce102 commit d5d9438
Show file tree
Hide file tree
Showing 4 changed files with 43 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 ``launch`` endpoint also include the warnings of the validation of the workflow specification.
- 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
17 changes: 17 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,30 @@
"message": {
"type": "string"
},
"validation_warnings": {
"description": "Dictionary of validation warnings, if any. Each key is a property that was not correctly validated.",
"properties": {
"additional_properties": {
"items": {
"type": "string"
},
"type": "array"
}
},
"type": "object"
},
"workflow_id": {
"type": "string"
},
"workflow_name": {
"type": "string"
}
},
"required": [
"workflow_id",
"workflow_name",
"message"
],
"type": "object"
}
},
Expand Down
22 changes: 21 additions & 1 deletion reana_server/rest/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,27 @@ 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
properties:
additional_properties:
type: array
items:
type: string
examples:
application/json:
{
Expand Down Expand Up @@ -180,7 +194,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 197 in reana_server/rest/launch.py

View check run for this annotation

Codecov / codecov/patch

reana_server/rest/launch.py#L197

Added line #L197 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 +237,11 @@ def launch(user, url, name="", parameters="{}", specification=None):
"workflow_name": workflow.name,
"message": "The workflow has been successfully submitted.",
}
if validation_warnings:
response_data[

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

View check run for this annotation

Codecov / codecov/patch

reana_server/rest/launch.py#L240-L241

Added lines #L240 - L241 were not covered by tests
"message"
] = "The workflow has been successfully submitted, but some warnings were issued."
response_data["validation_warnings"] = validation_warnings

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

View check run for this annotation

Codecov / codecov/patch

reana_server/rest/launch.py#L244

Added line #L244 was not covered by tests
return LaunchSchema().dump(response_data)
except HTTPError as e:
logging.error(traceback.format_exc())
Expand Down Expand Up @@ -271,3 +290,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) -> Dict:
"""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 d5d9438

Please sign in to comment.