aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/search/StreamingSearchCluster.java
blob: e188a0866142d530686803ce2e3d81e157bb298d (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.search;

import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.producer.AnyConfigProducer;
import com.yahoo.config.model.producer.TreeConfigProducer;
import com.yahoo.schema.Schema;
import com.yahoo.schema.derived.AttributeFields;
import com.yahoo.schema.derived.DerivedConfiguration;
import com.yahoo.schema.derived.SchemaInfo;
import com.yahoo.vespa.config.search.AttributesConfig;
import com.yahoo.vespa.config.search.RankProfilesConfig;
import com.yahoo.vespa.config.search.SummaryConfig;
import com.yahoo.vespa.config.search.core.OnnxModelsConfig;
import com.yahoo.vespa.config.search.core.ProtonConfig;
import com.yahoo.vespa.config.search.core.RankingConstantsConfig;
import com.yahoo.vespa.config.search.core.RankingExpressionsConfig;
import com.yahoo.vespa.config.search.summary.JuniperrcConfig;
import com.yahoo.vespa.config.search.vsm.VsmfieldsConfig;
import com.yahoo.vespa.config.search.vsm.VsmsummaryConfig;

/**
 * A search cluster of type streaming.
 * 
 * @author baldersheim
 * @author vegardh
 */
public class StreamingSearchCluster extends SearchCluster implements
        AttributesConfig.Producer,
        RankProfilesConfig.Producer,
        RankingConstantsConfig.Producer,
        RankingExpressionsConfig.Producer,
        OnnxModelsConfig.Producer,
        JuniperrcConfig.Producer,
        SummaryConfig.Producer,
        VsmsummaryConfig.Producer,
        VsmfieldsConfig.Producer
{
    private final String storageRouteSpec;
    private final AttributesProducer attributesConfig;
    private final String docTypeName;

    public StreamingSearchCluster(TreeConfigProducer<AnyConfigProducer> parent, String clusterName, int index,
                                  String docTypeName, String storageRouteSpec) {
        super(parent, clusterName, index);
        attributesConfig = new AttributesProducer(parent, docTypeName);
        this.docTypeName = docTypeName;
        this.storageRouteSpec = storageRouteSpec;
    }

    @Override
    protected IndexingMode getIndexingMode() { return IndexingMode.STREAMING; }
    public final String getStorageRouteSpec() { return storageRouteSpec; }

    public String getDocTypeName() { return docTypeName; }

    public DerivedConfiguration derived() { return db().getDerivedConfiguration(); }

    @Override
    public void deriveFromSchemas(DeployState deployState) {
        if (schemas().isEmpty()) return;
        if (schemas().size() > 1) throw new IllegalArgumentException("Only a single schema is supported, got " + schemas().size());

        Schema schema = schemas().values().stream().findAny().get().fullSchema();
        if ( ! schema.getName().equals(docTypeName))
            throw new IllegalArgumentException("Document type name '" + docTypeName +
                                               "' must be the same as the schema name '" + schema.getName() + "'");
        add(new DocumentDatabase(this, docTypeName, new DerivedConfiguration(deployState, schema, SchemaInfo.IndexMode.STREAMING)));
    }

    protected void fillDocumentDBConfig(DocumentDatabase sdoc, ProtonConfig.Documentdb.Builder ddbB) {
        super.fillDocumentDBConfig(sdoc, ddbB);
        ddbB.configid(attributesConfig.getConfigId()); // Temporary until fully cleaned up
    }

    private DocumentDatabase db() { return getDocumentDbs().get(0); }

    // These are temporary until backend uses correct config id.
    @Override public void getConfig(SummaryConfig.Builder builder) { db().getConfig(builder); }
    @Override public void getConfig(OnnxModelsConfig.Builder builder) { db().getConfig(builder); }
    @Override public void getConfig(RankingConstantsConfig.Builder builder) { db().getConfig(builder); }
    @Override public void getConfig(RankProfilesConfig.Builder builder) { db().getConfig(builder); }
    @Override public void getConfig(RankingExpressionsConfig.Builder builder) { db().getConfig(builder); }
    @Override public void getConfig(JuniperrcConfig.Builder builder) { db().getConfig(builder); }
    @Override public void getConfig(VsmfieldsConfig.Builder builder) { db().getConfig(builder); }
    @Override public void getConfig(VsmsummaryConfig.Builder builder) { db().getConfig(builder);}

    private class AttributesProducer extends AnyConfigProducer implements AttributesConfig.Producer {

        AttributesProducer(TreeConfigProducer<AnyConfigProducer> parent, String docType) {
            super(parent, docType);
        }

        @Override
        public void getConfig(AttributesConfig.Builder builder) {
            derived().getConfig(builder, AttributeFields.FieldSet.FAST_ACCESS);
        }
    }

}