Ejemplo n.º 1
0
  @SuppressWarnings("rawtypes")
  private boolean retryFailedEntries(InputStream content, TrackingBytesArray data)
      throws IOException {
    ObjectReader r = mapper.reader(Map.class);
    JsonParser parser = mapper.getJsonFactory().createJsonParser(content);
    if (ParsingUtils.seek("items", new JacksonJsonParser(parser)) == null) {
      return false;
    }

    int entryToDeletePosition = 0; // head of the list
    for (Iterator<Map> iterator = r.readValues(parser); iterator.hasNext(); ) {
      Map map = iterator.next();
      Map values = (Map) map.values().iterator().next();
      String error = (String) values.get("error");
      if (error != null) {
        // status - introduced in 1.0.RC1
        Integer status = (Integer) values.get("status");
        if (status != null && HttpStatus.canRetry(status)
            || error.contains("EsRejectedExecutionException")) {
          entryToDeletePosition++;
        } else {
          String message =
              (status != null
                  ? String.format("%s(%s) - %s", HttpStatus.getText(status), status, error)
                  : error);
          throw new IllegalStateException(
              String.format("Found unrecoverable error [%s]; Bailing out..", message));
        }
      } else {
        data.remove(entryToDeletePosition);
      }
    }

    return entryToDeletePosition > 0;
  }
 /** Extracts the fields from a json record and returns a map containing field names and values */
 @Override
 Map<String, Object> extractFields(String line) {
   try {
     return reader.readValue(line);
   } catch (IOException e) {
     logger.error("Exception while extracting fields {}", e);
   }
   return null;
 }