Example #1
0
def commonheader(title, section, user, padding="90px"):
  """
  Returns the rendered common header
  """
  current_app = None
  other_apps = []
  if user.is_authenticated():
    apps = appmanager.get_apps(user)
    apps_list = appmanager.get_apps_dict(user)
    for app in apps:
      if app.display_name not in [
          'beeswax', 'impala', 'pig', 'jobsub', 'jobbrowser', 'metastore', 'hbase', 'sqoop', 'oozie', 'filebrowser',
          'useradmin', 'search', 'help', 'about', 'zookeeper', 'proxy', 'rdbms', 'spark']:
        other_apps.append(app)
      if section == app.display_name:
        current_app = app
  else:
    apps_list = []

  return django_mako.render_to_string("common_header.mako", {
    'current_app': current_app,
    'apps': apps_list,
    'other_apps': other_apps,
    'title': title,
    'section': section,
    'padding': padding,
    'user': user
  })
Example #2
0
def commonheader(title, section, user, padding="90px"):
    """
  Returns the rendered common header
  """
    current_app = None
    other_apps = []
    if user.is_authenticated():
        apps = appmanager.get_apps(user)
        apps_list = appmanager.get_apps_dict(user)
        for app in apps:
            if app.display_name not in [
                    'beeswax', 'impala', 'pig', 'jobsub', 'jobbrowser',
                    'metastore', 'hbase', 'sqoop', 'oozie', 'filebrowser',
                    'useradmin', 'search', 'help', 'about', 'zookeeper',
                    'proxy', 'rdbms', 'spark'
            ]:
                other_apps.append(app)
            if section == app.display_name:
                current_app = app
    else:
        apps_list = []

    return django_mako.render_to_string(
        "common_header.mako", {
            'current_app': current_app,
            'apps': apps_list,
            'other_apps': other_apps,
            'title': title,
            'section': section,
            'padding': padding,
            'user': user,
            'is_demo': desktop.conf.DEMO_ENABLED.get()
        })
Example #3
0
def home2(request):
  apps = appmanager.get_apps_dict(request.user)

  return render('home2.mako', request, {
    'apps': apps,
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })
Example #4
0
File: views.py Project: prateek/hue
def home(request):
    docs = itertools.chain(
        Document.objects.get_docs(request.user).order_by("-last_modified").exclude(tags__tag__in=["history"])[:500],
        Document.objects.get_docs(request.user).order_by("-last_modified").filter(tags__tag__in=["history"])[:100],
    )
    docs = list(docs)
    trash = DocumentTag.objects.get_trash_tag(request.user)
    history = DocumentTag.objects.get_history_tag(request.user)
    tags = list(
        set(
            [tag for doc in docs for tag in doc.tags.all()]
            + [tag for tag in DocumentTag.objects.get_tags(user=request.user)]
        )
    )  # List of all personal and share tags

    apps = appmanager.get_apps_dict(request.user)

    return render(
        "home.mako",
        request,
        {
            "apps": apps,
            "documents": augment_docs(docs, request.user),
            "json_documents": json.dumps(massaged_documents_for_json(docs, request.user)),
            "tags": augment_tags(tags, request.user),
            "json_tags": json.dumps(massaged_tags_for_json(tags, request.user)),
        },
    )
Example #5
0
def get_engines(user):
  engines = []
  apps = get_apps_dict(user=user)
  settings = get_properties()

  if 'search' in apps:
    engines.append({
      'name': _('Index (Solr)'),
      'type': 'solr',
      'analytics': settings.get('solr') and settings['solr'].get('analytics'),
      'nesting': settings.get('solr') and settings['solr'].get('nesting'),
    })

  if HAS_SQL_ENABLED.get() and ('beeswax' in apps or 'rdbms' in apps):
    engines += [{
          'name': _('Table (%s)') % interpreter['name'],
          'type': interpreter['type'],
          'async': interpreter['interface'] == 'hiveserver2',
          'analytics': settings.get('sql') and settings['sql'].get('analytics'),
          'nesting': settings.get('sql') and settings['sql'].get('nesting'),
      }
      for interpreter in get_ordered_interpreters(user) if interpreter['interface'] in ('hiveserver2', 'jdbc', 'rdbms')
    ]

  return engines
Example #6
0
def hue(request):
    apps = appmanager.get_apps_dict(request.user)

    return render(
        'hue.mako', request, {
            'apps':
            apps,
            'tours_and_tutorials':
            Settings.get_settings().tours_and_tutorials,
            'interpreters':
            get_ordered_interpreters(request.user),
            'is_s3_enabled':
            is_s3_enabled() and has_s3_access(request.user),
            'is_ldap_setup':
            'desktop.auth.backend.LdapBackend'
            in desktop.conf.AUTH.BACKEND.get(),
            'leaflet': {
                'layer': desktop.conf.LEAFLET_TILE_LAYER.get(),
                'attribution':
                desktop.conf.LEAFLET_TILE_LAYER_ATTRIBUTION.get()
            },
            'is_demo':
            desktop.conf.DEMO_ENABLED.get(),
            'banner_message':
            get_banner_message(request),
            'cluster_config':
            ClusterConfig(request.user)
        })
Example #7
0
File: views.py Project: uk0/hue
def home2(request, is_embeddable=False):
  apps = appmanager.get_apps_dict(request.user)

  return render('home2.mako', request, {
    'apps': apps,
    'is_embeddable': request.GET.get('is_embeddable', False)
  })
Example #8
0
def hue(request):
    apps = appmanager.get_apps_dict(request.user)

    return render(
        'hue.mako', request, {
            'apps':
            apps,
            'interpreters':
            get_ordered_interpreters(request.user),
            'is_s3_enabled':
            is_s3_enabled() and has_s3_access(request.user),
            'is_ldap_setup':
            'desktop.auth.backend.LdapBackend'
            in desktop.conf.AUTH.BACKEND.get(),
            'leaflet': {
                'layer': desktop.conf.LEAFLET_TILE_LAYER.get(),
                'attribution':
                desktop.conf.LEAFLET_TILE_LAYER_ATTRIBUTION.get()
            },
            'is_demo':
            desktop.conf.DEMO_ENABLED.get(),
            'banner_message':
            get_banner_message(request),
            'cluster_config':
            ClusterConfig(request.user),
            'user_preferences':
            dict((x.key, x.value)
                 for x in UserPreferences.objects.filter(user=request.user))
        })
Example #9
0
File: views.py Project: uk0/hue
def hue(request):
  apps = appmanager.get_apps_dict(request.user)
  current_app, other_apps, apps_list = _get_apps(request.user, '')
  default_cluster_index, default_cluster_interface = Cluster(request.user).get_list_interface_indexes()
  clusters = get_clusters().values()

  return render('hue.mako', request, {
    'apps': apps,
    'other_apps': other_apps,
    'is_s3_enabled': is_s3_enabled() and has_s3_access(request.user),
    'is_adls_enabled': is_adls_enabled() and has_adls_access(request.user),
    'is_ldap_setup': 'desktop.auth.backend.LdapBackend' in desktop.conf.AUTH.BACKEND.get(),
    'leaflet': {
      'layer': desktop.conf.LEAFLET_TILE_LAYER.get(),
      'attribution': desktop.conf.LEAFLET_TILE_LAYER_ATTRIBUTION.get(),
      'map_options': json.dumps(desktop.conf.LEAFLET_MAP_OPTIONS.get()),
      'layer_options': json.dumps(desktop.conf.LEAFLET_TILE_LAYER_OPTIONS.get()),
    },
    'is_demo': desktop.conf.DEMO_ENABLED.get(),
    'banner_message': get_banner_message(request),
    'user_preferences': dict((x.key, x.value) for x in UserPreferences.objects.filter(user=request.user)),
    'cluster': clusters[0]['type'] if clusters else None,
    'clusters_config_json': json.dumps(clusters),
    'default_cluster_index': default_cluster_index,
    'default_cluster_interface': default_cluster_interface
  })
Example #10
0
def ko_metastore(request):
  apps = appmanager.get_apps_dict(request.user)

  return render('ko_metastore.mako', request, {
    'apps': apps,
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })
Example #11
0
File: models.py Project: hwl-py/hue
  def icon(self):
    apps = appmanager.get_apps_dict()

    try:
      if self.extra == 'workflow2':
        return staticfiles_storage.url('oozie/art/icon_oozie_workflow_48.png')
      elif self.extra == 'coordinator2':
        return staticfiles_storage.url('oozie/art/icon_oozie_coordinator_48.png')
      elif self.extra == 'bundle2':
        return staticfiles_storage.url('oozie/art/icon_oozie_bundle_48.png')
      elif self.extra == 'notebook':
        return staticfiles_storage.url('spark/art/icon_spark_48.png')
      elif self.extra.startswith('search'):
        return staticfiles_storage.url('search/art/icon_search_48.png')
      elif self.content_type.app_label == 'beeswax':
        if self.extra == '0':
          return staticfiles_storage.url(apps['beeswax'].icon_path)
        elif self.extra == '3':
          return staticfiles_storage.url(apps['spark'].icon_path)
        else:
          return staticfiles_storage.url(apps['impala'].icon_path)
      elif self.content_type.app_label == 'oozie':
        if self.extra == 'jobsub':
          return staticfiles_storage.url(apps['jobsub'].icon_path)
        else:
          return staticfiles_storage.url(self.content_type.model_class().ICON)
      elif self.content_type.app_label in apps:
        return staticfiles_storage.url(apps[self.content_type.app_label].icon_path)
      else:
        return staticfiles_storage.url('desktop/art/icon_hue_48.png')
    except Exception, e:
      LOG.warn(force_unicode(e))
      return staticfiles_storage.url('desktop/art/icon_hue_48.png')
Example #12
0
  def icon(self):
    apps = appmanager.get_apps_dict()

    try:
      if self.extra == 'workflow2':
        return staticfiles_storage.url('oozie/art/icon_oozie_workflow_48.png')
      elif self.extra == 'coordinator2':
        return staticfiles_storage.url('oozie/art/icon_oozie_coordinator_48.png')
      elif self.extra == 'bundle2':
        return staticfiles_storage.url('oozie/art/icon_oozie_bundle_48.png')
      elif self.extra == 'notebook':
        return staticfiles_storage.url('spark/art/icon_spark_48.png')
      elif self.extra.startswith('search'):
        return staticfiles_storage.url('search/art/icon_search_48.png')
      elif self.content_type.app_label == 'beeswax':
        if self.extra == '0':
          return staticfiles_storage.url(apps['beeswax'].icon_path)
        elif self.extra == '3':
          return staticfiles_storage.url(apps['spark'].icon_path)
        else:
          return staticfiles_storage.url(apps['impala'].icon_path)
      elif self.content_type.app_label == 'oozie':
        if self.extra == 'jobsub':
          return staticfiles_storage.url(apps['jobsub'].icon_path)
        else:
          return staticfiles_storage.url(self.content_type.model_class().ICON)
      elif self.content_type.app_label in apps:
        return staticfiles_storage.url(apps[self.content_type.app_label].icon_path)
      else:
        return staticfiles_storage.url('desktop/art/icon_hue_48.png')
    except Exception, e:
      LOG.warn(force_unicode(e))
      return staticfiles_storage.url('desktop/art/icon_hue_48.png')
Example #13
0
def commonheader(title, section, user, padding="90px", skip_topbar=False):
  """
  Returns the rendered common header
  """
  current_app = None
  other_apps = []
  if user.is_authenticated():
    apps = appmanager.get_apps(user)
    apps_list = appmanager.get_apps_dict(user)
    for app in apps:
      if app.display_name not in [
          'beeswax', 'impala', 'pig', 'jobsub', 'jobbrowser', 'metastore', 'hbase', 'sqoop', 'oozie', 'filebrowser',
          'useradmin', 'search', 'help', 'about', 'zookeeper', 'proxy', 'rdbms', 'spark', 'indexer', 'security', 'notebook'] and app.menu_index != -1:
        other_apps.append(app)
      if section == app.display_name:
        current_app = app
  else:
    apps_list = []

  return django_mako.render_to_string("common_header.mako", {
    'current_app': current_app,
    'apps': apps_list,
    'other_apps': other_apps,
    'title': title,
    'section': section,
    'padding': padding,
    'user': user,
    'skip_topbar': skip_topbar,
    'leaflet': {
      'layer': desktop.conf.LEAFLET_TILE_LAYER.get(),
      'attribution': desktop.conf.LEAFLET_TILE_LAYER_ATTRIBUTION.get()
    },
    'is_demo': desktop.conf.DEMO_ENABLED.get(),
    'is_ldap_setup': 'desktop.auth.backend.LdapBackend' in desktop.conf.AUTH.BACKEND.get()
  })
Example #14
0
def check_permissions(user, interpreter):
    user_apps = appmanager.get_apps_dict(user)
    return (interpreter == 'hive' and 'beeswax' not in user_apps) or \
           (interpreter == 'impala' and 'impala' not in user_apps) or \
           (interpreter == 'pig' and 'pig' not in user_apps) or \
           (interpreter == 'solr' and 'search' not in user_apps) or \
           (interpreter in ('spark', 'pyspark', 'r', 'jar', 'py') and 'spark' not in user_apps) or \
           (interpreter in ('java', 'spark2', 'mapreduce', 'shell', 'sqoop1', 'distcp') and 'oozie' not in user_apps)
Example #15
0
File: views.py Project: miho120/hue
def home2(request, is_embeddable=False):
  apps = appmanager.get_apps_dict(request.user)

  return render('home2.mako', request, {
    'apps': apps,
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials,
    'is_embeddable': request.GET.get('is_embeddable', False)
  })
Example #16
0
def get_ordered_interpreters(user=None):
    if has_connectors():
        from desktop.lib.connectors.api import _get_installed_connectors
        interpreters = [
            _connector_to_iterpreter(connector)
            for connector in _get_installed_connectors(
                categories=['editor', 'catalogs'], user=user)
        ]
    else:
        if not INTERPRETERS.get():
            _default_interpreters(user)
        interpreters = INTERPRETERS.get()

        user_apps = appmanager.get_apps_dict(user)
        user_interpreters = []
        for interpreter in interpreters:
            if check_permissions(user, interpreter, user_apps=user_apps):
                pass  # Not allowed
            else:
                user_interpreters.append(interpreter)

        interpreters_shown_on_wheel = _remove_duplications(
            INTERPRETERS_SHOWN_ON_WHEEL.get())
        unknown_interpreters = set(interpreters_shown_on_wheel) - set(
            user_interpreters)
        if unknown_interpreters:
            # Just filtering it out might be better than failing for this user
            raise ValueError(
                "Interpreters from interpreters_shown_on_wheel is not in the list of Interpreters %s"
                % unknown_interpreters)

        reordered_interpreters = interpreters_shown_on_wheel + [
            i
            for i in user_interpreters if i not in interpreters_shown_on_wheel
        ]

        interpreters = [{
            'name': interpreters[i].NAME.get(),
            'type': i,
            'interface': interpreters[i].INTERFACE.get(),
            'options': interpreters[i].OPTIONS.get()
        } for i in reordered_interpreters]

    return [{
        "name": i.get('nice_name', i['name']),
        "type": i['type'],
        "interface": i['interface'],
        "options": i['options'],
        'dialect': i.get('dialect', i['name']).lower(),
        'dialect_properties': i.get('dialect_properties'),
        'category': i.get('category', 'editor'),
        "is_sql": i.get('is_sql') or \
            i['interface'] in ["hiveserver2", "rdbms", "jdbc", "solr", "sqlalchemy", "ksql", "flink"] or \
            i['type'] == 'sql',
        "is_catalog": i['interface'] in ["hms",],
      }
      for i in interpreters
    ]
Example #17
0
def home2(request):
  _convert_documents(request.user)

  apps = appmanager.get_apps_dict(request.user)

  return render('home2.mako', request, {
    'apps': apps,
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })
Example #18
0
def execute_query(request, design_id=None, query_history_id=None):
  """
  View function for executing an arbitrary query.
  """
  action = 'query'

  if query_history_id:
    query_history = authorized_get_query_history(request, query_history_id, must_exist=True)
    design = query_history.design

    try:
      if query_history.server_id and query_history.server_guid:
        handle, state = _get_query_handle_and_state(query_history)

      if 'on_success_url' in request.GET:
        if request.GET.get('on_success_url') and any(
            [regexp.match(request.GET.get('on_success_url')) for regexp in REDIRECT_WHITELIST.get()]
          ):
          action = 'watch-redirect'
        else:
          action = 'watch-results'
      else:
        action = 'editor-results'
    except QueryServerException as e:
      if 'Invalid query handle' in e.message or 'Invalid OperationHandle' in e.message:
        query_history.save_state(QueryHistory.STATE.expired)
        LOG.warn("Invalid query handle", exc_info=sys.exc_info())
        action = 'editor-expired-results'
      else:
        raise e
  else:
    # Check perms.
    authorized_get_design(request, design_id)

    app_name = get_app_name(request)
    query_type = SavedQuery.TYPES_MAPPING[app_name]
    design = safe_get_design(request, query_type, design_id)
    query_history = None

  current_app, other_apps, apps_list = _get_apps(request.user, '')
  doc = design and design.id and design.doc.get()
  context = {
    'design': design,
    'apps': apps_list,
    'query': query_history, # Backward
    'query_history': query_history,
    'autocomplete_base_url': reverse(get_app_name(request) + ':api_autocomplete_databases', kwargs={}),
    'autocomplete_base_url_hive': reverse('beeswax:api_autocomplete_databases', kwargs={}),
    'can_edit_name': design and design.id and not design.is_auto,
    'doc_id': doc and doc.id or -1,
    'can_edit': doc and doc.can_write(request.user),
    'action': action,
    'on_success_url': request.GET.get('on_success_url'),
    'has_metastore': 'metastore' in get_apps_dict(request.user)
  }

  return render('execute.mako', request, context)
Example #19
0
def check_permissions(user, interpreter, user_apps=None):
  if user_apps is None:
    user_apps = appmanager.get_apps_dict(user) # Expensive method
  return (interpreter == 'hive' and 'hive' not in user_apps) or \
         (interpreter == 'impala' and 'impala' not in user_apps) or \
         (interpreter == 'pig' and 'pig' not in user_apps) or \
         (interpreter == 'solr' and 'search' not in user_apps) or \
         (interpreter in ('spark', 'pyspark', 'r', 'jar', 'py', 'sparksql') and 'spark' not in user_apps) or \
         (interpreter in ('java', 'spark2', 'mapreduce', 'shell', 'sqoop1', 'distcp') and 'oozie' not in user_apps)
Example #20
0
def home(request):
  docs = _get_docs(request.user)

  apps = appmanager.get_apps_dict(request.user)

  return render('home.mako', request, {
    'apps': apps,
    'json_documents': json.dumps(massaged_documents_for_json(docs, request.user)),
    'json_tags': json.dumps(massaged_tags_for_json(docs, request.user)),
  })
Example #21
0
File: views.py Project: shobull/hue
def home2(request):
  docs = Document2.objects.filter(owner=request.user)

  apps = appmanager.get_apps_dict(request.user)

  return render('home2.mako', request, {
    'apps': apps,
    'json_documents': json.dumps([doc.to_dict() for doc in docs]),
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })
Example #22
0
File: views.py Project: mastanr/hue
def responsive(request):
    apps = appmanager.get_apps_dict(request.user)

    return render(
        'responsive.mako', request, {
            'apps': apps,
            'tours_and_tutorials': Settings.get_settings().tours_and_tutorials,
            'interpreters': get_interpreters(request.user),
            'is_s3_enabled': is_s3_enabled() and has_s3_access(request.user)
        })
Example #23
0
def responsive(request):
  apps = appmanager.get_apps_dict(request.user)

  return render('responsive.mako', request, {
    'apps': apps,
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials,
    'interpreters': get_ordered_interpreters(request.user),
    'is_s3_enabled': is_s3_enabled() and has_s3_access(request.user),
    'is_ldap_setup': 'desktop.auth.backend.LdapBackend' in desktop.conf.AUTH.BACKEND.get()
  })
Example #24
0
def home(request):
  docs = _get_docs(request.user)

  apps = appmanager.get_apps_dict(request.user)

  return render('home.mako', request, {
    'apps': apps,
    'json_documents': json.dumps(massaged_documents_for_json(docs, request.user)),
    'json_tags': json.dumps(massaged_tags_for_json(docs, request.user)),
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })
Example #25
0
def home(request):
  docs = _get_docs(request.user)

  apps = appmanager.get_apps_dict(request.user)

  return render('home.mako', request, {
    'apps': apps,
    'json_documents': json.dumps(massaged_documents_for_json(docs, request.user)),
    'json_tags': json.dumps(massaged_tags_for_json(docs, request.user)),
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })
Example #26
0
def get_ordered_interpreters(user=None):
  if not INTERPRETERS.get():
    _default_interpreters(user)

  interpreters = INTERPRETERS.get()
  interpreters_shown_on_wheel = _remove_duplications(INTERPRETERS_SHOWN_ON_WHEEL.get())

  user_apps = appmanager.get_apps_dict(user)
  user_interpreters = []
  for interpreter in interpreters:
    if check_permissions(user, interpreter, user_apps=user_apps):
      pass # Not allowed
    else:
      user_interpreters.append(interpreter)

  unknown_interpreters = set(interpreters_shown_on_wheel) - set(user_interpreters)
  if unknown_interpreters:
    raise ValueError("Interpreters from interpreters_shown_on_wheel is not in the list of Interpreters %s" % unknown_interpreters)

  if has_connectors():
    from desktop.lib.connectors.api import _get_installed_connectors
    reordered_interpreters = [{
        'name': connector['nice_name'],
        'type': connector['name'],
        'dialect': connector['dialect'],
        'category': connector['category'],
        'is_sql': connector.get('is_sql', False),
        'interface': connector['interface'],
        'options': {setting['name']: setting['value'] for setting in connector['settings']}
      } for connector in _get_installed_connectors(categories=['editor', 'catalogs'])
    ]
  else:
    reordered_interpreters = interpreters_shown_on_wheel + [i for i in user_interpreters if i not in interpreters_shown_on_wheel]
    reordered_interpreters = [{
        'name': interpreters[i].NAME.get(),
        'type': i,
        'interface': interpreters[i].INTERFACE.get(),
        'options': interpreters[i].OPTIONS.get()
      } for i in reordered_interpreters
    ]

  return [{
      "name": i.get('nice_name', i['name']),
      "type": i['type'],
      "interface": i['interface'],
      "options": i['options'],
      'dialect': i.get('dialect', i['name']).lower(),
      'category': i.get('category', 'editor'),
      "is_sql": i.get('is_sql') or i['interface'] in ["hiveserver2", "rdbms", "jdbc", "solr", "sqlalchemy"],
      "is_catalog": i['interface'] in ["hms",],
    }
    for i in reordered_interpreters
  ]
Example #27
0
def home(request):
  docs = Document.objects.get_docs(request.user).order_by('-last_modified')[:1000]
  tags = DocumentTag.objects.get_tags(user=request.user)

  apps = appmanager.get_apps_dict(request.user)

  return render('home.mako', request, {
    'apps': apps,
    'documents': docs,
    'json_documents': json.dumps(massaged_documents_for_json(docs)),
    'tags': tags,
    'json_tags': json.dumps(massaged_tags_for_json(tags, request.user))
  })
Example #28
0
def home(request):
  docs = Document.objects.get_docs(request.user).order_by('-last_modified')[:1000]
  tags = DocumentTag.objects.get_tags(user=request.user)

  apps = appmanager.get_apps_dict(request.user)

  return render('home.mako', request, {
    'apps': apps,
    'documents': docs,
    'json_documents': json.dumps(massaged_documents_for_json(docs)),
    'tags': tags,
    'json_tags': json.dumps(massaged_tags_for_json(tags, request.user))
  })
Example #29
0
def commonheader(title, section, user, padding="90px"):
    """
  Returns the rendered common header
  """
    current_app = None
    other_apps = []
    if user.is_authenticated():
        apps = appmanager.get_apps(user)
        apps_list = appmanager.get_apps_dict(user)
        for app in apps:
            if app.display_name not in [
                "beeswax",
                "impala",
                "pig",
                "jobsub",
                "jobbrowser",
                "metastore",
                "hbase",
                "sqoop",
                "oozie",
                "filebrowser",
                "useradmin",
                "search",
                "help",
                "about",
                "zookeeper",
                "proxy",
                "rdbms",
                "spark",
                "indexer",
                "security",
            ]:
                other_apps.append(app)
            if section == app.display_name:
                current_app = app
    else:
        apps_list = []

    return django_mako.render_to_string(
        "common_header.mako",
        {
            "current_app": current_app,
            "apps": apps_list,
            "other_apps": other_apps,
            "title": title,
            "section": section,
            "padding": padding,
            "user": user,
            "is_demo": desktop.conf.DEMO_ENABLED.get(),
        },
    )
Example #30
0
def get_ordered_interpreters(user=None):
  from desktop.lib.connectors.api import CONNECTOR_INSTANCES
  global CONNECTOR_INSTANCES

  if not INTERPRETERS.get():
    _default_interpreters(user)

  interpreters = INTERPRETERS.get()
  interpreters_shown_on_wheel = _remove_duplications(INTERPRETERS_SHOWN_ON_WHEEL.get())

  user_apps = appmanager.get_apps_dict(user)
  user_interpreters = []
  for interpreter in interpreters:
    if check_permissions(user, interpreter, user_apps=user_apps):
      pass # Not allowed
    else:
      user_interpreters.append(interpreter)

  unknown_interpreters = set(interpreters_shown_on_wheel) - set(user_interpreters)
  if unknown_interpreters:
    raise ValueError("Interpreters from interpreters_shown_on_wheel is not in the list of Interpreters %s" % unknown_interpreters)

  if has_connectors():
    reordered_interpreters = [{
        'name': i['name'],
        'type': i['type'],
        'interface': i['interface'],
        'options': {setting['name']: setting['value'] for setting in i['settings']}
      } for i in CONNECTOR_INSTANCES
    ]
  else:
    reordered_interpreters = interpreters_shown_on_wheel + [i for i in user_interpreters if i not in interpreters_shown_on_wheel]
    reordered_interpreters = [{
        'name': interpreters[i].NAME.get(),
        'type': i,
        'interface': interpreters[i].INTERFACE.get(),
        'options': interpreters[i].OPTIONS.get()
      } for i in reordered_interpreters
    ]

  return [{
      "name": i['name'],
      "type": i['type'],
      "interface": i['interface'],
      "options": i['options'],
      "is_sql": i['interface'] in ["hiveserver2", "rdbms", "jdbc", "solr", "sqlalchemy"],
      "is_catalog": i['interface'] in ["hms",],
    }
    for i in reordered_interpreters
  ]
Example #31
0
def home(request):
    docs = _get_docs(request.user)

    apps = appmanager.get_apps_dict(request.user)

    return render(
        "home.mako",
        request,
        {
            "apps": apps,
            "json_documents": json.dumps(massaged_documents_for_json(docs, request.user)),
            "json_tags": json.dumps(massaged_tags_for_json(docs, request.user)),
            "tours_and_tutorials": Settings.get_settings().tours_and_tutorials,
        },
    )
Example #32
0
def home(request):
  docs = itertools.chain(
      Document.objects.get_docs(request.user).order_by('-last_modified').exclude(tags__tag__in=['history'])[:500],
      Document.objects.get_docs(request.user).order_by('-last_modified').filter(tags__tag__in=['history'])[:100]
  )
  docs = list(docs)
  tags = DocumentTag.objects.get_tags(user=request.user)

  apps = appmanager.get_apps_dict(request.user)

  return render('home.mako', request, {
    'apps': apps,
    'documents': augment_docs(docs, request.user),
    'json_documents': json.dumps(massaged_documents_for_json(docs, request.user)),
    'tags': augment_tags(tags, request.user),
    'json_tags': json.dumps(massaged_tags_for_json(tags, request.user))
  })
Example #33
0
def home(request):
  docs = itertools.chain(
      Document.objects.get_docs(request.user).order_by('-last_modified').exclude(tags__tag__in=['history'])[:500],
      Document.objects.get_docs(request.user).order_by('-last_modified').filter(tags__tag__in=['history'])[:100]
  )
  docs = list(docs)
  tags = list(set([tag for doc in docs for tag in doc.tags.all()])) # List of all personal and share tags

  apps = appmanager.get_apps_dict(request.user)

  return render('home.mako', request, {
    'apps': apps,
    'documents': augment_docs(docs, request.user),
    'json_documents': json.dumps(massaged_documents_for_json(docs, request.user)),
    'tags': augment_tags(tags, request.user),
    'json_tags': json.dumps(massaged_tags_for_json(tags, request.user))
  })
Example #34
0
def get_ordered_interpreters(user=None):
    if not INTERPRETERS.get():
        _default_interpreters(user)

    interpreters = INTERPRETERS.get()
    interpreters_shown_on_wheel = _remove_duplications(
        INTERPRETERS_SHOWN_ON_WHEEL.get())

    user_apps = appmanager.get_apps_dict(user)
    user_interpreters = []
    for interpreter in interpreters:
        if (interpreter == 'hive' and 'beeswax' not in user_apps) or \
            (interpreter == 'impala' and 'impala' not in user_apps) or \
            (interpreter == 'pig' and 'pig' not in user_apps) or \
            (interpreter in ('java', 'spark2', 'mapreduce', 'shell', 'sqoop1', 'distcp') and 'oozie' not in user_apps):
            pass  # Not allowed
        else:
            user_interpreters.append(interpreter)

    unknown_interpreters = set(interpreters_shown_on_wheel) - set(
        user_interpreters)
    if unknown_interpreters:
        raise ValueError(
            "Interpreters from interpreters_shown_on_wheel is not in the list of Interpreters %s"
            % unknown_interpreters)

    reordered_interpreters = interpreters_shown_on_wheel + [
        i for i in user_interpreters if i not in interpreters_shown_on_wheel
    ]

    return [{
        "name":
        interpreters[i].NAME.get(),
        "type":
        i,
        "interface":
        interpreters[i].INTERFACE.get(),
        "options":
        interpreters[i].OPTIONS.get(),
        "is_sql":
        interpreters[i].INTERFACE.get()
        in ["hiveserver2", "rdbms", "jdbc", "solr"]
    } for i in reordered_interpreters]
Example #35
0
  def icon(self):
    apps = appmanager.get_apps_dict()

    try:
      if self.content_type.app_label == 'beeswax':
        if self.extra == '0':
          return apps['beeswax'].icon_path
        else:
          return apps['impala'].icon_path
      elif self.content_type.app_label == 'oozie':
        if self.extra == 'jobsub':
          return apps['jobsub'].icon_path
        else:
          return self.content_type.model_class().ICON
      elif self.content_type.app_label in apps:
        return apps[self.content_type.app_label].icon_path
      else:
        return '/static/art/favicon.png'
    except Exception, e:
      LOG.warn(force_unicode(e))
      return '/static/art/favicon.png'
Example #36
0
  def icon(self):
    apps = appmanager.get_apps_dict()

    try:
      if self.content_type.app_label == 'beeswax':
        if self.extra == '0':
          return apps['beeswax'].icon_path
        else:
          return apps['impala'].icon_path
      elif self.content_type.app_label == 'oozie':
        if self.extra == 'jobsub':
          return apps['jobsub'].icon_path
        else:
          return self.content_type.model_class().ICON
      elif self.content_type.app_label in apps:
        return apps[self.content_type.app_label].icon_path
      else:
        return '/static/art/favicon.png'
    except Exception, e:
      LOG.warn(force_unicode(e))
      return '/static/art/favicon.png'
Example #37
0
def list_designs(request):
  '''
  List all workflow designs. Result sorted by last modification time.
  Query params:
    owner       - Substring filter by owner field
    name        - Substring filter by design name field
  '''
  owner = request.GET.get('owner', '')
  name = request.GET.get('name', '')

  if request.is_ajax():
    return render_json({
      'designs': _list_designs(request, owner, name)
    }, js_safe=True)
  else:
    return render("designs.mako", request, {
      'currentuser': request.user,
      'owner': owner,
      'name': name,
      'apps': appmanager.get_apps_dict()
    })
Example #38
0
def list_designs(request):
    '''
  List all workflow designs. Result sorted by last modification time.
  Query params:
    owner       - Substring filter by owner field
    name        - Substring filter by design name field
  '''
    owner = request.GET.get('owner', '')
    name = request.GET.get('name', '')

    if request.is_ajax():
        return render_json({'designs': _list_designs(request, owner, name)},
                           js_safe=True)
    else:
        return render(
            "designs.mako", request, {
                'currentuser': request.user,
                'owner': owner,
                'name': name,
                'apps': appmanager.get_apps_dict()
            })
Example #39
0
    def icon(self):
        apps = appmanager.get_apps_dict()

        try:
            if self.content_type.app_label == "beeswax":
                if self.extra == "0":
                    return apps["beeswax"].icon_path
                else:
                    return apps["impala"].icon_path
            elif self.content_type.app_label == "oozie":
                if self.extra == "jobsub":
                    return apps["jobsub"].icon_path
                else:
                    return self.content_type.model_class().ICON
            elif self.content_type.app_label in apps:
                return apps[self.content_type.app_label].icon_path
            else:
                return "/static/art/favicon.png"
        except Exception, e:
            LOG.warn(force_unicode(e))
            return "/static/art/favicon.png"
Example #40
0
File: views.py Project: jekey/hue
def execute_query(request, design_id=None, query_history_id=None):
  """
  View function for executing an arbitrary query.
  """
  action = 'query'

  if query_history_id:
    query_history = authorized_get_query_history(request, query_history_id, must_exist=True)
    design = query_history.design

    if 'on_success_url' in request.GET:
      if request.GET.get('on_success_url'):
        action = 'watch-redirect'
      else:
        action = 'watch-results'
    else:
      action = 'editor-results'
  else:
    # Check perms.
    authorized_get_design(request, design_id)

    app_name = get_app_name(request)
    query_type = SavedQuery.TYPES_MAPPING[app_name]
    design = safe_get_design(request, query_type, design_id)
    query_history = None

  context = {
    'design': design,
    'query': query_history, # Backward
    'query_history': query_history,
    'autocomplete_base_url': reverse(get_app_name(request) + ':api_autocomplete_databases', kwargs={}),
    'can_edit_name': design and design.id and not design.is_auto,
    'action': action,
    'on_success_url': request.GET.get('on_success_url'),
    'has_metastore': 'metastore' in get_apps_dict(request.user)
  }

  return render('execute.mako', request, context)
Example #41
0
    def icon(self):
        apps = appmanager.get_apps_dict()

        try:
            if self.extra == "workflow2":
                return staticfiles_storage.url("oozie/art/icon_oozie_workflow_48.png")
            elif self.extra == "coordinator2":
                return staticfiles_storage.url("oozie/art/icon_oozie_coordinator_48.png")
            elif self.extra == "bundle2":
                return staticfiles_storage.url("oozie/art/icon_oozie_bundle_48.png")
            elif self.extra == "notebook":
                return staticfiles_storage.url("notebook/art/icon_notebook_48.png")
            elif self.extra.startswith("query"):
                if self.extra == "query-impala":
                    return staticfiles_storage.url(apps["impala"].icon_path)
                else:
                    return staticfiles_storage.url(apps["beeswax"].icon_path)
            elif self.extra.startswith("search"):
                return staticfiles_storage.url("search/art/icon_search_48.png")
            elif self.content_type.app_label == "beeswax":
                if self.extra == "0":
                    return staticfiles_storage.url(apps["beeswax"].icon_path)
                elif self.extra == "3":
                    return staticfiles_storage.url(apps["spark"].icon_path)
                else:
                    return staticfiles_storage.url(apps["impala"].icon_path)
            elif self.content_type.app_label == "oozie":
                if self.extra == "jobsub":
                    return staticfiles_storage.url(apps["jobsub"].icon_path)
                else:
                    return staticfiles_storage.url(self.content_type.model_class().ICON)
            elif self.content_type.app_label in apps:
                return staticfiles_storage.url(apps[self.content_type.app_label].icon_path)
            else:
                return staticfiles_storage.url("desktop/art/icon_hue_48.png")
        except Exception, e:
            LOG.warn(force_unicode(e))
            return staticfiles_storage.url("desktop/art/icon_hue_48.png")
Example #42
0
def is_enabled():
    """Automatic if Hue 4 or when search is enabled."""
    apps = get_apps_dict()

    return is_hue4() or 'search' in apps
Example #43
0
def is_enabled():
    """Automatic when search is enabled."""
    apps = get_apps_dict()

    return 'search' in apps or HAS_SQL_ENABLED.get()
Example #44
0
def ko_metastore(request):
    apps = appmanager.get_apps_dict(request.user)

    return render('ko_metastore.mako', request, {
        'apps': apps,
    })
Example #45
0
def ko_editor(request):
    apps = appmanager.get_apps_dict(request.user)

    return render('ko_editor.mako', request, {
        'apps': apps,
    })
Example #46
0
def listdir_paged(request, path):
    """
    A paginated version of listdir.

    Query parameters:
      pagenum           - The page number to show. Defaults to 1.
      pagesize          - How many to show on a page. Defaults to 15.
      sortby=?          - Specify attribute to sort by. Accepts:
                            (type, name, atime, mtime, size, user, group)
                          Defaults to name.
      descending        - Specify a descending sort order.
                          Default to false.
      filter=?          - Specify a substring filter to search for in
                          the filename field.
    """
    if not request.fs.isdir(path):
        raise PopupException("Not a directory: %s" % (path,))

    pagenum = int(request.GET.get('pagenum', 1))
    pagesize = int(request.GET.get('pagesize', 30))
    do_as = None
    if request.user.is_superuser or request.user.has_hue_permission(action="impersonate", app="security"):
      do_as = request.GET.get('doas', request.user.username)
    if hasattr(request, 'doas'):
      do_as = request.doas

    home_dir_path = request.user.get_home_directory()
    breadcrumbs = parse_breadcrumbs(path)

    if do_as:
      all_stats = request.fs.do_as_user(do_as, request.fs.listdir_stats, path)
    else:
      all_stats = request.fs.listdir_stats(path)


    # Filter first
    filter_str = request.GET.get('filter', None)
    if filter_str:
        filtered_stats = filter(lambda sb: filter_str in sb['name'], all_stats)
        all_stats = filtered_stats

    # Sort next
    sortby = request.GET.get('sortby', None)
    descending_param = request.GET.get('descending', None)
    if sortby is not None:
        if sortby not in ('type', 'name', 'atime', 'mtime', 'user', 'group', 'size'):
            logger.info("Invalid sort attribute '%s' for listdir." %
                        (sortby,))
        else:
            all_stats = sorted(all_stats,
                               key=operator.attrgetter(sortby),
                               reverse=coerce_bool(descending_param))


    # Do pagination
    page = paginator.Paginator(all_stats, pagesize).page(pagenum)
    shown_stats = page.object_list

    # Include parent dir always as second option, unless at filesystem root.
    if not request.fs.isroot(path):
        parent_path = request.fs.join(path, "..")
        parent_stat = request.fs.stats(parent_path)
        # The 'path' field would be absolute, but we want its basename to be
        # actually '..' for display purposes. Encode it since _massage_stats expects byte strings.
        parent_stat['path'] = parent_path
        parent_stat['name'] = ".."
        shown_stats.insert(0, parent_stat)

    # Include same dir always as first option to see stats of the current folder
    current_stat = request.fs.stats(path)
    # The 'path' field would be absolute, but we want its basename to be
    # actually '.' for display purposes. Encode it since _massage_stats expects byte strings.
    current_stat['path'] = path
    current_stat['name'] = "."
    shown_stats.insert(1, current_stat)

    page.object_list = [ _massage_stats(request, s) for s in shown_stats ]

    is_fs_superuser = _is_hdfs_superuser(request)
    data = {
        'path': path,
        'breadcrumbs': breadcrumbs,
        'current_request_path': request.path,
        'files': page.object_list,
        'page': _massage_page(page),
        'pagesize': pagesize,
        'home_directory': request.fs.isdir(home_dir_path) and home_dir_path or None,
        'sortby': sortby,
        'descending': descending_param,
        # The following should probably be deprecated
        'cwd_set': True,
        'file_filter': 'any',
        'current_dir_path': path,
        'is_fs_superuser': is_fs_superuser,
        'groups': is_fs_superuser and [str(x) for x in Group.objects.values_list('name', flat=True)] or [],
        'users': is_fs_superuser and [str(x) for x in User.objects.values_list('username', flat=True)] or [],
        'superuser': request.fs.superuser,
        'supergroup': request.fs.supergroup,
        'is_sentry_managed': request.fs.is_sentry_managed(path),
        'apps': appmanager.get_apps_dict(request.user).keys(),
        'show_download_button': SHOW_DOWNLOAD_BUTTON.get(),
        'show_upload_button': SHOW_UPLOAD_BUTTON.get()
    }
    return render('listdir.mako', request, data)
Example #47
0
    design = safe_get_design(request, query_type, design_id)
    query_history = None

  doc = design and design.id and design.doc.get()
  context = {
    'design': design,
    'query': query_history, # Backward
    'query_history': query_history,
    'autocomplete_base_url': reverse(get_app_name(request) + ':api_autocomplete_databases', kwargs={}),
    'autocomplete_base_url_hive': reverse('beeswax:api_autocomplete_databases', kwargs={}),
    'can_edit_name': design and design.id and not design.is_auto,
    'doc_id': doc and doc.id or -1,
    'can_edit': doc and doc.can_write(request.user),
    'action': action,
    'on_success_url': request.GET.get('on_success_url'),
    'has_metastore': 'metastore' in get_apps_dict(request.user)
  }

  return render('execute.mako', request, context)


def view_results(request, id, first_row=0):
  """
  Returns the view for the results of the QueryHistory with the given id.

  The query results MUST be ready.
  To display query results, one should always go through the execute_query view.
  If the result set has has_result_set=False, display an empty result.

  If ``first_row`` is 0, restarts (if necessary) the query read.  Otherwise, just
  spits out a warning if first_row doesn't match the servers conception.
Example #48
0
        design = safe_get_design(request, query_type, design_id)
        query_history = None

    doc = design and design.id and design.doc.get()
    context = {
        "design": design,
        "query": query_history,  # Backward
        "query_history": query_history,
        "autocomplete_base_url": reverse(get_app_name(request) + ":api_autocomplete_databases", kwargs={}),
        "autocomplete_base_url_hive": reverse("beeswax:api_autocomplete_databases", kwargs={}),
        "can_edit_name": design and design.id and not design.is_auto,
        "doc_id": doc and doc.id or -1,
        "can_edit": doc and doc.can_write(request.user),
        "action": action,
        "on_success_url": request.GET.get("on_success_url"),
        "has_metastore": "metastore" in get_apps_dict(request.user),
    }

    return render("execute.mako", request, context)


def view_results(request, id, first_row=0):
    """
  Returns the view for the results of the QueryHistory with the given id.

  The query results MUST be ready.
  To display query results, one should always go through the execute_query view.
  If the result set has has_result_set=False, display an empty result.

  If ``first_row`` is 0, restarts (if necessary) the query read.  Otherwise, just
  spits out a warning if first_row doesn't match the servers conception.
Example #49
0
  return render('home.mako', request, {
    'apps': apps,
    'json_documents': json.dumps(massaged_documents_for_json(docs, request.user)),
    'json_tags': json.dumps(massaged_tags_for_json(docs, request.user)),
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })


def home2(request):
  try:
    converter = DocumentConverter(request.user)
    converter.convert()
  except Exception, e:
    LOG.warning("Failed to convert and import documents: %s" % e)

  apps = appmanager.get_apps_dict(request.user)

  return render('home2.mako', request, {
    'apps': apps,
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })


@access_log_level(logging.WARN)
def log_view(request):
  """
  We have a log handler that retains the last X characters of log messages.
  If it is attached to the root logger, this view will display that history,
  otherwise it will report that it can't be found.
  """
  if not request.user.is_superuser:
Example #50
0
  return render('home.mako', request, {
    'apps': apps,
    'json_documents': json.dumps(massaged_documents_for_json(docs, request.user)),
    'json_tags': json.dumps(massaged_tags_for_json(docs, request.user)),
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials
  })


def home2(request, is_embeddable=False):
  try:
    converter = DocumentConverter(request.user)
    converter.convert()
  except Exception, e:
    LOG.warning("Failed to convert and import documents: %s" % e)

  apps = appmanager.get_apps_dict(request.user)

  return render('home2.mako', request, {
    'apps': apps,
    'tours_and_tutorials': Settings.get_settings().tours_and_tutorials,
    'is_embeddable': request.GET.get('is_embeddable', False)
  })

def home_embeddable(request):
  return home2(request, True)

def not_found(request):
  return render('404.mako', request, {
    'is_embeddable': request.GET.get('is_embeddable', False)
  })