Search in sources :

Example 1 with Reporter

use of io.gravitee.am.model.Reporter 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 2 with Reporter

use of io.gravitee.am.model.Reporter 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 3 with Reporter

use of io.gravitee.am.model.Reporter in project gravitee-access-management by gravitee-io.

the class MongoReporterRepository method convert.

private Reporter convert(ReporterMongo reporterMongo) {
    if (reporterMongo == null) {
        return null;
    }
    Reporter reporter = new Reporter();
    reporter.setId(reporterMongo.getId());
    reporter.setEnabled(reporterMongo.isEnabled());
    reporter.setDomain(reporterMongo.getDomain());
    reporter.setName(reporterMongo.getName());
    reporter.setSystem(reporterMongo.isSystem());
    reporter.setType(reporterMongo.getType());
    reporter.setDataType(reporterMongo.getDataType());
    reporter.setConfiguration(reporterMongo.getConfiguration());
    reporter.setCreatedAt(reporterMongo.getCreatedAt());
    reporter.setUpdatedAt(reporterMongo.getUpdatedAt());
    return reporter;
}
Also used : Reporter(io.gravitee.am.model.Reporter)

Example 4 with Reporter

use of io.gravitee.am.model.Reporter in project gravitee-access-management by gravitee-io.

the class ReporterServiceImpl method checkReporterConfiguration.

/**
 * This method check if the configuration attribute of a Reporter is valid
 *
 * @param reporter to check
 * @return
 */
private Single<Reporter> checkReporterConfiguration(Reporter reporter) {
    Single<Reporter> result = Single.just(reporter);
    if (REPORTER_AM_FILE.equalsIgnoreCase(reporter.getType())) {
        // for FileReporter we have to check if the filename isn't used by another reporter
        final JsonObject configuration = (JsonObject) Json.decodeValue(reporter.getConfiguration());
        final String reporterId = reporter.getId();
        result = reporterRepository.findByDomain(reporter.getDomain()).filter(r -> r.getType().equalsIgnoreCase(REPORTER_AM_FILE)).filter(// exclude 'self' in case of update
        r -> reporterId == null || !r.getId().equals(reporterId)).map(r -> (JsonObject) Json.decodeValue(r.getConfiguration())).filter(cfg -> cfg.containsKey(REPORTER_CONFIG_FILENAME) && cfg.getString(REPORTER_CONFIG_FILENAME).equals(configuration.getString(REPORTER_CONFIG_FILENAME))).count().flatMap(reporters -> {
            if (reporters > 0) {
                // more than one reporter use the same filename
                return Single.error(new ReporterConfigurationException("Filename already defined"));
            } else {
                return Single.just(reporter);
            }
        });
    }
    return result;
}
Also used : Json(io.vertx.core.json.Json) Primary(org.springframework.context.annotation.Primary) MessageDigest(java.security.MessageDigest) Date(java.util.Date) Completable(io.reactivex.Completable) Maybe(io.reactivex.Maybe) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ReporterRepository(io.gravitee.am.repository.management.api.ReporterRepository) AuditService(io.gravitee.am.service.AuditService) Single(io.reactivex.Single) Event(io.gravitee.am.model.common.event.Event) ReporterService(io.gravitee.am.service.ReporterService) NewReporter(io.gravitee.am.service.model.NewReporter) ArrayList(java.util.ArrayList) Type(io.gravitee.am.common.event.Type) TechnicalManagementException(io.gravitee.am.service.exception.TechnicalManagementException) BackendConfigurationUtils.getMongoDatabaseName(io.gravitee.am.service.utils.BackendConfigurationUtils.getMongoDatabaseName) Flowable(io.reactivex.Flowable) User(io.gravitee.am.identityprovider.api.User) AuditBuilder(io.gravitee.am.service.reporter.builder.AuditBuilder) ReferenceType(io.gravitee.am.model.ReferenceType) EventService(io.gravitee.am.service.EventService) JsonObject(io.vertx.core.json.JsonObject) Action(io.gravitee.am.common.event.Action) Logger(org.slf4j.Logger) ReporterAuditBuilder(io.gravitee.am.service.reporter.builder.management.ReporterAuditBuilder) BaseEncoding(com.google.common.io.BaseEncoding) EventType(io.gravitee.am.common.audit.EventType) Reporter(io.gravitee.am.model.Reporter) AbstractManagementException(io.gravitee.am.service.exception.AbstractManagementException) Collectors(java.util.stream.Collectors) RandomString(io.gravitee.am.common.utils.RandomString) Component(org.springframework.stereotype.Component) List(java.util.List) ReporterNotFoundException(io.gravitee.am.service.exception.ReporterNotFoundException) UpdateReporter(io.gravitee.am.service.model.UpdateReporter) Payload(io.gravitee.am.model.common.event.Payload) Environment(org.springframework.core.env.Environment) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Optional(java.util.Optional) Lazy(org.springframework.context.annotation.Lazy) ReporterConfigurationException(io.gravitee.am.service.exception.ReporterConfigurationException) StringUtils(org.springframework.util.StringUtils) NewReporter(io.gravitee.am.service.model.NewReporter) Reporter(io.gravitee.am.model.Reporter) UpdateReporter(io.gravitee.am.service.model.UpdateReporter) JsonObject(io.vertx.core.json.JsonObject) RandomString(io.gravitee.am.common.utils.RandomString) ReporterConfigurationException(io.gravitee.am.service.exception.ReporterConfigurationException)

Example 5 with Reporter

use of io.gravitee.am.model.Reporter in project gravitee-access-management by gravitee-io.

the class DefaultReporterUpgraderTest method createDefaultTestReporter.

private Reporter createDefaultTestReporter(boolean system) {
    Reporter reporter = new Reporter();
    reporter.setName("Default test Reporter");
    reporter.setSystem(system);
    reporter.setId("test-reporter-id");
    reporter.setConfiguration("configuration-test-reporter");
    reporter.setDomain("domain-id");
    return reporter;
}
Also used : UpdateReporter(io.gravitee.am.service.model.UpdateReporter) Reporter(io.gravitee.am.model.Reporter)

Aggregations

Reporter (io.gravitee.am.model.Reporter)20 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Single (io.reactivex.Single)8 NewReporter (io.gravitee.am.service.model.NewReporter)7 User (io.gravitee.am.identityprovider.api.User)6 ReferenceType (io.gravitee.am.model.ReferenceType)6 Payload (io.gravitee.am.model.common.event.Payload)6 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)6 ReporterRepository (io.gravitee.am.repository.management.api.ReporterRepository)6 UpdateReporter (io.gravitee.am.service.model.UpdateReporter)6 Maybe (io.reactivex.Maybe)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Test (org.junit.Test)4 BaseEncoding (com.google.common.io.BaseEncoding)3 EventType (io.gravitee.am.common.audit.EventType)3 Action (io.gravitee.am.common.event.Action)3 Type (io.gravitee.am.common.event.Type)3