public void handleRequest()

in hms-lambda-rnp/src/main/java/com/amazonaws/athena/HiveMetaStoreRnPBaseLambdaFunc.java [176:219]


  public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException
  {
    try (MetadataRequest metadataRequest = objectMapper.readValue(inputStream, MetadataRequest.class)) {
      // cloud watch logs, we need them for monitoring and debugging
      context.getLogger().log("Lambda Func in mode: " + mode);
      context.getLogger().log("RequestContext: " + metadataRequest.getContext());
      String apiName = metadataRequest.getApiName();
      context.getLogger().log("API: " + apiName);
      HandlerContext handlerContext = handlers.get(apiName);
      if (handlerContext == null) {
        throw new RuntimeException("Cannot find handler for API " + apiName);
      }
      ApiRequest apiRequest = metadataRequest.getApiRequest();
      ApiResponse apiResponse;
      if (mode == RNPMode.REPLAY) {
        apiResponse = getResponseFromS3(context, handlerContext, apiName, apiRequest);
      }
      else {
        apiResponse = getResponseDirectly(context, handlerContext, apiName, apiRequest);
      }
      // serialize ApiResponse to String to get its size. Please be aware this isn't accurate
      String responseAsString = objectMapper.writerFor(handlerContext.getResponseClass()).writeValueAsString(apiResponse);
      // get the response String size
      long responseSize = responseAsString.getBytes().length;
      context.getLogger().log("Response size: " + responseSize);
      MetadataResponse response;
      if (responseSize >= responseSpillThreshold) {
        String spillPath = spillToS3(context, responseAsString);
        context.getLogger().log("Response size " + responseAsString.length() + " exceeded threshold "
            + responseSpillThreshold + ", is saved to s3: " + spillPath);
        response = new MetadataResponse(apiName, true, spillPath, null);
      }
      else {
        response = new MetadataResponse(apiName, false, null, apiResponse);
      }
      objectMapper.writeValue(outputStream, response);
      if (mode == RNPMode.RECORD) {
        recordToS3(context, metadataRequest, responseAsString);
      }
    }
    catch (Exception e) {
      throw new IOException(e);
    }
  }