|
| 1 | +# This file is part of REANA. |
| 2 | +# Copyright (C) 2024 CERN. |
| 3 | +# |
| 4 | +# REANA is free software; you can redistribute it and/or modify it |
| 5 | +# under the terms of the MIT License; see LICENSE file for more details. |
| 6 | + |
| 7 | + |
| 8 | +# This file provides primitives required for gherkin_parser/functions.py, allowing for different |
| 9 | +# implementations in both the client side (api calls) and server side (database access). This avoids |
| 10 | +# circular dependencies between reana-commons and reana-client. |
| 11 | +"""Base class for fetching data related to a workflow.""" |
| 12 | + |
| 13 | +from abc import ABC, abstractmethod |
| 14 | + |
| 15 | + |
| 16 | +class DataFetcherBase(ABC): |
| 17 | + """Base class for fetching date related to a workflow.""" |
| 18 | + |
| 19 | + @abstractmethod |
| 20 | + def list_files(self, workflow, file_name=None, page=None, size=None, search=None): |
| 21 | + """Return the list of files for a given workflow workspace. |
| 22 | +
|
| 23 | + :param workflow: name or id of the workflow. |
| 24 | + :param file_name: file name(s) (glob) to list. |
| 25 | + :param page: page number of returned file list. |
| 26 | + :param size: page size of returned file list. |
| 27 | + :param search: filter search results by parameters. |
| 28 | + :returns: a list of dictionaries that have the ``name``, ``size`` and |
| 29 | + ``last-modified`` keys. |
| 30 | + """ |
| 31 | + pass |
| 32 | + |
| 33 | + @abstractmethod |
| 34 | + def get_workflow_disk_usage(self, workflow, parameters): |
| 35 | + """Display disk usage workflow. |
| 36 | +
|
| 37 | + :param workflow: name or id of the workflow. |
| 38 | + :param parameters: a dictionary to customize the response. It has the following |
| 39 | + (optional) keys: |
| 40 | +
|
| 41 | + - ``summarize``: a boolean value to indicate whether to summarize the response |
| 42 | + to include only the total workspace disk usage |
| 43 | + - ``search``: a string to filter the response by file name |
| 44 | +
|
| 45 | + :return: a dictionary containing the ``workflow_id``, ``workflow_name``, and the ``user`` ID, with |
| 46 | + a ``disk_usage_info`` keys that contains a list of dictionaries, each of one corresponding |
| 47 | + to a file, with the ``name`` and ``size`` keys. |
| 48 | + """ |
| 49 | + pass |
| 50 | + |
| 51 | + @abstractmethod |
| 52 | + def get_workflow_logs(self, workflow, steps=None, page=None, size=None): |
| 53 | + """Get logs from a workflow engine. |
| 54 | +
|
| 55 | + :param workflow: name or id of the workflow. |
| 56 | + :param steps: list of step names to get logs for. |
| 57 | + :param page: page number of returned log list. |
| 58 | + :param size: page size of returned log list. |
| 59 | +
|
| 60 | + :return: a dictionary with a ``logs`` key containing a JSON string that |
| 61 | + contains the requested logs. |
| 62 | + """ |
| 63 | + pass |
| 64 | + |
| 65 | + @abstractmethod |
| 66 | + def get_workflow_status(self, workflow): |
| 67 | + """Get status of previously created workflow. |
| 68 | +
|
| 69 | + :param workflow: name or id of the workflow. |
| 70 | + :return: a dictionary with the information about the workflow status. |
| 71 | + The dictionary has the following keys: ``id``, ``logs``, ``name``, |
| 72 | + ``progress``, ``status``, ``user``. |
| 73 | + """ |
| 74 | + pass |
| 75 | + |
| 76 | + @abstractmethod |
| 77 | + def get_workflow_specification(self, workflow): |
| 78 | + """Get specification of previously created workflow. |
| 79 | +
|
| 80 | + :param workflow: name or id of the workflow. |
| 81 | + :returns: a dictionary that cointains two top-level keys: ``parameters``, and |
| 82 | + ``specification`` (which contains a dictionary created from the workflow specification). |
| 83 | + """ |
| 84 | + pass |
| 85 | + |
| 86 | + @abstractmethod |
| 87 | + def download_file(self, workflow, file_name): |
| 88 | + """Download the requested file if it exists. |
| 89 | +
|
| 90 | + :param workflow: name or id of the workflow. |
| 91 | + :param file_name: file name or path to the file requested. |
| 92 | + :return: a tuple containing file binary content, filename and whether |
| 93 | + the returned file is a zip archive containing multiple files. |
| 94 | + """ |
| 95 | + pass |
0 commit comments