Jelajahi Sumber

HUE-1897 [oozie] Workflow ids have double trailing slashes

Using GET parameters instead.

Same for:
- Bundles
- Coordinators
- Workflow Actions
Romain Rigaux 11 tahun lalu
induk
melakukan
8c9388c

+ 1 - 1
apps/oozie/src/oozie/models.py

@@ -1908,7 +1908,7 @@ class History(models.Model):
       pass
 
   @classmethod
-  def cross_reference_submission_history(cls, user, oozie_id, coordinator_job_id):
+  def cross_reference_submission_history(cls, user, oozie_id):
     # Try do get the history
     history = None
     try:

+ 1 - 1
apps/oozie/src/oozie/templates/dashboard/list_oozie_bundle.mako

@@ -427,7 +427,7 @@ ${ layout.menubar(section='bundles', dashboard=True) }
     var logsAtEnd = true;
 
     function refreshView() {
-      $.getJSON("${ oozie_bundle.get_absolute_url() }" + "?format=json", function (data) {
+      $.getJSON("${ oozie_bundle.get_absolute_url(format='json') }", function (data) {
         viewModel.isLoading(false);
         if (data.actions){
           viewModel.actions(ko.utils.arrayMap(data.actions, function (action) {

+ 1 - 1
apps/oozie/src/oozie/templates/dashboard/list_oozie_coordinator.mako

@@ -534,7 +534,7 @@ ${ layout.menubar(section='coordinators', dashboard=True) }
     var logsAtEnd = true;
 
     function refreshView() {
-      $.getJSON("${ oozie_coordinator.get_absolute_url(oozie_bundle) }" + "?format=json" + "${ "&show_all_actions=true" if show_all_actions else '' | n,unicode }", function (data) {
+      $.getJSON("${ oozie_coordinator.get_absolute_url(oozie_bundle=oozie_bundle, format='json') }" + "${ "&show_all_actions=true" if show_all_actions else '' | n,unicode }", function (data) {
         viewModel.isLoading(false);
         if (data.actions){
           viewModel.actions(ko.utils.arrayMap(data.actions, function (action) {

+ 1 - 1
apps/oozie/src/oozie/templates/dashboard/list_oozie_workflow.mako

@@ -580,7 +580,7 @@ ${ layout.menubar(section='workflows', dashboard=True) }
     var logsAtEnd = true;
 
     function refreshView() {
-      $.getJSON("${ oozie_workflow.get_absolute_url() }" + "?format=json", function (data) {
+      $.getJSON("${ oozie_workflow.get_absolute_url(format='json') }", function (data) {
 
         if (data.actions){
           viewModel.actions(ko.utils.arrayMap(data.actions, function (action) {

+ 4 - 4
apps/oozie/src/oozie/tests.py

@@ -3231,7 +3231,7 @@ class TestDashboard(OozieMockBase):
     assert_true('Workflow WordCount1' in response.content, response.content)
     assert_true('Workflow' in response.content, response.content)
 
-    response = self.c.get(reverse('oozie:list_oozie_workflow', args=[MockOozieApi.WORKFLOW_IDS[0], MockOozieApi.COORDINATOR_IDS[0]]))
+    response = self.c.get(reverse('oozie:list_oozie_workflow', args=[MockOozieApi.WORKFLOW_IDS[0]]) + '?coordinator_job_id=%s' % MockOozieApi.COORDINATOR_IDS[0])
     assert_true('Workflow WordCount1' in response.content, response.content)
     assert_true('Workflow' in response.content, response.content)
     assert_true('DailyWordCount1' in response.content, response.content)
@@ -3245,7 +3245,7 @@ class TestDashboard(OozieMockBase):
     assert_true('job_201302280955_0019' in response.content, response.content)
     assert_true('job_201302280955_0020' in response.content, response.content)
 
-    response = self.c.get(reverse('oozie:list_oozie_workflow_action', args=['XXX', MockOozieApi.COORDINATOR_IDS[0], MockOozieApi.BUNDLE_IDS[0]]))
+    response = self.c.get(reverse('oozie:list_oozie_workflow_action', args=['XXX']) + '?coordinator_job_id=%s&bundle_job_id=%s' % (MockOozieApi.COORDINATOR_IDS[0], MockOozieApi.BUNDLE_IDS[0]))
     assert_true('Bundle' in response.content, response.content)
     assert_true('MyBundle1' in response.content, response.content)
     assert_true('Coordinator' in response.content, response.content)
@@ -3279,7 +3279,7 @@ class TestDashboard(OozieMockBase):
 
 
   def test_workflows_permissions(self):
-    response = self.c.get(reverse('oozie:list_oozie_workflows')+"?format=json")
+    response = self.c.get(reverse('oozie:list_oozie_workflows') + '?format=json')
     assert_true('WordCount1' in response.content, response.content)
 
     # Rerun
@@ -3291,7 +3291,7 @@ class TestDashboard(OozieMockBase):
     client_not_me = make_logged_in_client(username='not_me', is_superuser=False, groupname='test', recreate=True)
     grant_access("not_me", "not_me", "oozie")
 
-    response = client_not_me.get(reverse('oozie:list_oozie_workflows')+"?format=json")
+    response = client_not_me.get(reverse('oozie:list_oozie_workflows') + '?format=json')
     assert_false('WordCount1' in response.content, response.content)
 
     # Rerun

+ 3 - 3
apps/oozie/src/oozie/urls.py

@@ -87,9 +87,9 @@ urlpatterns += patterns(
   url(r'^list_oozie_workflows/$', 'list_oozie_workflows', name='list_oozie_workflows'),
   url(r'^list_oozie_coordinators/$', 'list_oozie_coordinators', name='list_oozie_coordinators'),
   url(r'^list_oozie_bundles/$', 'list_oozie_bundles', name='list_oozie_bundles'),
-  url(r'^list_oozie_workflow/(?P<job_id>[-\w]+)/(?P<coordinator_job_id>[-\w]+)?/(?P<bundle_job_id>[-\w]+)?$', 'list_oozie_workflow', name='list_oozie_workflow'),
-  url(r'^list_oozie_coordinator/(?P<job_id>[-\w]+)/(?P<bundle_job_id>[-\w]+)?$', 'list_oozie_coordinator', name='list_oozie_coordinator'),
-  url(r'^list_oozie_workflow_action/(?P<action>[-\w@]+)/(?P<coordinator_job_id>[-\w]+)?/(?P<bundle_job_id>[-\w]+)?$', 'list_oozie_workflow_action', name='list_oozie_workflow_action'),
+  url(r'^list_oozie_workflow/(?P<job_id>[-\w]+)/$', 'list_oozie_workflow', name='list_oozie_workflow'),
+  url(r'^list_oozie_coordinator/(?P<job_id>[-\w]+)/$', 'list_oozie_coordinator', name='list_oozie_coordinator'),
+  url(r'^list_oozie_workflow_action/(?P<action>[-\w@]+)/$', 'list_oozie_workflow_action', name='list_oozie_workflow_action'),
   url(r'^list_oozie_bundle/(?P<job_id>[-\w]+)$', 'list_oozie_bundle', name='list_oozie_bundle'),
 
   url(r'^rerun_oozie_job/(?P<job_id>[-\w]+)/(?P<app_path>.+?)$', 'rerun_oozie_job', name='rerun_oozie_job'),

+ 19 - 19
apps/oozie/src/oozie/views/dashboard.py

@@ -163,23 +163,23 @@ def list_oozie_bundles(request):
 
 
 @show_oozie_error
-def list_oozie_workflow(request, job_id, coordinator_job_id=None, bundle_job_id=None):
+def list_oozie_workflow(request, job_id):
   oozie_workflow = check_job_access_permission(request, job_id)
 
   oozie_coordinator = None
-  if coordinator_job_id is not None:
-    oozie_coordinator = check_job_access_permission(request, coordinator_job_id)
+  if request.GET.get('coordinator_job_id'):
+    oozie_coordinator = check_job_access_permission(request, request.GET.get('coordinator_job_id'))
 
   oozie_bundle = None
-  if bundle_job_id is not None:
-    oozie_bundle = check_job_access_permission(request, bundle_job_id)
+  if request.GET.get('bundle_job_id'):
+    oozie_bundle = check_job_access_permission(request, request.GET.get('bundle_job_id'))
 
   if oozie_coordinator is not None:
     setattr(oozie_workflow, 'oozie_coordinator', oozie_coordinator)
   if oozie_bundle is not None:
     setattr(oozie_workflow, 'oozie_bundle', oozie_bundle)
 
-  history = History.cross_reference_submission_history(request.user, job_id, coordinator_job_id)
+  history = History.cross_reference_submission_history(request.user, job_id)
 
   hue_coord = history and history.get_coordinator() or History.get_coordinator_from_config(oozie_workflow.conf_dict)
   hue_workflow = (hue_coord and hue_coord.workflow) or (history and history.get_workflow()) or History.get_workflow_from_config(oozie_workflow.conf_dict)
@@ -233,7 +233,7 @@ def list_oozie_workflow(request, job_id, coordinator_job_id=None, bundle_job_id=
 
 
 @show_oozie_error
-def list_oozie_coordinator(request, job_id, bundle_job_id=None):
+def list_oozie_coordinator(request, job_id):
   oozie_coordinator = check_job_access_permission(request, job_id)
 
   # Cross reference the submission history (if any)
@@ -244,8 +244,8 @@ def list_oozie_coordinator(request, job_id, bundle_job_id=None):
     pass
 
   oozie_bundle = None
-  if bundle_job_id is not None:
-    oozie_bundle = check_job_access_permission(request, bundle_job_id)
+  if request.GET.get('bundle_job_id'):
+    oozie_bundle = check_job_access_permission(request, request.GET.get('bundle_job_id'))
 
   show_all_actions =request.GET.get('show_all_actions') == 'true'
 
@@ -316,7 +316,7 @@ def list_oozie_bundle(request, job_id):
 
 
 @show_oozie_error
-def list_oozie_workflow_action(request, action, coordinator_job_id=None, bundle_job_id=None):
+def list_oozie_workflow_action(request, action):
   try:
     action = get_oozie(request.user).get_action(action)
     workflow = check_job_access_permission(request, action.id.split('@')[0])
@@ -324,12 +324,12 @@ def list_oozie_workflow_action(request, action, coordinator_job_id=None, bundle_
     raise PopupException(_("Error accessing Oozie action %s.") % (action,), detail=ex.message)
 
   oozie_coordinator = None
-  if coordinator_job_id is not None:
-    oozie_coordinator = check_job_access_permission(request, coordinator_job_id)
+  if request.GET.get('coordinator_job_id'):
+    oozie_coordinator = check_job_access_permission(request, request.GET.get('coordinator_job_id'))
 
   oozie_bundle = None
-  if bundle_job_id is not None:
-    oozie_bundle = check_job_access_permission(request, bundle_job_id)
+  if request.GET.get('bundle_job_id'):
+    oozie_bundle = check_job_access_permission(request, request.GET.get('bundle_job_id'))
 
   workflow.oozie_coordinator = oozie_coordinator
   workflow.oozie_bundle = oozie_bundle
@@ -659,15 +659,15 @@ def massaged_coordinator_actions_for_json(coordinator, oozie_bundle):
   coordinator_actions = coordinator.get_working_actions()
   actions = []
 
-  action_link_params = {}
+  related_job_ids = []
   if oozie_bundle is not None:
-    action_link_params['bundle_job_id'] = oozie_bundle.id
+    related_job_ids.append('bundle_job_id=%s' %oozie_bundle.id)
 
   for action in coordinator_actions:
-    action_link_params.update({'job_id': action.externalId, 'coordinator_job_id': coordinator_id})
+    related_job_ids.append('coordinator_job_id=%s' % coordinator_id)
     massaged_action = {
       'id': action.id,
-      'url': action.externalId and reverse('oozie:list_oozie_workflow', kwargs=action_link_params) or '',
+      'url': action.externalId and reverse('oozie:list_oozie_workflow', kwargs={'job_id': action.externalId}) + '?%s' % '&'.join(related_job_ids) or '',
       'number': action.actionNumber,
       'type': action.type,
       'status': action.status,
@@ -694,7 +694,7 @@ def massaged_bundle_actions_for_json(bundle):
   for action in bundle_actions:
     massaged_action = {
       'id': action.coordJobId,
-      'url': action.coordJobId and reverse('oozie:list_oozie_coordinator', kwargs={'job_id': action.coordJobId, 'bundle_job_id': bundle.id}) or '',
+      'url': action.coordJobId and reverse('oozie:list_oozie_coordinator', kwargs={'job_id': action.coordJobId}) + '?bundle_job_id=%s' % bundle.id or '',
       'name': action.coordJobName,
       'type': action.type,
       'status': action.status,

+ 46 - 15
desktop/libs/liboozie/src/liboozie/types.py

@@ -156,13 +156,19 @@ class WorkflowAction(Action):
       self.externalId = None
 
   def get_absolute_url(self):
-    kwargs = {'action': self.id}
+    related_job_ids = []
+
     if hasattr(self, 'oozie_coordinator') and self.oozie_coordinator:
-      kwargs['coordinator_job_id'] = self.oozie_coordinator.id
+      related_job_ids.append('coordinator_job_id=%s' % self.oozie_coordinator.id)
     if hasattr(self, 'oozie_bundle') and self.oozie_bundle:
-      kwargs['bundle_job_id'] = self.oozie_bundle.id
+      related_job_ids.append('bundle_job_id=%s' % self.oozie_bundle.id)
+
+    if related_job_ids:
+      extra_params = '?' + '&'.join(related_job_ids)
+    else:
+      extra_params = ''
 
-    return reverse('oozie:list_oozie_workflow_action', kwargs=kwargs)
+    return reverse('oozie:list_oozie_workflow_action', kwargs={'action': self.id}) + extra_params
 
 
 class CoordinatorAction(Action):
@@ -414,13 +420,22 @@ class Workflow(Job):
   def type(self):
     return 'Workflow'
 
-  def get_absolute_url(self):
-    kwargs = {'job_id': self.id}
+  def get_absolute_url(self, format='html'):
+    extra_params = []
+
+    if format == 'json':
+      extra_params.append('format=json')
     if hasattr(self, 'oozie_coordinator') and self.oozie_coordinator:
-      kwargs['coordinator_job_id'] = self.oozie_coordinator.id
+      extra_params.append('coordinator_job_id=%s' % self.oozie_coordinator.id)
     if hasattr(self, 'oozie_bundle') and self.oozie_bundle:
-      kwargs['bundle_job_id'] = self.oozie_bundle.id
-    return reverse('oozie:list_oozie_workflow', kwargs=kwargs)
+      extra_params.append('bundle_job_id=%s' % self.oozie_bundle.id)
+
+    if extra_params:
+      extra_params = '?' + '&'.join(extra_params)
+    else:
+      extra_params = ''
+
+    return reverse('oozie:list_oozie_workflow', kwargs={'job_id': self.id}) + extra_params
 
   def get_progress(self, full_node_list=None):
     if self.status == 'SUCCEEDED':
@@ -458,6 +473,7 @@ class Coordinator(Job):
     'timeUnit',
     'timeZone',
     'user',
+    'bundleId'
   ]
   ACTION = CoordinatorAction
 
@@ -477,11 +493,22 @@ class Coordinator(Job):
   def type(self):
     return 'Coordinator'
 
-  def get_absolute_url(self, oozie_bundle=None):
-    kwargs = {'job_id': self.id}
+  def get_absolute_url(self, oozie_bundle=None, format='html'):
+    extra_params = []
+
+    if format == 'json':
+      extra_params.append('format=json')
     if oozie_bundle:
-      kwargs.update({'bundle_job_id': oozie_bundle.id})
-    return reverse('oozie:list_oozie_coordinator', kwargs=kwargs)
+      extra_params.append('bundle_job_id=%s' % oozie_bundle.id)
+    if hasattr(self, 'bundleId') and self.bundleId:
+      extra_params.append('bundle_job_id=%s' % self.bundleId)
+
+    if extra_params:
+      extra_params = '?' + '&'.join(extra_params)
+    else:
+      extra_params = ''
+
+    return reverse('oozie:list_oozie_coordinator', kwargs={'job_id': self.id}) + extra_params
 
   def get_progress(self):
     """How much more time before the final materialization."""
@@ -558,8 +585,12 @@ class Bundle(Job):
   def type(self):
     return 'Bundle'
 
-  def get_absolute_url(self):
-    return reverse('oozie:list_oozie_bundle', kwargs={'job_id': self.id})
+  def get_absolute_url(self, format='html'):
+    extra_params = ''
+    if format == 'json':
+      extra_params = '?format=json'
+
+    return reverse('oozie:list_oozie_bundle', kwargs={'job_id': self.id}) + extra_params
 
   def get_progress(self):
     progresses = [action.get_progress() for action in self.actions]