Search in sources :

Example 41 with Registration

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

the class RegistrationDeserializer method deserialize.

@Override
public Registration deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    JsonNode node = p.readValueAsTree();
    Registration.Builder builder = Registration.builder();
    if (node.hasNonNull("name")) {
        builder.name(node.get("name").asText());
    }
    if (node.hasNonNull("url")) {
        String url = node.get("url").asText();
        builder.healthUrl(url.replaceFirst("/+$", "") + "/health").managementUrl(url);
    } else {
        if (node.hasNonNull("healthUrl")) {
            builder.healthUrl(node.get("healthUrl").asText());
        }
        if (node.hasNonNull("managementUrl")) {
            builder.managementUrl(node.get("managementUrl").asText());
        }
        if (node.hasNonNull("serviceUrl")) {
            builder.serviceUrl(node.get("serviceUrl").asText());
        }
    }
    if (node.has("metadata")) {
        Iterator<Map.Entry<String, JsonNode>> it = node.get("metadata").fields();
        while (it.hasNext()) {
            Map.Entry<String, JsonNode> entry = it.next();
            builder.metadata(entry.getKey(), entry.getValue().asText());
        }
    }
    if (node.hasNonNull("source")) {
        builder.source(node.get("source").asText());
    }
    return builder.build();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) JsonNode(com.fasterxml.jackson.databind.JsonNode) Map(java.util.Map)

Example 42 with Registration

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

the class InstanceRegistryTest method register.

@Test
public void register() {
    Registration registration = Registration.create("abc", "http://localhost:8080/health").build();
    InstanceId id = registry.register(registration).block();
    StepVerifier.create(registry.getInstance(id)).assertNext((app) -> {
        assertThat(app.getRegistration()).isEqualTo(registration);
        assertThat(app.getId()).isNotNull();
    }).verifyComplete();
    StepVerifier.create(registry.getInstances()).assertNext((app) -> {
        assertThat(app.getRegistration()).isEqualTo(registration);
        assertThat(app.getId()).isNotNull();
    }).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Info(de.codecentric.boot.admin.server.domain.values.Info) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections.singletonMap(java.util.Collections.singletonMap) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 43 with Registration

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

the class CloudFoundryInstanceIdGeneratorTest method test_health_url_instance_id.

@Test
public void test_health_url_instance_id() {
    Registration registration = Registration.create("foo", "http://health").build();
    assertThat(instance.generateId(registration)).isEqualTo(InstanceId.of("8f9960c48139"));
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 44 with Registration

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

the class InstanceTest method should_track_unsaved_events.

@Test
public void should_track_unsaved_events() {
    Registration registration = Registration.create("foo", "http://health").build();
    Info info = Info.from(singletonMap("foo", "bar"));
    Instance newInstance = Instance.create(InstanceId.of("id"));
    assertThat(newInstance.isRegistered()).isFalse();
    assertThatThrownBy(newInstance::getRegistration).isInstanceOf(IllegalStateException.class);
    assertThat(newInstance.getInfo()).isEqualTo(Info.empty());
    assertThat(newInstance.getStatusInfo()).isEqualTo(StatusInfo.ofUnknown());
    assertThat(newInstance.getUnsavedEvents()).isEmpty();
    Instance instance = newInstance.register(registration).register(registration);
    assertThat(instance.getRegistration()).isEqualTo(registration);
    assertThat(instance.isRegistered()).isTrue();
    assertThat(instance.getVersion()).isEqualTo(0L);
    Registration registration2 = Registration.create("foo2", "http://health").build();
    instance = instance.register(registration2);
    assertThat(instance.getRegistration()).isEqualTo(registration2);
    assertThat(instance.isRegistered()).isTrue();
    assertThat(instance.getVersion()).isEqualTo(1L);
    instance = instance.withStatusInfo(StatusInfo.ofUp()).withStatusInfo(StatusInfo.ofUp());
    assertThat(instance.getStatusInfo()).isEqualTo(StatusInfo.ofUp());
    assertThat(instance.getVersion()).isEqualTo(2L);
    instance = instance.withInfo(info).withInfo(info);
    assertThat(instance.getInfo()).isEqualTo(info);
    assertThat(instance.getVersion()).isEqualTo(3L);
    instance = instance.deregister().deregister();
    assertThat(instance.isRegistered()).isFalse();
    assertThat(instance.getRegistration()).isEqualTo(registration2);
    assertThat(instance.getInfo()).isEqualTo(Info.empty());
    assertThat(instance.getStatusInfo()).isEqualTo(StatusInfo.ofUnknown());
    assertThat(instance.getVersion()).isEqualTo(4L);
    assertThat(instance.getUnsavedEvents().stream().map(InstanceEvent::getType)).containsExactly("REGISTERED", "REGISTRATION_UPDATED", "STATUS_CHANGED", "INFO_CHANGED", "DEREGISTERED");
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) Info(de.codecentric.boot.admin.server.domain.values.Info) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) Test(org.junit.jupiter.api.Test)

Example 45 with Registration

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

the class InfoUpdaterTest method should_retry.

@Test
public void should_retry() {
    // given
    Registration registration = Registration.create("foo", this.wireMock.url("/health")).build();
    Instance instance = Instance.create(InstanceId.of("onl")).register(registration).withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp());
    StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();
    this.wireMock.stubFor(get("/info").inScenario("retry").whenScenarioStateIs(STARTED).willReturn(aResponse().withFixedDelay(5000)).willSetStateTo("recovered"));
    String body = "{ \"foo\": \"bar\" }";
    this.wireMock.stubFor(get("/info").inScenario("retry").whenScenarioStateIs("recovered").willReturn(okJson(body).withHeader("Content-Length", Integer.toString(body.length()))));
    // when
    StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel().verify();
    StepVerifier.create(this.repository.find(instance.getId())).assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.from(singletonMap("foo", "bar")))).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) StepVerifier(reactor.test.StepVerifier) InstanceExchangeFilterFunctions.timeout(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.timeout) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Endpoint(de.codecentric.boot.admin.server.domain.values.Endpoint) WireMock.okJson(com.github.tomakehurst.wiremock.client.WireMock.okJson) Info(de.codecentric.boot.admin.server.domain.values.Info) InstanceExchangeFilterFunctions.rewriteEndpointUrl(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.rewriteEndpointUrl) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) AfterAll(org.junit.jupiter.api.AfterAll) InstanceExchangeFilterFunctions.retry(de.codecentric.boot.admin.server.web.client.InstanceExchangeFilterFunctions.retry) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) WireMock.serverError(com.github.tomakehurst.wiremock.client.WireMock.serverError) Collections.singletonMap(java.util.Collections.singletonMap) InstanceWebClient(de.codecentric.boot.admin.server.web.client.InstanceWebClient) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Registration(de.codecentric.boot.admin.server.domain.values.Registration) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) Collections.emptyMap(java.util.Collections.emptyMap) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) STARTED(com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED) Options(com.github.tomakehurst.wiremock.core.Options) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) AfterEach(org.junit.jupiter.api.AfterEach) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Registration (de.codecentric.boot.admin.server.domain.values.Registration)53 Test (org.junit.jupiter.api.Test)46 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)15 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)12 ServiceInstance (org.springframework.cloud.client.ServiceInstance)9 JSONObject (org.json.JSONObject)8 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)8 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)7 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)6 Info (de.codecentric.boot.admin.server.domain.values.Info)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 StepVerifier (reactor.test.StepVerifier)6 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)5 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)5 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)5 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)5 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Collections.singletonMap (java.util.Collections.singletonMap)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3