Search in sources :

Example 1 with Endpoints

use of de.codecentric.boot.admin.server.domain.values.Endpoints in project spring-boot-admin by codecentric.

the class EndpointsMixinTest method verifyDeserialize.

@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
    String json = new JSONArray().put(new JSONObject().put("id", "info").put("url", "http://localhost:8080/info")).put(new JSONObject().put("id", "health").put("url", "http://localhost:8080/health")).toString();
    Endpoints endpoints = objectMapper.readValue(json, Endpoints.class);
    assertThat(endpoints).isNotNull();
    assertThat(endpoints).containsExactlyInAnyOrder(Endpoint.of("info", "http://localhost:8080/info"), Endpoint.of("health", "http://localhost:8080/health"));
}
Also used : Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.junit.jupiter.api.Test)

Example 2 with Endpoints

use of de.codecentric.boot.admin.server.domain.values.Endpoints in project spring-boot-admin by codecentric.

the class AbstractInstanceRepositoryTest method should_computeIfPresent.

@Test
public void should_computeIfPresent() {
    AtomicLong counter = new AtomicLong(3L);
    Endpoints infoEndpoint = Endpoints.single("info", "info");
    // given
    StepVerifier.create(this.repository.save(this.instance1)).expectNextCount(1).verifyComplete();
    // when
    StepVerifier.create(this.repository.computeIfPresent(this.instance1.getId(), (key, value) -> {
        if (counter.getAndDecrement() > 0L) {
            // causes OptimistickLockException
            return Mono.just(this.instance1);
        } else {
            return Mono.just(value.withEndpoints(infoEndpoint));
        }
    })).expectNext(this.instance1.withEndpoints(infoEndpoint)).verifyComplete();
    // then
    StepVerifier.create(this.repository.find(this.instance1.getId())).expectNext(this.instance1.withEndpoints(infoEndpoint)).verifyComplete();
}
Also used : Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) Test(org.junit.jupiter.api.Test) Registration(de.codecentric.boot.admin.server.domain.values.Registration) AtomicLong(java.util.concurrent.atomic.AtomicLong) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) AssertionFailedError(org.opentest4j.AssertionFailedError) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.jupiter.api.Test)

Example 3 with Endpoints

use of de.codecentric.boot.admin.server.domain.values.Endpoints in project spring-boot-admin by codecentric.

the class Instance method withEndpoints.

public Instance withEndpoints(Endpoints endpoints) {
    Assert.notNull(endpoints, "'endpoints' must not be null");
    Endpoints endpointsWithHealth = (this.registration != null) ? endpoints.withEndpoint(Endpoint.HEALTH, this.registration.getHealthUrl()) : endpoints;
    if (Objects.equals(this.endpoints, endpointsWithHealth)) {
        return this;
    }
    return this.apply(new InstanceEndpointsDetectedEvent(this.id, this.nextVersion(), endpoints), true);
}
Also used : Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)

Example 4 with Endpoints

use of de.codecentric.boot.admin.server.domain.values.Endpoints 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 5 with Endpoints

use of de.codecentric.boot.admin.server.domain.values.Endpoints in project spring-boot-admin by codecentric.

the class AbstractInstanceRepositoryTest method should_retry_compute.

@Test
public void should_retry_compute() {
    AtomicLong counter = new AtomicLong(3L);
    Endpoints infoEndpoint = Endpoints.single("info", "info");
    // given
    StepVerifier.create(this.repository.save(this.instance1)).expectNextCount(1).verifyComplete();
    // when
    StepVerifier.create(this.repository.compute(this.instance1.getId(), (key, value) -> {
        if (counter.getAndDecrement() > 0L) {
            // causes OptimistickLockException
            return Mono.just(this.instance1);
        } else {
            return Mono.just(value.withEndpoints(infoEndpoint));
        }
    })).expectNext(this.instance1.withEndpoints(infoEndpoint)).verifyComplete();
    // then
    StepVerifier.create(this.repository.find(this.instance1.getId())).expectNext(this.instance1.withEndpoints(infoEndpoint)).verifyComplete();
}
Also used : Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) Test(org.junit.jupiter.api.Test) Registration(de.codecentric.boot.admin.server.domain.values.Registration) AtomicLong(java.util.concurrent.atomic.AtomicLong) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) AssertionFailedError(org.opentest4j.AssertionFailedError) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) AtomicLong(java.util.concurrent.atomic.AtomicLong) Test(org.junit.jupiter.api.Test)

Aggregations

Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)7 Test (org.junit.jupiter.api.Test)5 InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)3 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)3 Registration (de.codecentric.boot.admin.server.domain.values.Registration)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 AssertionFailedError (org.opentest4j.AssertionFailedError)2 Mono (reactor.core.publisher.Mono)2 StepVerifier (reactor.test.StepVerifier)2 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)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 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)1 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)1 Info (de.codecentric.boot.admin.server.domain.values.Info)1 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)1 Instant (java.time.Instant)1 JSONArray (org.json.JSONArray)1