Exemple #1
0
def alter_database(request, database):
  response = {'status': -1, 'data': ''}

  source_type = request.POST.get('source_type', 'hive')
  cluster = json.loads(request.POST.get('cluster', '{}'))

  db = _get_db(user=request.user, source_type=source_type, cluster=cluster)

  try:
    properties = request.POST.get('properties')

    if not properties:
      raise PopupException(_("Alter database requires a properties value of key-value pairs."))

    properties = json.loads(properties)
    db.alter_database(database, properties=properties)

    db_metadata = db.get_database(database)
    db_metadata['hdfs_link'] = location_to_url(db_metadata['location'])
    response['status'] = 0
    response['data'] = db_metadata
  except Exception as ex:
    response['status'] = 1
    response['data'] = _("Failed to alter database `%s`: %s") % (database, ex)

  return JsonResponse(response)
Exemple #2
0
def get_database_metadata(request, database):
    response = {'status': -1, 'data': ''}

    source_type = request.POST.get('source_type', 'hive')
    cluster = json.loads(request.POST.get('cluster', '{}'))

    db = _get_db(user=request.user, source_type=source_type, cluster=cluster)

    try:
        db_metadata = db.get_database(database)
        response['status'] = 0
        if not db_metadata.get('owner_name'):
            db_metadata['owner_name'] = ''
        if not db_metadata.get('owner_type'):
            db_metadata['owner_type'] = ''
        if not db_metadata.get('parameters'):
            db_metadata['parameters'] = ''
        db_metadata['hdfs_link'] = location_to_url(db_metadata['location'])
        response['data'] = db_metadata
    except Exception as ex:
        response['status'] = 1
        response['data'] = _("Cannot get metadata for database %s: %s") % (
            database, ex)

    return JsonResponse(response)
Exemple #3
0
 def _replace_hdfs_link(self, is_embeddable=False, match=None):
     try:
         return '<a href="%s">%s</a>' % (location_to_url(
             match.group(0), strict=False,
             is_embeddable=is_embeddable), match.group(0))
     except:
         LOG.exception('failed to replace hdfs links: %s' %
                       (match.groups(), ))
         return match.group(0)
Exemple #4
0
def browse_partition(request, database, table, partition_spec):
  db = _get_db(user=request.user)
  try:
    decoded_spec = urllib.unquote(partition_spec)
    partition_table = db.describe_partition(database, table, decoded_spec)
    uri_path = location_to_url(partition_table.path_location)
    if request.GET.get("format", "html") == "json":
      return JsonResponse({'uri_path': uri_path})
    else:
      return redirect(uri_path)
  except Exception, e:
    raise PopupException(_('Cannot browse partition'), detail=e.message)
Exemple #5
0
def get_database_metadata(request, database):
  response = {'status': -1, 'data': ''}
  source_type = request.POST.get('source_type', 'hive')
  db = _get_db(user=request.user, source_type=source_type)

  try:
    db_metadata = db.get_database(database)
    response['status'] = 0
    db_metadata['hdfs_link'] = location_to_url(db_metadata['location'])
    response['data'] = db_metadata
  except Exception, ex:
    response['status'] = 1
    response['data'] = _("Cannot get metadata for database %s: %s") % (database, ex)
Exemple #6
0
def browse_partition(request, database, table, partition_spec):
  cluster = json.loads(request.POST.get('cluster', '{}'))

  db = _get_db(user=request.user, cluster=cluster)
  try:
    decoded_spec = urllib.unquote(partition_spec)
    partition_table = db.describe_partition(database, table, decoded_spec)
    uri_path = location_to_url(partition_table.path_location)
    if request.GET.get("format", "html") == "json":
      return JsonResponse({'uri_path': uri_path})
    else:
      return redirect(uri_path)
  except Exception, e:
    raise PopupException(_('Cannot browse partition'), detail=e.message)
Exemple #7
0
def get_database_metadata(request, database):
  response = {'status': -1, 'data': ''}

  source_type = request.POST.get('source_type', 'hive')
  cluster = json.loads(request.POST.get('cluster', '{}'))

  db = _get_db(user=request.user, source_type=source_type, cluster=cluster)

  try:
    db_metadata = db.get_database(database)
    response['status'] = 0
    if not db_metadata.get('owner_name'):
      db_metadata['owner_name'] = ''
    if not db_metadata.get('owner_type'):
      db_metadata['owner_type'] = ''
    if not db_metadata.get('parameters'):
      db_metadata['parameters'] = ''
    db_metadata['hdfs_link'] = location_to_url(db_metadata['location'])
    response['data'] = db_metadata
  except Exception, ex:
    response['status'] = 1
    response['data'] = _("Cannot get metadata for database %s: %s") % (database, ex)
Exemple #8
0
def alter_database(request, database):
  response = {'status': -1, 'data': ''}

  source_type = request.POST.get('source_type', 'hive')
  cluster = json.loads(request.POST.get('cluster', '{}'))

  db = _get_db(user=request.user, source_type=source_type, cluster=cluster)

  try:
    properties = request.POST.get('properties')

    if not properties:
      raise PopupException(_("Alter database requires a properties value of key-value pairs."))

    properties = json.loads(properties)
    db.alter_database(database, properties=properties)

    db_metadata = db.get_database(database)
    db_metadata['hdfs_link'] = location_to_url(db_metadata['location'])
    response['status'] = 0
    response['data'] = db_metadata
  except Exception, ex:
    response['status'] = 1
    response['data'] = _("Failed to alter database `%s`: %s") % (database, ex)
Exemple #9
0
 def hdfs_link(self):
   return location_to_url(self.path_location)
Exemple #10
0
 def _replace_hdfs_link(self, is_embeddable=False, match=None):
   try:
     return '<a href="%s">%s</a>' % (location_to_url(match.group(0), strict=False, is_embeddable=is_embeddable), match.group(0))
   except:
     LOG.exception('failed to replace hdfs links: %s' % (match.groups(),))
     return match.group(0)
Exemple #11
0
 def hdfs_link(self):
   return location_to_url(self.path_location)