@Path("/versions") @GET public void versions(@SuppressWarnings("UnusedParameters") HttpRequest request, HttpResponder responder) { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(versions)); }
@Path("/{dashboard-id}") @DELETE public void delete(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("dashboard-id") String id) throws Exception { try { dashboardStore.delete(namespace, id); responder.sendStatus(HttpResponseStatus.OK); } catch (ConfigNotFoundException e) { responder.sendString(HttpResponseStatus.NOT_FOUND, "Dashboard not found"); } }
@Override public void sendContent(HttpResponseStatus status, ByteBuf content, HttpHeaders headers) { delegate.sendContent(status, content, headers); runHook(status); }
private void getLiveInfo(HttpResponder responder, ProgramId programId, ProgramRuntimeService runtimeService) { try { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runtimeService.getLiveInfo(programId))); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } }
private void doDownloadQueryResults(HttpResponder responder, QueryHandle handle) throws ExploreException, IOException { try { if (handle.equals(QueryHandle.NO_OP) || !exploreService.getStatus(handle).getStatus().equals(QueryStatus.OpStatus.FINISHED)) { responder.sendStatus(HttpResponseStatus.CONFLICT); return; } QueryResultsBodyProducer queryResultsBodyProducer = new QueryResultsBodyProducer(exploreService, handle); responder.sendContent(HttpResponseStatus.OK, queryResultsBodyProducer, EmptyHttpHeaders.INSTANCE); } catch (IllegalArgumentException e) { LOG.debug("Got exception:", e); responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage()); } catch (SQLException e) { LOG.debug("Got exception:", e); responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage())); } catch (HandleNotFoundException e) { if (e.isInactive()) { responder.sendString(HttpResponseStatus.CONFLICT, "Query is inactive"); } else { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } } } }
@Path("/preferences") @DELETE public void deleteInstancePrefs(HttpRequest request, HttpResponder responder) throws Exception { preferencesService.deleteProperties(); responder.sendStatus(HttpResponseStatus.OK); }
private <T extends Throwable> boolean respondIfRootCauseOf(Throwable t, Class<T> type, HttpResponseStatus status, HttpResponder responder, String msgFormat, Object... args) { if (type.isAssignableFrom(Throwables.getRootCause(t).getClass())) { responder.sendString(status, String.format(msgFormat, args)); return true; } return false; }
responder.sendString(HttpResponseStatus.NOT_FOUND, "JobId not found for stage " + stageId); return; responder.sendString(HttpResponseStatus.GONE, "No transaction associated with the stage " + stageId + " of job " + jobId); return; if (transaction == null) { responder.sendString(HttpResponseStatus.GONE, "Failed to start transaction for stage " + stageId + " of job " + jobId); return; responder.sendByteArray(HttpResponseStatus.OK, TX_CODEC.encode(transaction), EmptyHttpHeaders.INSTANCE); } catch (IOException e) { responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Failed to encode transaction: " + e.getMessage());
@POST @Path("/publish") public void publish(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); StoreRequest storeRequest = createStoreRequest(topicId, request); // Empty payload is only allowed for transactional publish if (!storeRequest.isTransactional() && !storeRequest.hasPayload()) { throw new BadRequestException("Empty payload is only allowed for publishing transactional message. Topic: " + topicId); } // Publish the message and response with the rollback information RollbackDetail rollbackInfo = messagingService.publish(storeRequest); if (rollbackInfo == null) { // Non-tx publish doesn't have rollback info. responder.sendStatus(HttpResponseStatus.OK); return; } ByteBuf response = encodeRollbackDetail(rollbackInfo); responder.sendContent(HttpResponseStatus.OK, response, new DefaultHttpHeaders().set(HttpHeaderNames.CONTENT_TYPE, "avro/binary")); }
responder.sendStatus(HttpResponseStatus.NO_CONTENT); return null; ChunkResponder chunkResponder = responder.sendChunkStart( HttpResponseStatus.OK, new DefaultHttpHeaders().set(HttpHeaderNames.CONTENT_TYPE, "application/json; charset=utf-8"));
@Path("/{key-name}") @GET public void get(HttpRequest httpRequest, HttpResponder httpResponder, @PathParam("namespace-id") String namespace, @PathParam("key-name") String name) throws Exception { SecureKeyId secureKeyId = new SecureKeyId(namespace, name); httpResponder.sendByteArray(HttpResponseStatus.OK, secureStore.get(namespace, name).get(), new DefaultHttpHeaders().set(HttpHeaderNames.CONTENT_TYPE, "text/plain;charset=utf-8")); }
LOG.error("No input stream available, but metadata exists for version {} of resource {} for tenant {}.", version, name, account.getTenantId()); responder.sendError(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error getting resource."); ChunkResponder chunkResponder = responder.sendChunkStart( HttpResponseStatus.OK, ImmutableMultimap.<String, String>of()); while (true) { responder.sendError(HttpResponseStatus.BAD_REQUEST, "Invalid version " + versionStr); } catch (IOException e) { responder.sendError(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error getting resource."); } catch (MissingEntityException e) { responder.sendError(HttpResponseStatus.NOT_FOUND, "Resource not found.");
@Override public ChunkResponder sendChunkStart(final HttpResponseStatus status, HttpHeaders headers) { final ChunkResponder chunkResponder = delegate.sendChunkStart(status, headers); return new ChunkResponder() { @Override public void sendChunk(ByteBuffer chunk) throws IOException { chunkResponder.sendChunk(chunk); } @Override public void sendChunk(ByteBuf chunk) throws IOException { chunkResponder.sendChunk(chunk); } @Override public void close() throws IOException { chunkResponder.close(); runHook(status); } }; }
private void doDownloadQueryResults(HttpResponder responder, QueryHandle handle) throws ExploreException, IOException { try { if (handle.equals(QueryHandle.NO_OP) || !exploreService.getStatus(handle).getStatus().equals(QueryStatus.OpStatus.FINISHED)) { responder.sendStatus(HttpResponseStatus.CONFLICT); return; } QueryResultsBodyProducer queryResultsBodyProducer = new QueryResultsBodyProducer(exploreService, handle); responder.sendContent(HttpResponseStatus.OK, queryResultsBodyProducer, EmptyHttpHeaders.INSTANCE); } catch (IllegalArgumentException e) { LOG.debug("Got exception:", e); responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage()); } catch (SQLException e) { LOG.debug("Got exception:", e); responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage())); } catch (HandleNotFoundException e) { if (e.isInactive()) { responder.sendString(HttpResponseStatus.CONFLICT, "Query is inactive"); } else { responder.sendStatus(HttpResponseStatus.NOT_FOUND); } } } }
/** * Trigger transaction pruning. */ @Path("/transactions/prune/now") @POST public void pruneNow(HttpRequest request, HttpResponder responder) { txClient.pruneNow(); responder.sendStatus(HttpResponseStatus.OK); }
private <T extends Throwable> boolean respondIfRootCauseOf(Throwable t, Class<T> type, HttpResponseStatus status, HttpResponder responder, String msgFormat, Object... args) { if (type.isAssignableFrom(Throwables.getRootCause(t).getClass())) { responder.sendString(status, String.format(msgFormat, args)); return true; } return false; }
private void getLiveInfo(HttpResponder responder, ProgramId programId, ProgramRuntimeService runtimeService) { try { responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runtimeService.getLiveInfo(programId))); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } }
responder.sendString(HttpResponseStatus.NOT_FOUND, "JobId not found for stage " + stageId); return; responder.sendString(HttpResponseStatus.GONE, "No transaction associated with the stage " + stageId + " of job " + jobId); return; if (transaction == null) { responder.sendString(HttpResponseStatus.GONE, "Failed to start transaction for stage " + stageId + " of job " + jobId); return; responder.sendByteArray(HttpResponseStatus.OK, TX_CODEC.encode(transaction), EmptyHttpHeaders.INSTANCE); } catch (IOException e) { responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Failed to encode transaction: " + e.getMessage());
@POST @Path("/publish") public void publish(FullHttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("topic") String topic) throws Exception { TopicId topicId = new NamespaceId(namespace).topic(topic); StoreRequest storeRequest = createStoreRequest(topicId, request); // Empty payload is only allowed for transactional publish if (!storeRequest.isTransactional() && !storeRequest.hasPayload()) { throw new BadRequestException("Empty payload is only allowed for publishing transactional message. Topic: " + topicId); } // Publish the message and response with the rollback information RollbackDetail rollbackInfo = messagingService.publish(storeRequest); if (rollbackInfo == null) { // Non-tx publish doesn't have rollback info. responder.sendStatus(HttpResponseStatus.OK); return; } ByteBuf response = encodeRollbackDetail(rollbackInfo); responder.sendContent(HttpResponseStatus.OK, response, new DefaultHttpHeaders().set(HttpHeaderNames.CONTENT_TYPE, "avro/binary")); }
@Path("/{key-name}") @GET public void get(HttpRequest httpRequest, HttpResponder httpResponder, @PathParam("namespace-id") String namespace, @PathParam("key-name") String name) throws Exception { SecureKeyId secureKeyId = new SecureKeyId(namespace, name); httpResponder.sendByteArray(HttpResponseStatus.OK, secureStore.getSecureData(namespace, name).get(), new DefaultHttpHeaders().set(HttpHeaderNames.CONTENT_TYPE, "text/plain;charset=utf-8")); }