blob: 18683ce2411192e1cfc864deb36d5195a62b1615 (
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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.application.validation.change;
import com.yahoo.config.model.api.ConfigChangeAction;
import com.yahoo.vespa.model.VespaModel;
import com.yahoo.vespa.model.application.validation.ValidationOverrides;
import com.yahoo.vespa.model.application.validation.change.ChangeValidator;
import com.yahoo.vespa.model.application.validation.change.VespaRefeedAction;
import com.yahoo.vespa.model.content.cluster.ContentCluster;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* Returns any change to the indexing mode of a cluster.
*
* @author musum
*/
public class IndexingModeChangeValidator implements ChangeValidator {
@Override
public List<ConfigChangeAction> validate(VespaModel currentModel, VespaModel nextModel, ValidationOverrides overrides) {
List<ConfigChangeAction> actions = new ArrayList<>();
for (Map.Entry<String, ContentCluster> currentEntry : currentModel.getContentClusters().entrySet()) {
ContentCluster nextCluster = nextModel.getContentClusters().get(currentEntry.getKey());
if (nextCluster == null) continue;
Optional<ConfigChangeAction> change = validateContentCluster(currentEntry.getValue(), nextCluster, overrides);
if (change.isPresent())
actions.add(change.get());
}
return actions;
}
private Optional<ConfigChangeAction> validateContentCluster(ContentCluster currentCluster, ContentCluster nextCluster,
ValidationOverrides overrides) {
final boolean currentClusterIsIndexed = currentCluster.getSearch().hasIndexedCluster();
final boolean nextClusterIsIndexed = nextCluster.getSearch().hasIndexedCluster();
if (currentClusterIsIndexed == nextClusterIsIndexed) return Optional.empty();
return Optional.of(VespaRefeedAction.of("indexing-mode-change",
overrides,
"Cluster '" + currentCluster.getName() + "' changed indexing mode from '" +
indexingMode(currentClusterIsIndexed) + "' to '" + indexingMode(nextClusterIsIndexed) + "'"));
}
private String indexingMode(boolean isIndexed) {
return isIndexed ? "indexed" : "streaming";
}
}
|