public TaskIdResponseHeaderFilterHolder(String path, String taskId) { super(path, taskId == null ? ImmutableMap.of() : ImmutableMap.of(ChatHandlerResource.TASK_ID_HEADER, StringUtils.urlEncode(taskId)) ); } }
@Path("/chat/{id}") public Object doTaskChat(@PathParam("id") String handlerId, @Context HttpHeaders headers) { if (taskId != null) { List<String> requestTaskId = headers.getRequestHeader(TASK_ID_HEADER); if (requestTaskId != null && !requestTaskId.contains(StringUtils.urlEncode(taskId))) { return null; } } final Optional<ChatHandler> handler = handlers.get(handlerId); if (handler.isPresent()) { return handler.get(); } return null; } }
private String getMetadataSegmentsURL(String dataSource) { return StringUtils.format("%smetadata/datasources/%s/segments", getCoordinatorURL(), StringUtils.urlEncode(dataSource)); }
private String getIntervalsURL(String dataSource) { return StringUtils.format("%sdatasources/%s/intervals", getCoordinatorURL(), StringUtils.urlEncode(dataSource)); }
public void unloadSegmentsForDataSource(String dataSource) { try { makeRequest(HttpMethod.DELETE, StringUtils.format("%sdatasources/%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource))); } catch (Exception e) { throw Throwables.propagate(e); } }
public void deleteSegmentsDataSource(String dataSource, Interval interval) { try { makeRequest( HttpMethod.DELETE, StringUtils.format( "%sdatasources/%s/intervals/%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource), interval.toString().replace('/', '_') ) ); } catch (Exception e) { throw Throwables.propagate(e); } }
private URL getListenerURL(DruidNode druidNode, String baseUrl, String itemName) { try { return new URL( druidNode.getServiceScheme(), druidNode.getHost(), druidNode.getPortToUse(), StringUtils.format(baseUrl, StringUtils.urlEncode(itemName)) ); } catch (MalformedURLException mue) { LOG.error(callerName + ":WTF? Malformed url for DruidNode[%s] and itemName[%s]", druidNode, itemName); throw new RuntimeException(mue); } }
@Override public TaskStatusResponse getTaskStatus(String taskId) { try { final FullResponseHolder responseHolder = druidLeaderClient.go( druidLeaderClient.makeRequest(HttpMethod.GET, StringUtils.format( "/druid/indexer/v1/task/%s/status", StringUtils.urlEncode(taskId) )) ); return jsonMapper.readValue( responseHolder.getContent(), new TypeReference<TaskStatusResponse>() { } ); } catch (IOException | InterruptedException e) { throw new RuntimeException(e); } }
StringUtils.format( "/druid/indexer/v1/task/%s/shutdown", StringUtils.urlEncode(taskId)
@Override public int killPendingSegments(String dataSource, DateTime end) { final String endPoint = StringUtils.format( "/druid/indexer/v1/pendingSegments/%s?interval=%s", StringUtils.urlEncode(dataSource), new Interval(DateTimes.MIN, end) ); try { final FullResponseHolder responseHolder = druidLeaderClient.go( druidLeaderClient.makeRequest(HttpMethod.DELETE, endPoint) ); if (!responseHolder.getStatus().equals(HttpResponseStatus.OK)) { throw new ISE("Error while killing pendingSegments of dataSource[%s] created until [%s]", dataSource, end); } final Map<String, Object> resultMap = jsonMapper.readValue( responseHolder.getContent(), JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT ); final Object numDeletedObject = resultMap.get("numDeleted"); return (Integer) Preconditions.checkNotNull(numDeletedObject, "numDeletedObject"); } catch (Exception e) { throw new RuntimeException(e); } } }
public void shutdownSupervisor(String id) { try { StatusResponseHolder response = httpClient.go( new Request(HttpMethod.POST, new URL(StringUtils.format("%ssupervisor/%s/shutdown", getIndexerURL(), StringUtils.urlEncode(id)))), responseHandler ).get(); if (!response.getStatus().equals(HttpResponseStatus.OK)) { throw new ISE( "Error while shutting down supervisor, response [%s %s]", response.getStatus(), response.getContent() ); } LOG.info("Shutdown supervisor with id[%s]", id); } catch (Exception e) { throw Throwables.propagate(e); } }
private Request createRequest( String taskId, TaskLocation location, String path, @Nullable String encodedQueryString, HttpMethod method, @Nullable String mediaType, byte[] content ) throws MalformedURLException { final String host = location.getHost(); final String scheme = location.getTlsPort() >= 0 ? "https" : "http"; final int port = location.getTlsPort() >= 0 ? location.getTlsPort() : location.getPort(); // Use URL constructor, not URI, since the path is already encoded. // The below line can throw a MalformedURLException, and this method should return immediately without rety. final URL serviceUrl = new URL( scheme, host, port, encodedQueryString == null ? path : StringUtils.format("%s?%s", path, encodedQueryString) ); final Request request = new Request(method, serviceUrl); // used to validate that we are talking to the correct worker request.addHeader(ChatHandlerResource.TASK_ID_HEADER, StringUtils.urlEncode(taskId)); if (content.length > 0) { request.setContent(Preconditions.checkNotNull(mediaType, "mediaType"), content); } return request; }
public static class TaskNotRunnableException extends RuntimeException { public TaskNotRunnableException(String message) { super(message); } }
"%s/%s/dimensions?interval=%s", getBrokerURL(), StringUtils.urlEncode(dataSource), interval ))
public TaskState getTaskStatus(String taskID) { try { StatusResponseHolder response = makeRequest( HttpMethod.GET, StringUtils.format( "%stask/%s/status", getIndexerURL(), StringUtils.urlEncode(taskID) ) ); LOG.info("Index status response" + response.getContent()); TaskStatusResponse taskStatusResponse = jsonMapper.readValue( response.getContent(), new TypeReference<TaskStatusResponse>() { } ); return taskStatusResponse.getStatus().getStatusCode(); } catch (Exception e) { throw Throwables.propagate(e); } }
@Test public void testURLEncodeSpace() { String s1 = StringUtils.urlEncode("aaa bbb"); Assert.assertEquals(s1, "aaa%20bbb"); Assert.assertEquals("aaa bbb", StringUtils.urlDecode(s1)); String s2 = StringUtils.urlEncode("fff+ggg"); Assert.assertEquals(s2, "fff%2Bggg"); Assert.assertEquals("fff+ggg", StringUtils.urlDecode(s2)); } }
StringUtils.format( "/druid/coordinator/v1/datasources/%s/handoffComplete?interval=%s&partitionNumber=%d&version=%s", StringUtils.urlEncode(dataSource), descriptor.getInterval(), descriptor.getPartitionNumber(),
private URL getListenerURL(DruidNode druidNode, String baseUrl, String itemName) { try { return new URL( druidNode.getServiceScheme(), druidNode.getHost(), druidNode.getPortToUse(), StringUtils.format(baseUrl, StringUtils.urlEncode(itemName)) ); } catch (MalformedURLException mue) { LOG.error(callerName + ":WTF? Malformed url for DruidNode[%s] and itemName[%s]", druidNode, itemName); throw new RuntimeException(mue); } }
Request request = null; TaskLocation location = TaskLocation.unknown(); String path = StringUtils.format("%s/%s/%s", BASE_PATH, StringUtils.urlEncode(taskId), encodedPathSuffix);