Search in sources :

Example 1 with Payload

use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.

the class AlertTriggerManager method onAlertNotifierEvent.

void onAlertNotifierEvent(Event<AlertNotifierEvent, ?> event) {
    LOGGER.debug("Received alert notifier event {}", event);
    final Payload payload = (Payload) event.content();
    final AlertTriggerCriteria alertTriggerCriteria = new AlertTriggerCriteria();
    alertTriggerCriteria.setEnabled(true);
    alertTriggerCriteria.setAlertNotifierIds(Collections.singletonList(payload.getId()));
    domainService.findById(payload.getReferenceId()).filter(domain -> domain.isEnabled() && domain.isAlertEnabled()).flatMapPublisher(domain -> this.alertTriggerService.findByDomainAndCriteria(domain.getId(), alertTriggerCriteria).flatMapSingle(alertTrigger -> prepareAETrigger(domain, alertTrigger)).flatMapSingle(this::registerAETrigger)).count().subscribe(count -> LOGGER.info("{} alert triggers synchronized with the alerting system for domain [{}] after the update of alert notifier [{}].", count, payload.getReferenceId(), payload.getId()), throwable -> LOGGER.error("An error occurred when trying to synchronize alert triggers with alerting system for domain [{}] after the alert notifier {} event [{}].", payload.getReferenceId(), event.type().name().toLowerCase(), payload.getId(), throwable));
}
Also used : Trigger(io.gravitee.alert.api.trigger.Trigger) AlertNotifierEvent(io.gravitee.am.common.event.AlertNotifierEvent) LoggerFactory(org.slf4j.LoggerFactory) DomainService(io.gravitee.am.service.DomainService) ResolvePropertyCommandHandler(io.gravitee.am.management.service.alerts.handlers.ResolvePropertyCommandHandler) Single(io.reactivex.Single) DomainEvent(io.gravitee.am.common.event.DomainEvent) Flowable(io.reactivex.Flowable) AlertTriggerEvent(io.gravitee.am.common.event.AlertTriggerEvent) AlertTriggerCriteria(io.gravitee.am.repository.management.api.search.AlertTriggerCriteria) DomainCriteria(io.gravitee.am.repository.management.api.search.DomainCriteria) AlertNotifierService(io.gravitee.am.service.AlertNotifierService) AlertNotifierCriteria(io.gravitee.am.repository.management.api.search.AlertNotifierCriteria) Logger(org.slf4j.Logger) Event(io.gravitee.common.event.Event) AlertNotificationCommandHandler(io.gravitee.am.management.service.alerts.handlers.AlertNotificationCommandHandler) Domain(io.gravitee.am.model.Domain) AbstractService(io.gravitee.common.service.AbstractService) AlertTrigger(io.gravitee.am.model.alert.AlertTrigger) Component(org.springframework.stereotype.Component) TriggerProvider(io.gravitee.alert.api.trigger.TriggerProvider) AlertTriggerFactory(io.gravitee.am.management.service.alerts.AlertTriggerFactory) EventManager(io.gravitee.common.event.EventManager) Payload(io.gravitee.am.model.common.event.Payload) Environment(org.springframework.core.env.Environment) Collections(java.util.Collections) AlertTriggerService(io.gravitee.am.service.AlertTriggerService) AlertTriggerCriteria(io.gravitee.am.repository.management.api.search.AlertTriggerCriteria) Payload(io.gravitee.am.model.common.event.Payload)

Example 2 with Payload

use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.

the class SyncManagerTest method test_twiceWithTwoDomains_domainToRemove.

@Test
public void test_twiceWithTwoDomains_domainToRemove() throws Exception {
    final Domain domain = new Domain();
    domain.setId("domain-1");
    domain.setReferenceId("env-1");
    domain.setEnabled(true);
    when(domainRepository.findAll()).thenReturn(Flowable.just(domain));
    syncManager.refresh();
    Event event = new Event();
    event.setType(Type.DOMAIN);
    event.setPayload(new Payload("domain-1", ReferenceType.DOMAIN, "domain-1", Action.DELETE));
    when(eventRepository.findByTimeFrame(any(Long.class), any(Long.class))).thenReturn(Flowable.just(event));
    syncManager.refresh();
    verify(securityDomainManager, times(1)).deploy(any());
    verify(securityDomainManager, never()).update(any());
    verify(securityDomainManager, times(1)).undeploy(domain.getId());
}
Also used : Event(io.gravitee.am.model.common.event.Event) Payload(io.gravitee.am.model.common.event.Payload) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test)

Example 3 with Payload

use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.

the class SyncManagerTest method test_twiceWithTwoDomains_domainToUpdate.

@Test
public void test_twiceWithTwoDomains_domainToUpdate() throws Exception {
    final Domain domain = new Domain();
    domain.setId("domain-1");
    domain.setReferenceId("env-1");
    domain.setEnabled(true);
    domain.setUpdatedAt(new Date(System.currentTimeMillis() - 60 * 1000));
    when(domainRepository.findAll()).thenReturn(Flowable.just(domain));
    syncManager.refresh();
    Event event = new Event();
    event.setType(Type.DOMAIN);
    event.setPayload(new Payload("domain-1", ReferenceType.DOMAIN, "domain-1", Action.UPDATE));
    final Domain domainToUpdate = new Domain();
    domainToUpdate.setId("domain-1");
    domainToUpdate.setReferenceId("env-1");
    domainToUpdate.setEnabled(true);
    domainToUpdate.setUpdatedAt(new Date());
    when(eventRepository.findByTimeFrame(any(Long.class), any(Long.class))).thenReturn(Flowable.just(event));
    when(domainRepository.findById(domainToUpdate.getId())).thenReturn(Maybe.just(domainToUpdate));
    when(securityDomainManager.get(domainToUpdate.getId())).thenReturn(domain);
    syncManager.refresh();
    verify(securityDomainManager, times(1)).deploy(any());
    verify(securityDomainManager, times(1)).update(any());
    verify(securityDomainManager, never()).undeploy(domain.getId());
}
Also used : Event(io.gravitee.am.model.common.event.Event) Payload(io.gravitee.am.model.common.event.Payload) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test)

Example 4 with Payload

use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.

the class SyncManagerTest method shouldPropagateEvents.

@Test
public void shouldPropagateEvents() {
    when(domainRepository.findAll()).thenReturn(Flowable.empty());
    syncManager.refresh();
    Event event = new Event();
    event.setType(Type.IDENTITY_PROVIDER);
    event.setPayload(new Payload("idp-1", ReferenceType.DOMAIN, "domain-1", Action.UPDATE));
    when(eventRepository.findByTimeFrame(any(Long.class), any(Long.class))).thenReturn(Flowable.just(event));
    syncManager.refresh();
    verify(eventManager, times(1)).publishEvent(any(), any());
    verify(securityDomainManager, never()).deploy(any(Domain.class));
    verify(securityDomainManager, never()).update(any(Domain.class));
    verify(securityDomainManager, never()).undeploy(any(String.class));
}
Also used : Event(io.gravitee.am.model.common.event.Event) Payload(io.gravitee.am.model.common.event.Payload) Domain(io.gravitee.am.model.Domain) Test(org.junit.Test)

Example 5 with Payload

use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.

the class MongoEventRepository method convert.

private Payload convert(Document document) {
    if (document == null) {
        return null;
    }
    Payload content = new Payload(document.get("content", Map.class));
    content.put("action", Action.valueOf((String) content.get("action")));
    return content;
}
Also used : Payload(io.gravitee.am.model.common.event.Payload) RandomString(io.gravitee.am.common.utils.RandomString) Map(java.util.Map)

Aggregations

Payload (io.gravitee.am.model.common.event.Payload)44 Event (io.gravitee.am.model.common.event.Event)35 Component (org.springframework.stereotype.Component)29 Action (io.gravitee.am.common.event.Action)28 Logger (org.slf4j.Logger)28 LoggerFactory (org.slf4j.LoggerFactory)28 Type (io.gravitee.am.common.event.Type)27 RandomString (io.gravitee.am.common.utils.RandomString)27 Autowired (org.springframework.beans.factory.annotation.Autowired)27 Lazy (org.springframework.context.annotation.Lazy)27 EventType (io.gravitee.am.common.audit.EventType)26 AuditBuilder (io.gravitee.am.service.reporter.builder.AuditBuilder)26 ReferenceType (io.gravitee.am.model.ReferenceType)25 User (io.gravitee.am.identityprovider.api.User)24 Single (io.reactivex.Single)20 Completable (io.reactivex.Completable)18 Maybe (io.reactivex.Maybe)18 Date (java.util.Date)18 Collectors (java.util.stream.Collectors)16 Flowable (io.reactivex.Flowable)15