use of io.gravitee.am.service.reporter.vertx.EventBusReporterWrapper in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
logger.info("Register event listener for reporter events for the management API");
eventManager.subscribeForEvents(this, ReporterEvent.class);
// init noOpReporter
noOpReporter = new NoOpReporter();
// init internal reporter (organization reporter)
NewReporter organizationReporter = reporterService.createInternal();
logger.info("Initializing internal " + organizationReporter.getType() + " audit reporter");
internalReporter = reporterPluginManager.create(organizationReporter.getType(), organizationReporter.getConfiguration(), null);
logger.info("Internal audit " + organizationReporter.getType() + " reporter initialized");
logger.info("Initializing audit reporters");
reporterService.findAll().blockingForEach(reporter -> {
logger.info("Initializing audit reporter : {} for domain {}", reporter.getName(), reporter.getDomain());
try {
AuditReporterLauncher launcher = new AuditReporterLauncher(reporter);
domainService.findById(reporter.getDomain()).flatMapSingle(domain -> {
if (ReferenceType.ENVIRONMENT.equals(domain.getReferenceType())) {
return environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId()));
} else {
// currently domain is only linked to domainEnv
return Single.error(new EnvironmentNotFoundException("Domain " + reporter.getDomain() + " should be lined to an Environment"));
}
}).subscribeOn(Schedulers.io()).subscribe(launcher);
} catch (Exception ex) {
logger.error("An error has occurred while loading audit reporter: {} [{}]", reporter.getName(), reporter.getType(), ex);
removeReporter(reporter.getId());
}
});
// deploy internal reporter verticle
deployReporterVerticle(asList(new EventBusReporterWrapper(vertx, internalReporter)));
}
use of io.gravitee.am.service.reporter.vertx.EventBusReporterWrapper in project gravitee-access-management by gravitee-io.
the class AuditReporterManagerImpl method reloadReporter.
private void reloadReporter(String reporterId) {
logger.info("Management API has received an update reporter event for {}", reporterId);
reporterService.findById(reporterId).subscribe(reporter -> {
logger.debug("Reload reporter: {} after configuration update", reporter.getName());
Optional<Reporter> optionalAuditReporter = auditReporters.entrySet().stream().filter(entry -> reporter.getId().equals(entry.getKey().getId())).map(entry -> entry.getValue()).findFirst();
if (optionalAuditReporter.isPresent()) {
try {
Reporter auditReporter = optionalAuditReporter.get();
// reload the provider if it's enabled
if (reporter.isEnabled()) {
auditReporter.stop();
auditReporters.entrySet().removeIf(entry -> entry.getKey().getId().equals(reporter.getId()));
loadReporter(reporter);
} else {
logger.info("Reporter: {} has been disabled", reporter.getName());
// unregister event bus consumer
// we do not stop the underlying reporter if it manages search because it can be used to fetch reportable
((EventBusReporterWrapper) auditReporter).unregister();
if (!auditReporter.canSearch()) {
auditReporter.stop();
}
}
} catch (Exception e) {
logger.error("An error occurs while reloading reporter: {}", reporter.getName(), e);
}
} else {
logger.info("There is no reporter to reload");
}
}, error -> logger.error("Unable to reload reporter {}", reporterId, error), () -> logger.error("No reporter found with id {}", reporterId));
}
Aggregations