use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.
the class DefaultServiceInstanceConverterTest method should_convert_with_custom_defaults.
@Test
public void should_convert_with_custom_defaults() {
DefaultServiceInstanceConverter converter = new DefaultServiceInstanceConverter();
converter.setHealthEndpointPath("ping");
converter.setManagementContextPath("mgmt");
ServiceInstance service = new DefaultServiceInstance("test-1", "test", "localhost", 80, false);
Registration registration = converter.convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/mgmt");
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/mgmt/ping");
}
use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.
the class EurekaServiceInstanceConverterTest method convert_secure.
@Test
public void convert_secure() {
InstanceInfo instanceInfo = mock(InstanceInfo.class);
when(instanceInfo.getSecureHealthCheckUrl()).thenReturn("");
when(instanceInfo.getHealthCheckUrl()).thenReturn("http://localhost:80/mgmt/ping");
EurekaServiceInstance service = mock(EurekaServiceInstance.class);
when(service.getInstanceInfo()).thenReturn(instanceInfo);
when(service.getUri()).thenReturn(URI.create("http://localhost:80"));
when(service.getServiceId()).thenReturn("test");
when(service.getMetadata()).thenReturn(singletonMap("management.context-path", "/mgmt"));
Registration registration = new EurekaServiceInstanceConverter().convert(service);
assertThat(registration.getName()).isEqualTo("test");
assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80");
assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/mgmt");
assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/mgmt/ping");
}
use of de.codecentric.boot.admin.server.domain.values.Registration 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;
}
use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.
the class InstanceRegistry method register.
/**
* Register instance.
* @param registration instance to be registered.
* @return the id of the registered instance.
*/
public Mono<InstanceId> register(Registration registration) {
Assert.notNull(registration, "'registration' must not be null");
InstanceId id = generator.generateId(registration);
Assert.notNull(id, "'id' must not be null");
return repository.compute(id, (key, instance) -> {
if (instance == null) {
instance = Instance.create(key);
}
return Mono.just(instance.register(registration));
}).map(Instance::getId);
}
use of de.codecentric.boot.admin.server.domain.values.Registration in project spring-boot-admin by codecentric.
the class InstancesController method register.
/**
* Register an instance.
* @param registration registration info
* @param builder the UriComponentsBuilder
* @return the registered instance id;
*/
@PostMapping(path = "/instances", consumes = MediaType.APPLICATION_JSON_VALUE)
public Mono<ResponseEntity<Map<String, InstanceId>>> register(@RequestBody Registration registration, UriComponentsBuilder builder) {
Registration withSource = Registration.copyOf(registration).source("http-api").build();
LOGGER.debug("Register instance {}", withSource);
return registry.register(withSource).map((id) -> {
URI location = builder.replacePath("/instances/{id}").buildAndExpand(id).toUri();
return ResponseEntity.created(location).body(Collections.singletonMap("id", id));
});
}
Aggregations