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
|
// 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.change;
import com.yahoo.config.model.api.ConfigChangeAction;
import com.yahoo.config.provision.Capacity;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.vespa.model.VespaModel;
import com.yahoo.config.application.api.ValidationId;
import com.yahoo.config.application.api.ValidationOverrides;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.content.cluster.ContentCluster;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
/**
* Checks that no cluster sizes are reduced too much in one go.
*
* @author bratseth
*/
public class ClusterSizeReductionValidator implements ChangeValidator {
@Override
public List<ConfigChangeAction> validate(VespaModel current, VespaModel next, ValidationOverrides overrides, Instant now) {
for (var clusterId : current.allClusters()) {
Capacity currentCapacity = current.provisioned().all().get(clusterId);
Capacity nextCapacity = next.provisioned().all().get(clusterId);
if (currentCapacity == null || nextCapacity == null) continue;
validate(currentCapacity,
nextCapacity,
clusterId,
overrides,
now);
}
return Collections.emptyList();
}
private void validate(Capacity current,
Capacity next,
ClusterSpec.Id clusterId,
ValidationOverrides overrides,
Instant now) {
int currentSize = current.minResources().nodes();
int nextSize = next.minResources().nodes();
// don't allow more than 50% reduction, but always allow to reduce size with 1
if ( nextSize < ((double)currentSize) * 0.5 && nextSize != currentSize - 1)
overrides.invalid(ValidationId.clusterSizeReduction,
"Size reduction in '" + clusterId.value() + "' is too large: " +
"New min size must be at least 50% of the current min size. " +
"Current size: " + currentSize + ", new size: " + nextSize,
now);
}
}
|