aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/search/DocumentDatabaseChangeValidator.java
blob: f9b884756afee0eb36f4b61116290cf7f305ab27 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation.change.search;

import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.documentmodel.NewDocumentType;
import com.yahoo.vespa.model.application.validation.change.VespaConfigChangeAction;
import com.yahoo.vespa.model.search.DocumentDatabase;

import java.util.ArrayList;
import java.util.List;

/**
 * Validates the changes between a current and next document database that is part of an indexed search cluster.
 *
 * @author geirst
 */
public class DocumentDatabaseChangeValidator {

    private final ClusterSpec.Id id;
    private final DocumentDatabase currentDatabase;
    private final NewDocumentType currentDocType;
    private final DocumentDatabase nextDatabase;
    private final NewDocumentType nextDocType;
    private final DeployState deployState;

    public DocumentDatabaseChangeValidator(ClusterSpec.Id id,
                                           DocumentDatabase currentDatabase,
                                           NewDocumentType currentDocType,
                                           DocumentDatabase nextDatabase,
                                           NewDocumentType nextDocType,
                                           DeployState deployState) {
        this.id = id;
        this.currentDatabase = currentDatabase;
        this.currentDocType = currentDocType;
        this.nextDatabase = nextDatabase;
        this.nextDocType = nextDocType;
        this.deployState = deployState;
    }

    public List<VespaConfigChangeAction> validate() {
        List<VespaConfigChangeAction> result = new ArrayList<>();
        result.addAll(validateAttributeChanges());
        result.addAll(validateStructFieldAttributeChanges());
        result.addAll(validateIndexingScriptChanges());
        result.addAll(validateDocumentTypeChanges());
        return result;
    }

    private List<VespaConfigChangeAction> validateAttributeChanges() {
        return new AttributeChangeValidator(id,
                                            currentDatabase.getDerivedConfiguration().getAttributeFields(),
                                            currentDatabase.getDerivedConfiguration().getIndexSchema(), currentDocType,
                                            nextDatabase.getDerivedConfiguration().getAttributeFields(),
                                            nextDatabase.getDerivedConfiguration().getIndexSchema(), nextDocType,
                                            deployState)
                       .validate();
    }

    private List<VespaConfigChangeAction> validateStructFieldAttributeChanges() {
        return new StructFieldAttributeChangeValidator(id,
                                                       currentDocType,
                                                       currentDatabase.getDerivedConfiguration().getAttributeFields(),
                                                       nextDocType,
                                                       nextDatabase.getDerivedConfiguration().getAttributeFields())
                       .validate();
    }

    private List<VespaConfigChangeAction> validateIndexingScriptChanges() {
        return new IndexingScriptChangeValidator(id,
                                                 currentDatabase.getDerivedConfiguration().getSchema(),
                                                 nextDatabase.getDerivedConfiguration().getSchema())
                       .validate();
    }

    private List<VespaConfigChangeAction> validateDocumentTypeChanges() {
        return new DocumentTypeChangeValidator(id, currentDocType, nextDocType)
                       .validate();
    }

}