Search in sources :

Example 1 with Api

use of io.gravitee.definition.model.Api in project gravitee-gateway by gravitee-io.

the class EndpointHealthcheckResolver method resolve.

/**
 * Returns a {@link Stream} of {@link Endpoint} which have to be health-checked.
 *
 * @param api
 * @return
 */
public List<EndpointRule> resolve(Api api) {
    HealthCheckService rootHealthCheck = api.getServices().get(HealthCheckService.class);
    Stream<Endpoint> endpoints = api.getProxy().getEndpoints().stream();
    // Only HTTP endpoint
    Stream<HttpEndpoint> httpEndpoints = endpoints.filter(endpoint -> endpoint.getType() == EndpointType.HTTP).map(endpoint -> (HttpEndpoint) endpoint);
    // Filtering endpoints according to tenancy configuration
    if (gatewayConfiguration.tenant().isPresent()) {
        String tenant = gatewayConfiguration.tenant().get();
        httpEndpoints = httpEndpoints.filter(endpoint -> endpoint.getTenants() != null && endpoint.getTenants().contains(tenant));
    }
    // Remove backup endpoints
    httpEndpoints = httpEndpoints.filter(endpoint -> !endpoint.isBackup());
    // Keep only endpoints where health-check is enabled or not settled (inherit from service)
    httpEndpoints = httpEndpoints.filter(endpoint -> (endpoint.getHealthCheck() == null) || (endpoint.getHealthCheck() != null && endpoint.getHealthCheck().isEnabled()));
    return httpEndpoints.map((Function<HttpEndpoint, EndpointRule>) endpoint -> new DefaultEndpointRule(api.getId(), endpoint, (endpoint.getHealthCheck() == null || endpoint.getHealthCheck().isInherit()) ? rootHealthCheck : endpoint.getHealthCheck())).collect(Collectors.toList());
}
Also used : Endpoint(io.gravitee.definition.model.Endpoint) List(java.util.List) Stream(java.util.stream.Stream) EndpointType(io.gravitee.definition.model.EndpointType) DefaultEndpointRule(io.gravitee.gateway.services.healthcheck.rule.DefaultEndpointRule) HealthCheckService(io.gravitee.definition.model.services.healthcheck.HealthCheckService) Autowired(org.springframework.beans.factory.annotation.Autowired) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Api(io.gravitee.definition.model.Api) GatewayConfiguration(io.gravitee.gateway.env.GatewayConfiguration) Function(java.util.function.Function) DefaultEndpointRule(io.gravitee.gateway.services.healthcheck.rule.DefaultEndpointRule) HealthCheckService(io.gravitee.definition.model.services.healthcheck.HealthCheckService) Endpoint(io.gravitee.definition.model.Endpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint) HttpEndpoint(io.gravitee.definition.model.endpoint.HttpEndpoint)

Aggregations

Api (io.gravitee.definition.model.Api)1 Endpoint (io.gravitee.definition.model.Endpoint)1 EndpointType (io.gravitee.definition.model.EndpointType)1 HttpEndpoint (io.gravitee.definition.model.endpoint.HttpEndpoint)1 HealthCheckService (io.gravitee.definition.model.services.healthcheck.HealthCheckService)1 GatewayConfiguration (io.gravitee.gateway.env.GatewayConfiguration)1 DefaultEndpointRule (io.gravitee.gateway.services.healthcheck.rule.DefaultEndpointRule)1 List (java.util.List)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1