Search in sources :

Example 1 with MetaAlertDao

use of org.apache.metron.indexing.dao.MetaAlertDao 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)

Aggregations

HTableProvider (org.apache.metron.hbase.HTableProvider)1 AccessConfig (org.apache.metron.indexing.dao.AccessConfig)1 IndexDao (org.apache.metron.indexing.dao.IndexDao)1 MetaAlertDao (org.apache.metron.indexing.dao.MetaAlertDao)1 RestException (org.apache.metron.rest.RestException)1 Bean (org.springframework.context.annotation.Bean)1