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;
}
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");
}
}
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);
}
}
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;
}
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);
}
}
Aggregations