Example #1
0
  /**
   * After the log file has been processed, this inputs the log line into the database. It generates
   * the sql by reading in each log lines outputs data structure
   *
   * @param line The actual log line which is being entered into the database
   * @throws SQLException If an error occurs with the query
   */
  protected void insertToDB(LogLine line) throws SQLException {
    // Add the fields that are determined by the log file rather than the log line
    addLogFields(line.getOutputs());
    String sql = "INSERT INTO logdata_temp (";
    String fields = "";
    String inputs = "";
    for (Map.Entry<String, String> entry : line.getOutputs().entrySet()) {
      fields += entry.getKey() + ",";
      inputs += fieldType(entry.getKey(), entry.getValue()) + ",";
    }
    fields = sql + fields.substring(0, fields.lastIndexOf(",")) + ") VALUES ";
    inputs = "(" + inputs.substring(0, inputs.lastIndexOf(",")) + ")";

    db.bulkInsert(this, fields, inputs, Integer.parseInt(line.getOutputs().get("log_line")));
  }
 public static int Record(long sync_id, String idx) {
   LogLine temp = rec_map.get(sync_id);
   if (null == temp) {
     idx_map.put(sync_id, idx);
   } else {
     temp.dstidx = idx;
     // tell score system about temp;
     rec_map.remove(sync_id);
     // tell elasticsearch;
     IndexResponse response =
         client
             .prepareIndex(DATABASEINDEX, DATABASETYPE)
             .setSource(gson.toJson(temp))
             .execute()
             .actionGet();
     if (!response.isCreated()) {
       System.out.println(PROMPT + "Elasticsearch recording failed!");
       return ERROR;
     }
     // test
     WriteToDisk(temp);
   }
   return SUCCESS;
 }