aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/ConfigServerApi.java
blob: 90768facf342331cbd673b095f00f4370a0d0a89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.configserver;

import java.time.Duration;
import java.util.Optional;

/**
 * Interface to execute basic HTTP/HTTPS request against config server(s)
 *
 * @author freva
 */
public interface ConfigServerApi extends AutoCloseable {
    class Params {
        private Optional<Duration> connectionTimeout;

        /** Set the socket connect and read timeouts. */
        public Params setConnectionTimeout(Duration connectionTimeout) {
            this.connectionTimeout = Optional.of(connectionTimeout);
            return this;
        }

        public Optional<Duration> getConnectionTimeout() { return connectionTimeout; }
    }

    <T> T get(String path, Class<T> wantedReturnType, Params params);
    default <T> T get(String path, Class<T> wantedReturnType) {
        return get(path, wantedReturnType, null);
    }

    <T> T post(String path, Object bodyJsonPojo, Class<T> wantedReturnType, Params params);
    default <T> T post(String path, Object bodyJsonPojo, Class<T> wantedReturnType) {
        return post(path, bodyJsonPojo, wantedReturnType, null);
    }

    <T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType, Params params);
    default <T> T put(String path, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType) {
        return put(path, bodyJsonPojo, wantedReturnType, null);
    }

    <T> T patch(String path, Object bodyJsonPojo, Class<T> wantedReturnType, Params params);
    default <T> T patch(String path, Object bodyJsonPojo, Class<T> wantedReturnType) {
        return patch(path, bodyJsonPojo, wantedReturnType, null);
    }

    <T> T delete(String path, Class<T> wantedReturnType, Params params);
    default <T> T delete(String path, Class<T> wantedReturnType) {
        return delete(path, wantedReturnType, null);
    }

    /** Close the underlying HTTP client and any threads this class might have started. */
    @Override
    void close();
}