Skip to content

Commit 9b2a01a

Browse files
committed
Issue #125 Add "federation:missing" to /process_graphs
1 parent d305046 commit 9b2a01a

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is roughly based on [Keep a Changelog](https://keepachangelog.com/en/
1111
- Bump minimum required Python version to 3.11 ([#127](https://github.com/Open-EO/openeo-aggregator/issues/127), [#174](https://github.com/Open-EO/openeo-aggregator/issues/174))
1212
- Add title, description, online/offline status and last_status_check to federation listing in capabilities document ([#22](https://github.com/Open-EO/openeo-aggregator/issues/22))
1313
- Provide "federation:missing" on `/file_formats` ([#124](https://github.com/Open-EO/openeo-aggregator/issues/124))
14+
- Provide "federation:missing" on `/process_graphs` ([#125](https://github.com/Open-EO/openeo-aggregator/issues/125))
1415

1516
## 0.43.0
1617

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"requests",
3636
"attrs",
3737
"openeo>=0.38.0",
38-
"openeo_driver>=0.126.1.dev",
38+
"openeo_driver>=0.130.0.dev",
3939
"flask~=2.0",
4040
"gunicorn~=20.0",
4141
"python-json-logger>=2.0.0",

src/openeo_aggregator/backend.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
SecondaryServices,
5252
ServiceMetadata,
5353
UserDefinedProcesses,
54+
UserDefinedProcessesListing,
5455
UserDefinedProcessMetadata,
5556
)
5657
from openeo_driver.datacube import DriverDataCube
@@ -1392,17 +1393,31 @@ def update_service(self, user_id: str, service_id: str, process_graph: dict) ->
13921393
) from e
13931394

13941395

1396+
class AggregatorUserDefinedProcessesListing(UserDefinedProcessesListing):
1397+
1398+
def __init__(self, udps: List[UserDefinedProcessMetadata], *, federation_missing: Iterable[str] = ()):
1399+
super().__init__(udps=udps)
1400+
self._federation_missing = list(federation_missing)
1401+
1402+
def to_response_dict(self, full: bool = True) -> dict:
1403+
resp = super().to_response_dict(full=full)
1404+
resp["federation:missing"] = self._federation_missing
1405+
return resp
1406+
1407+
13951408
class AggregatorUserDefinedProcesses(UserDefinedProcesses):
13961409
def __init__(self, backends: MultiBackendConnection):
13971410
super(AggregatorUserDefinedProcesses, self).__init__()
13981411
self._backends = backends
13991412

14001413
@contextlib.contextmanager
1401-
def _get_connection(self, process_graph_id: Optional[str] = None) -> Iterator[openeo.Connection]:
1414+
def _get_connection(self, process_graph_id: Optional[str] = None) -> Iterator[BackendConnection]:
14021415
"""Get connection and handle/translate common errors"""
14031416
try:
1404-
# TODO: we blindly pick "first" upstream backend for now. Do better!
1405-
with self._backends.first().authenticated_from_request(request=flask.request) as con:
1417+
# TODO #90 #176 we blindly pick "first" upstream backend for now. Do better!
1418+
first = self._backends.first()
1419+
_log.warning(f"AggregatorUserDefinedProcesses: just using 'first' backend: {first!r}")
1420+
with first.authenticated_from_request(request=flask.request) as con:
14061421
yield con
14071422
except OpenEoApiError as e:
14081423
if e.code == ProcessGraphNotFoundException.code:
@@ -1414,10 +1429,17 @@ def get(self, user_id: str, process_id: str) -> Union[UserDefinedProcessMetadata
14141429
metadata = con.get(f"/process_graphs/{process_id}", expected_status=200).json()
14151430
return UserDefinedProcessMetadata.from_dict(metadata)
14161431

1417-
def get_for_user(self, user_id: str) -> List[UserDefinedProcessMetadata]:
1432+
def list_for_user(
1433+
self,
1434+
user_id: str,
1435+
) -> UserDefinedProcessesListing:
1436+
# TODO #175 how to handle pagination?
14181437
with self._get_connection() as con:
14191438
data = con.get(f"/process_graphs", expected_status=200).json()
1420-
return [UserDefinedProcessMetadata.from_dict(p) for p in data["processes"]]
1439+
udps = [UserDefinedProcessMetadata.from_dict(p) for p in data["processes"]]
1440+
federation_missing = [c for c in self._backends.get_all_connection_ids() if c != con.id]
1441+
1442+
return AggregatorUserDefinedProcessesListing(udps=udps, federation_missing=federation_missing)
14211443

14221444
def save(self, user_id: str, process_id: str, spec: dict) -> None:
14231445
with self._get_connection(process_graph_id=process_id) as con:

src/openeo_aggregator/connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ def get_connections(self) -> List[BackendConnection]:
303303
def __iter__(self) -> Iterator[BackendConnection]:
304304
return iter(self.get_connections())
305305

306+
def get_all_connection_ids(self) -> List[str]:
307+
"""Return all connection ids (regardless of online/offline status)."""
308+
return list(self._backend_urls.keys())
309+
306310
def get_disabled_connection_ids(self) -> Set[str]:
307311
all_ids = set(self._backend_urls.keys())
308312
active_ids = set(b.id for b in self.get_connections())

tests/test_connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,12 @@ def test_get_connections(self, requests_mock, backend1, backend2):
674674

675675
assert set(b.id for b in multi_backend_connection.get_connections()) == {"b1", "b2"}
676676
assert multi_backend_connection.get_disabled_connection_ids() == set()
677+
assert multi_backend_connection.get_all_connection_ids() == ["b1", "b2"]
677678

678679
# Wait for connections cache to expire
679680
with clock_mock(offset=1000):
680681
requests_mock.get(backend1 + "/", status_code=500, json={"error": "nope"})
681682

682683
assert set(b.id for b in multi_backend_connection.get_connections()) == {"b2"}
683684
assert multi_backend_connection.get_disabled_connection_ids() == {"b1"}
685+
assert multi_backend_connection.get_all_connection_ids() == ["b1", "b2"]

tests/test_views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3017,7 +3017,11 @@ def test_list_udps_empty(self, api100, requests_mock, backend1):
30173017
)
30183018
api100.set_auth_bearer_token(token=TEST_USER_BEARER_TOKEN)
30193019
res = api100.get("/process_graphs").assert_status_code(200).json
3020-
assert res == {"processes": [], "links": []}
3020+
assert res == {
3021+
"processes": [],
3022+
"links": [],
3023+
"federation:missing": ["b2"],
3024+
}
30213025
assert upstream.call_count == 1
30223026

30233027
def test_list_udps_existing(self, api100, requests_mock, backend1):
@@ -3043,6 +3047,7 @@ def test_list_udps_existing(self, api100, requests_mock, backend1):
30433047
{"id": "somethingelse"},
30443048
],
30453049
"links": [],
3050+
"federation:missing": ["b2"],
30463051
}
30473052
assert upstream.call_count == 1
30483053

0 commit comments

Comments
 (0)