Search in sources :

Example 1 with EventBusReporterWrapper

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)));
}
Also used : GraviteeContext(io.gravitee.am.common.utils.GraviteeContext) EnvironmentNotFoundException(io.gravitee.am.service.exception.EnvironmentNotFoundException) NoOpReporter(io.gravitee.am.reporter.api.provider.NoOpReporter) EventBusReporterWrapper(io.gravitee.am.service.reporter.vertx.EventBusReporterWrapper) NewReporter(io.gravitee.am.service.model.NewReporter) ReporterNotFoundForDomainException(io.gravitee.am.service.exception.ReporterNotFoundForDomainException) EnvironmentNotFoundException(io.gravitee.am.service.exception.EnvironmentNotFoundException)

Example 2 with EventBusReporterWrapper

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));
}
Also used : EnvironmentService(io.gravitee.am.service.EnvironmentService) ReporterEvent(io.gravitee.am.common.event.ReporterEvent) BiConsumer(io.reactivex.functions.BiConsumer) LoggerFactory(org.slf4j.LoggerFactory) DomainService(io.gravitee.am.service.DomainService) Autowired(org.springframework.beans.factory.annotation.Autowired) Single(io.reactivex.Single) ReporterService(io.gravitee.am.service.ReporterService) NewReporter(io.gravitee.am.service.model.NewReporter) ReporterNotFoundForDomainException(io.gravitee.am.service.exception.ReporterNotFoundForDomainException) ConcurrentMap(java.util.concurrent.ConcurrentMap) EventBusReporterWrapper(io.gravitee.am.service.reporter.vertx.EventBusReporterWrapper) Vertx(io.vertx.reactivex.core.Vertx) ReporterPluginManager(io.gravitee.am.plugins.reporter.core.ReporterPluginManager) Arrays.asList(java.util.Arrays.asList) ReferenceType(io.gravitee.am.model.ReferenceType) Schedulers(io.reactivex.schedulers.Schedulers) GraviteeContext(io.gravitee.am.common.utils.GraviteeContext) EventListener(io.gravitee.common.event.EventListener) AuditReporterVerticle(io.gravitee.am.service.reporter.impl.AuditReporterVerticle) Logger(org.slf4j.Logger) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Event(io.gravitee.common.event.Event) NoOpReporter(io.gravitee.am.reporter.api.provider.NoOpReporter) AbstractService(io.gravitee.common.service.AbstractService) Reporter(io.gravitee.am.reporter.api.provider.Reporter) ApplicationContext(org.springframework.context.ApplicationContext) AuditReporterManager(io.gravitee.am.management.service.AuditReporterManager) Component(org.springframework.stereotype.Component) List(java.util.List) EventManager(io.gravitee.common.event.EventManager) Payload(io.gravitee.am.model.common.event.Payload) Optional(java.util.Optional) RxHelper(io.vertx.reactivex.core.RxHelper) EnvironmentNotFoundException(io.gravitee.am.service.exception.EnvironmentNotFoundException) NewReporter(io.gravitee.am.service.model.NewReporter) NoOpReporter(io.gravitee.am.reporter.api.provider.NoOpReporter) Reporter(io.gravitee.am.reporter.api.provider.Reporter) EventBusReporterWrapper(io.gravitee.am.service.reporter.vertx.EventBusReporterWrapper) ReporterNotFoundForDomainException(io.gravitee.am.service.exception.ReporterNotFoundForDomainException) EnvironmentNotFoundException(io.gravitee.am.service.exception.EnvironmentNotFoundException)

Aggregations

GraviteeContext (io.gravitee.am.common.utils.GraviteeContext)2 NoOpReporter (io.gravitee.am.reporter.api.provider.NoOpReporter)2 EnvironmentNotFoundException (io.gravitee.am.service.exception.EnvironmentNotFoundException)2 ReporterNotFoundForDomainException (io.gravitee.am.service.exception.ReporterNotFoundForDomainException)2 NewReporter (io.gravitee.am.service.model.NewReporter)2 EventBusReporterWrapper (io.gravitee.am.service.reporter.vertx.EventBusReporterWrapper)2 ReporterEvent (io.gravitee.am.common.event.ReporterEvent)1 AuditReporterManager (io.gravitee.am.management.service.AuditReporterManager)1 ReferenceType (io.gravitee.am.model.ReferenceType)1 Payload (io.gravitee.am.model.common.event.Payload)1 ReporterPluginManager (io.gravitee.am.plugins.reporter.core.ReporterPluginManager)1 Reporter (io.gravitee.am.reporter.api.provider.Reporter)1 DomainService (io.gravitee.am.service.DomainService)1 EnvironmentService (io.gravitee.am.service.EnvironmentService)1 ReporterService (io.gravitee.am.service.ReporterService)1 AuditReporterVerticle (io.gravitee.am.service.reporter.impl.AuditReporterVerticle)1 Event (io.gravitee.common.event.Event)1 EventListener (io.gravitee.common.event.EventListener)1 EventManager (io.gravitee.common.event.EventManager)1 AbstractService (io.gravitee.common.service.AbstractService)1