-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #668 eliminate FederationExtension abstraction
- for user API that's simpler to navigate - revert to methods iso properties (to allow future tweaks, e.g. return parsed object instead of raw dicts)
- Loading branch information
Showing
8 changed files
with
74 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,39 @@ | ||
import logging | ||
from typing import List, Union | ||
import textwrap | ||
from typing import Dict, List, Union | ||
|
||
_log = logging.getLogger(__name__) | ||
|
||
class FederationExtension: | ||
""" | ||
Wrapper the openEO Federation extension as defined by | ||
https://github.com/Open-EO/openeo-api/tree/master/extensions/federation | ||
.. seealso:: :ref:`federation-extension` | ||
""" | ||
|
||
__slots__ = ["_data"] | ||
|
||
def __init__(self, data: dict): | ||
self._data = data | ||
def get_backend_details(data: dict) -> Union[Dict[str, dict], None]: | ||
""" | ||
Get federated backend details from capabilities document (``GET /``) | ||
at "federation" field | ||
""" | ||
# TODO: return a richer object instead of raw dicts? | ||
return data.get("federation", None) | ||
|
||
@property | ||
def missing(self) -> Union[List[str], None]: | ||
""" | ||
Get the ``federation:missing`` property (if any) of the resource, | ||
which lists back-ends that were not available during the request. | ||
|
||
Example usage with collection listing request | ||
(using :py:meth:`~openeo.rest.connection.Connection.list_collections()`): | ||
def get_federation_missing(data: dict, *, resource_name: str, auto_warn: bool = True) -> Union[List[str], None]: | ||
missing = data.get("federation:missing", None) | ||
if auto_warn and missing: | ||
_log.warning(f"Partial {resource_name}: missing federation components: {missing!r}.") | ||
return missing | ||
|
||
.. code-block:: pycon | ||
|
||
>>> collections = connection.list_collections() | ||
>>> collections.ext_federation.missing | ||
["backend1"] | ||
def get_federation_missing_doc(attribute_name: str = "ext_federation_missing", prefix: str = " ") -> str: | ||
# TODO: is there a cleaner way to append to doc strings, using some standard Sphinx API? | ||
doc = f""" | ||
.. py:attribute:: {attribute_name} | ||
:type: Union[None, List[str]] | ||
:return: list of back-end IDs that were not available. | ||
Or None, when ``federation:missing`` is not present in response. | ||
""" | ||
return self._data.get("federation:missing", None) | ||
List of backends IDs (from the federation) | ||
that were not available during the resource listing request. | ||
def warn_on_missing(self, resource_name: str) -> None: | ||
""" | ||
Warn about presence of non-empty ``federation:missing`` in the resource. | ||
""" | ||
missing = self.missing | ||
if missing: | ||
_log.warning(f"Partial {resource_name}: missing federation components: {missing!r}.") | ||
.. seealso:: :ref:`federation-extension` | ||
""" | ||
return textwrap.indent( | ||
"\n\n" + textwrap.dedent(doc).strip() + "\n\n", | ||
prefix=prefix, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters