def refresh_table(request, database, table): query_server = dbms.get_query_server_config() db = beeswax_dbms.get(request.user, query_server=query_server) response = {'status': 0, 'message': ''} db.refresh_table(database, table) response['message'] = _('Successfully refreshed metadata for `%s`.`%s`') % (database, table) return JsonResponse(response)
def invalidate(request): query_server = dbms.get_query_server_config() db = beeswax_dbms.get(request.user, query_server=query_server) response = {'status': 0, 'message': ''} database = request.POST.get('database', None) flush_all = request.POST.get('flush_all', 'false').lower() == 'true' db.invalidate(database=database, flush_all=flush_all) response['message'] = _('Successfully invalidated metadata') return JsonResponse(response)
def alanize(request): response = {'status': -1} cluster = json.loads(request.POST.get('cluster', '{}')) query_id = json.loads(request.POST.get('query_id')) application = _get_server_name(cluster) query_server = dbms.get_query_server_config() session = Session.objects.get_session(request.user, query_server['server_name']) server_url = _get_impala_server_url(session) if query_id: LOG.debug( "Attempting to get Impala query profile at server_url %s for query ID: %s" % (server_url, query_id)) doc = Document2.objects.get(id=query_id) snippets = doc.data_dict.get('snippets', []) secret = snippets[0]['result']['handle']['secret'] api = get_impalad_api(user=request.user, url=server_url) impala_query_id = "%x:%x" % struct.unpack(b"QQ", base64.decodestring(secret)) api.kill( impala_query_id ) # There are many statistics that are not present when the query is open. Close it first. query_profile = api.get_query_profile_encoded(impala_query_id) profile = analyzer.analyze(analyzer.parse_data(query_profile)) result = ANALYZER.run(profile) heatmap = {} summary = analyzer.summary(profile) heatmapMetrics = [ 'AverageThreadTokens', 'BloomFilterBytes', 'PeakMemoryUsage', 'PerHostPeakMemUsage', 'PrepareTime', 'RowsProduced', 'TotalCpuTime', 'TotalNetworkReceiveTime', 'TotalNetworkSendTime', 'TotalStorageWaitTime', 'TotalTime' ] for key in heatmapMetrics: metrics = analyzer.heatmap_by_host(profile, key) if metrics['data']: heatmap[key] = metrics response['data'] = { 'query': { 'healthChecks': result[0]['result'], 'summary': summary, 'heatmap': heatmap, 'heatmapMetrics': sorted(list(heatmap.iterkeys())) } } response['status'] = 0 return JsonResponse(response)
def refresh_tables(request): query_server = dbms.get_query_server_config() db = beeswax_dbms.get(request.user, query_server=query_server) response = {'status': 0, 'message': ''} if request.method == "POST": try: database = json.loads(request.POST['database']) added = json.loads(request.POST.get('added', [])) removed = json.loads(request.POST.get('removed', [])) db.invalidate_tables(database, added + removed) except Exception, e: response['message'] = str(e)
def test_get_connector_config(self): connector = { 'type': 'impala-1', 'dialect': 'impala', 'options': { 'server_host': 'gethue.com', 'server_port': 10000 } } with patch('impala.dbms.has_connectors') as has_connectors: has_connectors.return_value = True config = get_query_server_config(connector) assert_true('impersonation_enabled' in config, config)
def invalidate(request): cluster = json.loads(request.POST.get('cluster', '{}')) database = request.POST.get('database', None) table = request.POST.get('table', None) flush_all = request.POST.get('flush_all', 'false').lower() == 'true' query_server = dbms.get_query_server_config(connector=None) # TODO: connector support db = beeswax_dbms.get(request.user, query_server=query_server) response = {'status': 0, 'message': ''} db.invalidate(database=database, table=table, flush_all=flush_all) response['message'] = _('Successfully invalidated metadata') return JsonResponse(response)
def invalidate(request): cluster = json.loads(request.POST.get('cluster', '{}')) database = request.POST.get('database', None) table = request.POST.get('table', None) flush_all = request.POST.get('flush_all', 'false').lower() == 'true' cluster_config = get_cluster_config(cluster) query_server = dbms.get_query_server_config(cluster_config=cluster_config) db = beeswax_dbms.get(request.user, query_server=query_server) response = {'status': 0, 'message': ''} db.invalidate(database=database, table=table, flush_all=flush_all) response['message'] = _('Successfully invalidated metadata') return JsonResponse(response)
def get_runtime_profile(request, query_history_id): query_server = dbms.get_query_server_config() db = beeswax_dbms.get(request.user, query_server=query_server) response = {'status': -1} query_history = authorized_get_query_history(request, query_history_id, must_exist=True) if query_history is None: response['message'] = _('get_runtime_profile requires a valid query_history_id') else: session = Session.objects.get_session(request.user, query_server['server_name']) operation_handle = query_history.get_handle().get_rpc_handle() session_handle = session.get_handle() profile = db.get_runtime_profile(operation_handle, session_handle) response['status'] = 0 response['profile'] = profile return JsonResponse(response)
def get_exec_summary(request, query_history_id): query_server = dbms.get_query_server_config() db = beeswax_dbms.get(request.user, query_server=query_server) response = {'status': -1} query_history = authorized_get_query_history(request, query_history_id, must_exist=True) if query_history is None: response['message'] = _('get_exec_summary requires a valid query_history_id') else: session = Session.objects.get_session(request.user, query_server['server_name']) operation_handle = query_history.get_handle().get_rpc_handle() session_handle = session.get_handle() summary = db.get_exec_summary(operation_handle, session_handle) response['status'] = 0 response['summary'] = summary return JsonResponse(response)