Search in sources :

Example 26 with InstanceStatusChangedEvent

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));
}
Also used : URI(java.net.URI) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 27 with InstanceStatusChangedEvent

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);
}
Also used : InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceDeregisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent) 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 28 with InstanceStatusChangedEvent

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;
}
Also used : InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) Info(de.codecentric.boot.admin.server.domain.values.Info) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceDeregisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)

Example 29 with InstanceStatusChangedEvent

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;
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)

Example 30 with InstanceStatusChangedEvent

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));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) HttpEntity(org.springframework.http.HttpEntity) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceDeregisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)

Aggregations

InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)51 Test (org.junit.jupiter.api.Test)47 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)9 HttpEntity (org.springframework.http.HttpEntity)6 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)5 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)5 URI (java.net.URI)5 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)4 HashMap (java.util.HashMap)4 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)3 Message (de.codecentric.boot.admin.server.notify.MicrosoftTeamsNotifier.Message)3 Instant (java.time.Instant)3 JSONObject (org.json.JSONObject)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 Registration (de.codecentric.boot.admin.server.domain.values.Registration)2 MimeMessage (javax.mail.internet.MimeMessage)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)1 WireMock.ok (com.github.tomakehurst.wiremock.client.WireMock.ok)1