فهرست منبع

HUE-955 [core] Remove circular reference to exceptions

abec 13 سال پیش
والد
کامیت
68cc5f34d2

+ 1 - 1
apps/beeswax/src/beeswax/create_table.py

@@ -28,7 +28,7 @@ from django.utils.translation import ugettext as _
 from desktop.context_processors import get_app_name
 from desktop.lib import django_mako, i18n
 from desktop.lib.django_util import render
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.django_forms import MultiForm
 from hadoop.fs import hadoopfs
 

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

@@ -27,7 +27,7 @@ from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
 from enum import Enum
 
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 
 from beeswax.conf import SERVER_INTERFACE
 from beeswaxd.ttypes import QueryHandle as BeeswaxdQueryHandle, QueryState

+ 1 - 1
apps/beeswax/src/beeswax/views.py

@@ -34,7 +34,7 @@ from desktop.context_processors import get_app_name
 from desktop.lib.paginator import Paginator
 from desktop.lib.django_util import copy_query_dict, format_preserving_redirect, render
 from desktop.lib.django_util import login_notrequired, get_desktop_uri_prefix
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 
 from hadoop.fs.exceptions import WebHdfsException
 from jobsub.parameterization import find_variables, substitute_variables

+ 1 - 1
apps/filebrowser/src/filebrowser/views.py

@@ -51,7 +51,7 @@ from avro import datafile, io
 from desktop.lib import i18n, paginator
 from desktop.lib.conf import coerce_bool
 from desktop.lib.django_util import make_absolute, render, render_json, format_preserving_redirect
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from filebrowser.lib.archives import archive_factory
 from filebrowser.lib.rwx import filetype, rwx
 from filebrowser.lib import xxd

+ 1 - 1
apps/help/src/help/views.py

@@ -16,7 +16,7 @@
 # limitations under the License.
 
 from desktop.lib.django_util import render
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop import appmanager
 from hadoop.fs import LocalSubFileSystem
 

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

@@ -33,7 +33,7 @@ import hadoop.api.jobtracker.ttypes as ttypes
 from hadoop.api.jobtracker.ttypes import JobNotFoundException
 
 from django.utils.translation import ugettext as _
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 
 LOGGER = logging.getLogger(__name__)
 

+ 2 - 1
apps/jobbrowser/src/jobbrowser/views.py

@@ -25,7 +25,8 @@ from urllib import quote_plus
 
 from desktop.lib.paginator import Paginator
 from desktop.lib.django_util import render_json, render, copy_query_dict
-from desktop.lib.exceptions import PopupException, MessageException
+from desktop.lib.exceptions import MessageException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.conf import coerce_bool
 
 from django.http import HttpResponseRedirect

+ 1 - 1
apps/jobsub/src/jobsub/submit.py

@@ -23,7 +23,7 @@ import errno
 import logging
 
 from desktop.lib import django_mako
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 import hadoop.cluster
 from hadoop.fs.hadoopfs import Hdfs
 

+ 1 - 1
apps/jobsub/src/jobsub/views.py

@@ -35,7 +35,7 @@ from django.core import urlresolvers
 from django.shortcuts import redirect
 
 from desktop.lib.django_util import render, extract_field_data
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import RestException
 from desktop.log.access import access_warn
 

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

@@ -28,7 +28,7 @@ from django.utils.functional import curry, wraps
 from django.utils.translation import ugettext as _
 
 from desktop.lib.django_util import render, extract_field_data
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import RestException
 from hadoop.fs.exceptions import WebHdfsException
 from jobsub.models import OozieDesign

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

@@ -35,7 +35,7 @@ from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
 from desktop.log.access import access_warn
 from desktop.lib import django_mako
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from hadoop.fs.exceptions import WebHdfsException
 
 from hadoop.fs.hadoopfs import Hdfs

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

@@ -29,7 +29,7 @@ from django.core.urlresolvers import reverse
 from django.shortcuts import redirect
 
 from desktop.lib.django_util import render
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import RestException
 from desktop.log.access import access_warn
 from liboozie.oozie_api import get_oozie

+ 1 - 1
apps/oozie/src/oozie/views/editor.py

@@ -31,7 +31,7 @@ from django.utils.functional import curry
 from django.utils.translation import ugettext as _
 
 from desktop.lib.django_util import render, extract_field_data
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import RestException
 from hadoop.fs.exceptions import WebHdfsException
 from jobsub.models import OozieDesign

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

@@ -57,7 +57,7 @@ from django.contrib.auth import models as auth_models
 from django.utils.translation import ugettext_lazy as _t
 
 from desktop import appmanager
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 
 import useradmin.conf
 

+ 1 - 1
apps/useradmin/src/useradmin/views.py

@@ -28,7 +28,7 @@ import django.contrib.auth.forms
 from django import forms
 from django.contrib.auth.models import User, Group
 from desktop.lib.django_util import get_username_re_rule, get_groupname_re_rule, render
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from django.core.urlresolvers import reverse
 from django.forms.util import ErrorList
 from django.shortcuts import redirect

+ 1 - 1
desktop/core/src/desktop/decorators.py

@@ -16,7 +16,7 @@
 # limitations under the License.
 
 import logging
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from django.utils.translation import ugettext as _
 
 try:

+ 0 - 27
desktop/core/src/desktop/lib/exceptions.py

@@ -20,9 +20,6 @@ import traceback
 
 from thrift.transport.TTransport import TTransportException
 
-# Need full import statement
-import desktop.lib.django_util
-
 
 class StructuredException(Exception):
   """
@@ -64,30 +61,6 @@ class MessageException(StructuredException):
       data=dict(filename=filename),
       error_code=error_code)
 
-class PopupException(Exception):
-  """
-  Middleware will render this exception; and the template
-  renders it as a pop-up.
-  """
-  def __init__(self, message, title="Error", detail=None, error_code=500):
-    Exception.__init__(self, message)
-    self.message = message
-    self.title = title
-    self.detail = detail
-    self.error_code = error_code
-
-    # Traceback is only relevant if an exception was thrown, caught, and we reraise with this exception.
-    (type, value, tb) = sys.exc_info()
-    self.traceback = traceback.extract_tb(tb)
-
-  def response(self, request):
-    data = dict(title=self.title, message=self.message, detail=self.detail, traceback=self.traceback)
-    if not request.ajax:
-      data['request'] = request
-    response = desktop.lib.django_util.render("popup_error.mako", request, data)
-    response.status_code = self.error_code
-    return response
-
 class StructuredThriftTransportException(StructuredException, TTransportException):
   def __init__(self, ex, *args, **kwargs):
     kwargs['data'] = ex

+ 50 - 0
desktop/core/src/desktop/lib/exceptions_renderable.py

@@ -0,0 +1,50 @@
+#!/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.
+"""
+These methods should never be placed in 'desktop.lib.exceptions'.
+This file exists to remove circular reference caused by importing django_util.
+"""
+
+import sys
+import traceback
+
+# Need full import statement
+import desktop.lib.django_util
+
+class PopupException(Exception):
+  """
+  Middleware will render this exception; and the template
+  renders it as a pop-up.
+  """
+  def __init__(self, message, title="Error", detail=None, error_code=500):
+    Exception.__init__(self, message)
+    self.message = message
+    self.title = title
+    self.detail = detail
+    self.error_code = error_code
+
+    # Traceback is only relevant if an exception was thrown, caught, and we reraise with this exception.
+    (type, value, tb) = sys.exc_info()
+    self.traceback = traceback.extract_tb(tb)
+
+  def response(self, request):
+    data = dict(title=self.title, message=self.message, detail=self.detail, traceback=self.traceback)
+    if not request.ajax:
+      data['request'] = request
+    response = desktop.lib.django_util.render("popup_error.mako", request, data)
+    response.status_code = self.error_code
+    return response

+ 4 - 6
desktop/core/src/desktop/lib/thrift_util.py

@@ -16,7 +16,6 @@
 # limitations under the License.
 #
 # Utilities for Thrift
-import desktop.lib.eventlet_util
 
 import Queue
 import logging
@@ -32,9 +31,8 @@ from thrift.transport.TSocket import TSocket
 from thrift.transport.TTransport import TBufferedTransport, TMemoryBuffer,\
                                         TTransportException
 from thrift.protocol.TBinaryProtocol import TBinaryProtocol
-from desktop.lib.exceptions import StructuredThriftTransportException
 from desktop.lib.thrift_sasl import TSaslClientTransport
-import desktop.lib.exceptions as exceptions
+from desktop.lib.exceptions import StructuredException, StructuredThriftTransportException
 
 # The maximum depth that we will recurse through a "jsonable" structure
 # while converting to thrift. This prevents us from infinite recursion
@@ -286,13 +284,13 @@ class PooledClient(object):
           except TApplicationException, e:
             # Unknown thrift exception... typically IO errors
             logging.info("Thrift saw an application exception: " + str(e), exc_info=False)
-            raise exceptions.StructuredException('THRIFTAPPLICATION', str(e), data=None, error_code=502)
+            raise StructuredException('THRIFTAPPLICATION', str(e), data=None, error_code=502)
           except socket.error, e:
             logging.info("Thrift saw a socket error: " + str(e), exc_info=False)
-            raise exceptions.StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502)
+            raise StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502)
           except TTransportException, e:
             logging.info("Thrift saw a transport exception: " + str(e), exc_info=False)
-            raise exceptions.StructuredThriftTransportException(e, error_code=502)
+            raise StructuredThriftTransportException(e, error_code=502)
           except Exception, e:
             # Stack tends to be only noisy here.
             logging.info("Thrift saw exception: " + str(e), exc_info=False)

+ 2 - 1
desktop/core/src/desktop/middleware.py

@@ -36,7 +36,8 @@ import django.views.generic.simple
 import desktop.conf
 from desktop.lib import apputil, i18n
 from desktop.lib.django_util import render, render_json, is_jframe_request
-from desktop.lib.exceptions import PopupException, StructuredException
+from desktop.lib.exceptions import StructuredException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.log.access import access_log, log_page_hit
 from desktop import appmanager
 from hadoop import cluster

+ 1 - 1
desktop/core/src/desktop/tests.py

@@ -31,7 +31,7 @@ import desktop.conf
 import logging
 import time
 from desktop.lib.django_util import TruncatingModel
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 import desktop.views as views
 import proxy.conf
 

+ 1 - 1
desktop/libs/liboozie/src/liboozie/submittion.py

@@ -21,7 +21,7 @@ import time
 
 from django.utils.translation import ugettext as _
 
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from hadoop import cluster
 from hadoop.fs.hadoopfs import Hdfs
 from liboozie.oozie_api import get_oozie

+ 1 - 1
desktop/libs/liboozie/src/liboozie/types.py

@@ -28,7 +28,7 @@ from cStringIO import StringIO
 from time import mktime
 
 from desktop.lib import i18n
-from desktop.lib.exceptions import PopupException
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.log.access import access_warn
 
 import hadoop.confparse