-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: orchestrator client return algo objects (#1272)
In this PR I removed the `Algo` class I introduced at some point and replaced it with `orchestrator.Algo`. It makes mocking easier. The only drawback was that I had to do the query to retrieve the algo asset in the image builder. That's the reason I introduced the `Datastore` class. Doing this it is easier to mock the asset retrieval and open the possibility for another kind of storage without having to change all our code.
- Loading branch information
1 parent
3144e30
commit 1e81bdf
Showing
19 changed files
with
197 additions
and
179 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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import orchestrator | ||
import substrapp.clients.organization as organization_client | ||
|
||
|
||
class Datastore: | ||
def __init__(self, channel: str) -> None: | ||
self.channel = channel | ||
|
||
def _get_from_address(self, organization: str, address: orchestrator.Address) -> bytes: | ||
return organization_client.get( | ||
channel=self.channel, organization_id=organization, url=address.uri, checksum=address.checksum | ||
) | ||
|
||
def get_algo(self, algo: orchestrator.Algo) -> bytes: | ||
return self._get_from_address(algo.owner, algo.algorithm) | ||
|
||
|
||
def get_datastore(channel: str) -> Datastore: | ||
return Datastore(channel) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import orchestrator | ||
|
||
|
||
def container_image_tag_from_algo(algo: orchestrator.Algo) -> str: | ||
"""builds the container image tag from the algo checksum | ||
Args: | ||
algo (orchestrator.Algo): an algo retrieved from the orchestrator | ||
Returns: | ||
str: the container image tag | ||
""" | ||
return f"algo-{algo.algorithm.checksum[:16]}" |
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,5 +1,15 @@ | ||
# flake8: noqa | ||
from .tasks_compute_plan import * | ||
from .tasks_compute_task import * | ||
from .tasks_docker_registry import * | ||
from .tasks_remove_intermediary_models import * | ||
from substrapp.tasks.tasks_compute_plan import delete_cp_pod_and_dirs_and_optionally_images | ||
from substrapp.tasks.tasks_compute_task import compute_task | ||
from substrapp.tasks.tasks_docker_registry import clean_old_images_task | ||
from substrapp.tasks.tasks_docker_registry import docker_registry_garbage_collector_task | ||
from substrapp.tasks.tasks_remove_intermediary_models import remove_intermediary_models_from_buffer | ||
from substrapp.tasks.tasks_remove_intermediary_models import remove_intermediary_models_from_db | ||
|
||
__all__ = [ | ||
"delete_cp_pod_and_dirs_and_optionally_images", | ||
"compute_task", | ||
"clean_old_images_task", | ||
"docker_registry_garbage_collector_task", | ||
"remove_intermediary_models_from_db", | ||
"remove_intermediary_models_from_buffer", | ||
] |
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
Oops, something went wrong.