Search in sources :

Example 1 with KibanaImporter

use of org.n52.iceland.statistics.api.utils.KibanaImporter in project arctic-sea by 52North.

the class KibanaImporterIT method importValidJson.

@Test
public void importValidJson() throws IOException, InterruptedException {
    String json = IOUtils.toString(KibanaImporter.class.getResourceAsStream("/kibana/kibana_config.json"), StandardCharsets.UTF_8);
    new KibanaImporter(getEmbeddedClient(), ".kibana", "my-index").importJson(json);
    Thread.sleep(1500);
    Assert.assertTrue(getEmbeddedClient().prepareExists(".kibana").get().exists());
    SearchResponse resp = getEmbeddedClient().prepareSearch(".kibana").setTypes("visualization").get();
    Assert.assertTrue(resp.getHits().getTotalHits() > 0);
    for (SearchHit hit : resp.getHits().getHits()) {
        Assert.assertFalse(hit.getSourceAsString().contains(KibanaImporter.INDEX_NEEDLE));
    }
    SearchResponse resp2 = getEmbeddedClient().prepareSearch(".kibana").setTypes("dashboard").get();
    Assert.assertTrue(resp2.getHits().getTotalHits() > 0);
    for (SearchHit hit : resp2.getHits().getHits()) {
        Assert.assertFalse(hit.getSourceAsString().contains(KibanaImporter.INDEX_NEEDLE));
    }
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAwareTest(org.n52.iceland.statistics.basetests.ElasticsearchAwareTest) Test(org.junit.Test)

Example 2 with KibanaImporter

use of org.n52.iceland.statistics.api.utils.KibanaImporter in project arctic-sea by 52North.

the class ElasticsearchAdminHandler method importPreconfiguredKibana.

public void importPreconfiguredKibana() throws JsonParseException, JsonMappingException, IOException {
    String json;
    if (settings.getKibanaConfPath() == null || settings.getKibanaConfPath().trim().isEmpty()) {
        logger.info("No path is defined. Use default settings values");
        json = IOUtils.toString(this.getClass().getResourceAsStream("/kibana/kibana_config.json"), StandardCharsets.UTF_8);
    } else {
        logger.info("Use content of path {}", settings.getKibanaConfPath());
        json = IOUtils.toString(new FileInputStream(settings.getKibanaConfPath()), StandardCharsets.UTF_8);
    }
    new KibanaImporter(client, ".kibana", settings.getIndexId()).importJson(json);
    // set to false after successful import
    settings.saveBooleanValueToConfigFile(ElasticsearchSettingsKeys.KIBANA_CONFIG_ENABLE, false);
    settings.setKibanaConfigEnable(false);
}
Also used : KibanaImporter(org.n52.iceland.statistics.api.utils.KibanaImporter) FileInputStream(java.io.FileInputStream)

Aggregations

FileInputStream (java.io.FileInputStream)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 SearchHit (org.elasticsearch.search.SearchHit)1 Test (org.junit.Test)1 KibanaImporter (org.n52.iceland.statistics.api.utils.KibanaImporter)1 ElasticsearchAwareTest (org.n52.iceland.statistics.basetests.ElasticsearchAwareTest)1