Skip to content
Snippets Groups Projects
Commit c37f3e36 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-860: specialized method to get latest strategy template

parent c4cee8ed
No related branches found
No related tags found
1 merge request!828TMSS-860
......@@ -152,7 +152,7 @@ def populate_schemas(schema_dir: str=None, dbcreds_name: str=None, parallel: boo
try:
template_type_name = template.pop('template_type_name')
try:
known_template = client._get_template(template_type_name=template_type_name, name=template['name'], version=template['version'])
known_template = client._get_schema_template(template_type_name=template_type_name, name=template['name'], version=template['version'])
if known_template['schema'] == template['schema']:
logger.info("Skipping template with name='%s' version='%s' because it is already known and the contents did not change: url='%s'",
template['name'], template['version'], known_template['url'])
......@@ -198,7 +198,7 @@ def populate_schemas(schema_dir: str=None, dbcreds_name: str=None, parallel: boo
strategy_template_type = template.pop('template_type_name')
try:
known_template = client._get_template(template_type_name=strategy_template_type, name=template['name'], version=template['version'])
known_template = client._get_schema_template(template_type_name=strategy_template_type, name=template['name'], version=template['version'])
if known_template['template'] == template['template']:
logger.info("Skipping strategy template with name='%s' version='%s' because it is already known and the contents did not change: url='%s'", template['name'], template['version'], known_template['url'])
else:
......
......@@ -343,8 +343,8 @@ class TMSSsession(object):
response.elapsed.total_seconds()*1000, ' SLOW!' if response.elapsed > timedelta(seconds=1) else '',
response.request.url))
def _get_template(self, template_type_name: str, name: str, version: int=None) -> dict:
'''get the template of the given type as dict for the given name (and version)'''
def _get_schema_template(self, template_type_name: str, name: str, version: int=None) -> dict:
'''get the schema template of the given type as dict for the given name (and version)'''
clauses = {}
if name is not None:
clauses["name"] = name
......@@ -372,19 +372,19 @@ class TMSSsession(object):
def get_schedulingunit_template(self, name: str, version: int=None) -> dict:
'''get the schedulingunit_template as dict for the given name (and version)'''
return self._get_template('scheduling_unit_template', name, version)
return self._get_schema_template('scheduling_unit_template', name, version)
def get_task_template(self, name: str, version: int=None) -> dict:
'''get the task_template as dict for the given name (and version)'''
return self._get_template('task_template', name, version)
return self._get_schema_template('task_template', name, version)
def get_subtask_template(self, name: str, version: int=None) -> dict:
'''get the subtask_template as dict for the given name (and version)'''
return self._get_template('subtask_template', name, version)
return self._get_schema_template('subtask_template', name, version)
def get_scheduling_constraints_template(self, name: str='constraints', version: int=None) -> dict:
'''get the scheduling_constraints_template as dict for the given name (and version)'''
return self._get_template('scheduling_constraints_template', name, version)
return self._get_schema_template('scheduling_constraints_template', name, version)
def get_schedulingunit_template_default_specification(self, name: str, version: int=None) -> dict:
template = self.get_schedulingunit_template(name=name, version=version)
......@@ -400,7 +400,7 @@ class TMSSsession(object):
def get_dataproduct_specifications_template(self, name: str, version: int=None) -> dict:
'''get the subtask_template as dict for the given name (and version)'''
return self._get_template('dataproduct_specifications_template', name, version)
return self._get_schema_template('dataproduct_specifications_template', name, version)
def get_dataproduct_specifications_template_default_specification(self, name: str, version: int=None) -> dict:
'''get the subtask_template as dict for the given name (and version)'''
......@@ -702,7 +702,31 @@ class TMSSsession(object):
def get_scheduling_unit_observing_strategy_template(self, name: str, version: int=None) -> dict:
'''get the scheduling_unit_observing_strategy_template as dict for the given name (and version)'''
return self._get_template('scheduling_unit_observing_strategy_template', name, version)
clauses = {}
if name is not None:
clauses["name"] = name
if version is not None:
clauses["version"] = version
else:
# try to determine the latest version
if name is not None:
try:
templates = self.get_path_as_json_object('/scheduling_unit_observing_strategy_template', params={'name':name})
if templates:
templates = sorted(templates, key=lambda t: t['version'])
clauses["version"] = templates[-1]['version']
except Exception as e:
# could not determine latest version
pass
result = self.get_path_as_json_object('/scheduling_unit_observing_strategy_template', clauses)
if isinstance(result, list):
if len(result) > 1:
raise ValueError("Found more then one scheduling_unit_observing_strategy_template for clauses: %s" % (clauses,))
elif len(result) == 1:
return result[0]
raise ValueError("Could not find any template of type='scheduling_unit_observing_strategy_template' and clauses='%s'" % (clauses,))
return result
def get_scheduling_unit_observing_strategy_template_default_specification(self, name: str, version: int=None) -> dict:
'''get the scheduling_unit_observing_strategy_template as dict for the given name (and version) with completely filled in with all defaults'''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment