use of org.apache.metron.elasticsearch.client.ElasticsearchClient in project metron by apache.
the class ElasticsearchRequestSubmitterTest method setup.
public ElasticsearchRequestSubmitter setup(SearchResponse response) throws IOException {
// mocks
RestHighLevelClient highLevelClient = mock(RestHighLevelClient.class);
ElasticsearchClient client = new ElasticsearchClient(mock(RestClient.class), highLevelClient);
// the client should return the given search response
when(highLevelClient.search(any())).thenReturn(response);
return new ElasticsearchRequestSubmitter(client);
}
use of org.apache.metron.elasticsearch.client.ElasticsearchClient in project metron by apache.
the class ElasticsearchUpdateDaoTest method setup.
@BeforeEach
public void setup() {
accessConfig = new AccessConfig();
retrieveLatestDao = mock(ElasticsearchRetrieveLatestDao.class);
RestHighLevelClient highLevel = mock(RestHighLevelClient.class);
ElasticsearchClient client = new ElasticsearchClient(mock(RestClient.class), highLevel);
updateDao = new ElasticsearchUpdateDao(client, accessConfig, retrieveLatestDao);
}
use of org.apache.metron.elasticsearch.client.ElasticsearchClient in project metron by apache.
the class ElasticsearchUpdateIntegrationTest method installIndexTemplate.
/**
* Install the index template to ensure that "guid" is of type "keyword". The
* {@link org.apache.metron.elasticsearch.dao.ElasticsearchRetrieveLatestDao} cannot find
* documents if the type is not "keyword".
*
* See https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-term-query.html
*/
private static void installIndexTemplate() throws IOException {
HttpEntity broEntity = new NStringEntity(indexTemplate, ContentType.APPLICATION_JSON);
ElasticsearchClient client = ElasticsearchClientFactory.create(globalConfig);
Response response = client.getLowLevelClient().performRequest("PUT", "/_template/test_template", Collections.emptyMap(), broEntity);
assertThat(response.getStatusLine().getStatusCode(), CoreMatchers.equalTo(200));
}
use of org.apache.metron.elasticsearch.client.ElasticsearchClient in project metron by apache.
the class ElasticsearchDaoTest method setup.
private void setup(RestStatus status, int maxSearchResults, Map<String, FieldType> metadata) throws Exception {
// setup the mock search hits
SearchHit hit1 = mock(SearchHit.class);
when(hit1.getId()).thenReturn("id1");
when(hit1.getSource()).thenReturn(new HashMap<String, Object>() {
{
put("field", "value1");
}
});
when(hit1.getScore()).thenReturn(0.1f);
SearchHit hit2 = mock(SearchHit.class);
when(hit2.getId()).thenReturn("id2");
when(hit2.getSource()).thenReturn(new HashMap<String, Object>() {
{
put("field", "value2");
}
});
when(hit2.getScore()).thenReturn(0.2f);
// search hits
SearchHit[] hits = { hit1, hit2 };
SearchHits searchHits = mock(SearchHits.class);
when(searchHits.getHits()).thenReturn(hits);
when(searchHits.getTotalHits()).thenReturn(Integer.toUnsignedLong(hits.length));
// search response which returns the search hits
org.elasticsearch.action.search.SearchResponse response = mock(org.elasticsearch.action.search.SearchResponse.class);
when(response.status()).thenReturn(status);
when(response.getHits()).thenReturn(searchHits);
// provides column metadata
ElasticsearchColumnMetadataDao columnMetadataDao = mock(ElasticsearchColumnMetadataDao.class);
when(columnMetadataDao.getColumnMetadata(any())).thenReturn(metadata);
// returns the search response
requestSubmitter = mock(ElasticsearchRequestSubmitter.class);
when(requestSubmitter.submitSearch(any())).thenReturn(response);
RestHighLevelClient highLevel = mock(RestHighLevelClient.class);
ElasticsearchClient client = new ElasticsearchClient(mock(RestClient.class), highLevel);
// provides configuration
AccessConfig config = mock(AccessConfig.class);
when(config.getMaxSearchResults()).thenReturn(maxSearchResults);
ElasticsearchSearchDao elasticsearchSearchDao = new ElasticsearchSearchDao(client, config, columnMetadataDao, requestSubmitter);
ElasticsearchRetrieveLatestDao elasticsearchRetrieveLatestDao = new ElasticsearchRetrieveLatestDao(client);
ElasticsearchUpdateDao elasticsearchUpdateDao = new ElasticsearchUpdateDao(client, config, elasticsearchRetrieveLatestDao);
dao = new ElasticsearchDao(client, config, elasticsearchSearchDao, elasticsearchUpdateDao, elasticsearchRetrieveLatestDao, columnMetadataDao, requestSubmitter);
}
use of org.apache.metron.elasticsearch.client.ElasticsearchClient in project metron by apache.
the class ElasticsearchSearchIntegrationTest method setup.
@BeforeAll
public static void setup() throws Exception {
globalConfig = new HashMap<String, Object>() {
{
put("es.clustername", "metron");
put("es.port", "9200");
put("es.ip", "localhost");
put("es.date.format", dateFormat);
}
};
accessConfig = new AccessConfig();
accessConfig.setMaxSearchResults(100);
accessConfig.setMaxSearchGroups(100);
accessConfig.setGlobalConfigSupplier(() -> globalConfig);
indexComponent = startIndex();
ElasticsearchClient esClient = ElasticsearchClientFactory.create(globalConfig);
lowLevelClient = esClient.getLowLevelClient();
highLevelClient = esClient.getHighLevelClient();
dao = new ElasticsearchDao();
dao.init(accessConfig);
// The data is all static for searches, so we can set it up beforehand, and it's faster
loadTestData();
}
Aggregations