Browse Source

HUE-1657 [oozie] SLA search/lookup

Romain Rigaux 12 năm trước cách đây
mục cha
commit
ac64189

+ 157 - 0
apps/oozie/src/oozie/templates/dashboard/list_oozie_sla.mako

@@ -0,0 +1,157 @@
+## 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.
+
+<%!
+  from desktop.views import commonheader, commonfooter
+  from django.utils.translation import ugettext as _
+%>
+
+<%namespace name="layout" file="../navigation-bar.mako" />
+<%namespace name="utils" file="../utils.inc.mako" />
+
+${ commonheader(_("SLA"), "sla", user) | n,unicode }
+${ layout.menubar(section='sla', dashboard=True) }
+
+
+<div class="container-fluid">
+
+  <div class="card card-small">
+  <div class="card-body">
+  <p>
+
+  <h1 class="card-heading card-heading-noborder simple pull-right" style="margin-top: -4px;">
+    Import / Export
+  </h1>
+
+  <ul class="nav nav-tabs">
+      <form class="form-search" id="search" method="GET" action=".">
+        <input type="text" name="job" class="searchFilter input-xlarge search-query" placeholder="${_('Job Name or Id (required)')}">
+        <input type="checkbox" name="isParent" placeholder="${_('Text Filter')}">
+        ${ _('Parent ID') }
+        Start
+        <input type="text" name="start" class="searchFilter input-xlarge search-query" placeholder="${_('Start in GMT')}">
+        End
+        <input type="text" name="end" class="searchFilter input-xlarge search-query" placeholder="${_('End')}">
+      </form>
+    <li class="active"><a href="#slaListTab" data-toggle="tab">${ _('List') }</a></li>
+    <li><a href="#graphTab" data-toggle="tab">${ _('Graph') }</a></li>
+  </ul>
+
+  <div class="tab-content" style="padding-bottom:200px">
+    <div class="tab-pane active" id="slaListTab">
+      <form class="form-search">
+        <input type="text" class="searchFilter input-xlarge search-query" placeholder="${_('Text Filter')}">
+      </form>
+      <div class="tabbable">
+
+        <div class="tab-content">
+
+            <table id="intrumentationTable" class="table table-striped table-condensed">
+              <thead>
+                <%
+                columns = [
+                  'slaStatus',
+                  'id',
+                  'appType',
+                  'appName',
+                  'user',
+                  'nominalTime',
+                  'expectedStart',
+                  'actualStart',
+                  'expectedEnd',
+                  'actualEnd',                  
+                  'jobStatus',
+                  #'expectedDuration',
+                  #'actualDuration',
+                  'lastModified'
+                ]
+                %>
+                % for col in columns:
+                  <th>${ col }</th>
+                % endfor
+              </thead>
+              <tbody>
+                % for sla in oozie_slas:
+                <tr>
+                  % for col in columns:
+                    <td>${ sla.get(col, '') }</td>
+                  % endfor
+                </tr>
+                % endfor
+              </tbody>
+              </table>
+
+        </div>
+      </div>
+
+    </div>
+
+    <div class="tab-pane" id="graphTab">
+      MY GRAPH      
+    </div>
+
+    </p>
+    </div>
+    </div>
+  </div>
+
+
+<script>
+  $(document).ready(function(){
+    $("a[data-row-selector='true']").jHueRowSelector();
+
+    $("*[rel=tooltip]").tooltip();
+
+/**
+        var _metadataTable = $("#graphTable").dataTable({
+            "bPaginate": false,
+            "bLengthChange": false,
+            "bInfo": false,
+            "bAutoWidth": false,
+            "aoColumns": [
+                { "sWidth": "30%" },
+                { "sWidth": "70%" }
+            ],
+            "oLanguage": {
+                "sEmptyTable": "${_('No data available')}",
+                "sZeroRecords": "${_('No matching records')}",
+            }
+        });
+*/
+        var slaList = $("#intrumentationTable").dataTable({
+            "bPaginate": false,
+            "bLengthChange": false,
+            "bInfo": false,
+            "bAutoWidth": false,
+
+            "oLanguage": {
+                "sEmptyTable": "${_('No data available')}",
+                "sZeroRecords": "${_('No matching records')}"
+            }
+        });
+
+    $(".searchFilter").keyup(function(){
+      ("form#search").submit();
+       // _metadataTable.fnFilter($(this).val());
+       // slaList.fnFilter($(".searchFilter").val());
+    });
+
+    $(".dataTables_wrapper").css("min-height","0");
+    $(".dataTables_filter").hide();
+  });
+</script>
+
+${ commonfooter(messages) | n,unicode }

+ 1 - 0
apps/oozie/src/oozie/templates/navigation-bar.mako

@@ -41,6 +41,7 @@
                 <li class="${utils.is_selected(section, 'workflows')}"><a href="${url('oozie:list_oozie_workflows')}">${ _('Workflows') }</a></li>
                 <li class="${utils.is_selected(section, 'coordinators')}"><a href="${url('oozie:list_oozie_coordinators')}">${ _('Coordinators') }</a></li>
                 <li class="${utils.is_selected(section, 'bundles')}"><a href="${url('oozie:list_oozie_bundles')}">${ _('Bundles') }</a></li>
+                <li class="${utils.is_selected(section, 'sla')}"><a href="${url('oozie:list_oozie_sla')}">${ _('SLA') }</a></li>
                 <li class="${utils.is_selected(section, 'oozie')}"><a href="${url('oozie:list_oozie_info')}">${ _('Oozie') }</a></li>
               % else:
                 <li class="${utils.is_selected(section, 'workflows')}"><a href="${url('oozie:list_workflows')}">${ _('Workflows') }</a></li>

+ 2 - 0
apps/oozie/src/oozie/urls.py

@@ -100,4 +100,6 @@ urlpatterns += patterns(
   url(r'^submit_external_job/(?P<application_path>.+?)$', 'submit_external_job', name='submit_external_job'),
 
   url(r'^list_oozie_info/$', 'list_oozie_info', name='list_oozie_info'),
+  
+  url(r'^list_oozie_sla/$', 'list_oozie_sla', name='list_oozie_sla'),
 )

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

@@ -327,6 +327,37 @@ def list_oozie_info(request):
   })
 
 
+@show_oozie_error
+def list_oozie_sla(request):
+  api = get_oozie(request.user, api_version="v2")
+
+  # filter=nominal_start=2013-06-18T00:01Z;nominal_end=2013-06-23T00:01Z;app_name=my-sla-app
+  params = {}
+  
+  # query matches Oozie id
+  # if parent checkbox:
+  #  parent_id = query
+  # else:
+  #   id = query
+  # else if query:
+  # app_name = query
+  
+  # if start
+  #   nominal_start=2013-06-18T00:01Z
+  # if end
+  #   nominal_end=2013-06-23T00:01Z
+
+  params['app_name'] = 'Forks'
+
+  oozie_slas = api.get_oozie_slas(**params)  
+  configuration = api.get_configuration()
+
+  return render('dashboard/list_oozie_sla.mako', request, {
+    'configuration': configuration,
+    'oozie_slas': oozie_slas,
+  })
+
+
 @show_oozie_error
 def rerun_oozie_job(request, job_id, app_path):
   ParametersFormSet = formset_factory(ParameterForm, extra=0)

+ 21 - 4
desktop/libs/liboozie/src/liboozie/oozie_api.py

@@ -40,14 +40,14 @@ _api_cache = None
 _api_cache_lock = threading.Lock()
 
 
-def get_oozie(user):
+def get_oozie(user, api_version=API_VERSION):
   global _api_cache
   if _api_cache is None:
     _api_cache_lock.acquire()
     try:
       if _api_cache is None:
         secure = SECURITY_ENABLED.get()
-        _api_cache = OozieApi(OOZIE_URL.get(), secure)
+        _api_cache = OozieApi(OOZIE_URL.get(), secure, api_version)
     finally:
       _api_cache_lock.release()
   _api_cache.setuser(user)
@@ -55,8 +55,8 @@ def get_oozie(user):
 
 
 class OozieApi(object):
-  def __init__(self, oozie_url, security_enabled=False):
-    self._url = posixpath.join(oozie_url, API_VERSION)
+  def __init__(self, oozie_url, security_enabled=False, api_version=API_VERSION):
+    self._url = posixpath.join(oozie_url, api_version)
     self._client = HttpClient(self._url, logger=LOG)
     if security_enabled:
       self._client.set_kerberos_auth()
@@ -287,3 +287,20 @@ class OozieApi(object):
     params = self._get_params()
     resp = self._root.get('admin/status', params)
     return resp
+
+  def get_oozie_slas(self, **kwargs):
+    """
+    filter=
+      app_name=my-sla-app
+      id=0000002-131206135002457-oozie-oozi-W
+      nominal_start=2013-06-18T00:01Z
+      nominal_end=2013-06-23T00:01Z
+    timezone=GMT
+    """
+    params = self._get_params()
+    if 'timezone' in kwargs:
+      params['timezone'] = kwargs.pop('timezone')
+    params['filter'] = ';'.join(['%s=%s' % (key, val) for key, val in kwargs.iteritems()])    
+    resp = self._root.get('sla', params)
+    # resp = {u'slaSummaryList': [{u'actualDuration': 68406, u'appType': u'WORKFLOW_JOB', u'appName': u'Forks', u'actualStart': u'Fri, 06 Dec 2013 14:01:53 PST', u'jobStatus': u'SUCCEEDED', u'id': u'0000002-131206135002457-oozie-oozi-W', u'expectedDuration': 1800000, u'nominalTime': u'Mon, 17 Jun 2013 17:01:00 PDT', u'slaStatus': u'MISS', u'lastModified': u'Fri, 06 Dec 2013 14:03:05 PST', u'actualEnd': u'Fri, 06 Dec 2013 14:03:01 PST', u'expectedEnd': u'Mon, 17 Jun 2013 17:31:00 PDT', u'expectedStart': u'Mon, 17 Jun 2013 17:11:00 PDT', u'user': u'romain'}]}
+    return resp['slaSummaryList']