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 static TimeRange parseTime(long fromTimeSecsParam, long toTimeSecsParam, HttpResponder responder) { long currentTimeMillis = System.currentTimeMillis(); long fromMillis = fromTimeSecsParam < 0 ? currentTimeMillis - TimeUnit.HOURS.toMillis(1) : TimeUnit.SECONDS.toMillis(fromTimeSecsParam); long toMillis = toTimeSecsParam < 0 ? currentTimeMillis : TimeUnit.SECONDS.toMillis(toTimeSecsParam); if (toMillis <= fromMillis) { responder.sendString(HttpResponseStatus.BAD_REQUEST, "Invalid time range. " + "'stop' should be greater than 'start'."); return null; } return new TimeRange(fromMillis, toMillis); }
private boolean checkIfProgramExists(ProgramId programId, HttpResponder responder) throws Exception { if (!store.programExists(programId)) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Program %s not found", programId)); return false; } return true; }
@Path(Constants.Gateway.API_VERSION_3 + "/system/services/{service-name}/stacks") @GET public void stacks(HttpRequest request, HttpResponder responder, @PathParam("service-name") String serviceName, @QueryParam("depth") @DefaultValue("20") int depth) { StringWriter stringWriter = new StringWriter(); getThreadInfo(new PrintWriter(stringWriter), serviceName, depth); responder.sendString(HttpResponseStatus.OK, stringWriter.toString()); }
/** * Shuts down the runtime monitor server. */ @POST @Path("/shutdown") public void shutdown(HttpRequest request, HttpResponder responder) { responder.sendString(HttpResponseStatus.OK, "Triggering shutdown down Runtime Http Server."); shutdownLatch.countDown(); stop(); }
@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"); } }
@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"); } }
@DELETE @Path("/**/properties/{property}") public void removeProperty(HttpRequest request, HttpResponder responder, @PathParam("property") String property, @QueryParam("type") String type) { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/properties"); metadataAdmin.removeProperties(metadataEntity, Collections.singleton(property)); responder.sendString(HttpResponseStatus.OK, String.format("Metadata property %s for %s deleted successfully.", property, metadataEntity)); }
@DELETE @Path("/**/metadata/tags/{tag}") public void removeTag(HttpRequest request, HttpResponder responder, @PathParam("tag") String tag, @QueryParam("type") String type) { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/tags"); metadataAdmin.removeTags(metadataEntity, Collections.singleton(tag)); responder.sendString(HttpResponseStatus.OK, String.format("Metadata tag %s for %s deleted successfully.", tag, metadataEntity)); }
@DELETE @Path("/**/properties/{property}") public void removeProperty(HttpRequest request, HttpResponder responder, @PathParam("property") String property, @QueryParam("type") String type) { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/properties"); metadataAdmin.removeProperties(metadataEntity, Collections.singleton(property)); responder.sendString(HttpResponseStatus.OK, String.format("Metadata property %s for %s deleted successfully.", property, metadataEntity)); }
@DELETE @Path("/**/metadata") public void removeMetadata(HttpRequest request, HttpResponder responder, @QueryParam("type") String type) { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata"); metadataAdmin.removeMetadata(metadataEntity); responder.sendString(HttpResponseStatus.OK, String.format("Metadata for %s deleted successfully.", metadataEntity)); }
@DELETE @Path("/**/metadata/properties") public void removeProperties(HttpRequest request, HttpResponder responder, @QueryParam("type") String type) { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/properties"); metadataAdmin.removeProperties(metadataEntity); responder.sendString(HttpResponseStatus.OK, String.format("Metadata properties for %s deleted successfully.", metadataEntity)); }
@DELETE @Path("/**/metadata/tags") public void removeTags(HttpRequest request, HttpResponder responder, @QueryParam("type") String type) { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/tags"); metadataAdmin.removeTags(metadataEntity); responder.sendString(HttpResponseStatus.OK, String.format("Metadata tags for %s deleted successfully.", metadataEntity)); }
@DELETE @Path("/**/metadata/tags") public void removeTags(HttpRequest request, HttpResponder responder, @QueryParam("type") String type) { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/tags"); metadataAdmin.removeTags(metadataEntity); responder.sendString(HttpResponseStatus.OK, String.format("Metadata tags for %s deleted successfully.", metadataEntity)); }
@DELETE @Path("/**/metadata/properties") public void removeProperties(HttpRequest request, HttpResponder responder, @QueryParam("type") String type) { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/properties"); metadataAdmin.removeProperties(metadataEntity); responder.sendString(HttpResponseStatus.OK, String.format("Metadata properties for %s deleted successfully.", metadataEntity)); }
@Path("/namespaces/{namespace-id}/preferences") @DELETE public void deleteNamespacePrefs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (nsStore.get(namespaceId) == null) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Namespace %s not present", namespace)); } else { preferencesService.deleteProperties(namespaceId); responder.sendStatus(HttpResponseStatus.OK); } }
@PUT @Path("/namespaces/{namespace-id}/properties") @AuditPolicy(AuditDetail.REQUEST_BODY) public void updateNamespaceProperties(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception { NamespaceMeta meta = getNamespaceMeta(request); namespaceAdmin.updateProperties(new NamespaceId(namespaceId), meta); responder.sendString(HttpResponseStatus.OK, String.format("Updated properties for namespace '%s'.", namespaceId)); }
@Path("/namespaces/{namespace-id}/preferences") @DELETE public void deleteNamespacePrefs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception { NamespaceId namespaceId = new NamespaceId(namespace); if (nsStore.get(namespaceId) == null) { responder.sendString(HttpResponseStatus.NOT_FOUND, String.format("Namespace %s not present", namespace)); } else { preferencesService.deleteProperties(namespaceId); responder.sendStatus(HttpResponseStatus.OK); } }
@POST @Path("/**/metadata/properties") @AuditPolicy(AuditDetail.REQUEST_BODY) public void addProperties(FullHttpRequest request, HttpResponder responder, @QueryParam("type") String type) throws BadRequestException { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/properties"); metadataAdmin.addProperties(metadataEntity, readProperties(request)); responder.sendString(HttpResponseStatus.OK, String.format("Metadata properties for %s added successfully.", metadataEntity)); }
@POST @Path("/**/metadata/properties") @AuditPolicy(AuditDetail.REQUEST_BODY) public void addProperties(FullHttpRequest request, HttpResponder responder, @QueryParam("type") String type) throws BadRequestException { MetadataEntity metadataEntity = getMetadataEntityFromPath(request.uri(), type, "/metadata/properties"); metadataAdmin.addProperties(metadataEntity, readProperties(request)); responder.sendString(HttpResponseStatus.OK, String.format("Metadata properties for %s added successfully.", metadataEntity)); }