Search in sources :

Example 6 with InstanceRegistrationUpdatedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent 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 7 with InstanceRegistrationUpdatedEvent

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

the class StatusUpdateTriggerTest method should_update_on_instance_registration_update_event.

@Test
public void should_update_on_instance_registration_update_event() {
    // when registered event is emitted
    this.events.next(new InstanceRegistrationUpdatedEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration()));
    // then should update
    verify(this.updater, times(1)).updateStatus(this.instance.getId());
}
Also used : InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) Test(org.junit.jupiter.api.Test)

Example 8 with InstanceRegistrationUpdatedEvent

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

the class EndpointDetectionTriggerTest method should_detect_on_registration_updated.

@Test
public void should_detect_on_registration_updated() {
    // when status-change event is emitted
    this.events.next(new InstanceRegistrationUpdatedEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration()));
    // then should update
    verify(this.detector, times(1)).detectEndpoints(this.instance.getId());
}
Also used : InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) Test(org.junit.jupiter.api.Test)

Example 9 with InstanceRegistrationUpdatedEvent

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

the class InstanceRegistrationUpdatedEventMixinTest method verifySerializeWithOnlyRequiredProperties.

@Test
public void verifySerializeWithOnlyRequiredProperties() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    Registration registration = Registration.create("test", "http://localhost:9080/heath").build();
    InstanceRegistrationUpdatedEvent event = new InstanceRegistrationUpdatedEvent(id, 0L, timestamp, registration);
    JsonContent<InstanceRegistrationUpdatedEvent> jsonContent = jsonTester.write(event);
    assertThat(jsonContent).extractingJsonPathStringValue("$.instance").isEqualTo("test123");
    assertThat(jsonContent).extractingJsonPathNumberValue("$.version").isEqualTo(0);
    assertThat(jsonContent).extractingJsonPathNumberValue("$.timestamp").isEqualTo(1587751031.000000000);
    assertThat(jsonContent).extractingJsonPathStringValue("$.type").isEqualTo("REGISTRATION_UPDATED");
    assertThat(jsonContent).extractingJsonPathValue("$.registration").isNotNull();
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.name").isEqualTo("test");
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.managementUrl").isNull();
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.healthUrl").isEqualTo("http://localhost:9080/heath");
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.serviceUrl").isNull();
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.source").isNull();
    assertThat(jsonContent).extractingJsonPathMapValue("$.registration.metadata").isEmpty();
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Instant(java.time.Instant) InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) Test(org.junit.jupiter.api.Test)

Example 10 with InstanceRegistrationUpdatedEvent

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

the class InstanceRegistrationUpdatedEventMixinTest method verifySerializeWithoutRegistration.

@Test
public void verifySerializeWithoutRegistration() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    InstanceRegistrationUpdatedEvent event = new InstanceRegistrationUpdatedEvent(id, 12345678L, timestamp, null);
    JsonContent<InstanceRegistrationUpdatedEvent> jsonContent = jsonTester.write(event);
    assertThat(jsonContent).extractingJsonPathStringValue("$.instance").isEqualTo("test123");
    assertThat(jsonContent).extractingJsonPathNumberValue("$.version").isEqualTo(12345678);
    assertThat(jsonContent).extractingJsonPathNumberValue("$.timestamp").isEqualTo(1587751031.000000000);
    assertThat(jsonContent).extractingJsonPathStringValue("$.type").isEqualTo("REGISTRATION_UPDATED");
    assertThat(jsonContent).extractingJsonPathMapValue("$.registration").isNull();
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instant(java.time.Instant) InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)11 Test (org.junit.jupiter.api.Test)10 Registration (de.codecentric.boot.admin.server.domain.values.Registration)5 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)3 Instant (java.time.Instant)3 JSONObject (org.json.JSONObject)3 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)1 InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)1 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)1 InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)1 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)1 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)1 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)1 Info (de.codecentric.boot.admin.server.domain.values.Info)1 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)1