Explorar o código

HUE-1176 [jb] Split up the APIs in dedicated modules

Romain Rigaux %!s(int64=9) %!d(string=hai) anos
pai
achega
fde7f5c

+ 1 - 1
apps/jobbrowser/src/jobbrowser/api2.py

@@ -22,7 +22,7 @@ from django.utils.translation import ugettext as _
 from desktop.lib.i18n import smart_unicode
 from desktop.lib.django_util import JsonResponse
 
-from jobbrowser.job_api import get_api
+from jobbrowser.apis.base_api import get_api
 
 
 LOG = logging.getLogger(__name__)

+ 16 - 0
apps/jobbrowser/src/jobbrowser/apis/__init__.py

@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+# 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.

+ 60 - 0
apps/jobbrowser/src/jobbrowser/apis/base_api.py

@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# 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.
+
+import logging
+
+from django.utils.translation import ugettext as _
+
+from desktop.lib.exceptions_renderable import PopupException
+
+
+LOG = logging.getLogger(__name__)
+
+
+def get_api(user, interface):
+  from jobbrowser.apis.batch_api import BatchApi
+  from jobbrowser.apis.job_api import YarnApi
+  from jobbrowser.apis.schedule_api import ScheduleApi
+
+  if interface == 'batches':
+    return BatchApi(user)
+  elif interface == 'schedules':
+    return ScheduleApi(user)
+  elif interface == 'jobs':
+    return YarnApi(user)
+  else:
+    raise PopupException(_('Interface %s is unknown') % interface)
+
+
+class Api():
+
+  def __init__(self, user):
+    self.user = user
+
+  def apps(self): return []
+
+  def app(self, appid): return {}
+
+  def kill(self): return {}
+
+  def progress(self): return {'progress': 0}
+
+  def tasks(self): return []
+
+  def logs(self): return {'stderr': '', 'stdout': ''}
+
+  def profile(self): return {}

+ 49 - 0
apps/jobbrowser/src/jobbrowser/apis/batch_api.py

@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# 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.
+
+import logging
+
+from django.utils.translation import ugettext as _
+
+from liboozie.oozie_api import get_oozie
+from jobbrowser.apis.base_api import Api
+
+
+LOG = logging.getLogger(__name__)
+
+
+try:
+  from oozie.conf import OOZIE_JOBS_COUNT
+except Exception, e:
+  LOG.exception('Some application are not enabled for Job Browser v2: %s' % e)
+
+
+
+class BatchApi(Api):
+
+  def apps(self):
+    oozie_api = get_oozie(self.user)
+    kwargs = {'cnt': OOZIE_JOBS_COUNT.get(), 'filters': []}
+    wf_list = oozie_api.get_workflows(**kwargs)
+
+    return [{'id': app.id, 'status': app.status} for app in wf_list.jobs]
+
+  def app(self, appid):
+    oozie_api = get_oozie(self.user)
+    workflow = oozie_api.get_job(jobid=appid)
+
+    return {'id': workflow.id, 'name': workflow.appName, 'status': workflow.status}

+ 30 - 0
apps/jobbrowser/src/jobbrowser/apis/history_api.py

@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# 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.
+
+import logging
+
+from django.utils.translation import ugettext as _
+
+from jobbrowser.apis.base_api import Api
+
+
+LOG = logging.getLogger(__name__)
+
+
+class HueHistoryApi(Api):
+
+  def apps(self): return []

+ 73 - 0
apps/jobbrowser/src/jobbrowser/apis/job_api.py

@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+# 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.
+
+import logging
+
+from django.utils.translation import ugettext as _
+
+from jobbrowser.apis.base_api import Api
+
+
+LOG = logging.getLogger(__name__)
+
+
+try:
+  from jobbrowser.api import YarnApi as NativeYarnApi
+except Exception, e:
+  LOG.exception('Some application are not enabled: %s' % e)
+
+
+class JobApi(Api):
+
+  def __init__(self, user):
+    self.user =  user
+    self.yarn_api = YarnApi(user)
+
+  def apps(self):
+    jobs = self.self.yarn_api.apps()
+
+    return jobs
+
+  def app(self, appid):
+    app = self.self.yarn_api.app(appid)
+
+    return app
+
+
+# Hadoop 2, to be removed in Hue 4
+
+class YarnApi(Api):
+
+  def apps(self):
+    jobs = NativeYarnApi(self.user).get_jobs(self.user, username=self.user.username, state='all', text='')
+    return [{'id': app.jobId, 'status': app.status} for app in jobs]
+
+  def app(self, appid):
+    app = NativeYarnApi(self.user).get_job(jobid=appid)
+    return {'id': app.jobId, 'name': app.name, 'status': app.status}
+
+# Hadoop 3
+
+class YarnAtsApi(Api):
+  pass
+
+
+# Impala
+
+class ImpalaApi(Api):
+  pass
+

+ 49 - 0
apps/jobbrowser/src/jobbrowser/apis/schedule_api.py

@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# 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.
+
+import logging
+
+from django.utils.translation import ugettext as _
+
+from liboozie.oozie_api import get_oozie
+
+from jobbrowser.apis.base_api import Api
+
+
+LOG = logging.getLogger(__name__)
+
+
+try:
+  from oozie.conf import OOZIE_JOBS_COUNT
+except Exception, e:
+  LOG.exception('Some application are not enabled: %s' % e)
+
+
+class ScheduleApi(Api):
+
+  def apps(self):
+    oozie_api = get_oozie(self.user)
+    kwargs = {'cnt': OOZIE_JOBS_COUNT.get(), 'filters': []}
+    wf_list = oozie_api.get_coordinators(**kwargs)
+
+    return [{'id': app.id, 'status': app.status} for app in wf_list.jobs]
+
+  def app(self, appid):
+    oozie_api = get_oozie(self.user)
+    workflow = oozie_api.get_coordinator(jobid=appid)
+
+    return {'id': workflow.coordJobId, 'name': workflow.coordJobName, 'status': workflow.status}

+ 0 - 140
apps/jobbrowser/src/jobbrowser/job_api.py

@@ -1,140 +0,0 @@
-#!/usr/bin/env python
-# 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.
-
-import logging
-
-from django.utils.translation import ugettext as _
-
-from liboozie.oozie_api import get_oozie
-
-from desktop.lib.exceptions_renderable import PopupException
-
-
-LOG = logging.getLogger(__name__)
-
-
-try:
-  from jobbrowser.api import YarnApi as NativeYarnApi
-  from oozie.conf import OOZIE_JOBS_COUNT
-except Exception, e:
-  LOG.exception('Some application are not enabled: %s' % e)
-
-
-def get_api(user, interface):
-  if interface == 'batches':
-    return BatchApi(user)
-  elif interface == 'schedules':
-    return ScheduleApi(user)
-  elif interface == 'jobs':
-    return YarnApi(user)
-  else:
-    raise PopupException(_('Interface %s is unknown') % interface)
-
-
-class Api():
-
-  def __init__(self, user):
-    self.user = user
-
-  def apps(self): return []
-
-  def app(self, appid): return {}
-
-  def kill(self): return {}
-
-  def progress(self): return {'progress': 0}
-
-  def tasks(self): return []
-
-  def logs(self): return {'stderr': '', 'stdout': ''}
-
-  def profile(self): return {}
-
-
-# Job
-
-class YarnApi(Api):
-
-  def apps(self):
-    jobs = NativeYarnApi(self.user).get_jobs(self.user, username=self.user.username, state='all', text='')
-    return [{'id': app.jobId, 'status': app.status} for app in jobs]
-
-  def app(self, appid):
-    app = NativeYarnApi(self.user).get_job(jobid=appid)
-    return {'id': app.jobId, 'name': app.name, 'status': app.status}
-
-
-class MapReduce2Api(Api):
-  pass
-
-class MapReduceHistoryServerApi(Api):
-  pass
-
-
-class SparkApi(Api):
-  pass
-
-class SparkHistoryServerApi(Api):
-  pass
-
-
-class ImpalaApi(Api):
-  pass
-
-
-# Batch
-
-class BatchApi(Api):
-
-  def apps(self):
-    oozie_api = get_oozie(self.user)
-    kwargs = {'cnt': OOZIE_JOBS_COUNT.get(), 'filters': []}
-    wf_list = oozie_api.get_workflows(**kwargs)
-
-    return [{'id': app.id, 'status': app.status} for app in wf_list.jobs]
-
-  def app(self, appid):
-    oozie_api = get_oozie(self.user)
-    workflow = oozie_api.get_job(jobid=appid)
-
-    return {'id': workflow.id, 'name': workflow.appName, 'status': workflow.status}
-
-
-# Schedule
-
-class ScheduleApi(Api):
-
-  def apps(self):
-    oozie_api = get_oozie(self.user)
-    kwargs = {'cnt': OOZIE_JOBS_COUNT.get(), 'filters': []}
-    wf_list = oozie_api.get_coordinators(**kwargs)
-
-    return [{'id': app.id, 'status': app.status} for app in wf_list.jobs]
-
-  def app(self, appid):
-    oozie_api = get_oozie(self.user)
-    workflow = oozie_api.get_coordinator(jobid=appid)
-
-    return {'id': workflow.coordJobId, 'name': workflow.coordJobName, 'status': workflow.status}
-
-
-# History
-
-class HueHistoryApi(Api):
-
-  def apps(self): return []
-