Skip to content

Commit

Permalink
Issue #78 force/hardcode sentinelhub as secondary service backend for…
Browse files Browse the repository at this point in the history
… now
  • Loading branch information
soxofaan committed Nov 28, 2022
1 parent 4feb389 commit 9730e88
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,16 @@ def create_service(self, user_id: str, process_graph: dict, service_type: str, a
"""
# TODO: configuration is not used. What to do with it?

# TODO: Determine backend based on service type?
# TODO: hardcoded/forced "SentinelHub only" support for now.
# Instead, properly determine backend based on service type?
# See https://github.com/Open-EO/openeo-aggregator/issues/78#issuecomment-1326180557
# and https://github.com/Open-EO/openeo-aggregator/issues/83
backend_id = self._processing.get_backend_for_process_graph(
process_graph=process_graph, api_version=api_version
)
if "sentinelhub" in self._backends._backend_urls:
backend_id = "sentinelhub"
else:
backend_id = self._processing.get_backend_for_process_graph(
process_graph=process_graph, api_version=api_version
)
process_graph = self._processing.preprocess_process_graph(process_graph, backend_id=backend_id)

con = self._backends.get_connection(backend_id)
Expand Down
20 changes: 17 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,26 @@ def base_config(


@pytest.fixture
def config(base_config, backend1, backend2) -> AggregatorConfig:
def backend1_id() -> str:
"""Id of first upstream backend. As a fixture to allow per-test override"""
return "b1"


@pytest.fixture
def backend2_id() -> str:
"""Id of second upstream backend. As a fixture to allow per-test override"""
return "b2"


@pytest.fixture
def config(
base_config, backend1, backend2, backend1_id, backend2_id
) -> AggregatorConfig:
"""Config for most tests with two backends."""
conf = base_config
conf.aggregator_backends = {
"b1": backend1,
"b2": backend2,
backend1_id: backend1,
backend2_id: backend2,
}
return conf

Expand Down
51 changes: 46 additions & 5 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,13 +1475,13 @@ def test_create_wmts(self, api100, requests_mock, backend1):
api100.set_auth_bearer_token(TEST_USER_BEARER_TOKEN)

backend_service_id = 'c63d6c27-c4c2-4160-b7bd-9e32f582daec'
expected_openeo_id = "b1-" + backend_service_id
expected_agg_id = f"b1-{backend_service_id}"

# The aggregator MUST NOT point to the backend instance but to its own endpoint.
# This is handled by the openeo python driver in openeo_driver.views.services_post.
expected_location = "/openeo/1.0.0/services/" + expected_openeo_id
expected_location = f"/openeo/1.0.0/services/{expected_agg_id}"
# However, backend1 must report its OWN location.
location_backend_1 = backend1 + "/services" + backend_service_id
location_backend_1 = f"{backend1}/services/{backend_service_id}"

process_graph = {"foo": {"process_id": "foo", "arguments": {}}}
post_data = {
Expand All @@ -1504,8 +1504,49 @@ def test_create_wmts(self, api100, requests_mock, backend1):

resp = api100.post('/services', json=post_data).assert_status_code(201)

assert resp.headers['OpenEO-Identifier'] == expected_openeo_id
assert resp.headers['Location'] == expected_location
assert resp.headers["OpenEO-Identifier"] == expected_agg_id
assert resp.headers["Location"] == expected_location

@pytest.mark.parametrize("backend2_id", ["sentinelhub"])
def test_create_wmts_forced_sentinelhub(
self, api100, requests_mock, backend1, backend2_id, backend2
):
"""When the payload is correct the service should be successfully created,
the service ID should be prepended with the backend ID,
and location should point to the aggregator, not to the backend directly.
"""
# TODO this is a temp test for a temp "force sentinelhub" workaround hack (https://github.com/Open-EO/openeo-aggregator/issues/78)

api100.set_auth_bearer_token(TEST_USER_BEARER_TOKEN)

backend_service_id = "c63d6c27-c4c2-4160-b7bd-9e32f582daec"
expected_agg_id = "sentinelhub-" + backend_service_id

# The aggregator MUST NOT point to the backend instance but to its own endpoint.
# This is handled by the openeo python driver in openeo_driver.views.services_post.
expected_location = f"/openeo/1.0.0/services/{expected_agg_id}"
upstream_location = f"{backend2}/services/{backend_service_id}"

process_graph = {"foo": {"process_id": "foo", "arguments": {}}}
post_data = {
"type": "WMTS",
"process": {"process_graph": process_graph, "id": "filter_temporal_wmts"},
"title": "My Service",
"description": "Service description",
}
requests_mock.post(
backend2 + "/services",
headers={
"OpenEO-Identifier": backend_service_id,
"Location": upstream_location,
},
status_code=201,
)

resp = api100.post("/services", json=post_data).assert_status_code(201)

assert resp.headers["OpenEO-Identifier"] == expected_agg_id
assert resp.headers["Location"] == expected_location

# ProcessGraphMissingException and ProcessGraphInvalidException are well known reasons for a bad client request.
@pytest.mark.parametrize("exception_class", [ProcessGraphMissingException, ProcessGraphInvalidException])
Expand Down

0 comments on commit 9730e88

Please sign in to comment.