aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/configserver/state/StateImpl.java
blob: ed42f0ed971bf527d23dd6a70526542041c63ea2 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.configserver.state;

import com.yahoo.vespa.hosted.node.admin.configserver.ConfigServerApi;
import com.yahoo.vespa.hosted.node.admin.configserver.ConnectionException;
import com.yahoo.vespa.hosted.node.admin.configserver.HttpException;
import com.yahoo.vespa.hosted.node.admin.configserver.state.bindings.HealthResponse;

/**
 * @author hakon
 */
public class StateImpl implements State {
    private final ConfigServerApi configServerApi;

    public StateImpl(ConfigServerApi configServerApi) {
        this.configServerApi = configServerApi;
    }

    @Override
    public HealthCode getHealth() {
        try {
            HealthResponse response = configServerApi.get("/state/v1/health", HealthResponse.class);
            return HealthCode.fromString(response.status.code);
        } catch (ConnectionException | HttpException e) {
            return HealthCode.DOWN;
        }
    }

}