Search in sources :

Example 26 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance 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)

Example 27 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class InstanceIdNotificationFilterTest method test_filterByName.

@Test
public void test_filterByName() {
    NotificationFilter filter = new InstanceIdNotificationFilter(InstanceId.of("cafebabe"), null);
    Instance filteredInstance = Instance.create(InstanceId.of("cafebabe")).register(Registration.create("foo", "http://health").build());
    InstanceRegisteredEvent filteredEvent = new InstanceRegisteredEvent(filteredInstance.getId(), filteredInstance.getVersion(), filteredInstance.getRegistration());
    assertThat(filter.filter(filteredEvent, filteredInstance)).isTrue();
    Instance ignoredInstance = Instance.create(InstanceId.of("-")).register(Registration.create("foo", "http://health").build());
    InstanceRegisteredEvent ignoredEvent = new InstanceRegisteredEvent(ignoredInstance.getId(), ignoredInstance.getVersion(), ignoredInstance.getRegistration());
    assertThat(filter.filter(ignoredEvent, ignoredInstance)).isFalse();
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Test(org.junit.jupiter.api.Test)

Example 28 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class ApplicationRegistry method getStatus.

protected Tuple2<String, Instant> getStatus(List<Instance> instances) {
    // TODO: Correct is just a second readmodel for groups
    Map<String, Instant> statusWithTime = instances.stream().collect(toMap((instance) -> instance.getStatusInfo().getStatus(), Instance::getStatusTimestamp, this::getMax));
    if (statusWithTime.size() == 1) {
        Map.Entry<String, Instant> e = statusWithTime.entrySet().iterator().next();
        return Tuples.of(e.getKey(), e.getValue());
    }
    if (statusWithTime.containsKey(StatusInfo.STATUS_UP)) {
        Instant oldestNonUp = statusWithTime.entrySet().stream().filter((e) -> !StatusInfo.STATUS_UP.equals(e.getKey())).map(Map.Entry::getValue).min(naturalOrder()).orElse(Instant.EPOCH);
        Instant latest = getMax(oldestNonUp, statusWithTime.getOrDefault(StatusInfo.STATUS_UP, Instant.EPOCH));
        return Tuples.of(StatusInfo.STATUS_RESTRICTED, latest);
    }
    return statusWithTime.entrySet().stream().min(Map.Entry.comparingByKey(StatusInfo.severity())).map((e) -> Tuples.of(e.getKey(), e.getValue())).orElse(Tuples.of(STATUS_UNKNOWN, Instant.EPOCH));
}
Also used : Comparator.naturalOrder(java.util.Comparator.naturalOrder) Application(de.codecentric.boot.admin.server.domain.entities.Application) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Tuples(reactor.util.function.Tuples) Tuple2(reactor.util.function.Tuple2) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) Objects(java.util.Objects) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Flux(reactor.core.publisher.Flux) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) InstanceEventPublisher(de.codecentric.boot.admin.server.eventstore.InstanceEventPublisher) BuildVersion(de.codecentric.boot.admin.server.domain.values.BuildVersion) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) STATUS_UNKNOWN(de.codecentric.boot.admin.server.domain.values.StatusInfo.STATUS_UNKNOWN) Nullable(javax.annotation.Nullable) Instant(java.time.Instant) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Example 29 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class InstanceRegistry method register.

/**
 * Register instance.
 * @param registration instance to be registered.
 * @return the id of the registered instance.
 */
public Mono<InstanceId> register(Registration registration) {
    Assert.notNull(registration, "'registration' must not be null");
    InstanceId id = generator.generateId(registration);
    Assert.notNull(id, "'id' must not be null");
    return repository.compute(id, (key, instance) -> {
        if (instance == null) {
            instance = Instance.create(key);
        }
        return Mono.just(instance.register(registration));
    }).map(Instance::getId);
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Flux(reactor.core.publisher.Flux) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Mono(reactor.core.publisher.Mono) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Assert(org.springframework.util.Assert) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instance(de.codecentric.boot.admin.server.domain.entities.Instance)

Example 30 with Instance

use of de.codecentric.boot.admin.server.domain.entities.Instance in project spring-boot-admin by codecentric.

the class InstanceRegistryTest method findByName.

@Test
public void findByName() {
    InstanceId id1 = registry.register(Registration.create("abc", "http://localhost:8080/health").build()).block();
    InstanceId id2 = registry.register(Registration.create("abc", "http://localhost:8081/health").build()).block();
    InstanceId id3 = registry.register(Registration.create("zzz", "http://localhost:9999/health").build()).block();
    StepVerifier.create(registry.getInstances("abc")).recordWith(ArrayList::new).thenConsumeWhile((a) -> true).consumeRecordedWith((applications) -> assertThat(applications.stream().map(Instance::getId)).doesNotContain(id3).containsExactlyInAnyOrder(id1, id2)).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Info(de.codecentric.boot.admin.server.domain.values.Info) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections.singletonMap(java.util.Collections.singletonMap) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Test(org.junit.jupiter.api.Test)

Aggregations

Instance (de.codecentric.boot.admin.server.domain.entities.Instance)44 Test (org.junit.jupiter.api.Test)42 Registration (de.codecentric.boot.admin.server.domain.values.Registration)23 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 StepVerifier (reactor.test.StepVerifier)14 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 Mono (reactor.core.publisher.Mono)10 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)9 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)8 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)8 Flux (reactor.core.publisher.Flux)8 ArrayList (java.util.ArrayList)7 Collections.singletonMap (java.util.Collections.singletonMap)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Application (de.codecentric.boot.admin.server.domain.entities.Application)6 Info (de.codecentric.boot.admin.server.domain.values.Info)6 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)6 Mockito.mock (org.mockito.Mockito.mock)6