use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class SlackNotifierTest method test_onApplicationEvent_resolve_with_given_message.
@Test
public void test_onApplicationEvent_resolve_with_given_message() {
notifier.setMessage(message);
notifier.setChannel(channel);
notifier.setIcon(icon);
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))).verifyComplete();
clearInvocations(restTemplate);
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))).verifyComplete();
Object expected = expectedMessage("good", user, icon, channel, message);
verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class));
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class AbstractEventStoreTest method should_throw_optimictic_locking_exception.
@Test
public void should_throw_optimictic_locking_exception() {
InstanceEvent event0 = new InstanceRegisteredEvent(id, 0L, registration);
InstanceEvent event1 = new InstanceStatusChangedEvent(id, 1L, StatusInfo.ofDown());
InstanceEvent event1b = new InstanceDeregisteredEvent(id, 1L);
InstanceEventStore store = createStore(100);
StepVerifier.create(store.append(asList(event0, event1))).verifyComplete();
StepVerifier.create(store.append(singletonList(event1b))).verifyError(OptimisticLockingException.class);
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class Instance method apply.
private Instance apply(InstanceEvent event, boolean isNewEvent) {
Assert.notNull(event, "'event' must not be null");
Assert.isTrue(this.id.equals(event.getInstance()), "'event' must refer the same instance");
Assert.isTrue(event.getVersion() >= this.nextVersion(), () -> "Event " + event.getVersion() + " must be greater or equal to " + this.nextVersion());
List<InstanceEvent> unsavedEvents = appendToEvents(event, isNewEvent);
if (event instanceof InstanceRegisteredEvent) {
Registration registration = ((InstanceRegisteredEvent) event).getRegistration();
return new Instance(this.id, event.getVersion(), registration, true, StatusInfo.ofUnknown(), event.getTimestamp(), Info.empty(), Endpoints.empty(), updateBuildVersion(registration.getMetadata()), updateTags(registration.getMetadata()), unsavedEvents);
} else if (event instanceof InstanceRegistrationUpdatedEvent) {
Registration registration = ((InstanceRegistrationUpdatedEvent) event).getRegistration();
return new Instance(this.id, event.getVersion(), registration, this.registered, this.statusInfo, this.statusTimestamp, this.info, this.endpoints, updateBuildVersion(registration.getMetadata(), this.info.getValues()), updateTags(registration.getMetadata(), this.info.getValues()), unsavedEvents);
} else if (event instanceof InstanceStatusChangedEvent) {
StatusInfo statusInfo = ((InstanceStatusChangedEvent) event).getStatusInfo();
return new Instance(this.id, event.getVersion(), this.registration, this.registered, statusInfo, event.getTimestamp(), this.info, this.endpoints, this.buildVersion, this.tags, unsavedEvents);
} else if (event instanceof InstanceEndpointsDetectedEvent) {
Endpoints endpoints = ((InstanceEndpointsDetectedEvent) event).getEndpoints();
return new Instance(this.id, event.getVersion(), this.registration, this.registered, this.statusInfo, this.statusTimestamp, this.info, endpoints, this.buildVersion, this.tags, unsavedEvents);
} else if (event instanceof InstanceInfoChangedEvent) {
Info info = ((InstanceInfoChangedEvent) event).getInfo();
Map<String, ?> metaData = (this.registration != null) ? this.registration.getMetadata() : emptyMap();
return new Instance(this.id, event.getVersion(), this.registration, this.registered, this.statusInfo, this.statusTimestamp, info, this.endpoints, updateBuildVersion(metaData, info.getValues()), updateTags(metaData, info.getValues()), unsavedEvents);
} else if (event instanceof InstanceDeregisteredEvent) {
return new Instance(this.id, event.getVersion(), this.registration, false, StatusInfo.ofUnknown(), event.getTimestamp(), Info.empty(), Endpoints.empty(), null, Tags.empty(), unsavedEvents);
}
return this;
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class AbstractStatusChangeNotifier method shouldNotify.
@Override
protected boolean shouldNotify(InstanceEvent event, Instance instance) {
if (event instanceof InstanceStatusChangedEvent) {
InstanceStatusChangedEvent statusChange = (InstanceStatusChangedEvent) event;
String from = getLastStatus(event.getInstance());
String to = statusChange.getStatusInfo().getStatus();
return Arrays.binarySearch(ignoreChanges, from + ":" + to) < 0 && Arrays.binarySearch(ignoreChanges, "*:" + to) < 0 && Arrays.binarySearch(ignoreChanges, from + ":*") < 0;
}
return false;
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class MicrosoftTeamsNotifier method doNotify.
@Override
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
Message message;
StandardEvaluationContext context = createEvaluationContext(event, instance);
if (event instanceof InstanceRegisteredEvent) {
message = getRegisteredMessage(instance, context);
} else if (event instanceof InstanceDeregisteredEvent) {
message = getDeregisteredMessage(instance, context);
} else if (event instanceof InstanceStatusChangedEvent) {
message = getStatusChangedMessage(instance, context);
} else {
return Mono.empty();
}
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
if (webhookUrl == null) {
return Mono.error(new IllegalStateException("'webhookUrl' must not be null."));
}
return Mono.fromRunnable(() -> this.restTemplate.postForEntity(webhookUrl, new HttpEntity<Object>(message, headers), Void.class));
}
Aggregations