Search in sources :

Example 1 with InstanceEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceEvent in project spring-boot-admin by codecentric.

the class Instance method apply.

Instance apply(Collection<InstanceEvent> events) {
    Assert.notNull(events, "'events' must not be null");
    Instance instance = this;
    for (InstanceEvent event : events) {
        instance = instance.apply(event);
    }
    return instance;
}
Also used : InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent)

Example 2 with InstanceEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceEvent in project spring-boot-admin by codecentric.

the class ConcurrentMapEventStore method doAppend.

protected boolean doAppend(List<InstanceEvent> events) {
    if (events.isEmpty()) {
        return true;
    }
    InstanceId id = events.get(0).getInstance();
    if (!events.stream().allMatch((event) -> event.getInstance().equals(id))) {
        throw new IllegalArgumentException("'events' must only refer to the same instance.");
    }
    List<InstanceEvent> oldEvents = eventLog.computeIfAbsent(id, (key) -> new ArrayList<>(maxLogSizePerAggregate + 1));
    long lastVersion = getLastVersion(oldEvents);
    if (lastVersion >= events.get(0).getVersion()) {
        throw createOptimisticLockException(events.get(0), lastVersion);
    }
    List<InstanceEvent> newEvents = new ArrayList<>(oldEvents);
    newEvents.addAll(events);
    if (newEvents.size() > maxLogSizePerAggregate) {
        log.debug("Threshold for {} reached. Compacting events", id);
        compact(newEvents);
    }
    if (eventLog.replace(id, oldEvents, newEvents)) {
        log.debug("Events appended to log {}", events);
        return true;
    }
    log.debug("Unsuccessful attempt append the events {} ", events);
    return false;
}
Also used : Logger(org.slf4j.Logger) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) LoggerFactory(org.slf4j.LoggerFactory) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Mono(reactor.core.publisher.Mono) Collectors.reducing(java.util.stream.Collectors.reducing) Function(java.util.function.Function) BinaryOperator(java.util.function.BinaryOperator) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Objects(java.util.Objects) Flux(reactor.core.publisher.Flux) List(java.util.List) Map(java.util.Map) Optional(java.util.Optional) Comparator.comparing(java.util.Comparator.comparing) Comparator(java.util.Comparator) Collections(java.util.Collections) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) ArrayList(java.util.ArrayList) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent)

Example 3 with InstanceEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceEvent in project spring-boot-admin by codecentric.

the class FilteringNotifierTest method test_filter.

@Test
public void test_filter() {
    TestNotifier delegate = new TestNotifier();
    FilteringNotifier notifier = new FilteringNotifier(delegate, repository);
    AbstractNotificationFilter trueFilter = new AbstractNotificationFilter() {

        @Override
        public boolean filter(InstanceEvent event, Instance instance) {
            return true;
        }
    };
    notifier.addFilter(trueFilter);
    StepVerifier.create(notifier.notify(event)).verifyComplete();
    assertThat(delegate.getEvents()).doesNotContain(event);
    notifier.removeFilter(trueFilter.getId());
    StepVerifier.create(notifier.notify(event)).verifyComplete();
    assertThat(delegate.getEvents()).contains(event);
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) TestNotifier(de.codecentric.boot.admin.server.notify.TestNotifier) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) Test(org.junit.jupiter.api.Test)

Example 4 with InstanceEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceEvent in project spring-boot-admin by codecentric.

the class AbstractEventStoreTest method should_shorten_log_on_exceeded_capacity.

@Test
public void should_shorten_log_on_exceeded_capacity() {
    InstanceEventStore store = createStore(2);
    InstanceEvent event1 = new InstanceRegisteredEvent(id, 0L, registration);
    InstanceEvent event2 = new InstanceStatusChangedEvent(id, 1L, StatusInfo.ofDown());
    InstanceEvent event3 = new InstanceStatusChangedEvent(id, 2L, StatusInfo.ofUp());
    StepVerifier.create(store.append(asList(event1, event2, event3))).verifyComplete();
    StepVerifier.create(store.findAll()).expectNext(event1, event3).verifyComplete();
}
Also used : InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 5 with InstanceEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceEvent in project spring-boot-admin by codecentric.

the class MailNotifierTest method should_not_propagate_error.

@Test
public void should_not_propagate_error() {
    Notifier notifier = new AbstractStatusChangeNotifier(repository) {

        @Override
        protected Mono<Void> doNotify(InstanceEvent event, Instance application) {
            return Mono.error(new IllegalStateException("test"));
        }
    };
    StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))).verifyComplete();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)11 Test (org.junit.jupiter.api.Test)8 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)5 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)5 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)5 Registration (de.codecentric.boot.admin.server.domain.values.Registration)3 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 Info (de.codecentric.boot.admin.server.domain.values.Info)2 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)2 Instant (java.time.Instant)2 List (java.util.List)2 Function (java.util.function.Function)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Flux (reactor.core.publisher.Flux)2 Mono (reactor.core.publisher.Mono)2 InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)1 InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)1 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)1