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
|
// 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.application.validation;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.config.application.api.ValidationOverrides;
import com.yahoo.config.model.api.ConfigChangeAction;
import com.yahoo.config.model.api.Model;
import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.vespa.model.VespaModel;
import com.yahoo.vespa.model.application.validation.change.ChangeValidator;
import com.yahoo.vespa.model.application.validation.change.ClusterSizeReductionValidator;
import com.yahoo.vespa.model.application.validation.change.ConfigValueChangeValidator;
import com.yahoo.vespa.model.application.validation.change.ContainerRestartValidator;
import com.yahoo.vespa.model.application.validation.change.ContentClusterRemovalValidator;
import com.yahoo.vespa.model.application.validation.change.IndexedSearchClusterChangeValidator;
import com.yahoo.vespa.model.application.validation.change.IndexingModeChangeValidator;
import com.yahoo.vespa.model.application.validation.change.StartupCommandChangeValidator;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.toList;
/**
* Executor of validators. This defines the right order of validator execution.
*
* @author hmusum
*/
public class Validation {
/** Validate everything */
public static List<ConfigChangeAction> validate(VespaModel model, boolean force, DeployState deployState) {
return validate(model, true, force, deployState);
}
/**
* Validate with optional checking of routing, which cannot always be valid in unit tests
*
* @return a list of required changes needed to make this configuration live
*/
public static List<ConfigChangeAction> validate(VespaModel model, boolean checkRouting, boolean force, DeployState deployState) {
if (checkRouting) {
new RoutingValidator().validate(model, deployState);
new RoutingSelectorValidator().validate(model, deployState);
}
new ComponentValidator().validate(model, deployState);
new SearchDataTypeValidator().validate(model, deployState);
new StreamingValidator().validate(model, deployState);
new RankSetupValidator(force).validate(model, deployState);
new NoPrefixForIndexes().validate(model, deployState);
new DeploymentFileValidator().validate(model, deployState);
new RankingConstantsValidator().validate(model, deployState);
Optional<Model> currentActiveModel = deployState.getPreviousModel();
if (currentActiveModel.isPresent() && (currentActiveModel.get() instanceof VespaModel))
return validateChanges((VespaModel)currentActiveModel.get(), model,
deployState.validationOverrides(), deployState.getDeployLogger(), deployState.now());
else
return new ArrayList<>();
}
private static List<ConfigChangeAction> validateChanges(VespaModel currentModel, VespaModel nextModel,
ValidationOverrides overrides, DeployLogger logger,
Instant now) {
ChangeValidator[] validators = new ChangeValidator[] {
new IndexingModeChangeValidator(),
new IndexedSearchClusterChangeValidator(),
new ConfigValueChangeValidator(logger),
new StartupCommandChangeValidator(),
new ContentClusterRemovalValidator(),
new ClusterSizeReductionValidator(),
new ContainerRestartValidator(),
};
return Arrays.stream(validators)
.flatMap(v -> v.validate(currentModel, nextModel, overrides, now).stream())
.collect(toList());
}
}
|