Search in sources :

Example 36 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_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");
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) 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 37 with Registration

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");
}
Also used : EurekaServiceInstance(org.springframework.cloud.netflix.eureka.EurekaServiceInstance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.jupiter.api.Test)

Example 38 with Registration

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;
}
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 39 with Registration

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);
}
Also used : Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Flux(reactor.core.publisher.Flux) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Mono(reactor.core.publisher.Mono) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) Assert(org.springframework.util.Assert) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instance(de.codecentric.boot.admin.server.domain.entities.Instance)

Example 40 with Registration

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));
    });
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping)

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