Search in sources :

Example 1 with AccessConfig

use of org.apache.metron.indexing.dao.AccessConfig in project metron by apache.

the class IndexConfig method indexDao.

@Bean
public IndexDao indexDao() {
    try {
        String hbaseProviderImpl = environment.getProperty(MetronRestConstants.INDEX_HBASE_TABLE_PROVIDER_IMPL, String.class, null);
        String indexDaoImpl = environment.getProperty(MetronRestConstants.INDEX_DAO_IMPL, String.class, null);
        int searchMaxResults = environment.getProperty(MetronRestConstants.SEARCH_MAX_RESULTS, Integer.class, 1000);
        int searchMaxGroups = environment.getProperty(MetronRestConstants.SEARCH_MAX_GROUPS, Integer.class, 1000);
        String metaDaoImpl = environment.getProperty(MetronRestConstants.META_DAO_IMPL, String.class, null);
        String metaDaoSort = environment.getProperty(MetronRestConstants.META_DAO_SORT, String.class, null);
        AccessConfig config = new AccessConfig();
        config.setMaxSearchResults(searchMaxResults);
        config.setMaxSearchGroups(searchMaxGroups);
        config.setGlobalConfigSupplier(() -> {
            try {
                return globalConfigService.get();
            } catch (RestException e) {
                throw new IllegalStateException("Unable to retrieve the global config.", e);
            }
        });
        config.setTableProvider(TableProvider.create(hbaseProviderImpl, () -> new HTableProvider()));
        if (indexDaoImpl == null) {
            throw new IllegalStateException("You must provide an index DAO implementation via the " + INDEX_DAO_IMPL + " config");
        }
        IndexDao indexDao = IndexDaoFactory.combine(IndexDaoFactory.create(indexDaoImpl, config));
        if (indexDao == null) {
            throw new IllegalStateException("IndexDao is unable to be created.");
        }
        if (metaDaoImpl == null) {
            // We're not using meta alerts.
            return indexDao;
        }
        // Create the meta alert dao and wrap it around the index dao.
        MetaAlertDao ret = (MetaAlertDao) IndexDaoFactory.create(metaDaoImpl, config).get(0);
        ret.init(indexDao, Optional.ofNullable(metaDaoSort));
        return ret;
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new IllegalStateException("Unable to create index DAO: " + e.getMessage(), e);
    }
}
Also used : HTableProvider(org.apache.metron.hbase.HTableProvider) RestException(org.apache.metron.rest.RestException) MetaAlertDao(org.apache.metron.indexing.dao.MetaAlertDao) AccessConfig(org.apache.metron.indexing.dao.AccessConfig) IndexDao(org.apache.metron.indexing.dao.IndexDao) RestException(org.apache.metron.rest.RestException) Bean(org.springframework.context.annotation.Bean)

Example 2 with AccessConfig

use of org.apache.metron.indexing.dao.AccessConfig in project metron by apache.

the class ElasticsearchMetaAlertIntegrationTest method setupBefore.

@BeforeClass
public static void setupBefore() throws Exception {
    // setup the client
    es = new ElasticSearchComponent.Builder().withHttpPort(9211).withIndexDir(new File(INDEX_DIR)).build();
    es.start();
    AccessConfig accessConfig = new AccessConfig();
    Map<String, Object> globalConfig = new HashMap<String, Object>() {

        {
            put("es.clustername", "metron");
            put("es.port", "9300");
            put("es.ip", "localhost");
            put("es.date.format", DATE_FORMAT);
        }
    };
    accessConfig.setMaxSearchResults(1000);
    accessConfig.setGlobalConfigSupplier(() -> globalConfig);
    accessConfig.setMaxSearchGroups(100);
    esDao = new ElasticsearchDao();
    esDao.init(accessConfig);
    metaDao = new ElasticsearchMetaAlertDao(esDao);
}
Also used : ElasticsearchDao(org.apache.metron.elasticsearch.dao.ElasticsearchDao) HashMap(java.util.HashMap) AccessConfig(org.apache.metron.indexing.dao.AccessConfig) File(java.io.File) ElasticsearchMetaAlertDao(org.apache.metron.elasticsearch.dao.ElasticsearchMetaAlertDao) BeforeClass(org.junit.BeforeClass)

Example 3 with AccessConfig

use of org.apache.metron.indexing.dao.AccessConfig 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
    ColumnMetadataDao columnMetadataDao = mock(ColumnMetadataDao.class);
    when(columnMetadataDao.getColumnMetadata(any())).thenReturn(metadata);
    // returns the search response
    requestSubmitter = mock(ElasticsearchRequestSubmitter.class);
    when(requestSubmitter.submitSearch(any())).thenReturn(response);
    TransportClient client = mock(TransportClient.class);
    // provides configuration
    AccessConfig config = mock(AccessConfig.class);
    when(config.getMaxSearchResults()).thenReturn(maxSearchResults);
    dao = new ElasticsearchDao(client, columnMetadataDao, requestSubmitter, config);
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) SearchHit(org.elasticsearch.search.SearchHit) AccessConfig(org.apache.metron.indexing.dao.AccessConfig) JSONObject(org.json.simple.JSONObject) SearchHits(org.elasticsearch.search.SearchHits)

Example 4 with AccessConfig

use of org.apache.metron.indexing.dao.AccessConfig in project metron by apache.

the class ElasticsearchMetaAlertDaoTest method testInvalidInit.

@Test(expected = IllegalArgumentException.class)
public void testInvalidInit() {
    IndexDao dao = new IndexDao() {

        @Override
        public SearchResponse search(SearchRequest searchRequest) throws InvalidSearchException {
            return null;
        }

        @Override
        public GroupResponse group(GroupRequest groupRequest) throws InvalidSearchException {
            return null;
        }

        @Override
        public void init(AccessConfig config) {
        }

        @Override
        public Document getLatest(String guid, String sensorType) throws IOException {
            return null;
        }

        @Override
        public Iterable<Document> getAllLatest(List<GetRequest> getRequests) throws IOException {
            return null;
        }

        @Override
        public void update(Document update, Optional<String> index) throws IOException {
        }

        @Override
        public void batchUpdate(Map<Document, Optional<String>> updates) throws IOException {
        }

        @Override
        public Map<String, FieldType> getColumnMetadata(List<String> indices) throws IOException {
            return null;
        }
    };
    ElasticsearchMetaAlertDao metaAlertDao = new ElasticsearchMetaAlertDao();
    metaAlertDao.init(dao);
}
Also used : SearchRequest(org.apache.metron.indexing.dao.search.SearchRequest) Optional(java.util.Optional) GroupRequest(org.apache.metron.indexing.dao.search.GroupRequest) ArrayList(java.util.ArrayList) List(java.util.List) AccessConfig(org.apache.metron.indexing.dao.AccessConfig) Document(org.apache.metron.indexing.dao.update.Document) HashMap(java.util.HashMap) Map(java.util.Map) IndexDao(org.apache.metron.indexing.dao.IndexDao) FieldType(org.apache.metron.indexing.dao.search.FieldType) Test(org.junit.Test)

Example 5 with AccessConfig

use of org.apache.metron.indexing.dao.AccessConfig in project metron by apache.

the class ElasticsearchSearchIntegrationTest method createDao.

@Override
protected IndexDao createDao() throws Exception {
    AccessConfig config = new AccessConfig();
    config.setMaxSearchResults(100);
    config.setMaxSearchGroups(100);
    config.setGlobalConfigSupplier(() -> new HashMap<String, Object>() {

        {
            put("es.clustername", "metron");
            put("es.port", "9300");
            put("es.ip", "localhost");
            put("es.date.format", dateFormat);
        }
    });
    IndexDao dao = new ElasticsearchDao();
    dao.init(config);
    return dao;
}
Also used : ElasticsearchDao(org.apache.metron.elasticsearch.dao.ElasticsearchDao) JSONObject(org.json.simple.JSONObject) AccessConfig(org.apache.metron.indexing.dao.AccessConfig) IndexDao(org.apache.metron.indexing.dao.IndexDao)

Aggregations

AccessConfig (org.apache.metron.indexing.dao.AccessConfig)6 IndexDao (org.apache.metron.indexing.dao.IndexDao)3 HashMap (java.util.HashMap)2 ElasticsearchDao (org.apache.metron.elasticsearch.dao.ElasticsearchDao)2 JSONObject (org.json.simple.JSONObject)2 BeforeClass (org.junit.BeforeClass)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ElasticsearchMetaAlertDao (org.apache.metron.elasticsearch.dao.ElasticsearchMetaAlertDao)1 HTableProvider (org.apache.metron.hbase.HTableProvider)1 MockHBaseTableProvider (org.apache.metron.hbase.mock.MockHBaseTableProvider)1 HBaseDao (org.apache.metron.indexing.dao.HBaseDao)1 MetaAlertDao (org.apache.metron.indexing.dao.MetaAlertDao)1 FieldType (org.apache.metron.indexing.dao.search.FieldType)1 GroupRequest (org.apache.metron.indexing.dao.search.GroupRequest)1 SearchRequest (org.apache.metron.indexing.dao.search.SearchRequest)1 Document (org.apache.metron.indexing.dao.update.Document)1