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