瀏覽代碼

HUE-801 [core] Added a new exception for thrift transport exception handling

abec 13 年之前
父節點
當前提交
0201afac1f

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

@@ -25,7 +25,8 @@ import gzip
 from django.core import urlresolvers
 from django.core import urlresolvers
 
 
 from desktop.lib import django_mako, i18n
 from desktop.lib import django_mako, i18n
-from desktop.lib.django_util import render, PopupException
+from desktop.lib.django_util import render
+from desktop.lib.exceptions import PopupException
 from desktop.lib.django_forms import MultiForm
 from desktop.lib.django_forms import MultiForm
 from hadoop.fs import hadoopfs
 from hadoop.fs import hadoopfs
 
 

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

@@ -24,7 +24,7 @@ from enum import Enum
 from django.db import models
 from django.db import models
 from django.contrib.auth.models import User
 from django.contrib.auth.models import User
 
 
-from desktop.lib.django_util import PopupException
+from desktop.lib.exceptions import PopupException
 from beeswaxd.ttypes import QueryState
 from beeswaxd.ttypes import QueryState
 
 
 from django.utils.translation import ugettext as _
 from django.utils.translation import ugettext as _

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

@@ -32,7 +32,7 @@ from desktop.lib import django_mako
 from desktop.lib.paginator import Paginator
 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 copy_query_dict, format_preserving_redirect, render
 from desktop.lib.django_util import login_notrequired, get_desktop_uri_prefix
 from desktop.lib.django_util import login_notrequired, get_desktop_uri_prefix
-from desktop.lib.django_util import PopupException
+from desktop.lib.exceptions import PopupException
 
 
 from hadoop.fs.exceptions import WebHdfsException
 from hadoop.fs.exceptions import WebHdfsException
 from jobsub.parameterization import find_variables, substitute_variables
 from jobsub.parameterization import find_variables, substitute_variables

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

@@ -47,8 +47,8 @@ from avro import datafile, io
 
 
 from desktop.lib import i18n, paginator
 from desktop.lib import i18n, paginator
 from desktop.lib.conf import coerce_bool
 from desktop.lib.conf import coerce_bool
-from desktop.lib.django_util import make_absolute, render, render_json
-from desktop.lib.django_util import PopupException, format_preserving_redirect
+from desktop.lib.django_util import make_absolute, render, render_json, format_preserving_redirect
+from desktop.lib.exceptions import PopupException
 from filebrowser.lib.rwx import filetype, rwx
 from filebrowser.lib.rwx import filetype, rwx
 from filebrowser.lib import xxd
 from filebrowser.lib import xxd
 from filebrowser.forms import RenameForm, UploadForm, MkDirForm, RmDirForm, RmTreeForm,\
 from filebrowser.forms import RenameForm, UploadForm, MkDirForm, RmDirForm, RmTreeForm,\

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

@@ -15,7 +15,8 @@
 # See the License for the specific language governing permissions and
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from desktop.lib.django_util import render, PopupException
+from desktop.lib.django_util import render
+from desktop.lib.exceptions import PopupException
 from desktop import appmanager
 from desktop import appmanager
 from hadoop.fs import LocalSubFileSystem
 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 hadoop.api.jobtracker.ttypes import JobNotFoundException
 
 
 from django.utils.translation import ugettext as _
 from django.utils.translation import ugettext as _
-from desktop.lib.django_util import PopupException
+from desktop.lib.exceptions import PopupException
 
 
 LOGGER = logging.getLogger(__name__)
 LOGGER = logging.getLogger(__name__)
 
 

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

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

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

@@ -15,7 +15,7 @@
 # See the License for the specific language governing permissions and
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # limitations under the License.
 
 
-from desktop.lib.django_util import StructuredException
+from desktop.lib.exceptions import StructuredException
 
 
 from jobsubd.ttypes import SubmissionError
 from jobsubd.ttypes import SubmissionError
 
 

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

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

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

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

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

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

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

@@ -25,7 +25,8 @@ from django.http import HttpResponse
 from django.utils.functional import wraps
 from django.utils.functional import wraps
 from django.utils.translation import ugettext as _
 from django.utils.translation import ugettext as _
 
 
-from desktop.lib.django_util import render, PopupException
+from desktop.lib.django_util import render
+from desktop.lib.exceptions import PopupException
 from desktop.lib.rest.http_client import RestException
 from desktop.lib.rest.http_client import RestException
 from desktop.log.access import access_warn
 from desktop.log.access import access_warn
 from liboozie.oozie_api import get_oozie
 from liboozie.oozie_api import get_oozie

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

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

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

@@ -30,7 +30,7 @@ from urlparse import urlparse, urlunparse
 
 
 from django.core import urlresolvers
 from django.core import urlresolvers
 from django.http import HttpResponse
 from django.http import HttpResponse
-from desktop.lib.django_util import MessageException
+from desktop.lib.exceptions import MessageException
 
 
 from proxy import conf
 from proxy import conf
 
 

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

@@ -54,7 +54,7 @@ import logging
 from django.db import models
 from django.db import models
 from django.contrib.auth import models as auth_models
 from django.contrib.auth import models as auth_models
 from desktop import appmanager
 from desktop import appmanager
-from desktop.lib.django_util import PopupException
+from desktop.lib.exceptions import PopupException
 from enum import Enum
 from enum import Enum
 
 
 import useradmin.conf
 import useradmin.conf

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

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

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

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

+ 0 - 55
desktop/core/src/desktop/lib/django_util.py

@@ -307,61 +307,6 @@ def get_app_nice_name(app_name):
   except:
   except:
     return app_name
     return app_name
 
 
-class StructuredException(Exception):
-  """
-  Many exceptions in this application are a string and some data
-  that applies to.  The middleware will take these exceptions
-  and render them.
-  """
-  def __init__(self, code, message, data=None, error_code=500):
-    Exception.__init__(self, message)
-    self.code = code
-    self.message = message
-    self.data = data
-    self.error_code = error_code
-
-  def __str__(self):
-    return "%s (code %s): %s" % (self.message, self.code, repr(self.data))
-
-  @property
-  def response_data(self):
-    return dict(code=self.code,
-                message=self.message,
-                data=self.data)
-
-class MessageException(StructuredException):
-  """
-  Explicitly specified msg/filename exception.
-
-  This has been superceded by PopupException.
-  """
-  def __init__(self, msg, filename=None, error_code=500):
-    StructuredException.__init__(self,
-      code="GENERIC_MESSAGE",
-      message=msg,
-      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
-
-  def response(self, request):
-    data = dict(title=self.title, message=self.message, detail=self.detail)
-    if not request.ajax:
-      data['request'] = request
-    response = render("popup_error.mako", request, data)
-    response.status_code = self.error_code
-    return response
-
 class TruncatingModel(models.Model):
 class TruncatingModel(models.Model):
   """
   """
   Abstract class which truncates Text and Char fields to their configured
   Abstract class which truncates Text and Char fields to their configured

+ 2 - 2
desktop/core/src/desktop/lib/django_util_test.py

@@ -25,7 +25,7 @@ from desktop.lib.django_test_util import configure_django_for_test, create_table
 from desktop.lib.django_util import reverse_with_get, timesince, humanize_duration
 from desktop.lib.django_util import reverse_with_get, timesince, humanize_duration
 configure_django_for_test()
 configure_django_for_test()
 
 
-from desktop.lib import django_util
+from desktop.lib import django_util, exceptions
 from django.db import models
 from django.db import models
 
 
 class TestModel(models.Model):
 class TestModel(models.Model):
@@ -135,7 +135,7 @@ class TestDjangoUtil(object):
     msg = "b0rked file"
     msg = "b0rked file"
     the_file = "foobar"
     the_file = "foobar"
     try:
     try:
-      raise django_util.MessageException(msg, the_file)
+      raise exceptions.MessageException(msg, the_file)
     except Exception, e:
     except Exception, e:
       assert_equal(msg, e.message)
       assert_equal(msg, e.message)
       assert_equal(the_file, e.data['filename'])
       assert_equal(the_file, e.data['filename'])

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

@@ -0,0 +1,83 @@
+#!/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.
+
+from thrift.transport.TTransport import TTransportException
+
+from desktop.lib.django_util import render
+
+
+class StructuredException(Exception):
+  """
+  Many exceptions in this application are a string and some data
+  that applies to.  The middleware will take these exceptions
+  and render them.
+  """
+  def __init__(self, code, message, data=None, error_code=500):
+    Exception.__init__(self, message)
+    self.code = code
+    self.message = message
+    self.data = data
+    self.error_code = error_code
+
+  def __str__(self):
+    return "%s (code %s): %s" % (self.message, self.code, repr(self.data))
+
+  @property
+  def response_data(self):
+    return dict(code=self.code,
+                message=self.message,
+                data=self.data)
+
+class MessageException(StructuredException):
+  """
+  Explicitly specified msg/filename exception.
+
+  This has been superceded by PopupException.
+  """
+  def __init__(self, msg, filename=None, error_code=500):
+    StructuredException.__init__(self,
+      code="GENERIC_MESSAGE",
+      message=msg,
+      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
+
+  def response(self, request):
+    data = dict(title=self.title, message=self.message, detail=self.detail)
+    if not request.ajax:
+      data['request'] = request
+    response = 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
+    kwargs['message'] = ex.message
+    kwargs['code'] = "THRIFTTRANSPORT"
+    StructuredException.__init__(self, *args, **kwargs)

+ 3 - 2
desktop/core/src/desktop/lib/thrift_util.py

@@ -17,7 +17,7 @@
 #
 #
 # Utilities for Thrift
 # Utilities for Thrift
 import desktop.lib.eventlet_util
 import desktop.lib.eventlet_util
-from desktop.lib.django_util import StructuredException
+from desktop.lib.exceptions import StructuredException
 
 
 import Queue
 import Queue
 import logging
 import logging
@@ -33,6 +33,7 @@ from thrift.transport.TSocket import TSocket
 from thrift.transport.TTransport import TBufferedTransport, TMemoryBuffer,\
 from thrift.transport.TTransport import TBufferedTransport, TMemoryBuffer,\
                                         TTransportException
                                         TTransportException
 from thrift.protocol.TBinaryProtocol import TBinaryProtocol
 from thrift.protocol.TBinaryProtocol import TBinaryProtocol
+from desktop.lib.exceptions import StructuredThriftTransportException
 from desktop.lib.thrift_sasl import TSaslClientTransport
 from desktop.lib.thrift_sasl import TSaslClientTransport
 
 
 # The maximum depth that we will recurse through a "jsonable" structure
 # The maximum depth that we will recurse through a "jsonable" structure
@@ -294,7 +295,7 @@ class PooledClient(object):
             raise StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502)
             raise StructuredException('THRIFTSOCKET', str(e), data=None, error_code=502)
           except TTransportException, e:
           except TTransportException, e:
             logging.info("Thrift saw a transport exception: " + str(e), exc_info=False)
             logging.info("Thrift saw a transport exception: " + str(e), exc_info=False)
-            raise StructuredException('THRIFTTRANSPORT', str(e), data=None, error_code=502)
+            raise StructuredThriftTransportException(e, error_code=502)
           except Exception, e:
           except Exception, e:
             # Stack tends to be only noisy here.
             # Stack tends to be only noisy here.
             logging.info("Thrift saw exception: " + str(e), exc_info=False)
             logging.info("Thrift saw exception: " + str(e), exc_info=False)

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

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

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

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

+ 1 - 1
desktop/libs/hadoop/src/hadoop/fs/exceptions.py

@@ -20,7 +20,7 @@ try:
 except:
 except:
   import simplejson as json
   import simplejson as json
 
 
-from desktop.lib.django_util import StructuredException
+from desktop.lib.exceptions import StructuredException
 from desktop.lib.rest.http_client import RestException
 from desktop.lib.rest.http_client import RestException
 
 
 
 

+ 1 - 1
desktop/libs/hadoop/src/hadoop/job_tracker.py

@@ -19,7 +19,7 @@
 
 
 from desktop.lib import thrift_util
 from desktop.lib import thrift_util
 from desktop.lib.conf import validate_port
 from desktop.lib.conf import validate_port
-from desktop.lib.django_util import StructuredException
+from desktop.lib.exceptions import StructuredException
 from desktop.lib.thrift_util import fixup_enums
 from desktop.lib.thrift_util import fixup_enums
 
 
 from hadoop.api.jobtracker import Jobtracker
 from hadoop.api.jobtracker import Jobtracker

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

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

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

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