private static WebApplicationException badRequest(String message) { throw new WebApplicationException(Response .status(Status.BAD_REQUEST) .type(MediaType.TEXT_PLAIN) .entity(message) .build()); }
@POST @Path("webapplication_entity") public String testWebApplicationExceptionEntity(String s) { String[] tokens = s.split(":"); assert tokens.length == 2; int statusCode = Integer.valueOf(tokens[1]); Response r = Response.status(statusCode).entity(s).build(); throw new WebApplicationException(r); }
@Override public String set(String value) { if (System.setProperty(name, value) == null) { throw new WebApplicationException(Response.created(uriInfo.getRequestUri()).entity(value).build()); } return value; } }
@PUT @Path("state") @Consumes(APPLICATION_JSON) @Produces(TEXT_PLAIN) public Response updateState(NodeState state) throws WebApplicationException { requireNonNull(state, "state is null"); switch (state) { case SHUTTING_DOWN: shutdownHandler.requestShutdown(); return Response.ok().build(); case ACTIVE: case INACTIVE: throw new WebApplicationException(Response .status(BAD_REQUEST) .type(MediaType.TEXT_PLAIN) .entity(format("Invalid state transition to %s", state)) .build()); default: return Response.status(BAD_REQUEST) .type(TEXT_PLAIN) .entity(format("Invalid state %s", state)) .build(); } }
@PUT @Path("/tasks/cleanuptasks/{taskType}") @ApiOperation("Clean up tasks for the given task type") public SuccessResponse cleanUpTasks( @ApiParam(value = "Task type", required = true) @PathParam("taskType") String taskType) { try { _pinotHelixTaskResourceManager.cleanUpTaskQueue(taskType); return new SuccessResponse("Successfully cleaned up tasks for task type: " + taskType); } catch (Exception e) { throw new WebApplicationException(e); } }
@GET @Path("/tasks/taskqueues") @ApiOperation("List all task queues") public Set<String> getTaskQueues() { try { return _pinotHelixTaskResourceManager.getTaskQueues(); } catch (Exception e) { throw new WebApplicationException(e); } }
@POST @Produces(MediaType.APPLICATION_JSON) @Path("query") @ApiOperation(value = "Querying pinot") @ApiResponses(value = {@ApiResponse(code = 200, message = "Query response"), @ApiResponse(code = 500, message = "Internal Server Error")}) public String processQueryPost(String query) { try { JsonNode requestJson = JsonUtils.stringToJsonNode(query); BrokerResponse brokerResponse = requestHandler.handleRequest(requestJson, null, new RequestStatistics()); return brokerResponse.toJsonString(); } catch (Exception e) { LOGGER.error("Caught exception while processing GET request", e); brokerMetrics.addMeteredGlobalValue(BrokerMeter.UNCAUGHT_GET_EXCEPTIONS, 1); throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR); } } }
@GET @Timed @Produces(MediaType.APPLICATION_JSON) public Map<String, String> naturalDateTester(@QueryParam("string") @NotEmpty String string) { try { return new NaturalDateParser().parse(string).asMap(); } catch (NaturalDateParser.DateNotParsableException e) { LOG.debug("Could not parse from natural date: " + string, e); throw new WebApplicationException(e, 422); } } }
@POST @Produces(MediaType.APPLICATION_JSON) public Response createQuery( String statement, throw new WebApplicationException(Response .status(Status.BAD_REQUEST) .type(MediaType.TEXT_PLAIN) .entity("SQL statement is empty") .build());
@Produces("*/*") @Consumes("*/*") public static final class General extends JettisonArrayProvider { @Override protected boolean isSupported(MediaType m) { return m.getSubtype().endsWith("+json"); } }
@PUT @Path("/tasks/scheduletasks") @ApiOperation("Schedule tasks") public Map<String, String> scheduleTasks() { try { return _pinotTaskManager.scheduleTasks(); } catch (Exception e) { throw new WebApplicationException(e); } }
@GET @Path("/tasks/taskstates/{taskType}") @ApiOperation("Get a map from task name to task state for the given task type") public Map<String, TaskState> getTaskStates( @ApiParam(value = "Task type", required = true) @PathParam("taskType") String taskType) { try { return _pinotHelixTaskResourceManager.getTaskStates(taskType); } catch (Exception e) { throw new WebApplicationException(e); } }
@DELETE @Path("/tasks/taskqueue/{taskType}") @ApiOperation("Delete a task queue") public SuccessResponse deleteTaskQueue( @ApiParam(value = "Task type", required = true) @PathParam("taskType") String taskType) { try { _pinotHelixTaskResourceManager.deleteTaskQueue(taskType); return new SuccessResponse("Successfully deleted task queue for task type: " + taskType); } catch (Exception e) { throw new WebApplicationException(e); } } }
private static WebApplicationException badRequest(Status status, String message) { throw new WebApplicationException( Response.status(status) .type(TEXT_PLAIN_TYPE) .entity(message) .build()); }
@GET @Path("/tasks/tasktypes") @ApiOperation("List all task types") public Set<String> listTaskTypes() { try { return _pinotHelixTaskResourceManager.getTaskTypes(); } catch (Exception e) { throw new WebApplicationException(e); } }
@POST @Path("webapplication_noentity") public String testWebApplicationExceptionNoEntity(String s) { String[] tokens = s.split(":"); assert tokens.length == 2; int statusCode = Integer.valueOf(tokens[1]); Response r = Response.status(statusCode).build(); throw new WebApplicationException(r); }
@Produces("*/*") @Consumes("*/*") public static final class General extends JettisonObjectProvider { @Override protected boolean isSupported(MediaType m) { return m.getSubtype().endsWith("+json"); } }
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(); }
@GET @Path("/tasks/tasks/{taskType}") @ApiOperation("List all tasks for the given task type") public Set<String> getTasks(@ApiParam(value = "Task type", required = true) @PathParam("taskType") String taskType) { try { return _pinotHelixTaskResourceManager.getTasks(taskType); } catch (Exception e) { throw new WebApplicationException(e); } }
@POST @Timed @Path("/multiple") @ApiOperation("Get the values of multiple metrics at once from node") @ApiResponses(value = { @ApiResponse(code = 400, message = "Malformed body") }) @NoAuditEvent("only used to get multiple metric values") public MetricsSummaryResponse multipleMetrics(@ApiParam(name = "nodeId", value = "The id of the node whose metrics we want.", required = true) @PathParam("nodeId") String nodeId, @ApiParam(name = "Requested metrics", required = true) @Valid @NotNull MetricsReadRequest request) throws IOException, NodeNotFoundException { final Response<MetricsSummaryResponse> result = getResourceForNode(nodeId).multipleMetrics(request).execute(); if (result.isSuccessful()) { return result.body(); } else { throw new WebApplicationException(result.message(), BAD_GATEWAY); } }