Search in sources :

Example 1 with EndpointId

use of org.springframework.boot.actuate.endpoint.EndpointId in project spring-boot by spring-projects.

the class EndpointDiscoverer method convertToEndpoint.

private E convertToEndpoint(EndpointBean endpointBean) {
    MultiValueMap<OperationKey, O> indexed = new LinkedMultiValueMap<>();
    EndpointId id = endpointBean.getId();
    addOperations(indexed, id, endpointBean.getBean(), false);
    if (endpointBean.getExtensions().size() > 1) {
        String extensionBeans = endpointBean.getExtensions().stream().map(ExtensionBean::getBeanName).collect(Collectors.joining(", "));
        throw new IllegalStateException("Found multiple extensions for the endpoint bean " + endpointBean.getBeanName() + " (" + extensionBeans + ")");
    }
    for (ExtensionBean extensionBean : endpointBean.getExtensions()) {
        addOperations(indexed, id, extensionBean.getBean(), true);
    }
    assertNoDuplicateOperations(endpointBean, indexed);
    List<O> operations = indexed.values().stream().map(this::getLast).filter(Objects::nonNull).collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
    return createEndpoint(endpointBean.getBean(), id, endpointBean.isEnabledByDefault(), operations);
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId)

Example 2 with EndpointId

use of org.springframework.boot.actuate.endpoint.EndpointId in project spring-boot by spring-projects.

the class JmxEndpointDiscovererTests method getEndpointsWhenHasJmxExtensionWithNewOperationAddsExtraOperation.

@Test
void getEndpointsWhenHasJmxExtensionWithNewOperationAddsExtraOperation() {
    load(AdditionalOperationJmxEndpointConfiguration.class, (discoverer) -> {
        Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        Map<String, JmxOperation> operationByName = mapOperations(endpoints.get(EndpointId.of("test")).getOperations());
        assertThat(operationByName).containsOnlyKeys("getAll", "getSomething", "update", "deleteSomething", "getAnother");
        JmxOperation getAnother = operationByName.get("getAnother");
        assertThat(getAnother.getDescription()).isEqualTo("Get another thing");
        assertThat(getAnother.getOutputType()).isEqualTo(Object.class);
        assertThat(getAnother.getParameters()).isEmpty();
    });
}
Also used : JmxOperation(org.springframework.boot.actuate.endpoint.jmx.JmxOperation) ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) Test(org.junit.jupiter.api.Test)

Example 3 with EndpointId

use of org.springframework.boot.actuate.endpoint.EndpointId in project spring-boot by spring-projects.

the class JmxEndpointDiscovererTests method getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue.

@Test
void getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue() {
    load(TestEndpoint.class, (id) -> 500L, (discoverer) -> {
        Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        Map<String, JmxOperation> operationByName = mapOperations(endpoints.get(EndpointId.of("test")).getOperations());
        assertThat(operationByName).containsOnlyKeys("getAll", "getSomething", "update", "deleteSomething");
        JmxOperation getAll = operationByName.get("getAll");
        assertThat(getInvoker(getAll)).isInstanceOf(CachingOperationInvoker.class);
        assertThat(((CachingOperationInvoker) getInvoker(getAll)).getTimeToLive()).isEqualTo(500);
    });
}
Also used : JmxOperation(org.springframework.boot.actuate.endpoint.jmx.JmxOperation) ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) CachingOperationInvoker(org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker) Test(org.junit.jupiter.api.Test)

Example 4 with EndpointId

use of org.springframework.boot.actuate.endpoint.EndpointId in project spring-boot by spring-projects.

the class JmxEndpointDiscovererTests method getEndpointsShouldCacheReadOperations.

@Test
void getEndpointsShouldCacheReadOperations() {
    load(AdditionalOperationJmxEndpointConfiguration.class, (id) -> 500L, (discoverer) -> {
        Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
        Map<String, JmxOperation> operationByName = mapOperations(endpoints.get(EndpointId.of("test")).getOperations());
        assertThat(operationByName).containsOnlyKeys("getAll", "getSomething", "update", "deleteSomething", "getAnother");
        JmxOperation getAll = operationByName.get("getAll");
        assertThat(getInvoker(getAll)).isInstanceOf(CachingOperationInvoker.class);
        assertThat(((CachingOperationInvoker) getInvoker(getAll)).getTimeToLive()).isEqualTo(500);
        JmxOperation getAnother = operationByName.get("getAnother");
        assertThat(getInvoker(getAnother)).isInstanceOf(CachingOperationInvoker.class);
        assertThat(((CachingOperationInvoker) getInvoker(getAnother)).getTimeToLive()).isEqualTo(500);
    });
}
Also used : JmxOperation(org.springframework.boot.actuate.endpoint.jmx.JmxOperation) ExposableJmxEndpoint(org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) CachingOperationInvoker(org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker) Test(org.junit.jupiter.api.Test)

Example 5 with EndpointId

use of org.springframework.boot.actuate.endpoint.EndpointId in project spring-boot by spring-projects.

the class WebEndpointDiscovererTests method getEndpointsWhenHasCustomMediaTypeShouldProduceCustomMediaType.

@Test
void getEndpointsWhenHasCustomMediaTypeShouldProduceCustomMediaType() {
    load(CustomMediaTypesEndpointConfiguration.class, (discoverer) -> {
        Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
        assertThat(endpoints).containsOnlyKeys(EndpointId.of("custommediatypes"));
        ExposableWebEndpoint endpoint = endpoints.get(EndpointId.of("custommediatypes"));
        assertThat(requestPredicates(endpoint)).has(requestPredicates(path("custommediatypes").httpMethod(WebEndpointHttpMethod.GET).consumes().produces("text/plain"), path("custommediatypes").httpMethod(WebEndpointHttpMethod.POST).consumes().produces("a/b", "c/d"), path("custommediatypes").httpMethod(WebEndpointHttpMethod.DELETE).consumes().produces("text/plain")));
    });
}
Also used : ExposableWebEndpoint(org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint) EndpointId(org.springframework.boot.actuate.endpoint.EndpointId) Test(org.junit.jupiter.api.Test)

Aggregations

EndpointId (org.springframework.boot.actuate.endpoint.EndpointId)13 Test (org.junit.jupiter.api.Test)11 ExposableWebEndpoint (org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint)7 ExposableJmxEndpoint (org.springframework.boot.actuate.endpoint.jmx.ExposableJmxEndpoint)4 JmxOperation (org.springframework.boot.actuate.endpoint.jmx.JmxOperation)4 CachingOperationInvoker (org.springframework.boot.actuate.endpoint.invoker.cache.CachingOperationInvoker)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 EndpointExposure (org.springframework.boot.actuate.autoconfigure.endpoint.expose.EndpointExposure)1 WebOperation (org.springframework.boot.actuate.endpoint.web.WebOperation)1 WebOperationRequestPredicate (org.springframework.boot.actuate.endpoint.web.WebOperationRequestPredicate)1 ConditionMessage (org.springframework.boot.autoconfigure.condition.ConditionMessage)1 ConditionOutcome (org.springframework.boot.autoconfigure.condition.ConditionOutcome)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1