Search in sources :

Example 1 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class GlobalConfigServiceImpl method get.

@Override
public Map<String, Object> get() throws RestException {
    Map<String, Object> globalConfig;
    try {
        EnrichmentConfigurations configs = cache.get(EnrichmentConfigurations.class);
        globalConfig = configs.getGlobalConfig(false);
    } catch (Exception e) {
        throw new RestException(e.getMessage(), e);
    }
    return globalConfig;
}
Also used : EnrichmentConfigurations(org.apache.metron.common.configuration.EnrichmentConfigurations) RestException(org.apache.metron.rest.RestException) KeeperException(org.apache.zookeeper.KeeperException) RestException(org.apache.metron.rest.RestException)

Example 2 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class GrokServiceImpl method saveTemporary.

@Override
public Path saveTemporary(String statement, String name) throws RestException {
    if (statement != null) {
        Path path = getTemporaryGrokRootPath();
        hdfsService.mkdirs(path);
        hdfsService.write(new Path(path, name), statement.getBytes(Charset.forName("utf-8")), null, null, null);
        return path;
    } else {
        throw new RestException("A grokStatement must be provided");
    }
}
Also used : Path(org.apache.hadoop.fs.Path) RestException(org.apache.metron.rest.RestException)

Example 3 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class SearchServiceImpl method search.

@Override
public SearchResponse search(SearchRequest searchRequest) throws RestException {
    try {
        if (searchRequest.getIndices() == null || searchRequest.getIndices().isEmpty()) {
            List<String> indices = getDefaultIndices();
            // metaalerts should be included by default in search requests
            indices.add(METAALERT_TYPE);
            searchRequest.setIndices(indices);
        }
        if (searchRequest.getFacetFields() != null && searchRequest.getFacetFields().isEmpty()) {
            searchRequest.setFacetFields(getDefaultFacetFields());
        }
        return dao.search(searchRequest);
    } catch (InvalidSearchException ise) {
        throw new RestException(ise.getMessage(), ise);
    }
}
Also used : InvalidSearchException(org.apache.metron.indexing.dao.search.InvalidSearchException) RestException(org.apache.metron.rest.RestException)

Example 4 with RestException

use of org.apache.metron.rest.RestException in project metron by apache.

the class HBaseConfig method userSettingsClient.

@Bean()
public UserSettingsClient userSettingsClient() {
    UserSettingsClient userSettingsClient = new UserSettingsClient();
    userSettingsClient.init(() -> {
        try {
            return globalConfigService.get();
        } catch (RestException e) {
            throw new IllegalStateException("Unable to retrieve the global config.", e);
        }
    }, new HTableProvider());
    return userSettingsClient;
}
Also used : HTableProvider(org.apache.metron.hbase.HTableProvider) UserSettingsClient(org.apache.metron.hbase.client.UserSettingsClient) RestException(org.apache.metron.rest.RestException) Bean(org.springframework.context.annotation.Bean)

Example 5 with RestException

use of org.apache.metron.rest.RestException 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

RestException (org.apache.metron.rest.RestException)10 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)2 HTableProvider (org.apache.metron.hbase.HTableProvider)2 Bean (org.springframework.context.annotation.Bean)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 Grok (oi.thekraken.grok.api.Grok)1 Match (oi.thekraken.grok.api.Match)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 FsAction (org.apache.hadoop.fs.permission.FsAction)1 FsPermission (org.apache.hadoop.fs.permission.FsPermission)1 EnrichmentConfigurations (org.apache.metron.common.configuration.EnrichmentConfigurations)1 UserSettingsClient (org.apache.metron.hbase.client.UserSettingsClient)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 InvalidSearchException (org.apache.metron.indexing.dao.search.InvalidSearchException)1 KeeperException (org.apache.zookeeper.KeeperException)1