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();
}
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();
}
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));
}
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);
}
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();
}
Aggregations