예제 #1
0
  @GET
  @Path("/system/{component-id}/{service-id}/logs/next")
  public void sysNext(
      HttpRequest request,
      HttpResponder responder,
      @PathParam("component-id") String componentId,
      @PathParam("service-id") String serviceId,
      @QueryParam("max") @DefaultValue("50") int maxEvents,
      @QueryParam("fromOffset") @DefaultValue("") String fromOffsetStr,
      @QueryParam("escape") @DefaultValue("true") boolean escape,
      @QueryParam("filter") @DefaultValue("") String filterStr) {
    try {
      Filter filter = FilterParser.parse(filterStr);

      LoggingContext loggingContext =
          LoggingContextHelper.getLoggingContext(
              Constants.SYSTEM_NAMESPACE, componentId, serviceId);
      LogReaderCallback logCallback = new LogReaderCallback(responder, logPattern, escape);
      LogOffset logOffset = FormattedLogEvent.parseLogOffset(fromOffsetStr);
      ReadRange readRange = ReadRange.createFromRange(logOffset);
      logReader.getLogNext(loggingContext, readRange, maxEvents, filter, logCallback);
      logCallback.close();
    } catch (IllegalArgumentException e) {
      responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (Throwable e) {
      LOG.error("Caught exception", e);
      responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
  }
예제 #2
0
  private void doNext(
      HttpResponder responder,
      LoggingContext loggingContext,
      int maxEvents,
      String fromOffsetStr,
      boolean escape,
      String filterStr,
      @Nullable RunRecord runRecord) {
    try {
      Filter filter = FilterParser.parse(filterStr);

      LogReaderCallback logCallback = new LogReaderCallback(responder, logPattern, escape);

      LogOffset logOffset = FormattedLogEvent.parseLogOffset(fromOffsetStr);
      ReadRange readRange = ReadRange.createFromRange(logOffset);
      readRange = adjustReadRange(readRange, runRecord);
      logReader.getLogNext(loggingContext, readRange, maxEvents, filter, logCallback);
      logCallback.close();
    } catch (SecurityException e) {
      responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (IllegalArgumentException e) {
      responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
    } catch (Throwable e) {
      LOG.error("Caught exception", e);
      responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
    }
  }