Search in sources :

Example 6 with GraviteeContext

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

the class JacksonSerializerUTests method Should_SerializeAnAuditAsJson.

@Test
public void Should_SerializeAnAuditAsJson() throws URISyntaxException, IOException {
    DtoMapper mapper = new DtoMapper();
    GraviteeContext context = GraviteeContext.defaultContext("acme");
    Node node = new DummyNode("node-id", "main.srv.local");
    AuditMessageValueDto auditMessageValueDto = mapper.map(AuditValueFactory.createAudit(), context, node);
    JacksonSerializer<AuditMessageValueDto> serializer = new JacksonSerializer<>();
    byte[] bytes = serializer.serialize("topic", auditMessageValueDto);
    URL resource = JacksonSerializerUTests.class.getResource("/json/audit.json");
    byte[] expected = Files.readAllBytes(Paths.get(resource.toURI()));
    assertEquals(new String(expected, StandardCharsets.UTF_8), new String(bytes, StandardCharsets.UTF_8));
}
Also used : GraviteeContext(io.gravitee.am.common.utils.GraviteeContext) DummyNode(io.gravitee.am.reporter.kafka.DummyNode) Node(io.gravitee.node.api.Node) DummyNode(io.gravitee.am.reporter.kafka.DummyNode) DtoMapper(io.gravitee.am.reporter.kafka.audit.DtoMapper) AuditMessageValueDto(io.gravitee.am.reporter.kafka.dto.AuditMessageValueDto) URL(java.net.URL) Test(org.junit.Test)

Example 7 with GraviteeContext

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

the class DtoMapperUTests method Should_MapAuditToAuditDto.

@Test
public void Should_MapAuditToAuditDto() {
    // arrange
    DtoMapper mapper = new DtoMapper();
    GraviteeContext context = GraviteeContext.defaultContext("domain");
    Node nodeMock = new DummyNode("first", "first.srv.local");
    Audit audit = AuditValueFactory.createAudit();
    // act
    AuditMessageValueDto dto = mapper.map(audit, context, nodeMock);
    // assert
    Assert.assertEquals("id", dto.getId());
    Assert.assertEquals("reference id", dto.getReferenceId());
    this.assertEquals(ReferenceType.APPLICATION, dto.getReferenceType());
    Assert.assertEquals(Instant.EPOCH, dto.getTimestamp());
    Assert.assertEquals("transaction id", dto.getTransactionId());
    Assert.assertEquals("type", dto.getType());
    Assert.assertEquals("status", dto.getStatus());
    this.assertEquals(audit.getActor(), dto.getActor());
    this.assertEquals(audit.getTarget(), dto.getTarget());
    Assert.assertEquals(context.getOrganizationId(), dto.getOrganizationId());
    Assert.assertEquals(context.getEnvironmentId(), dto.getEnvironmentId());
    Assert.assertEquals("first", dto.getNodeId());
    Assert.assertEquals("first.srv.local", dto.getNodeHostname());
    this.assertEquals(audit.getAccessPoint(), dto.getAccessPoint());
}
Also used : Audit(io.gravitee.am.reporter.api.audit.model.Audit) GraviteeContext(io.gravitee.am.common.utils.GraviteeContext) DummyNode(io.gravitee.am.reporter.kafka.DummyNode) Node(io.gravitee.node.api.Node) DummyNode(io.gravitee.am.reporter.kafka.DummyNode) AuditMessageValueDto(io.gravitee.am.reporter.kafka.dto.AuditMessageValueDto) Test(org.junit.Test)

Example 8 with GraviteeContext

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

the class AuditReporterManagerImpl method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    logger.info("Initializing reporters for domain {}", domain.getName());
    logger.info("\t Starting reporter verticle for domain {}", domain.getName());
    Single<String> deployment = RxHelper.deployVerticle(vertx, applicationContext.getBean(AuditReporterVerticle.class));
    deployment.subscribe(id -> {
        // Deployed
        deploymentId = id;
        // Start reporters
        reporterRepository.findByDomain(domain.getId()).toList().flatMap(reporters -> environmentService.findById(domain.getReferenceId()).map(env -> new GraviteeContext(env.getOrganizationId(), env.getId(), domain.getId())).map(ctx -> Tuples.of(reporters, ctx))).subscribeOn(Schedulers.io()).subscribe(tupleReportersContext -> {
            if (!tupleReportersContext.getT1().isEmpty()) {
                tupleReportersContext.getT1().forEach(reporter -> {
                    startReporterProvider(reporter, tupleReportersContext.getT2());
                });
                logger.info("Reporters loaded for domain {}", domain.getName());
            } else {
                logger.info("\tThere is no reporter to start");
            }
        }, err -> {
            logger.error("Reporter service can not be started", err);
        });
    }, err -> {
        // Could not deploy
        logger.error("Reporter service can not be started", err);
    });
}
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) AuditReporterVerticle(io.gravitee.am.service.reporter.impl.AuditReporterVerticle) GraviteeContext(io.gravitee.am.common.utils.GraviteeContext)

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