Explorar el Código

HUE-1176 [jb] Try to load and display the graph of a workflow

Romain Rigaux hace 9 años
padre
commit
6128313e0e

+ 3 - 1
apps/jobbrowser/src/jobbrowser/apis/base_api.py

@@ -51,6 +51,8 @@ class Api():
 
   def action(self, appid): return {} # Kill, suspend...
 
+  def status(self, appid): return {'status': 'RUNNING'}
+
   def logs(self, appid): return {'progress': 0, 'logs': {'default': ''}}
 
   def profile(self, appid): return {} # Tasks, XML, counters...
@@ -60,4 +62,4 @@ class MockDjangoRequest():
   def __init__(self, user):
     self.user = user
     self.jt = None
-    self.GET = {}
+    self.GET = {'format': 'json', 'is_jb2': True}

+ 2 - 2
apps/jobbrowser/src/jobbrowser/apis/job_api.py

@@ -106,8 +106,8 @@ class YarnApi(Api):
     # name = 'stdout'
     # attempt_index
     # offset=log_offset
-    data = job_attempt_logs_json(MockDjangoRequest(self.user), job=appid)
-    return {'progress': 0, 'logs': {'default': json.loads(data.content)['log']}}
+    response = job_attempt_logs_json(MockDjangoRequest(self.user), job=appid)
+    return {'progress': 0, 'logs': {'default': json.loads(response.content)['log']}}
 
 
 class YarnAtsApi(Api):

+ 11 - 4
apps/jobbrowser/src/jobbrowser/apis/workflow_api.py

@@ -22,14 +22,14 @@ from django.utils.translation import ugettext as _
 
 from jobbrowser.apis.base_api import Api, MockDjangoRequest
 from liboozie.oozie_api import get_oozie
-from notebook.connectors.oozie_batch import OozieApi
+
 
 LOG = logging.getLogger(__name__)
 
 
 try:
   from oozie.conf import OOZIE_JOBS_COUNT
-  from oozie.views.dashboard import get_oozie_job_log
+  from oozie.views.dashboard import get_oozie_job_log, list_oozie_workflow
 except Exception, e:
   LOG.exception('Some application are not enabled for Job Browser v2: %s' % e)
 
@@ -56,9 +56,16 @@ class WorkflowApi(Api):
     oozie_api = get_oozie(self.user)
     workflow = oozie_api.get_job(jobid=appid)
 
-    return {'id': workflow.id, 'name': workflow.appName, 'status': workflow.status}
+    common = {'id': workflow.id, 'name': workflow.appName, 'status': workflow.status}
+
+    request = MockDjangoRequest(self.user)
+    response = list_oozie_workflow(request, job_id=appid)
+    common['properties'] = json.loads(response.content)
+
+    return common
 
   def logs(self, appid):
-    data = get_oozie_job_log(MockDjangoRequest(self.user), job_id=appid)
+    request = MockDjangoRequest(self.user)
+    data = get_oozie_job_log(request, job_id=appid)
 
     return {'progress': 0, 'logs': {'default': json.loads(data.content)['log']}}

+ 1 - 1
apps/jobbrowser/src/jobbrowser/templates/apps.mako

@@ -397,7 +397,7 @@ ${ commonheader("Job Browser", "jobbrowser", user, request) | n,unicode }
   </ul>
 
   <div class="tab-content active" id="workflow-page-graph">
-    Graph
+    <span data-bind="html: properties().graph"></span>
   </div>
 
   <div class="tab-content" id="workflow-page-logs">

+ 20 - 0
apps/oozie/src/oozie/templates/dashboard/list_oozie_workflow_graph.mako

@@ -0,0 +1,20 @@
+## -*- coding: utf-8 -*-
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+
+<%namespace name="workflow" file="../editor2/common_workflow.mako" />
+
+${ workflow.render() }

+ 3 - 0
apps/oozie/src/oozie/views/dashboard.py

@@ -51,6 +51,7 @@ from oozie.models import Workflow as OldWorkflow, Job, utc_datetime_format, Bund
 from oozie.models2 import History, Workflow, WORKFLOW_NODE_PROPERTIES
 from oozie.settings import DJANGO_APPS
 from oozie.utils import convert_to_server_timezone
+from desktop.lib import django_mako
 
 
 def get_history():
@@ -380,6 +381,8 @@ def list_oozie_workflow(request, job_id):
 
 
   if request.GET.get('format') == 'json':
+    if not workflow_graph and request.GET.get('is_jb2'):      
+      workflow_graph = django_mako.render_to_string('dashboard/list_oozie_workflow_graph.mako', {})
     return_obj = {
       'id': oozie_workflow.id,
       'status':  oozie_workflow.status,