コード例 #1
0
 @POST
 @Path("data/explore/queries/{id}/preview")
 public void getQueryResultPreview(
     HttpRequest request, HttpResponder responder, @PathParam("id") String id) {
   // NOTE: this call is a POST because it is not idempotent: cursor of results is moved
   try {
     QueryHandle handle = QueryHandle.fromId(id);
     List<QueryResult> results;
     if (handle.equals(QueryHandle.NO_OP)) {
       results = Lists.newArrayList();
     } else {
       results = exploreService.previewResults(handle);
     }
     responder.sendJson(HttpResponseStatus.OK, results);
   } 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, "Preview is unavailable for inactive queries.");
       return;
     }
     responder.sendStatus(HttpResponseStatus.NOT_FOUND);
   } catch (Throwable e) {
     LOG.error("Got exception:", e);
     responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
   }
 }
コード例 #2
0
 @GET
 @Path("data/explore/queries/{id}/status")
 public void getQueryStatus(
     HttpRequest request, HttpResponder responder, @PathParam("id") String id) {
   try {
     QueryHandle handle = QueryHandle.fromId(id);
     QueryStatus status;
     if (!handle.equals(QueryHandle.NO_OP)) {
       status = exploreService.getStatus(handle);
     } else {
       status = QueryStatus.NO_OP;
     }
     responder.sendJson(HttpResponseStatus.OK, status);
   } 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) {
     responder.sendStatus(HttpResponseStatus.NOT_FOUND);
   } catch (Throwable e) {
     LOG.error("Got exception:", e);
     responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
   }
 }
コード例 #3
0
 @POST
 @Path("data/explore/queries/{id}/next")
 public void getQueryNextResults(
     HttpRequest request, HttpResponder responder, @PathParam("id") String id) {
   // NOTE: this call is a POST because it is not idempotent: cursor of results is moved
   try {
     QueryHandle handle = QueryHandle.fromId(id);
     List<QueryResult> results;
     if (handle.equals(QueryHandle.NO_OP)) {
       results = Lists.newArrayList();
     } else {
       Map<String, String> args = decodeArguments(request);
       int size = args.containsKey("size") ? Integer.valueOf(args.get("size")) : 100;
       results = exploreService.nextResults(handle, size);
     }
     responder.sendJson(HttpResponseStatus.OK, results);
   } 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) {
     responder.sendStatus(HttpResponseStatus.NOT_FOUND);
   } catch (Throwable e) {
     LOG.error("Got exception:", e);
     responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
   }
 }
コード例 #4
0
ファイル: LogHandler.java プロジェクト: ngopina/cdap
  private void doPrev(
      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.createToRange(logOffset);
      readRange = adjustReadRange(readRange, runRecord);
      logReader.getLogPrev(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);
    }
  }
コード例 #5
0
ファイル: LogHandler.java プロジェクト: ngopina/cdap
  private void doGetLogs(
      HttpResponder responder,
      LoggingContext loggingContext,
      long fromTimeSecsParam,
      long toTimeSecsParam,
      boolean escape,
      String filterStr,
      @Nullable RunRecord runRecord) {
    try {
      TimeRange timeRange = parseTime(fromTimeSecsParam, toTimeSecsParam, responder);
      if (timeRange == null) {
        return;
      }

      Filter filter = FilterParser.parse(filterStr);

      ReadRange readRange =
          new ReadRange(
              timeRange.getFromMillis(), timeRange.getToMillis(), LogOffset.INVALID_KAFKA_OFFSET);
      readRange = adjustReadRange(readRange, runRecord);

      ChunkedLogReaderCallback logCallback =
          new ChunkedLogReaderCallback(responder, logPattern, escape);
      logReader.getLog(
          loggingContext, readRange.getFromMillis(), readRange.getToMillis(), 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);
    }
  }
コード例 #6
0
ファイル: LogHandler.java プロジェクト: ngopina/cdap
  @GET
  @Path("/system/{component-id}/{service-id}/logs/prev")
  public void sysPrev(
      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.createToRange(logOffset);
      logReader.getLogPrev(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);
    }
  }
コード例 #7
0
ファイル: LogHandler.java プロジェクト: ngopina/cdap
  @GET
  @Path("/system/{component-id}/{service-id}/logs")
  public void sysList(
      HttpRequest request,
      HttpResponder responder,
      @PathParam("component-id") String componentId,
      @PathParam("service-id") String serviceId,
      @QueryParam("start") @DefaultValue("-1") long fromTimeSecsParam,
      @QueryParam("stop") @DefaultValue("-1") long toTimeSecsParam,
      @QueryParam("escape") @DefaultValue("true") boolean escape,
      @QueryParam("filter") @DefaultValue("") String filterStr) {
    try {
      TimeRange timeRange = parseTime(fromTimeSecsParam, toTimeSecsParam, responder);
      if (timeRange == null) {
        return;
      }

      Filter filter = FilterParser.parse(filterStr);
      LoggingContext loggingContext =
          LoggingContextHelper.getLoggingContext(
              Constants.SYSTEM_NAMESPACE, componentId, serviceId);
      ChunkedLogReaderCallback logCallback =
          new ChunkedLogReaderCallback(responder, logPattern, escape);
      logReader.getLog(
          loggingContext, timeRange.getFromMillis(), timeRange.getToMillis(), 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);
    }
  }
コード例 #8
0
ファイル: SQLFlowTestBase.java プロジェクト: HarrellC/tigon
 @Path("/queue")
 @POST
 public void getPing(HttpRequest request, HttpResponder responder) {
   String dataPacket = request.getContent().toString(Charsets.UTF_8);
   LOG.info("/ping Got Data {}", dataPacket);
   queue.add(dataPacket);
   latch.countDown();
   responder.sendStatus(HttpResponseStatus.OK);
 }
コード例 #9
0
ファイル: SQLFlowTestBase.java プロジェクト: HarrellC/tigon
 @Path("/queue/poll")
 @GET
 public void pollData(HttpRequest request, HttpResponder responder) {
   if (queue.size() == 0) {
     responder.sendStatus(HttpResponseStatus.NO_CONTENT);
     return;
   }
   String dataPacket = queue.poll();
   responder.sendString(HttpResponseStatus.OK, dataPacket);
 }
コード例 #10
0
 @DELETE
 @Path("data/explore/queries/{id}")
 public void closeQuery(HttpRequest request, HttpResponder responder, @PathParam("id") String id) {
   try {
     QueryHandle handle = QueryHandle.fromId(id);
     if (!handle.equals(QueryHandle.NO_OP)) {
       exploreService.close(handle);
     }
     responder.sendStatus(HttpResponseStatus.OK);
   } catch (IllegalArgumentException e) {
     LOG.debug("Got exception:", e);
     responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
   } catch (HandleNotFoundException e) {
     responder.sendStatus(HttpResponseStatus.NOT_FOUND);
   } catch (Throwable e) {
     LOG.error("Got exception:", e);
     responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
   }
 }
コード例 #11
0
ファイル: MetricsHandler.java プロジェクト: domarps/cdap
 private void searchMetricAndRespond(HttpResponder responder, List<String> tagValues) {
   try {
     responder.sendJson(
         HttpResponseStatus.OK, getMetrics(humanToTagNames(parseTagValues(tagValues))));
   } catch (IllegalArgumentException e) {
     LOG.warn("Invalid request", e);
     responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
   } catch (Exception e) {
     LOG.warn("Exception while retrieving available metrics", e);
     responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
   }
 }
コード例 #12
0
  @POST
  @Path("data/explore/queries/{id}/download")
  public void downloadQueryResults(
      HttpRequest request, HttpResponder responder, @PathParam("id") final String id) {
    // NOTE: this call is a POST because it is not idempotent: cursor of results is moved
    boolean responseStarted = false;
    try {
      QueryHandle handle = QueryHandle.fromId(id);
      if (handle.equals(QueryHandle.NO_OP)
          || !exploreService.getStatus(handle).getStatus().equals(QueryStatus.OpStatus.FINISHED)) {
        responder.sendStatus(HttpResponseStatus.CONFLICT);
        return;
      }

      StringBuffer sb = new StringBuffer();
      sb.append(getCSVHeaders(exploreService.getResultSchema(handle)));
      sb.append('\n');

      List<QueryResult> results;
      results = exploreService.previewResults(handle);
      if (results.isEmpty()) {
        results = exploreService.nextResults(handle, DOWNLOAD_FETCH_CHUNK_SIZE);
      }

      ChunkResponder chunkResponder = responder.sendChunkStart(HttpResponseStatus.OK, null);
      responseStarted = true;
      while (!results.isEmpty()) {
        for (QueryResult result : results) {
          appendCSVRow(sb, result);
          sb.append('\n');
        }
        // If failed to send to client, just propagate the IOException and let netty-http to handle
        chunkResponder.sendChunk(ChannelBuffers.wrappedBuffer(sb.toString().getBytes("UTF-8")));
        sb.delete(0, sb.length());
        results = exploreService.nextResults(handle, DOWNLOAD_FETCH_CHUNK_SIZE);
      }
      Closeables.closeQuietly(chunkResponder);

    } catch (IllegalArgumentException e) {
      LOG.debug("Got exception:", e);
      // We can't send another response if sendChunkStart has been called
      if (!responseStarted) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
      }
    } catch (SQLException e) {
      LOG.debug("Got exception:", e);
      if (!responseStarted) {
        responder.sendString(
            HttpResponseStatus.BAD_REQUEST,
            String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage()));
      }
    } catch (HandleNotFoundException e) {
      if (!responseStarted) {
        if (e.isInactive()) {
          responder.sendString(HttpResponseStatus.CONFLICT, "Query is inactive");
        } else {
          responder.sendStatus(HttpResponseStatus.NOT_FOUND);
        }
      }
    } catch (Throwable e) {
      LOG.error("Got exception:", e);
      if (!responseStarted) {
        responder.sendStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
      }
    }
  }