Search in sources :

Example 26 with Registration

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

the class InstanceTest method should_update_buildVersion.

@Test
public void should_update_buildVersion() {
    Instance instance = Instance.create(InstanceId.of("id"));
    assertThat(instance.getBuildVersion()).isNull();
    Registration registration = Registration.create("foo-instance", "http://health").metadata("version", "1.0.0").build();
    instance = instance.register(registration).withInfo(Info.empty());
    assertThat(instance.getBuildVersion()).isEqualTo(BuildVersion.valueOf("1.0.0"));
    instance = instance.register(registration.toBuilder().clearMetadata().build());
    assertThat(instance.getBuildVersion()).isNull();
    instance = instance.withInfo(Info.from(singletonMap("build", singletonMap("version", "2.1.1"))));
    assertThat(instance.getBuildVersion()).isEqualTo(BuildVersion.valueOf("2.1.1"));
    instance = instance.deregister();
    assertThat(instance.getBuildVersion()).isNull();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 27 with Registration

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

the class QueryIndexEndpointStrategy method detectEndpoints.

@Override
public Mono<Endpoints> detectEndpoints(Instance instance) {
    Registration registration = instance.getRegistration();
    String managementUrl = registration.getManagementUrl();
    if (managementUrl == null || Objects.equals(registration.getServiceUrl(), managementUrl)) {
        log.debug("Querying actuator-index for instance {} omitted.", instance.getId());
        return Mono.empty();
    }
    return this.instanceWebClient.instance(instance).get().uri(managementUrl).exchangeToMono(this.convert(instance, managementUrl)).onErrorResume((e) -> {
        log.warn("Querying actuator-index for instance {} on '{}' failed: {}", instance.getId(), managementUrl, e.getMessage());
        log.debug("Querying actuator-index for instance {} on '{}' failed.", instance.getId(), managementUrl, e);
        return Mono.empty();
    });
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration)

Example 28 with Registration

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

the class InstanceDiscoveryListener method registerInstance.

protected Mono<InstanceId> registerInstance(ServiceInstance instance) {
    try {
        Registration registration = converter.convert(instance).toBuilder().source(SOURCE).build();
        log.debug("Registering discovered instance {}", registration);
        return registry.register(registration);
    } catch (Exception ex) {
        log.error("Couldn't register instance for discovered instance ({})", toString(instance), ex);
        return Mono.empty();
    }
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration)

Example 29 with Registration

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

the class DefaultServiceInstanceConverterTest method should_convert_with_metadata_having_null_value.

@Test
public void should_convert_with_metadata_having_null_value() {
    ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
    Map<String, String> metadata = new HashMap<>();
    metadata.put("health.path", "ping");
    metadata.put("management.scheme", "https");
    metadata.put("management.address", "127.0.0.1");
    metadata.put("management.port", "1234");
    metadata.put("null.value", null);
    metadata.put(null, "null.key");
    service.getMetadata().putAll(metadata);
    Registration registration = new DefaultServiceInstanceConverter().convert(service);
    assertThat(registration.getHealthUrl()).isEqualTo("https://127.0.0.1:1234/actuator/ping");
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HashMap(java.util.HashMap) Registration(de.codecentric.boot.admin.server.domain.values.Registration) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Test(org.junit.jupiter.api.Test)

Example 30 with Registration

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

the class DefaultServiceInstanceConverterTest method should_convert_service_with_uri_and_metadata.

@Test
public void should_convert_service_with_uri_and_metadata() {
    Map<String, String> metadata = new HashMap<>();
    metadata.put("health.path", "ping");
    metadata.put("management.context-path", "mgmt");
    ServiceInstance service = new TestServiceInstance("test", URI.create("http://localhost/test"), metadata);
    Registration registration = new DefaultServiceInstanceConverter().convert(service);
    assertThat(registration.getName()).isEqualTo("test");
    assertThat(registration.getServiceUrl()).isEqualTo("http://localhost/test");
    assertThat(registration.getManagementUrl()).isEqualTo("http://localhost/test/mgmt");
    assertThat(registration.getHealthUrl()).isEqualTo("http://localhost/test/mgmt/ping");
    assertThat(registration.getMetadata()).isEqualTo(metadata);
}
Also used : HashMap(java.util.HashMap) Registration(de.codecentric.boot.admin.server.domain.values.Registration) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) 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