@Override public URI createStageLocation(StageId stageId) { requireNonNull(stageId, "stageId is null"); return uriBuilderFrom(baseUri) .appendPath("v1/stage") .appendPath(stageId.toString()) .build(); }
@Override public URI createQueryLocation(QueryId queryId) { requireNonNull(queryId, "queryId is null"); return uriBuilderFrom(baseUri) .appendPath("/v1/query") .appendPath(queryId.toString()) .build(); }
@Override public URI createTaskLocation(Node node, TaskId taskId) { requireNonNull(node, "node is null"); requireNonNull(taskId, "taskId is null"); return uriBuilderFrom(node.getHttpUri()) .appendPath("/v1/task") .appendPath(taskId.toString()) .build(); }
private static void updateQueryOutputLocations(QueryStateMachine queryStateMachine, OutputBufferId rootBufferId, Set<RemoteTask> tasks, boolean noMoreExchangeLocations) { Set<URI> bufferLocations = tasks.stream() .map(task -> task.getTaskStatus().getSelf()) .map(location -> uriBuilderFrom(location).appendPath("results").appendPath(rootBufferId.toString()).build()) .collect(toImmutableSet()); queryStateMachine.updateOutputLocations(bufferLocations, noMoreExchangeLocations); }
@Override public URI createMemoryInfoLocation(Node node) { requireNonNull(node, "node is null"); return uriBuilderFrom(node.getHttpUri()) .appendPath("/v1/memory").build(); } }
private Response proxyJsonResponse(String nodeId, String workerPath) { Set<Node> nodes = nodeManager.getNodes(NodeState.ACTIVE); Node node = nodes.stream() .filter(n -> n.getNodeIdentifier().equals(nodeId)) .findFirst() .orElseThrow(() -> new WebApplicationException(NOT_FOUND)); Request request = prepareGet() .setUri(uriBuilderFrom(node.getHttpUri()) .appendPath(workerPath) .build()) .build(); InputStream responseStream = httpClient.execute(request, new StreamingJsonResponseHandler()); return Response.ok(responseStream, APPLICATION_JSON_TYPE).build(); }
private static Split createRemoteSplitFor(TaskId taskId, URI taskLocation) { // Fetch the results from the buffer assigned to the task based on id URI splitLocation = uriBuilderFrom(taskLocation).appendPath("results").appendPath(String.valueOf(taskId.getId())).build(); return new Split(REMOTE_CONNECTOR_ID, new RemoteTransactionHandle(), new RemoteSplit(splitLocation)); }
@Override public Optional<QueryStats> getQueryStats(String queryId) { URI uri = uriBuilderFrom(baseUri).appendPath("/v1/query").appendPath(queryId).build(); Request request = prepareGet().setUri(uri).build(); return httpClient.execute(request, new GetQueryStatsResponseHandler()); }
public Response cancel(String queryId) { requireNonNull(queryId, "queryId is null"); URI cancelUri = uriBuilderFrom(uri).appendPath("/v1/query").appendPath(queryId).build(); Request request = prepareDelete().setUri(cancelUri).build(); return httpClient.execute(request, new ResponseHandler<Response, RuntimeException>() { @Override public Response handleException(Request request, Exception exception) { throw propagate(request, exception); } @Override public Response handle(Request request, Response response) { return response; } }); }
private void pollWorkers() { AllNodes allNodes = getAllNodes(); Set<Node> aliveNodes = ImmutableSet.<Node>builder() .addAll(allNodes.getActiveNodes()) .addAll(allNodes.getShuttingDownNodes()) .build(); ImmutableSet<String> aliveNodeIds = aliveNodes.stream() .map(Node::getNodeIdentifier) .collect(toImmutableSet()); // Remove nodes that don't exist anymore // Make a copy to materialize the set difference Set<String> deadNodes = difference(nodeStates.keySet(), aliveNodeIds).immutableCopy(); nodeStates.keySet().removeAll(deadNodes); // Add new nodes for (Node node : aliveNodes) { nodeStates.putIfAbsent(node.getNodeIdentifier(), new RemoteNodeState(httpClient, uriBuilderFrom(node.getHttpUri()).appendPath("/v1/info/state").build())); } // Schedule refresh nodeStates.values().forEach(RemoteNodeState::asyncRefresh); // update indexes refreshNodesInternal(); }
URI uri = HttpUriBuilder.uriBuilderFrom(location).appendPath(String.valueOf(result.getNextToken())).appendPath("acknowledge").build(); httpClient.executeAsync(prepareGet().setUri(uri).build(), new ResponseHandler<Void, RuntimeException>()
private synchronized void sendGetResults() URI uri = HttpUriBuilder.uriBuilderFrom(location).appendPath(String.valueOf(token)).build(); HttpResponseFuture<PagesResponse> resultFuture = httpClient.executeAsync( prepareGet()
private synchronized void scheduleNextRequest() { // stopped or done? TaskStatus taskStatus = getTaskStatus(); if (!running || taskStatus.getState().isDone()) { return; } // outstanding request? if (future != null && !future.isDone()) { // this should never happen log.error("Can not reschedule update because an update is already running"); return; } // if throttled due to error, asynchronously wait for timeout and try again ListenableFuture<?> errorRateLimit = errorTracker.acquireRequestPermit(); if (!errorRateLimit.isDone()) { errorRateLimit.addListener(this::scheduleNextRequest, executor); return; } Request request = prepareGet() .setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("status").build()) .setHeader(CONTENT_TYPE, JSON_UTF_8.toString()) .setHeader(PRESTO_CURRENT_STATE, taskStatus.getState().toString()) .setHeader(PRESTO_MAX_WAIT, refreshMaxWait.toString()) .build(); errorTracker.startRequest(); future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskStatusCodec)); currentRequestStartNanos.set(System.nanoTime()); Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor); }
private static void updateQueryOutputLocations(QueryStateMachine queryStateMachine, OutputBufferId rootBufferId, Set<RemoteTask> tasks, boolean noMoreExchangeLocations) { Set<URI> bufferLocations = tasks.stream() .map(task -> task.getTaskStatus().getSelf()) .map(location -> uriBuilderFrom(location).appendPath("results").appendPath(rootBufferId.toString()).build()) .collect(toImmutableSet()); queryStateMachine.updateOutputLocations(bufferLocations, noMoreExchangeLocations); }
@Test public void testAppendAbsolutePath() { URI uri = uriBuilder() .scheme("http") .host("www.example.com") .appendPath("/a/b/c") .appendPath("/x/y/z") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com/a/b/c/x/y/z"); }
@Test public void testAppendPathElidesSlashes() { URI uri = uriBuilder() .scheme("http") .host("www.example.com") .appendPath("/a/b/c/") .appendPath("/x/y/z") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com/a/b/c/x/y/z"); }
@Test public void testAppendAbsolutePath() { URI uri = uriBuilder() .scheme("http") .host("www.example.com") .appendPath("/a/b/c") .appendPath("/x/y/z") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com/a/b/c/x/y/z"); }
@Test(dataProvider = "mbeanNames") public void testGetMBean(String mbeanName) throws Exception { URI uri = uriBuilderFrom(uriFor("/v1/jmx/mbean")) .appendPath(mbeanName) .build(); JsonNode mbean = jsonRequest(uri); JsonNode name = mbean.get("objectName"); assertTrue(name.isTextual()); assertEquals(name.asText(), mbeanName); }
@Test public void testAppendToDefaultPath() { URI uri = uriBuilder() .scheme("http") .host("www.example.com") .appendPath("/a/b/c") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com/a/b/c"); }
@Test public void testDoesNotStripTrailingSlash() { URI uri = uriBuilder() .scheme("http") .host("www.example.com") .appendPath("/a/b/c/") .build(); assertEquals(uri.toASCIIString(), "http://www.example.com/a/b/c/"); }