예제 #1
0
  /** Helper method to delete an already existing dump directory */
  private void deleteDefaultDir() {
    ExportRequest exportRequest = new ExportRequest();
    exportRequest.source(
        "{\"output_file\": \"dump\", \"fields\": [\"_source\", \"_id\", \"_index\", \"_type\"], \"force_overwrite\": true, \"explain\": true}");
    ExportResponse explain = client().execute(ExportAction.INSTANCE, exportRequest).actionGet();

    try {
      Map<String, Object> res = toMap(explain);
      List<Map<String, String>> list = (ArrayList<Map<String, String>>) res.get("exports");
      for (Map<String, String> map : list) {
        File defaultDir = new File(map.get("output_file").toString());
        if (defaultDir.exists()) {
          for (File c : defaultDir.listFiles()) {
            c.delete();
          }
          defaultDir.delete();
        }
      }
    } catch (IOException e) {
    }
  }
예제 #2
0
  /** Dump request must also work with multiple nodes. */
  @Test
  public void testWithMultipleNodes() {

    // make sure target directory exists and is empty
    File dumpDir = new File("/tmp/multipleNodes");
    if (dumpDir.exists()) {
      for (File c : dumpDir.listFiles()) {
        c.delete();
      }
      dumpDir.delete();
    }
    dumpDir.mkdir();

    // Prepare a second node and wait for relocation
    String node2 = cluster().startNode();
    client(node2)
        .index(new IndexRequest("users", "d").source("{\"name\": \"motorbike\"}"))
        .actionGet();
    client(node2)
        .admin()
        .cluster()
        .prepareHealth()
        .setWaitForGreenStatus()
        .setWaitForNodes("2")
        .setWaitForRelocatingShards(0)
        .execute()
        .actionGet();

    // Do dump request
    String source = "{\"force_overwrite\": true, \"directory\":\"/tmp/multipleNodes\"}";
    ExportRequest exportRequest = new ExportRequest();
    exportRequest.source(source);
    ExportResponse response = client().execute(DumpAction.INSTANCE, exportRequest).actionGet();

    // The two shard results are from different nodes and have no failures
    assertEquals(0, response.getFailedShards());
    List<Map<String, Object>> infos = getExports(response);
    assertNotSame(infos.get(0).get("node_id"), infos.get(1).get("node_id"));
  }
예제 #3
0
 /**
  * Execute a dump request with a JSON string as source query. Waits for async callback and writes
  * result in response member variable.
  *
  * @param source
  */
 private ExportResponse executeDumpRequest(String source) {
   ExportRequest exportRequest = new ExportRequest();
   exportRequest.source(source);
   return client().execute(DumpAction.INSTANCE, exportRequest).actionGet();
 }