/** * Gets the query context. * * @param handle the handle * @return the query context * @throws LensException the lens exception */ protected JdbcQueryContext getQueryContext(QueryHandle handle) throws LensException { JdbcQueryContext ctx = queryContextMap.get(handle); if (ctx == null) { throw new LensException("Query not found:" + handle.getHandleId()); } return ctx; }
/** * Gets the query context. * * @param handle the handle * @return the query context * @throws LensException the lens exception */ protected JdbcQueryContext getQueryContext(QueryHandle handle) throws LensException { JdbcQueryContext ctx = queryContextMap.get(handle); if (ctx == null) { throw new LensException("Query not found:" + handle.getHandleId()); } return ctx; }
/** * Close the query specified by the handle, releases all the resources held by the query. * * @param handle The query handle * @throws LensException the lens exception */ @Override public void closeQuery(QueryHandle handle) throws LensException { checkConfigured(); try { JdbcQueryContext ctx = getQueryContext(handle); if (ctx != null) { ctx.getResultFuture().cancel(true); ctx.closeResult(); } } catch (LensException exc) { log.error("{} Failed to close query {}", getFullyQualifiedName(), handle.getHandleId()); } finally { queryContextMap.remove(handle); } log.info("{} Closed query {}", getFullyQualifiedName(), handle.getHandleId()); }
closeQuery(query); } catch (LensException e) { log.warn("{} Error closing query : {}", getFullyQualifiedName(), query.getHandleId(), e);
closeQuery(query); } catch (LensException e) { log.warn("{} Error closing query : {}", getFullyQualifiedName(), query.getHandleId(), e);
/** * Close the query specified by the handle, releases all the resources held by the query. * * @param handle The query handle * @throws LensException the lens exception */ @Override public void closeQuery(QueryHandle handle) throws LensException { checkConfigured(); try { JdbcQueryContext ctx = getQueryContext(handle); ctx.getResultFuture().cancel(true); ctx.closeResult(); } finally { queryContextMap.remove(handle); } log.info("{} Closed query {}", getFullyQualifiedName(), handle.getHandleId()); }
private QueryHandle submitQuery(final QueryContext ctx) throws LensException { synchronized (ctx) { QueryStatus before = ctx.getStatus(); ctx.setStatus(QueryStatus.getQueuedStatus()); queuedQueries.add(ctx); log.info("Added to Queued Queries:{}", ctx.getQueryHandleString()); allQueries.put(ctx.getQueryHandle(), ctx); // Add to session's active query list getSession(SESSION_MAP.get(ctx.getLensSessionIdentifier())).addToActiveQueries(ctx.getQueryHandle()); fireStatusChangeEvent(ctx, ctx.getStatus(), before); log.info("Returning handle {}", ctx.getQueryHandle().getHandleId()); return ctx.getQueryHandle(); } }
@Override public QueryHandle runQuery(String testQuery) throws LensException { // Run the query in query executions service QueryExecutionService queryService = getServiceProvider().getService(QueryExecutionService.NAME); LensConf queryConf = new LensConf(); queryConf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_SET, false + ""); queryConf.addProperty(LensConfConstants.QUERY_PERSISTENT_RESULT_INDRIVER, false + ""); QueryHandle testQueryHandle = queryService.executeAsync(sessionHandle, testQuery, queryConf, queryName); // Wait for test query to complete LensQuery query = queryService.getQuery(sessionHandle, testQueryHandle); log.info("Submitted query {}", testQueryHandle.getHandleId()); while (!query.getStatus().finished()) { try { Thread.sleep(500); } catch (InterruptedException e) { throw new LensException(e); } query = queryService.getQuery(sessionHandle, testQueryHandle); } if (query.getStatus().getStatus() != QueryStatus.Status.SUCCESSFUL) { throw new LensException("Failed to run test query: " + testQueryHandle.getHandleId() + " reason= " + query.getStatus().getErrorMessage()); } return testQueryHandle; } }
@Override public void run() { SessionState.setCurrentSessionState(state); for (int i = 0; i < 1000; i++) { try { thrDriver.updateStatus(qctx); if (qctx.getDriverStatus().isFinished()) { log.info("@@ " + handle.getHandleId() + " >> " + qctx.getDriverStatus().getState()); break; } Thread.sleep(POLL_DELAY); } catch (LensException e) { log.error("Got Exception " + e.getCause(), e); errCount.incrementAndGet(); break; } catch (InterruptedException e) { log.error("Encountred Interrupted exception", e); break; } } } });
/** * Execute prepared query. * * @param phandle the phandle * @param async the asynch * @param queryName the query name * @return the string */ @CliCommand(value = "prepQuery execute", help = "Execute prepared query with handle <prepare_handle>." + " If <async> is supplied and is true, query is run in async manner and query handle is returned immediately." + " Optionally, <query-name> can be provided, though not required.") public String executePreparedQuery( @CliOption(key = {"", "prepare_handle"}, mandatory = true, help = "Prepare handle to execute") String phandle, @CliOption(key = {"async"}, mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "<async>") boolean async, @CliOption(key = {"name"}, mandatory = false, help = "<query-name>") String queryName) { try { if (async) { QueryHandle handle = getClient().executePrepared(QueryPrepareHandle.fromString(phandle), queryName); return handle.getHandleId().toString(); } else { LensClient.LensClientResultSetWithStats result = getClient().getResultsFromPrepared(QueryPrepareHandle.fromString(phandle), queryName); return formatResultSet(result); } } catch (Throwable t) { return t.getMessage(); } }
throw new LensException("Query failed " + ctx.getQueryHandle().getHandleId() + " reason:" + stat.getErrorMessage());
/** * Execute prepared query. * * @param phandle the phandle * @param async the asynch * @param queryName the query name * @return the string */ @CliCommand(value = "prepQuery execute", help = "Execute prepared query with handle <prepare_handle>." + " If <async> is supplied and is true, query is run in async manner and query handle is returned immediately." + " Optionally, <query-name> can be provided, though not required.") public String executePreparedQuery( @CliOption(key = {"", "prepare_handle"}, mandatory = true, help = "Prepare handle to execute") String phandle, @CliOption(key = {"async"}, mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "<async>") boolean async, @CliOption(key = {"name"}, mandatory = false, help = "<query-name>") String queryName) { try { if (async) { QueryHandle handle = getClient().executePrepared(QueryPrepareHandle.fromString(phandle), queryName); return handle.getHandleId().toString(); } else { LensClient.LensClientResultSetWithStats result = getClient().getResultsFromPrepared(QueryPrepareHandle.fromString(phandle), queryName); return formatResultSet(result); } } catch (Throwable t) { return t.getMessage(); } }
QueryStatus status = getClient().getQueryStatus(queryHandle); if (!status.finished() && !status.isResultSetAvailable()) { throw new LensException(queryHandle.getHandleId() + " query not finished or result unavailable"); throw new LensException("Result set not available for query " + queryHandle.getHandleId());
for (QueryHandle handle : persistedHandles) { LensQuery query = service.getQuery(session, handle); if (!handle.getHandleId().toString().equals(finishedHandle)) { Assert.assertTrue(query.getStatus().finished(), query.getQueryHandle() + " STATUS=" + query.getStatus().getStatus()); queryContext.getSelectedDriver().getFullyQualifiedName(), "daotestquery1", -1L, Long.MAX_VALUE); Assert.assertEquals(daoTestQueryHandles.size(), 1); Assert.assertEquals(daoTestQueryHandles.get(0).getHandleId().toString(), finishedHandle);