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();
}
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();
}
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"));
}
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");
}
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();
}
Aggregations