Search in sources :

Example 1 with AssertionEvaluation

use of io.gravitee.gateway.services.healthcheck.eval.assertion.AssertionEvaluation in project gravitee-gateway by gravitee-io.

the class HttpEndpointRuleHandler method validateAssertions.

private EndpointStatus.StepBuilder validateAssertions(final io.gravitee.definition.model.services.healthcheck.Step step, final EvaluableHttpResponse response) {
    EndpointStatus.StepBuilder stepBuilder = EndpointStatus.forStep(step.getName());
    // Run assertions
    if (step.getResponse().getAssertions() != null) {
        Iterator<String> assertionIterator = step.getResponse().getAssertions().iterator();
        boolean success = true;
        while (success && assertionIterator.hasNext()) {
            try {
                // TODO: assertion must be compiled only one time to preserve CPU
                AssertionEvaluation evaluation = new AssertionEvaluation(assertionIterator.next());
                evaluation.setVariable("response", response);
                // Run validation
                success = evaluation.validate();
                if (success) {
                    stepBuilder.success();
                } else {
                    stepBuilder.fail("Assertion not validated: " + evaluation.getAssertion());
                }
            } catch (EvaluationException eex) {
                success = false;
                stepBuilder.fail(eex.getMessage());
            }
        }
    }
    return stepBuilder;
}
Also used : EndpointStatus(io.gravitee.reporter.api.health.EndpointStatus) EvaluationException(io.gravitee.gateway.services.healthcheck.eval.EvaluationException) AssertionEvaluation(io.gravitee.gateway.services.healthcheck.eval.assertion.AssertionEvaluation)

Aggregations

EvaluationException (io.gravitee.gateway.services.healthcheck.eval.EvaluationException)1 AssertionEvaluation (io.gravitee.gateway.services.healthcheck.eval.assertion.AssertionEvaluation)1 EndpointStatus (io.gravitee.reporter.api.health.EndpointStatus)1