aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/prelude/IndexFactsFactory.java
blob: fe2a264e03a9808bc0b2286fae4e9b605b5bd6a4 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude;

import com.yahoo.config.subscription.ConfigGetter;
import com.yahoo.config.ConfigInstance;
import com.yahoo.search.config.IndexInfoConfig;
import com.yahoo.container.QrSearchersConfig;

/**
 * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
 */
public abstract class IndexFactsFactory {

    public static IndexFacts newInstance(String configId) {
        return new IndexFacts(new IndexModel(resolveConfig(IndexInfoConfig.class, configId),
                                             resolveConfig(QrSearchersConfig.class, configId)));

    }

    public static IndexFacts newInstance(String indexInfoConfigId, String qrSearchersConfigId) {
        return new IndexFacts(new IndexModel(resolveConfig(IndexInfoConfig.class, indexInfoConfigId),
                                             resolveConfig(QrSearchersConfig.class, qrSearchersConfigId)));

    }

    private static <T extends ConfigInstance> T resolveConfig(Class<T> configClass, String configId) {
        if (configId == null) return null;
        return ConfigGetter.getConfig(configClass, configId);
    }

}