[jb] Integrate text, status and time filtering to Oozie Workflows
@@ -20,7 +20,7 @@ import json
from django.utils.translation import ugettext as _
-from jobbrowser.apis.base_api import Api, MockDjangoRequest
+from jobbrowser.apis.base_api import Api, MockDjangoRequest, _extract_query_params
from liboozie.oozie_api import get_oozie
@@ -28,8 +28,8 @@ LOG = logging.getLogger(__name__)
try:
- from oozie.conf import OOZIE_JOBS_COUNT
- from oozie.views.dashboard import get_oozie_job_log, list_oozie_workflow, manage_oozie_jobs, bulk_manage_oozie_jobs
+ from oozie.conf import OOZIE_JOBS_COUNT, ENABLE_OOZIE_BACKEND_FILTERING
+ from oozie.views.dashboard import get_oozie_job_log, list_oozie_workflow, manage_oozie_jobs, bulk_manage_oozie_jobs, has_dashboard_jobs_access
except Exception, e:
LOG.exception('Some applications are not enabled for Job Browser v2: %s' % e)
@@ -37,8 +37,29 @@ except Exception, e:
class WorkflowApi(Api):
def apps(self, filters):
+ kwargs = {'cnt': OOZIE_JOBS_COUNT.get(), 'filters': []}
+
+ text_filters = _extract_query_params(filters)
+
+ if not has_dashboard_jobs_access(self.user):
+ kwargs['filters'].append(('user', self.user.username))
+ elif 'user' in text_filters:
+ kwargs['filters'].append(('user', text_filters['username']))
+
+ if 'time' in filters:
+ kwargs['filters'].extend([('startcreatedtime', '-%s%s' % (filters['time']['time_value'], filters['time']['time_unit'][:1]))])
+
+ if ENABLE_OOZIE_BACKEND_FILTERING.get() and text_filters.get('text'):
+ kwargs['filters'].extend([('text', text_filters.get('text'))])
+
+ if filters.get('states'):
+ states_filters = {'running': ['RUNNING', 'PREP', 'SUSPENDED'], 'completed': ['SUCCEEDED'], 'failed': ['FAILED', 'KILLED'],}
+ for _state in filters.get('states'):
+ for _status in states_filters[_state]:
+ kwargs['filters'].extend([('status', _status)])
+
oozie_api = get_oozie(self.user)
- kwargs = {'cnt': OOZIE_JOBS_COUNT.get(), 'filters': filters}
+
wf_list = oozie_api.get_workflows(**kwargs)
return [{
