Search in sources :

Example 1 with SetResult

use of org.apache.druid.common.config.ConfigManager.SetResult in project druid by druid-io.

the class CoordinatorCompactionConfigsResource method updateConfigHelper.

@VisibleForTesting
Response updateConfigHelper(Callable<SetResult> updateMethod) {
    int attemps = 0;
    SetResult setResult = null;
    try {
        while (attemps < UPDATE_NUM_RETRY) {
            setResult = updateMethod.call();
            if (setResult.isOk() || !setResult.isRetryable()) {
                break;
            }
            attemps++;
            updateRetryDelay();
        }
    } catch (Exception e) {
        LOG.warn(e, "Update compaction config failed");
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ImmutableMap.of("error", createErrorMessage(e))).build();
    }
    if (setResult.isOk()) {
        return Response.ok().build();
    } else if (setResult.getException() instanceof NoSuchElementException) {
        LOG.warn(setResult.getException(), "Update compaction config failed");
        return Response.status(Response.Status.NOT_FOUND).build();
    } else {
        LOG.warn(setResult.getException(), "Update compaction config failed");
        return Response.status(Response.Status.BAD_REQUEST).entity(ImmutableMap.of("error", createErrorMessage(setResult.getException()))).build();
    }
}
Also used : SetResult(org.apache.druid.common.config.ConfigManager.SetResult) NoSuchElementException(java.util.NoSuchElementException) NoSuchElementException(java.util.NoSuchElementException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with SetResult

use of org.apache.druid.common.config.ConfigManager.SetResult in project druid by druid-io.

the class CoordinatorDynamicConfigsResource method setDynamicConfigs.

// default value is used for backwards compatibility
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response setDynamicConfigs(final CoordinatorDynamicConfig.Builder dynamicConfigBuilder, @HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author, @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment, @Context HttpServletRequest req) {
    try {
        CoordinatorDynamicConfig current = CoordinatorDynamicConfig.current(manager);
        final SetResult setResult = manager.set(CoordinatorDynamicConfig.CONFIG_KEY, dynamicConfigBuilder.build(current), new AuditInfo(author, comment, req.getRemoteAddr()));
        if (setResult.isOk()) {
            return Response.ok().build();
        } else {
            return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(setResult.getException())).build();
        }
    } catch (IllegalArgumentException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity(ServletResourceUtils.sanitizeException(e)).build();
    }
}
Also used : AuditInfo(org.apache.druid.audit.AuditInfo) CoordinatorDynamicConfig(org.apache.druid.server.coordinator.CoordinatorDynamicConfig) SetResult(org.apache.druid.common.config.ConfigManager.SetResult) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

SetResult (org.apache.druid.common.config.ConfigManager.SetResult)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 NoSuchElementException (java.util.NoSuchElementException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 AuditInfo (org.apache.druid.audit.AuditInfo)1 CoordinatorDynamicConfig (org.apache.druid.server.coordinator.CoordinatorDynamicConfig)1