Skip to content

Commit c481d28

Browse files
authored
MRG: Merge pull request #604 from octue/require-children-to-be-registered-if-registry-specified
Require children to be registered in service registry if provided
2 parents 207f378 + eb4b5be commit c481d28

File tree

10 files changed

+550
-264
lines changed

10 files changed

+550
-264
lines changed

.github/workflows/add-issues-to-octue-board.yaml renamed to .github/workflows/add-issues-to-octue-board.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ on:
66

77
jobs:
88
add-issues-to-octue-board:
9-
uses: octue/.github/.github/workflows/reusable-add-issues-to-octue-board.yaml@main
9+
uses: octue/.github/.github/workflows/reusable-add-issues-to-octue-board.yml@main
1010
secrets:
1111
github-token: ${{ secrets.PROJECT_AUTOMATION_GITHUB_TOKEN_2 }}

docs/source/asking_questions.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ sent back to the parent. If you're not sure how long a particular analysis might
6363

6464
Asking multiple questions in parallel
6565
=====================================
66-
You can also ask multiple questions to a service in parallel.
66+
You can also ask multiple questions to a service in parallel. By default, if any of the questions fail, an error is
67+
raised and no answers are returned. If ``raise_errors=False`` is provided, answers are returned for all successful
68+
questions while errors are returned unraised for unsuccessful ones.
6769

6870
.. code-block:: python
6971

docs/source/inter_service_compatibility.rst

Lines changed: 167 additions & 165 deletions
Large diffs are not rendered by default.

octue/cloud/pub_sub/service.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
convert_service_id_to_pub_sub_form,
2121
create_sruid,
2222
get_default_sruid,
23+
raise_if_revision_not_registered,
2324
split_service_id,
2425
validate_sruid,
2526
)
@@ -77,19 +78,18 @@ def __init__(self, backend, service_id=None, run_function=None, name=None, servi
7778
self.run_function = run_function
7879
self.name = name
7980

80-
self.service_registries = service_registries or [
81-
{
82-
"name": "Octue Registry",
83-
"endpoint": OCTUE_SERVICE_REGISTRY_ENDPOINT,
84-
},
85-
]
81+
self.service_registries = service_registries
8682

8783
self._pub_sub_id = convert_service_id_to_pub_sub_form(self.id)
8884
self._local_sdk_version = importlib.metadata.version("octue")
8985
self._publisher = None
9086
self._message_handler = None
9187

9288
def __repr__(self):
89+
"""Represent the service as a string.
90+
91+
:return str: the service represented as a string
92+
"""
9393
return f"<{type(self).__name__}({self.name or self.id!r})>"
9494

9595
@property
@@ -286,11 +286,19 @@ def ask(
286286
"""
287287
service_namespace, service_name, service_revision_tag = split_service_id(service_id)
288288

289-
if not service_revision_tag:
290-
service_id = get_default_sruid(
291-
namespace=service_namespace,
292-
name=service_name,
293-
service_registries=self.service_registries,
289+
if self.service_registries:
290+
if service_revision_tag:
291+
raise_if_revision_not_registered(sruid=service_id, service_registries=self.service_registries)
292+
else:
293+
service_id = get_default_sruid(
294+
namespace=service_namespace,
295+
name=service_name,
296+
service_registries=self.service_registries,
297+
)
298+
299+
elif not service_revision_tag:
300+
raise octue.exceptions.InvalidServiceID(
301+
f"A service revision tag for {service_id!r} must be provided if service registries aren't being used."
294302
)
295303

296304
if not allow_local_files:

octue/cloud/service_id.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,12 @@ def convert_service_id_to_pub_sub_form(service_id):
209209
return service_id
210210

211211

212-
def split_service_id(service_id):
212+
def split_service_id(service_id, require_revision_tag=False):
213213
"""Split an SRUID or service ID into its namespace, name, and, if present, its revision tag. The split parts are
214214
validated before being returned.
215215
216216
:param str service_id: the SRUID or service ID to split
217+
:param bool require_revision_tag: if `True`, require the service ID to include a revision tag (i.e. require the service ID to be an SRUID)
217218
:raise octue.exceptions.InvalidServiceID: if any of the namespace, name, or revision tag are invalid
218219
:return tuple(str, str, str|None): the namespace, name, and revision tag
219220
"""
@@ -225,7 +226,7 @@ def split_service_id(service_id):
225226
name = name_and_revision_tag
226227
revision_tag = None
227228

228-
if revision_tag is None:
229+
if revision_tag is None and not require_revision_tag:
229230
validate_service_id(namespace=namespace, name=name)
230231
else:
231232
validate_sruid(namespace=namespace, name=name, revision_tag=revision_tag)
@@ -257,3 +258,25 @@ def get_default_sruid(namespace, name, service_registries):
257258
f"No revisions for the service {service_id!r} were found in any of the specified service registries: "
258259
f"{service_registries!r}"
259260
)
261+
262+
263+
def raise_if_revision_not_registered(sruid, service_registries):
264+
"""Raise an error if the service revision isn't registered in the given service registries.
265+
266+
:param str sruid: the SRUID of the service revision
267+
:param iter(dict) service_registries: the registries to look for the service revision in
268+
:raise octue.exceptions.ServiceNotFound: if the service revision isn't registered in any of the service registries
269+
:return None:
270+
"""
271+
namespace, name, revision_tag = split_service_id(sruid, require_revision_tag=True)
272+
273+
for registry in service_registries:
274+
response = requests.get(f"{registry['endpoint']}/{namespace}/{name}?revision_tag={revision_tag}")
275+
276+
if response.ok:
277+
logger.info("Found service revision %r in %r registry.", sruid, registry["name"])
278+
return
279+
280+
raise octue.exceptions.ServiceNotFound(
281+
f"Service revision {sruid!r} was not found in any of the specified service registries: {service_registries!r}"
282+
)

octue/metadata/recorded_questions.jsonl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@
7979
{"parent_sdk_version": "0.48.0", "question": {"data": "{\"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"eb846c0b-3bc4-4eb6-896b-81c4404d3d24\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmpy5_c3ggz\"}}, \"children\": null, \"message_number\": 0}", "attributes": {"question_uuid": "a1523bd3-f64d-4de3-af4c-823a2cfea204", "forward_logs": "1", "allow_save_diagnostics_data_on_crash": "1", "octue_sdk_version": "0.48.0"}}}
8080
{"parent_sdk_version": "0.49.0", "question": {"data": "{\"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"34216d6d-e32e-4c40-8b05-ee9bd71966c9\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmppi1e5t2n\"}}, \"children\": null, \"message_number\": 0}", "attributes": {"question_uuid": "3b1224da-8e7f-4b1b-8ef3-c5cf1a5e698c", "forward_logs": "1", "allow_save_diagnostics_data_on_crash": "1", "octue_sdk_version": "0.49.0"}}}
8181
{"parent_sdk_version": "0.49.1", "question": {"data": "{\"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"34216d6d-e32e-4c40-8b05-ee9bd71966c9\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmppi1e5t2n\"}}, \"children\": null, \"message_number\": 0}", "attributes": {"question_uuid": "3b1224da-8e7f-4b1b-8ef3-c5cf1a5e698c", "forward_logs": "1", "allow_save_diagnostics_data_on_crash": "1", "octue_sdk_version": "0.49.1"}}}
82+
{"parent_sdk_version": "0.49.2", "question": {"data": "{\"input_values\": {\"height\": 4, \"width\": 72}, \"input_manifest\": {\"id\": \"bdadcd12-a51b-4571-9db3-9d240bd15faa\", \"name\": null, \"datasets\": {\"my_dataset\": \"/var/folders/sk/hf5fbp616c77tsys9lz55qn40000gp/T/tmpw3232ii0\"}}, \"children\": null, \"message_number\": 0}", "attributes": {"question_uuid": "0b57da2c-38e2-4f8b-9368-fe35125da8fb", "forward_logs": "1", "allow_save_diagnostics_data_on_crash": "1", "octue_sdk_version": "0.49.2"}}}

0 commit comments

Comments
 (0)