use of org.opennms.newts.api.SampleRepository in project newts by OpenNMS.
the class ImportRunner method directPoster.
private Observable<Boolean> directPoster(Observable<List<Sample>> samples, MetricRegistry metrics) {
final SampleRepository repository = repository();
final Timer timer = metrics.timer("writes");
final Meter completions = metrics.meter("samples-completed");
Func1<List<Sample>, Boolean> insert = new Func1<List<Sample>, Boolean>() {
@Override
public Boolean call(List<Sample> s) {
int sz = s.size();
try (Context timerCtx = timer.time()) {
repository.insert(s);
return true;
} finally {
completions.mark(sz);
}
}
};
return (m_threadCount == 1 ? samples.map(insert) : parMap(samples, metrics, insert)).all(Functions.<Boolean>identity());
}
use of org.opennms.newts.api.SampleRepository in project newts by OpenNMS.
the class NewtsService method run.
@Override
public void run(final NewtsConfig config, Environment environment) throws Exception {
// Filters
configureCors(environment);
configureUIRedirect(environment);
configureAuthentication(environment, config);
final Injector injector = Guice.createInjector(new NewtsGuiceModule(), new CassandraGuiceModule(config), new GraphiteGuiceModule(config));
MetricRegistry metricRegistry = injector.getInstance(MetricRegistry.class);
// Create/start a JMX reporter for our MetricRegistry
final JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).inDomain("newts").build();
// Create (and start if so configured), a Graphite line-protocol listener
final GraphiteListenerThread listener = new GraphiteListenerThread(injector.getInstance(GraphiteListener.class));
environment.lifecycle().manage(new Managed() {
@Override
public void stop() throws Exception {
reporter.stop();
}
@Override
public void start() throws Exception {
reporter.start();
if (config.getGraphiteConfig().isEnabled()) {
listener.start();
}
}
});
SampleRepository repository = injector.getInstance(SampleRepository.class);
Indexer indexer = injector.getInstance(Indexer.class);
// Rest resources
environment.jersey().register(new MeasurementsResource(repository, config.getReports()));
environment.jersey().register(new SamplesResource(repository, indexer));
// Add search resource only if search is enabled
if (config.getSearchConfig().isEnabled()) {
environment.jersey().register(new SearchResource(injector.getInstance(Searcher.class)));
}
// Health checks
environment.healthChecks().register("repository", new RepositoryHealthCheck(repository));
// Mapped exceptions
environment.jersey().register(IllegalArgumentExceptionMapper.class);
}
use of org.opennms.newts.api.SampleRepository in project newts by OpenNMS.
the class ImportRunner method repository.
private SampleRepository repository() {
if (m_repository == null) {
Injector injector = Guice.createInjector(new Config());
m_repository = injector.getInstance(SampleRepository.class);
}
return m_repository;
}
Aggregations