public QueryStatus getQueryStatus(QueryId queryId) throws ServiceException { GetQueryStatusRequest.Builder builder = GetQueryStatusRequest.newBuilder(); builder.setQueryId(queryId.getProto()); GetQueryStatusResponse res = null; if (queryMasterMap.containsKey(queryId)) { NettyClientBase qmClient = null; try { qmClient = connPool.getConnection( queryMasterMap.get(queryId), QueryMasterClientProtocol.class, false); QueryMasterClientProtocolService.BlockingInterface queryMasterService = qmClient.getStub(); res = queryMasterService.getQueryStatus(null, builder.build()); } catch (Exception e) { throw new ServiceException(e.getMessage(), e); } finally { connPool.releaseConnection(qmClient); } } else { NettyClientBase tmClient = null; try { tmClient = connPool.getConnection(tajoMasterAddr, TajoMasterClientProtocol.class, false); TajoMasterClientProtocolService.BlockingInterface tajoMasterService = tmClient.getStub(); res = tajoMasterService.getQueryStatus(null, builder.build()); String queryMasterHost = res.getQueryMasterHost(); if (queryMasterHost != null && !queryMasterHost.isEmpty()) { NettyClientBase qmClient = null; try { InetSocketAddress qmAddr = NetUtils.createSocketAddr(queryMasterHost, res.getQueryMasterPort()); qmClient = connPool.getConnection(qmAddr, QueryMasterClientProtocol.class, false); QueryMasterClientProtocolService.BlockingInterface queryMasterService = qmClient.getStub(); res = queryMasterService.getQueryStatus(null, builder.build()); queryMasterMap.put(queryId, qmAddr); } catch (Exception e) { throw new ServiceException(e.getMessage(), e); } finally { connPool.releaseConnection(qmClient); } } } catch (Exception e) { throw new ServiceException(e.getMessage(), e); } finally { connPool.releaseConnection(tmClient); } } return new QueryStatus(res); }
public GetQueryResultResponse getResultResponse(QueryId queryId) throws ServiceException { if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) { return null; } NettyClientBase client = null; try { InetSocketAddress queryMasterAddr = queryMasterMap.get(queryId); if (queryMasterAddr == null) { LOG.warn("No Connection to QueryMaster for " + queryId); return null; } client = connPool.getConnection(queryMasterAddr, QueryMasterClientProtocol.class, false); QueryMasterClientProtocolService.BlockingInterface queryMasterService = client.getStub(); GetQueryResultRequest.Builder builder = GetQueryResultRequest.newBuilder(); builder.setQueryId(queryId.getProto()); GetQueryResultResponse response = queryMasterService.getQueryResult(null, builder.build()); return response; } catch (Exception e) { throw new ServiceException(e.getMessage(), e); } finally { connPool.releaseConnection(client); } }
/** * Call to QueryMaster closing query resources * * @param queryId */ public void closeQuery(final QueryId queryId) { if (queryMasterMap.containsKey(queryId)) { NettyClientBase qmClient = null; try { qmClient = connPool.getConnection( queryMasterMap.get(queryId), QueryMasterClientProtocol.class, false); QueryMasterClientProtocolService.BlockingInterface queryMasterService = qmClient.getStub(); queryMasterService.closeQuery(null, queryId.getProto()); } catch (Exception e) { LOG.warn( "Fail to close a QueryMaster connection (qid=" + queryId + ", msg=" + e.getMessage() + ")", e); } finally { connPool.closeConnection(qmClient); queryMasterMap.remove(queryId); } } }