diff options
Diffstat (limited to 'node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java index 90768facf34..87e2f6db761 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java @@ -10,41 +10,65 @@ import java.util.Optional; * @author freva */ public interface ConfigServerApi extends AutoCloseable { - class Params { - private Optional<Duration> connectionTimeout; + + /** + * The result of sending a request to a config server results in a jackson response or exception. If a response + * is returned, an instance of this interface is conferred to discard the result and try the next config server, + * unless it was the last attempt. + * + * @param <T> the type of the returned jackson response + */ + interface RetryPolicy<T> { + boolean tryNextConfigServer(T response); + } + + class Params<T> { + private Optional<Duration> connectionTimeout = Optional.empty(); + + private RetryPolicy<T> retryPolicy = response -> false; + + public Params() {} /** Set the socket connect and read timeouts. */ - public Params setConnectionTimeout(Duration connectionTimeout) { + public Params<T> setConnectionTimeout(Duration connectionTimeout) { this.connectionTimeout = Optional.of(connectionTimeout); return this; } public Optional<Duration> getConnectionTimeout() { return connectionTimeout; } + + /** Set the retry policy to use against the config servers. */ + public Params<T> setRetryPolicy(RetryPolicy<T> retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + public RetryPolicy<T> getRetryPolicy() { return retryPolicy; } } - <T> T get(String path, Class<T> wantedReturnType, Params params); + <T> T get(String path, Class<T> wantedReturnType, Params<T> params); default <T> T get(String path, Class<T> wantedReturnType) { - return get(path, wantedReturnType, null); + return get(path, wantedReturnType, new Params<>()); } - <T> T post(String path, Object bodyJsonPojo, Class<T> wantedReturnType, Params params); + <T> T post(String path, Object bodyJsonPojo, Class<T> wantedReturnType, Params<T> params); default <T> T post(String path, Object bodyJsonPojo, Class<T> wantedReturnType) { - return post(path, bodyJsonPojo, wantedReturnType, null); + return post(path, bodyJsonPojo, wantedReturnType, new Params<>()); } - <T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType, Params params); + <T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType, Params<T> params); default <T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType) { - return put(path, bodyJsonPojo, wantedReturnType, null); + return put(path, bodyJsonPojo, wantedReturnType, new Params<>()); } - <T> T patch(String path, Object bodyJsonPojo, Class<T> wantedReturnType, Params params); + <T> T patch(String path, Object bodyJsonPojo, Class<T> wantedReturnType, Params<T> params); default <T> T patch(String path, Object bodyJsonPojo, Class<T> wantedReturnType) { - return patch(path, bodyJsonPojo, wantedReturnType, null); + return patch(path, bodyJsonPojo, wantedReturnType, new Params<>()); } - <T> T delete(String path, Class<T> wantedReturnType, Params params); + <T> T delete(String path, Class<T> wantedReturnType, Params<T> params); default <T> T delete(String path, Class<T> wantedReturnType) { - return delete(path, wantedReturnType, null); + return delete(path, wantedReturnType, new Params<>()); } /** Close the underlying HTTP client and any threads this class might have started. */ |