summaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminConfig.java
blob: 9caf1307aa4e96441a885888d70c4bb24f7d08f9 (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
// Copyright 2017 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.nodeadmin;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

@JsonIgnoreProperties(ignoreUnknown = true)
public class NodeAdminConfig {
    private static final Logger logger = Logger.getLogger(NodeAdminConfig.class.getName());
    private static final ObjectMapper mapper = new ObjectMapper();

    enum Mode {
        tenant,
        config_server_host
    }

    @JsonProperty("mode")
    public Mode mode = Mode.tenant;

    public static NodeAdminConfig fromFile(File file) {
        if (!file.exists()) {
            return new NodeAdminConfig();
        }

        try {
            return mapper.readValue(file, NodeAdminConfig.class);
        } catch (IOException e) {
            throw new RuntimeException("Failed to read " + file + " as a " +
                    NodeAdminConfig.class.getName(), e);
        }
    }
}