aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModel.java
blob: 668596c3f1808f4ec02cb03ae9e9f73afb5c27eb (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
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container;

import com.yahoo.config.model.ConfigModel;
import com.yahoo.config.model.ConfigModelContext;
import com.yahoo.config.model.ConfigModelRepo;
import com.yahoo.vespa.model.content.Content;
import com.yahoo.vespa.model.search.AbstractSearchCluster;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;


/**
 * A model of a container cluster.
 *
 * @author tonytv
 */
public class ContainerModel extends ConfigModel {

    // TODO: Move to referer
    public static final String DOCPROC_RESERVED_NAME = "docproc";

    private ContainerCluster containerCluster;

    public ContainerModel(ConfigModelContext context) {
        super(context);
    }

    public void setCluster(ContainerCluster containerCluster) { this.containerCluster = containerCluster; }

    public ContainerCluster getCluster() { return containerCluster; }

    @Override
    public void prepare(ConfigModelRepo plugins) {
        assert (getCluster() != null) : "Null container cluster!";
        getCluster().prepare();
    }

    @Override
    @Deprecated
    public void initialize(ConfigModelRepo configModelRepo) {
        List<AbstractSearchCluster> searchClusters = Content.getSearchClusters(configModelRepo);

        Map<String, AbstractSearchCluster> searchClustersByName = new TreeMap<>();
        for (AbstractSearchCluster c : searchClusters) {
            searchClustersByName.put(c.getClusterName(), c);
        }

        getCluster().initialize(searchClustersByName);
    }

    public static Collection<ContainerCluster> containerClusters(ConfigModelRepo models) {
        List<ContainerCluster> containerClusters = new ArrayList<>();

        for (ContainerModel model: models.getModels(ContainerModel.class))
            containerClusters.add(model.getCluster());

        return containerClusters;
    }

}