Skip to content

Commit

Permalink
pasta with ketchup is my culinary peak
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppe-steduto committed Nov 21, 2023
1 parent 9a314a6 commit eff8ac3
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 109 deletions.
220 changes: 115 additions & 105 deletions reana_commons/validation/schemas/reana_analysis_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
},
"resources": {
"$id": "/properties/workflow/properties/resources",
"type": "object",
"type": [
"object",
"null"
],
"title": "Workflow resources in yaml format.",
"properties": {
"cvmfs": {
Expand All @@ -109,112 +112,10 @@
"type": "boolean",
"title": "Kerberos authentication for the whole workflow."
}
}
},
"additionalProperties": false
}
},
"oneOf": [
{
"properties": {
"type": {
"const": "serial"
},
"specification": {
"type": "object",
"title": "Serial workflow specification.",
"description": "Serial workflow specification.",
"additionalProperties": false,
"properties": {
"steps": {
"type": "array",
"title": "Serial workflow steps.",
"description": "List of steps which represent the workflow.",
"items": {
"properties": {
"name": {
"type": "string",
"title": "Step name."
},
"environment": {
"type": "string",
"title": "Image to be used by the container in which the step should be run."
},
"kubernetes_memory_limit": {
"type": "string",
"title": "Memory limit for the step container (e.g. 256Mi)."
},
"commands": {
"type": "array",
"title": "Step commands.",
"description": "List of commands to be run in the step.",
"items": {
"type": "string",
"title": "Command to be run."
}
}
},
"required": [
"environment"
]
}
}
}
}
}
},
{
"properties": {
"type": {
"const": "cwl"
},
"specification": {
"type": "object",
"title": "CWL workflow specification.",
"description": "CWL workflow specification.",
"properties": {
"cwlVersion": {
"type": "string",
"title": "CWL version.",
"description": "CWL version to which the workflow was written for."
},
"class": {
"type": "string",
"title": "CWL class.",
"description": "CWL class which represents the type of the workflow."
},
"inputs": {
"type": "array",
"title": "CWL workflow inputs.",
"description": "CWL workflow inputs."
}
}
}
}
},
{
"properties": {
"type": {
"const": "snakemake"
},
"specification": {
"type": "object",
"title": "Snakemake workflow specification.",
"description": "Snakemake workflow specification."
}
}
},
{
"properties": {
"type": {
"const": "yadage"
},
"specification": {
"type": "object",
"title": "Yadage workflow specification.",
"description": "Yadage workflow specification."
}
}
}
],
"anyOf": [
{
"required": [
Expand Down Expand Up @@ -303,5 +204,114 @@
}
}
}
},
"if": {
"properties": {
"workflow": {
"properties": {
"type": {
"const": "serial"
}
}
}
}
},
"then": {
"properties": {
"workflow": {
"properties": {
"specification": {
"type": "object",
"title": "Serial workflow specification.",
"description": "Serial workflow specification.",
"additionalProperties": false,
"properties": {
"steps": {
"type": "array",
"title": "Serial workflow steps.",
"description": "List of steps which represent the workflow.",
"items": {
"type": "object",
"title": "Serial workflow step.",
"description": "Serial workflow step.",
"additionalProperties": false,
"properties": {
"commands": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"title": "Step commands",
"description": "List of commands to be run in the step."
},
"compute_backend": {
"type": "string",
"title": "Compute backend"
},
"environment": {
"type": "string",
"title": "Container image for the step",
"description": "Image to be used by the container in which the step should be run."
},
"htcondor_accounting_group": {
"type": "string",
"title": "HTCondor accounting group"
},
"htcondor_max_runtime": {
"type": "string",
"title": "HTCondor maximum runtime"
},
"kerberos": {
"type": "boolean",
"title": "Kerberos authentication"
},
"kubernetes_job_timeout": {
"type": "string",
"title": "Kubernetes job timeout"
},
"kubernetes_memory_limit": {
"type": "string",
"title": "Kubernetes memory limit"
},
"name": {
"type": "string",
"title": "Step name"
},
"rucio": {
"type": "boolean",
"title": "Rucio data management"
},
"unpacked_img": {
"type": "boolean",
"title": "Unpacked container image"
},
"voms_proxy": {
"type": "boolean",
"title": "VOMS proxy"
}
},
"required": [
"commands",
"environment"
]
}
}
}
}
}
}
}
},
"else": {
"properties": {
"workflow": {
"properties": {
"file": {
"type": "string"
}
}
}
}
}
}
17 changes: 13 additions & 4 deletions reana_commons/validation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import logging
import os
import re
from collections import deque
from typing import Dict, List

from jsonschema import ValidationError
from jsonschema.exceptions import best_match
from jsonschema.exceptions import best_match, ErrorTree
from jsonschema.validators import validator_for

from reana_commons.config import (
Expand Down Expand Up @@ -46,6 +47,10 @@ def _get_schema_validation_warnings(errors: List[ValidationError]) -> Dict:
# or describe the error
warnings = {}
for e in errors:
# Get the path of the error (where in reana.yaml it occurred).
# The `path` property of a ValidationError is only relative to its `parent`.
error_path = e.absolute_path
error_path = '.'.join(map(str, error_path))
if e.validator in non_critical_validators:
warning_value = [e.message]
if e.validator == "additionalProperties":
Expand All @@ -58,8 +63,12 @@ def _get_schema_validation_warnings(errors: List[ValidationError]) -> Dict:
# "Additional properties are not allowed ('<property>' was unexpected)"
# "Additional properties are not allowed ('<property1>', '<property2>' were unexpected)"
content_inside_parentheses = re.search(r"\((.*?)\)", e.message).group(1)
warning_value = re.findall(r"'(.*?)'", content_inside_parentheses or "")
warning_key = validator_to_warning.get(e.validator, e.validator)
additional_properties = re.findall(r"'(.*?)'", content_inside_parentheses or "")
warning_value = [{
"property": additional_property,
"path": error_path
} for additional_property in additional_properties]
warning_key = validator_to_warning.get(str(e.validator), str(e.validator))
warnings.setdefault(warning_key, []).extend(warning_value)
else:
critical_errors.append(e)
Expand Down Expand Up @@ -114,7 +123,7 @@ def validate_workflow_name(workflow_name: str) -> str:


def validate_workspace(
workspace_option: str, available_paths: List[str] = list(WORKSPACE_PATHS.values())
workspace_option: str, available_paths: List[str] = list(WORKSPACE_PATHS.values())
) -> str:
"""Validate and return workspace.
Expand Down

0 comments on commit eff8ac3

Please sign in to comment.