@SuppressWarnings("unchecked") @Test public void testGetQueries() throws IOException, BlurException, TException { Iface client = Config.getClient(); UserContext.setUser(new User("testUser",null)); BlurQuery query = new BlurQuery( new Query("fam0.col0:*", true, ScoreType.SUPER, null, null), null, null, false, 0, 10, 1, 2000, UUID.randomUUID().toString(), "testUser", false, System.currentTimeMillis(), null, null); int currentCount = 0; { Map<String, Object> queries = QueryUtil.getQueries(); Object o = queries.get("queries"); if (o != null) { currentCount = ((List<Map<String, Object>>) o).size(); } } client.query("queryUnitTable", query); UserContext.reset(); Map<String, Object> queries = QueryUtil.getQueries(); assertEquals(0, queries.get("slowQueries")); assertEquals(currentCount + 1, ((List<Map<String, Object>>) queries.get("queries")).size()); assertEquals("testUser", ((List<Map<String, Object>>) queries.get("queries")).get(0).get("user")); }
public static Map<String, Object> getQueries() throws TException, IOException { Map<String, Object> queriesInfo = new HashMap<String, Object>(); int slow = 0; List<Map<String, Object>> queries = new ArrayList<Map<String, Object>>(); CachingBlurClient client = Config.getCachingBlurClient(); List<String> tableList = client.enabledTables(); for (String table : tableList) { List<String> queriesForTable = client.queryStatusIdList(table); for (String id : queriesForTable) { BlurQueryStatus status = client.queryStatusById(table, id); if (Status.FOUND.equals(status.getStatus())) { Map<String, Object> info = new HashMap<String, Object>(); info.put("uuid", id); User user = status.getUser(); if(user != null && user.getUsername() != null) { info.put("user", user.getUsername()); } else { info.put("user", status.getQuery().getUserContext()); } info.put("query", status.getQuery().getQuery().getQuery()); info.put("table", table); info.put("state", status.getState().getValue()); info.put("percent", ((double) status.getCompleteShards()) / ((double) status.getTotalShards()) * 100); long startTime = status.getQuery().getStartTime(); info.put("startTime", startTime); queries.add(info); if (System.currentTimeMillis() - startTime > 60000) { slow++; } } } } queriesInfo.put("slowQueries", slow); queriesInfo.put("queries", queries); return queriesInfo; }
QueryUtil { public static Map<String, Object> getQueries() throws TException, IOException { Map<String, Object> queriesInfo = new HashMap<String, Object>(); int slow = 0; List<Map<String, Object>> queries = new ArrayList<Map<String, Object>>(); CachingBlurClient client = Config.getCachingBlurClient(); List<String> tableList = client.enabledTables(); for (String table : tableList) { List<String> queriesForTable = client.queryStatusIdList(table); for (String id : queriesForTable) { BlurQueryStatus status = client.queryStatusById(table, id); if (Status.FOUND.equals(status.getStatus())) { Map<String, Object> info = new HashMap<String, Object>(); info.put("uuid", id); User user = status.getUser(); if(user != null && user.getUsername() != null) { info.put("user", user.getUsername()); } else { info.put("user", status.getQuery().getUserContext()); } info.put("query", status.getQuery().getQuery().getQuery()); info.put("table", table); info.put("state", status.getState().getValue()); info.put("percent", ((double) status.getCompleteShards()) / ((double) status.getTotalShards()) * 100); long startTime = status.getQuery().getStartTime(); info.put("startTime", startTime); queries.add(info); if (System.currentTimeMillis() - startTime > 60000) { slow++; } } } } queriesInfo.put("slowQueries", slow); queriesInfo.put("queries", queries); return queriesInfo; } }
QueryUtil { public static Map<String, Object> getQueries() throws TException, IOException { Map<String, Object> queriesInfo = new HashMap<String, Object>(); int slow = 0; List<Map<String, Object>> queries = new ArrayList<Map<String, Object>>(); CachingBlurClient client = Config.getCachingBlurClient(); List<String> tableList = client.enabledTables(); for (String table : tableList) { List<String> queriesForTable = client.queryStatusIdList(table); for (String id : queriesForTable) { BlurQueryStatus status = client.queryStatusById(table, id); if (Status.FOUND.equals(status.getStatus())) { Map<String, Object> info = new HashMap<String, Object>(); info.put("uuid", id); User user = status.getUser(); if(user != null && user.getUsername() != null) { info.put("user", user.getUsername()); } else { info.put("user", status.getQuery().getUserContext()); } info.put("query", status.getQuery().getQuery().getQuery()); info.put("table", table); info.put("state", status.getState().getValue()); info.put("percent", ((double) status.getCompleteShards()) / ((double) status.getTotalShards()) * 100); long startTime = status.getQuery().getStartTime(); info.put("startTime", startTime); queries.add(info); if (System.currentTimeMillis() - startTime > 60000) { slow++; } } } } queriesInfo.put("slowQueries", slow); queriesInfo.put("queries", queries); return queriesInfo; }  }
QueryUtil { public static Map<String, Object> getQueries() throws TException, IOException { Map<String, Object> queriesInfo = new HashMap<String, Object>(); int slow = 0; List<Map<String, Object>> queries = new ArrayList<Map<String, Object>>(); CachingBlurClient client = Config.getCachingBlurClient(); List<String> tableList = client.enabledTables(); for (String table : tableList) { List<String> queriesForTable = client.queryStatusIdList(table); for (String id : queriesForTable) { BlurQueryStatus status = client.queryStatusById(table, id); if (Status.FOUND.equals(status.getStatus())) { Map<String, Object> info = new HashMap<String, Object>(); info.put("uuid", id); User user = status.getUser(); if(user != null && user.getUsername() != null) { info.put("user", user.getUsername()); } else { info.put("user", status.getQuery().getUserContext()); } info.put("query", status.getQuery().getQuery().getQuery()); info.put("table", table); info.put("state", status.getState().getValue()); info.put("percent", ((double) status.getCompleteShards()) / ((double) status.getTotalShards()) * 100); long startTime = status.getQuery().getStartTime(); info.put("startTime", startTime); queries.add(info); if (System.currentTimeMillis() - startTime > 60000) { slow++; } } } } queriesInfo.put("slowQueries", slow); queriesInfo.put("queries", queries); return queriesInfo; }  static int getCurrentQueryCount(); static Map<String, Object> getQueries(); static void cancelQuery(String table, String uuid); }
QueryUtil { public static Map<String, Object> getQueries() throws TException, IOException { Map<String, Object> queriesInfo = new HashMap<String, Object>(); int slow = 0; List<Map<String, Object>> queries = new ArrayList<Map<String, Object>>(); CachingBlurClient client = Config.getCachingBlurClient(); List<String> tableList = client.enabledTables(); for (String table : tableList) { List<String> queriesForTable = client.queryStatusIdList(table); for (String id : queriesForTable) { BlurQueryStatus status = client.queryStatusById(table, id); if (Status.FOUND.equals(status.getStatus())) { Map<String, Object> info = new HashMap<String, Object>(); info.put("uuid", id); User user = status.getUser(); if(user != null && user.getUsername() != null) { info.put("user", user.getUsername()); } else { info.put("user", status.getQuery().getUserContext()); } info.put("query", status.getQuery().getQuery().getQuery()); info.put("table", table); info.put("state", status.getState().getValue()); info.put("percent", ((double) status.getCompleteShards()) / ((double) status.getTotalShards()) * 100); long startTime = status.getQuery().getStartTime(); info.put("startTime", startTime); queries.add(info); if (System.currentTimeMillis() - startTime > 60000) { slow++; } } } } queriesInfo.put("slowQueries", slow); queriesInfo.put("queries", queries); return queriesInfo; }  static int getCurrentQueryCount(); static Map<String, Object> getQueries(); static void cancelQuery(String table, String uuid);  }