org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner Java Examples

The following examples show how to use org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicRankingPluginTest.java    From elasticsearch-dynarank with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    clusterName = "es-dynarank-" + System.currentTimeMillis();
    runner = new ElasticsearchClusterRunner();
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("dynarank.cache.clean_interval", "1s");
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.put("discovery.type", "single-node");
            // settingsBuilder.putList("discovery.seed_hosts", "127.0.0.1:9301");
            // settingsBuilder.putList("cluster.initial_master_nodes", "127.0.0.1:9301");
        }
    }).build(newConfigs().numOfNode(1).clusterName(clusterName).pluginTypes(
            "org.codelibs.elasticsearch.dynarank.DynamicRankingPlugin" + ",org.codelibs.elasticsearch.minhash.MinHashPlugin"));
    runner.ensureGreen();
}
 
Example #2
Source File: ReindexingPluginTest.java    From elasticsearch-reindexing with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    clusterName = "es-reindexing-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.put("index.number_of_shards", 3);
            settingsBuilder.put("index.number_of_replicas", 0);
            settingsBuilder.putArray("discovery.zen.ping.unicast.hosts",
                    "localhost:9301-9310");
            settingsBuilder.put("plugin.types",
                    "org.codelibs.elasticsearch.reindex.ReindexingPlugin");
            settingsBuilder
                    .put("index.unassigned.node_left.delayed_timeout", "0");
        }
    }).build(newConfigs().numOfNode(1).clusterName(clusterName));

    // wait for yellow status
    runner.ensureYellow();
}
 
Example #3
Source File: ReindexingPluginTest.java    From elasticsearch-reindexing with Apache License 2.0 6 votes vote down vote up
private void create_index(ElasticsearchClusterRunner runner, String index, String type, int number) {

        if (runner.indexExists(index))
            runner.deleteIndex(index);

        runner.createIndex(index, (Settings) null);

        if (!runner.indexExists(index))
            fail();

        for (int i = 0; i < number; i++) {
            final IndexResponse response = runner.insert(index, type, String.valueOf(i),
                    "{\"msg\":\"test " + i + "\", \"id\":\"" + i + "\"}");
            assertTrue(response.isCreated());
        }

        // make it searchable immediately
        runner.refresh();

        // search documents
        final SearchResponse searchResponse = runner.search(index, type, null, null, 0, 10);
        assertEquals(number, searchResponse.getHits().getTotalHits());

        assertTrue(runner.indexExists(index));
    }
 
Example #4
Source File: MinHashPluginTest.java    From elasticsearch-minhash with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    clusterName = "es-minhash-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.put("discovery.type", "single-node");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(1).pluginTypes("org.codelibs.elasticsearch.minhash.MinHashPlugin"));

    // wait for yellow status
    runner.ensureYellow();
}
 
Example #5
Source File: TastePluginTest.java    From elasticsearch-taste with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    clusterName = "es-taste-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", "localhost:9301-9305");
            settingsBuilder.put("plugin.types", "org.codelibs.elasticsearch.taste.TastePlugin");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(1));

    // wait for yellow status
    runner.ensureYellow();
}
 
Example #6
Source File: DataFormatPluginTest.java    From elasticsearch-dataformat with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws IOException {
    clusterName = "es-dataformat-" + System.currentTimeMillis();
    // create runner instance
    runner = new ElasticsearchClusterRunner();
    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.put("discovery.type", "single-node");
            // settingsBuilder.putList("discovery.seed_hosts", "127.0.0.1:9301");
            // settingsBuilder.putList("cluster.initial_master_nodes", "127.0.0.1:9301");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(1)
            .pluginTypes("org.codelibs.elasticsearch.df.DataFormatPlugin"));

    // wait for yellow status
    runner.ensureYellow();

    indexing();

    node = runner.node();
}
 
Example #7
Source File: AuthPluginTest.java    From elasticsearch-auth with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    // create ES instance
    runner = new ElasticsearchClusterRunner();

    // create ES nodes
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingBuilder) {
        }
    }).build(
            newConfigs()
                    .clusterName("es-auth" + System.currentTimeMillis())
                    .ramIndexStore().numOfNode(1));

    // wait for yellow status
    runner.ensureYellow();
}
 
Example #8
Source File: RiverWebTest.java    From elasticsearch-river-web with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    // create runner instance
    clusterName = "es-river-web-" + UUID.randomUUID().toString();
    runner = new ElasticsearchClusterRunner();
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.put("index.number_of_shards", 3);
            settingsBuilder.put("index.number_of_replicas", 0);
            settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", "localhost:9301-9310");
            settingsBuilder.put("index.unassigned.node_left.delayed_timeout", "0");
            settingsBuilder.put("network.host", "0");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(numOfNode));

    // wait for yellow status
    runner.ensureYellow();
}
 
Example #9
Source File: ElasticReportPluginTest.java    From elasticsearch-report-engine with GNU General Public License v3.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws IOException {

  runner = new ElasticsearchClusterRunner();

  runner.onBuild(new ElasticsearchClusterRunner.Builder() {
    @Override
    public void build(final int number, final Settings.Builder settingsBuilder) {
      settingsBuilder.put("http.cors.allow-origin", "*");
      settingsBuilder.put("http.cors.enabled", true);
      settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", CLUSTER_HOST_ADDRESS);
    }
  }).build(ElasticsearchClusterRunner.newConfigs().clusterName(CLUSTER_NAME).numOfNode(1)
      .pluginTypes("st.malike.elastic.report.engine.ElasticReportPlugin"));

  runner.ensureYellow();

  //setupup dummy data
  final String type = "reporttype";

  // create an index
  runner.createIndex(INDEX, (Settings) null);

  // create documents
  for (int i = 1; i <= DOC_SIZE; i++) {
    runner.insert(INDEX, type, String.valueOf(i),
        "{"
            + "\"type\":\"" + randomCDIndicator().toString() + "\","
            + "\"description\":\"Transaction " + i + "\","
            + "\"id\":" + i
            + "}");
  }
  runner.refresh();

  SearchResponse searchResponse = runner.search(INDEX, type, null, null, 0, 10);
  assertEquals(DOC_SIZE, searchResponse.getHits().getTotalHits());

  node = runner.node();
}
 
Example #10
Source File: SynonymPluginTest.java    From elasticsearch-analysis-synonym with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    clusterName = "es-analysissynonym-" + System.currentTimeMillis();
    runner = new ElasticsearchClusterRunner();
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
        }
    }).build(
            newConfigs().numOfNode(numOfNode).clusterName(clusterName).pluginTypes("org.codelibs.elasticsearch.synonym.SynonymPlugin"));

    synonymFiles = null;
}
 
Example #11
Source File: ElasticsearchResource.java    From vertexium with Apache License 2.0 4 votes vote down vote up
public ElasticsearchClusterRunner getRunner() {
    return runner;
}
 
Example #12
Source File: ElasticsearchResource.java    From vertexium with Apache License 2.0 4 votes vote down vote up
public ElasticsearchClusterRunner getRunner() {
    return runner;
}
 
Example #13
Source File: ElasticsearchDataModelTest.java    From elasticsearch-taste with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
    clusterName = "es-taste-" + System.currentTimeMillis();
    runner = new ElasticsearchClusterRunner();
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.put("index.number_of_shards", 3);
            settingsBuilder.put("index.number_of_replicas", 0);
            settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", "localhost:9301-9310");
            settingsBuilder.put("plugin.types",
                    "org.codelibs.elasticsearch.taste.TastePlugin");
            settingsBuilder.put("index.unassigned.node_left.delayed_timeout", "0");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(numOfNode));

    runner.ensureYellow();
    Client client = runner.client();

    // Wait for Yellow status
    client.admin().cluster().prepareHealth().setWaitForYellowStatus()
            .setTimeout(TimeValue.timeValueMinutes(1)).execute()
            .actionGet();

    final CreateIndexResponse response = client.admin().indices()
            .prepareCreate(TEST_INDEX).execute().actionGet();
    if (!response.isAcknowledged()) {
        throw new TasteException("Failed to create index: " + TEST_INDEX);
    }

    final XContentBuilder userBuilder = XContentFactory.jsonBuilder()//
            .startObject()//
            .startObject(TasteConstants.USER_TYPE)//
            .startObject("properties")//

            // @timestamp
            .startObject(TasteConstants.TIMESTAMP_FIELD)//
            .field("type", "date")//
            .field("format", "date_optional_time")//
            .endObject()//

            // user_id
            .startObject(TasteConstants.USER_ID_FIELD)//
            .field("type", "long")//
            .endObject()//

            // id
            .startObject("id")//
            .field("type", "string")//
            .field("index", "not_analyzed")//
            .endObject()//

            .endObject()//
            .endObject()//
            .endObject();

    final PutMappingResponse userResponse = client.admin().indices()
            .preparePutMapping(TEST_INDEX)
            .setType(TasteConstants.USER_TYPE).setSource(userBuilder)
            .execute().actionGet();
    if (!userResponse.isAcknowledged()) {
        throw new TasteException("Failed to create user mapping.");
    }

    final XContentBuilder itemBuilder = XContentFactory.jsonBuilder()//
            .startObject()//
            .startObject(TasteConstants.ITEM_TYPE)//
            .startObject("properties")//

            // @timestamp
            .startObject(TasteConstants.TIMESTAMP_FIELD)//
            .field("type", "date")//
            .field("format", "date_optional_time")//
            .endObject()//

            // item_id
            .startObject(TasteConstants.ITEM_ID_FIELD)//
            .field("type", "long")//
            .endObject()//

            // id
            .startObject("id")//
            .field("type", "string")//
            .field("index", "not_analyzed")//
            .endObject()//

            .endObject()//
            .endObject()//
            .endObject();

    final PutMappingResponse itemResponse = client.admin().indices()
            .preparePutMapping(TEST_INDEX)
            .setType(TasteConstants.ITEM_TYPE).setSource(itemBuilder)
            .execute().actionGet();
    if (!itemResponse.isAcknowledged()) {
        throw new TasteException("Failed to create item mapping.");
    }
}
 
Example #14
Source File: FessEsClient.java    From fess with Apache License 2.0 4 votes vote down vote up
public void setRunner(final ElasticsearchClusterRunner runner) {
    this.runner = runner;
}
 
Example #15
Source File: ScriptServiceTest.java    From elasticsearch-river-web with Apache License 2.0 4 votes vote down vote up
public void test_javascript_indexed() throws Exception {
    // create runner instance
    String clusterName = "es-river-web-" + UUID.randomUUID().toString();
    ElasticsearchClusterRunner runner = new ElasticsearchClusterRunner();
    runner.onBuild(new ElasticsearchClusterRunner.Builder() {
        @Override
        public void build(final int number, final Builder settingsBuilder) {
            settingsBuilder.put("http.cors.enabled", true);
            settingsBuilder.put("http.cors.allow-origin", "*");
            settingsBuilder.put("index.number_of_shards", 3);
            settingsBuilder.put("index.number_of_replicas", 0);
            settingsBuilder.putArray("discovery.zen.ping.unicast.hosts", "localhost:9301-9310");
            settingsBuilder.put("index.unassigned.node_left.delayed_timeout", "0");
        }
    }).build(newConfigs().clusterName(clusterName).numOfNode(1));
    // wait for yellow status
    runner.ensureYellow();

    try {
        esClient.setClusterName(clusterName);
        esClient.setAddresses(new String[] { "localhost:" + runner.node().settings().get("transport.tcp.port") });
        esClient.connect();

        Map<String, Object> localVars = new HashMap<>();

        String lang = "javascript";
        ScriptType scriptType = ScriptType.INDEXED;
        String script = "script1";
        runner.insert(ScriptService.SCRIPT_INDEX, lang, script, "{\"script\":\"'test';\"}");

        assertEquals("test", scriptService.execute(lang, script, scriptType, localVars));

        script = "script2";
        runner.insert(ScriptService.SCRIPT_INDEX, lang, script, "{\"script\":\"print('test');\"}");
        assertNull(scriptService.execute(lang, script, scriptType, localVars));

        localVars.put("testVar", "aaa");
        script = "script3";
        runner.insert(ScriptService.SCRIPT_INDEX, lang, script, "{\"script\":\"testVar;\"}");
        assertEquals("aaa", scriptService.execute(lang, script, scriptType, localVars));
    } finally {
        // close runner
        runner.close();
        // delete all files
        runner.clean();
    }
}