Search in sources :

Example 1 with GraviteeContext

use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.

the class AuditReporterManagerImpl method loadReporter.

private void loadReporter(io.gravitee.am.model.Reporter reporter) {
    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);
}
Also used : GraviteeContext(io.gravitee.am.common.utils.GraviteeContext) EnvironmentNotFoundException(io.gravitee.am.service.exception.EnvironmentNotFoundException)

Example 2 with GraviteeContext

use of io.gravitee.am.common.utils.GraviteeContext 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 3 with GraviteeContext

use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.

the class AuditReporterManagerImpl method updateReporter.

private void updateReporter(String reporterId, ReporterEvent reporterEvent) {
    final String eventType = reporterEvent.toString().toLowerCase();
    logger.info("Domain {} has received {} reporter event for {}", domain.getName(), eventType, reporterId);
    reporterRepository.findById(reporterId).flatMapSingle(reporter -> environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId())).map(ctx -> Tuples.of(reporter, ctx))).subscribeOn(Schedulers.io()).subscribe(tupleReporterContext -> {
        updateReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
        logger.info("Reporter {} {}d for domain {}", reporterId, eventType, domain.getName());
    }, error -> logger.error("Unable to {} reporter for domain {}", eventType, domain.getName(), error));
}
Also used : EnvironmentService(io.gravitee.am.service.EnvironmentService) ReporterEvent(io.gravitee.am.common.event.ReporterEvent) LoggerFactory(org.slf4j.LoggerFactory) Tuples(reactor.util.function.Tuples) Autowired(org.springframework.beans.factory.annotation.Autowired) ReporterRepository(io.gravitee.am.repository.management.api.ReporterRepository) Single(io.reactivex.Single) InitializingBean(org.springframework.beans.factory.InitializingBean) 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) 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) EventManager(io.gravitee.am.common.event.EventManager) AuditReporterManager(io.gravitee.am.gateway.handler.common.audit.AuditReporterManager) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Event(io.gravitee.common.event.Event) Domain(io.gravitee.am.model.Domain) Reporter(io.gravitee.am.model.Reporter) AbstractService(io.gravitee.common.service.AbstractService) Payload(io.gravitee.am.model.common.event.Payload) RxHelper(io.vertx.reactivex.core.RxHelper) GraviteeContext(io.gravitee.am.common.utils.GraviteeContext)

Example 4 with GraviteeContext

use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.

the class AuditReporterManagerImpl method deployReporter.

private void deployReporter(String reporterId, ReporterEvent reporterEvent) {
    final String eventType = reporterEvent.toString().toLowerCase();
    logger.info("Domain {} has received {} reporter event for {}", domain.getName(), eventType, reporterId);
    reporterRepository.findById(reporterId).flatMapSingle(reporter -> environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId())).map(ctx -> Tuples.of(reporter, ctx))).subscribeOn(Schedulers.io()).subscribe(tupleReporterContext -> {
        if (reporters.containsKey(reporterId)) {
            updateReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
        } else {
            startReporterProvider(tupleReporterContext.getT1(), tupleReporterContext.getT2());
        }
        logger.info("Reporter {} {}d for domain {}", reporterId, eventType, domain.getName());
    }, error -> logger.error("Unable to {} reporter for domain {}", eventType, domain.getName(), error));
}
Also used : EnvironmentService(io.gravitee.am.service.EnvironmentService) ReporterEvent(io.gravitee.am.common.event.ReporterEvent) LoggerFactory(org.slf4j.LoggerFactory) Tuples(reactor.util.function.Tuples) Autowired(org.springframework.beans.factory.annotation.Autowired) ReporterRepository(io.gravitee.am.repository.management.api.ReporterRepository) Single(io.reactivex.Single) InitializingBean(org.springframework.beans.factory.InitializingBean) 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) 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) EventManager(io.gravitee.am.common.event.EventManager) AuditReporterManager(io.gravitee.am.gateway.handler.common.audit.AuditReporterManager) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Event(io.gravitee.common.event.Event) Domain(io.gravitee.am.model.Domain) Reporter(io.gravitee.am.model.Reporter) AbstractService(io.gravitee.common.service.AbstractService) Payload(io.gravitee.am.model.common.event.Payload) RxHelper(io.vertx.reactivex.core.RxHelper) GraviteeContext(io.gravitee.am.common.utils.GraviteeContext)

Example 5 with GraviteeContext

use of io.gravitee.am.common.utils.GraviteeContext in project gravitee-access-management by gravitee-io.

the class FileAuditReporterTest method buildAuditLogsFilename.

protected String buildAuditLogsFilename() {
    GraviteeContext context = GraviteeContext.defaultContext("domain");
    String filename = Paths.get(System.getProperty(FileAuditReporter.REPORTERS_FILE_DIRECTORY), context.getOrganizationId(), context.getEnvironmentId(), context.getDomainId(), "FileAuditReporterTest-" + new SimpleDateFormat("yyyy_MM_dd").format(new Date(Instant.now().toEpochMilli())) + "." + Type.valueOf(System.getProperty(FileAuditReporter.REPORTERS_FILE_OUTPUT).toUpperCase()).getExtension()).toFile().getPath();
    return filename;
}
Also used : GraviteeContext(io.gravitee.am.common.utils.GraviteeContext) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

GraviteeContext (io.gravitee.am.common.utils.GraviteeContext)8 EventBusReporterWrapper (io.gravitee.am.service.reporter.vertx.EventBusReporterWrapper)4 EventManager (io.gravitee.am.common.event.EventManager)3 ReporterEvent (io.gravitee.am.common.event.ReporterEvent)3 AuditReporterManager (io.gravitee.am.gateway.handler.common.audit.AuditReporterManager)3 Domain (io.gravitee.am.model.Domain)3 ReferenceType (io.gravitee.am.model.ReferenceType)3 Reporter (io.gravitee.am.model.Reporter)3 Payload (io.gravitee.am.model.common.event.Payload)3 ReporterPluginManager (io.gravitee.am.plugins.reporter.core.ReporterPluginManager)3 ReporterRepository (io.gravitee.am.repository.management.api.ReporterRepository)3 EnvironmentService (io.gravitee.am.service.EnvironmentService)3 AuditReporterVerticle (io.gravitee.am.service.reporter.impl.AuditReporterVerticle)3 Event (io.gravitee.common.event.Event)3 EventListener (io.gravitee.common.event.EventListener)3 AbstractService (io.gravitee.common.service.AbstractService)3 Single (io.reactivex.Single)3 Schedulers (io.reactivex.schedulers.Schedulers)3 RxHelper (io.vertx.reactivex.core.RxHelper)3 Vertx (io.vertx.reactivex.core.Vertx)3