Skip to content

Commit

Permalink
Convert TemplateRepository to class
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandf committed Oct 18, 2023
1 parent cad6345 commit 6fd0f5a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 35 deletions.
13 changes: 6 additions & 7 deletions src/engine/src/core/workflows/executors/WorkflowExecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
)
from helpers.GraphValidator import GraphValidator # From shared
from helpers.TemplateMapper import TemplateMapper
from helpers.TemplateRepository import TemplateRepository
from errors.tasks import (
InvalidTaskTypeError,
MissingInitialTasksError,
Expand Down Expand Up @@ -441,12 +440,12 @@ def _prepare_pipeline(self):
# Create all of the directories needed for the pipeline to run and persist results and cache
self._prepare_pipeline_fs()

template = TemplateRepository(
self.state.ctx.pipeline.uses,
cache_dir=self.state.ctx.pipeline.git_cache_dir
)

# TODO map the template props to the pipeline
# template_mapper = TemplateMapper(cache_dir=self.state.ctx.pipeline.git_cache_dir)
# if self.state.ctx.pipeline.uses != None:
# self.state.ctx.pipeline = template_mapper.map(
# self.state.ctx.pipeline,
# self.state.ctx.pipeline.uses
# )

@interceptable()
def _prepare_pipeline_fs(self):
Expand Down
4 changes: 2 additions & 2 deletions src/engine/src/helpers/TemplateMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

class TemplateMapper:
def __init__(self, cache_dir: str):
self.cache_dir = cache_dir
self.task_map_by_type = {
"function": FunctionTask,
"application": ApplicationTask,
Expand All @@ -25,6 +24,7 @@ def __init__(self, cache_dir: str):
"tapis_job": TapisJobTask,
"tapis_actor": TapisActorTask
}
self.template_repo = TemplateRepository(cache_dir=cache_dir)

def map(self, obj: Union[Pipeline, Task], uses: Uses) -> Union[Pipeline, Task]:
"""This method takes an object(Pipeline or Task object), and updates its
Expand All @@ -35,7 +35,7 @@ def map(self, obj: Union[Pipeline, Task], uses: Uses) -> Union[Pipeline, Task]:
"""

# Clone git repository specified on the pipeline.uses if exists
template = TemplateRepository(uses, cache_dir=self.cache_dir)
template = self.template_repo.get_by_uses(uses)

# Resolve which class the final object should have
obj_class = Pipeline
Expand Down
55 changes: 29 additions & 26 deletions src/engine/src/helpers/TemplateRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@
from .GitCacheService import GitCacheService
from ..owe_python_sdk.schema import Uses

def TemplateRepository(uses: Uses, cache_dir: str):
# Clone git repository specified on the pipeline.uses if exists
git_cache_service = GitCacheService(cache_dir=cache_dir)
class TemplateRepository:
def __init__(self, cache_dir: str):
# Clone git repository specified on the pipeline.uses if exists
self.cache_dir = cache_dir
self.git_cache_service = GitCacheService(cache_dir=cache_dir)

git_cache_service.add_or_update(
uses.source.url,
# NOTE Using the url as the directory to clone into is intentional
uses.source.url
)
def get_by_uses(self, uses: Uses):
self.git_cache_service.add_or_update(
uses.source.url,
# NOTE Using the url as the directory to clone into is intentional
uses.source.url
)

template_root_dir = os.path.join(cache_dir, uses.source.url)

try:
# Open the owe-config.json file
with open(os.path.join(template_root_dir, "owe-config.json")) as file:
owe_config = json.loads(file.read())

# Open the etl pipeline schema.json
with open(
os.path.join(
template_root_dir,
owe_config.get(uses.name).get("path")
)
) as file:
template = json.loads(file.read())
except Exception as e:
raise Exception(f"Templating configuration Error (owe-config.json): {str(e)}")
template_root_dir = os.path.join(self.cache_dir, uses.source.url)

return template
try:
# Open the owe-config.json file
with open(os.path.join(template_root_dir, "owe-config.json")) as file:
owe_config = json.loads(file.read())

# Open the etl pipeline schema.json
with open(
os.path.join(
template_root_dir,
owe_config.get(uses.name).get("path")
)
) as file:
template = json.loads(file.read())
except Exception as e:
raise Exception(f"Templating configuration Error (owe-config.json): {str(e)}")

return template

0 comments on commit 6fd0f5a

Please sign in to comment.