Search in sources :

Example 1 with ConfigurationPresentation

use of org.apache.ignite.internal.configuration.rest.presentation.ConfigurationPresentation in project ignite-3 by apache.

the class ConfigurationHttpHandlers method handleUpdate.

/**
 * Handle a configuration update request as json.
 *
 * @param req          Rest request.
 * @param res          Rest response.
 * @param presentation Configuration presentation.
 */
private static CompletableFuture<RestApiHttpResponse> handleUpdate(RestApiHttpRequest req, RestApiHttpResponse res, ConfigurationPresentation<String> presentation) {
    String updateReq = req.request().content().toString(StandardCharsets.UTF_8);
    return presentation.update(updateReq).thenApply(v -> res).exceptionally(e -> {
        if (e instanceof CompletionException) {
            e = e.getCause();
        }
        ErrorResult errRes;
        if (e instanceof IllegalArgumentException) {
            errRes = new ErrorResult("INVALID_CONFIG_FORMAT", e.getMessage());
        } else if (e instanceof ConfigurationValidationException) {
            errRes = new ErrorResult("VALIDATION_EXCEPTION", e.getMessage());
        } else if (e instanceof IgniteException) {
            errRes = new ErrorResult("APPLICATION_EXCEPTION", e.getMessage());
        } else {
            throw new CompletionException(e);
        }
        res.status(BAD_REQUEST);
        res.json(Map.of("error", errRes));
        return res;
    });
}
Also used : IgniteException(org.apache.ignite.lang.IgniteException) RestHandlersRegister(org.apache.ignite.internal.rest.api.RestHandlersRegister) HoconPresentation(org.apache.ignite.internal.configuration.rest.presentation.hocon.HoconPresentation) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) StandardCharsets(java.nio.charset.StandardCharsets) RestApiHttpRequest(org.apache.ignite.internal.rest.api.RestApiHttpRequest) RestApiHttpResponse(org.apache.ignite.internal.rest.api.RestApiHttpResponse) BAD_REQUEST(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST) ConfigurationPresentation(org.apache.ignite.internal.configuration.rest.presentation.ConfigurationPresentation) ErrorResult(org.apache.ignite.internal.rest.api.ErrorResult) APPLICATION_JSON(io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON) Routes(org.apache.ignite.internal.rest.api.Routes) Map(java.util.Map) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) ConfigurationValidationException(org.apache.ignite.configuration.validation.ConfigurationValidationException) IgniteException(org.apache.ignite.lang.IgniteException) CompletionException(java.util.concurrent.CompletionException) ErrorResult(org.apache.ignite.internal.rest.api.ErrorResult)

Aggregations

APPLICATION_JSON (io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_JSON)1 BAD_REQUEST (io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 ConfigurationValidationException (org.apache.ignite.configuration.validation.ConfigurationValidationException)1 ConfigurationManager (org.apache.ignite.internal.configuration.ConfigurationManager)1 ConfigurationPresentation (org.apache.ignite.internal.configuration.rest.presentation.ConfigurationPresentation)1 HoconPresentation (org.apache.ignite.internal.configuration.rest.presentation.hocon.HoconPresentation)1 ErrorResult (org.apache.ignite.internal.rest.api.ErrorResult)1 RestApiHttpRequest (org.apache.ignite.internal.rest.api.RestApiHttpRequest)1 RestApiHttpResponse (org.apache.ignite.internal.rest.api.RestApiHttpResponse)1 RestHandlersRegister (org.apache.ignite.internal.rest.api.RestHandlersRegister)1 Routes (org.apache.ignite.internal.rest.api.Routes)1 IgniteException (org.apache.ignite.lang.IgniteException)1