Reflect job_id->job_template_id in v2 jobs

As the title says.
Note the fragmentation: some APIv2 deployments may not have the change.

Change-Id: Ie8e604d73c77a4e7672f87b95ecbe3c1de945293
This commit is contained in:
Jeremy Freudberg 2019-01-10 11:17:51 -05:00
parent 659b1e6a17
commit 8562ebd3b6
5 changed files with 44 additions and 8 deletions

View File

@ -696,11 +696,17 @@ def job_execution_list(request, search_opts=None, marker=None, limit=None):
job_dict = {j.id: j for j in _job_list(new_request)}
cluster_dict = {c.id: c for c in _cluster_list(new_request)}
def _find_jt_id(jex_obj):
try:
return jex_obj.job_template_id # typical APIv2
except AttributeError:
return jex_obj.job_id # APIv1.1, older APIv2
resolved_job_execution_list = [
_resolve_job_execution_names(
job_execution,
cluster_dict.get(job_execution.cluster_id),
job_dict.get(job_execution.job_id))
job_dict.get(_find_jt_id(job_execution)))
for job_execution in job_execution_list
]
@ -719,7 +725,11 @@ def job_execution_get(request, jex_id):
jex = getattr(sahara, je_manager).get(obj_id=jex_id)
cluster = safe_call(client(request).clusters.get, jex.cluster_id)
job = safe_call(getattr(sahara, jt_manager).get, jex.job_id)
try:
jt_id = jex.job_template_id # typical APIv2
except AttributeError:
jt_id = jex.job_id # APIv1.1, older APIv2
job = safe_call(getattr(sahara, jt_manager).get, jt_id)
return _resolve_job_execution_names(jex, cluster, job)

View File

@ -239,7 +239,11 @@ class JobConfigAction(workflows.Action):
job_ex_id = req.get("job_execution_id")
if job_ex_id is not None:
job_ex = saharaclient.job_execution_get(request, job_ex_id)
job = saharaclient.job_get(request, job_ex.job_id)
try:
jt_id = job_ex.job_template_id # typical APIv2
except AttributeError:
jt_id = job_ex.job_id # APIv1.1, older APIv2
job = saharaclient.job_get(request, jt_id)
job_configs, interface_args = _merge_interface_with_configs(
job.interface, job_ex.job_configs)
edp_configs = {}
@ -466,7 +470,11 @@ class JobExecutionInterfaceConfigAction(workflows.Action):
job_ex_id = req.get("job_execution_id")
if job_ex_id is not None:
job_ex = saharaclient.job_execution_get(request, job_ex_id)
job = saharaclient.job_get(request, job_ex.job_id)
try:
jt_id = job_ex.job_template_id # typical APIv2
except AttributeError:
jt_id = job_ex.job_id # APIv1.1, older APIv2
job = saharaclient.job_get(request, jt_id)
job_configs, interface_args = _merge_interface_with_configs(
job.interface, job_ex.job_configs)

View File

@ -92,7 +92,11 @@ class ReLaunchJobExistingCluster(j_t.ChoosePlugin):
def get_link_url(self, datum):
base_url = reverse(self.url)
params = http.urlencode({'job_id': datum.job_id,
try:
job_template_id = datum.job_template_id # typical APIv2
except AttributeError:
job_template_id = datum.job_id # APIv1.1, older APIv2
params = http.urlencode({'job_id': job_template_id,
'job_execution_id': datum.id})
return "?".join([base_url, params])
@ -164,9 +168,13 @@ class JobsTable(sahara_table.SaharaPaginateTabbedTable):
@staticmethod
def link(job_execution):
if job_execution.job_name:
try:
job_template_id = job_execution.job_template_id # typical APIv2
except AttributeError:
job_template_id = job_execution.job_id # APIv1.1, older APIv2
return reverse("horizon:project:data_processing."
"jobs:jt-details",
args=(http.urlquote(job_execution.job_id),))
args=(http.urlquote(job_template_id),))
else:
# No link should be generated for a deleted Job.
return None

View File

@ -95,14 +95,24 @@ class GeneralTab(tabs.Tab):
job_execution_engine_job_id = getattr(job_execution,
job_execution_engine_job_attr)
try:
job_template_id = job_execution.job_template_id # typical APIv2
except AttributeError:
job_template_id = job_execution.job_id # APIv1.1, older APIv2
return {"job_execution": job_execution,
"object_names": object_names,
"job_execution_job_template_id": job_template_id,
"job_execution_engine_job_id": job_execution_engine_job_id,
"job_execution_engine_job_attr_pretty":
job_execution_engine_job_attr_pretty}
def get_object_names(self, job_ex, request):
object_names = {}
try:
job_template_id = job_ex.job_template_id # typical APIv2
except AttributeError:
job_template_id = job_ex.job_id # APIv1.1, older APIv2
obj_names_map = {'input_name': {'obj': 'data_source_get',
'obj_id': job_ex.input_id},
'output_name': {'obj': 'data_source_get',
@ -110,7 +120,7 @@ class GeneralTab(tabs.Tab):
'cluster_name': {'obj': 'cluster_get',
'obj_id': job_ex.cluster_id},
'job_name': {'obj': 'job_get',
'obj_id': job_ex.job_id}}
'obj_id': job_template_id}}
for item in obj_names_map:
object_names[item] = (
self.get_object_name(obj_names_map[item]['obj_id'],

View File

@ -9,7 +9,7 @@
<dt>{% trans "Project ID" %}</dt>
<dd>{{ job_execution.tenant_id }}</dd>
<dt>{% trans "Job Template" %}</dt>
<dd><a href="{% url 'horizon:project:data_processing.jobs:jt-details' job_execution.job_id %}">{{ object_names.job_name }}</a></dd>
<dd><a href="{% url 'horizon:project:data_processing.jobs:jt-details' job_execution_job_template_id %}">{{ object_names.job_name }}</a></dd>
<dt>{% trans "Public" %}</dt>
<dd>{{ job_execution.is_public|yesno }}</dd>
<dt>{% trans "Protected" %}</dt>