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