aboutsummaryrefslogtreecommitdiffstats
path: root/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/ApplicationParams.java
blob: f148e9107e485bd7b7bb87e843dab85e6e9ba2fd (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.policy;

import com.yahoo.vespa.applicationmodel.ClusterId;
import com.yahoo.vespa.applicationmodel.ServiceCluster;
import com.yahoo.vespa.applicationmodel.ServiceClusterKey;
import com.yahoo.vespa.applicationmodel.ServiceType;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * Per-application parameters controlling the orchestration.
 *
 * @author hakonhall
 */
public class ApplicationParams {

    private static final ApplicationParams DEFAULT = new ApplicationParams.Builder().build();

    private final Map<ServiceClusterKey, ClusterParams> clusterParams;

    public static class Builder {
        private final Map<ServiceClusterKey, ClusterParams> clusterParams = new HashMap<>();

        public Builder() {}

        public Builder add(ClusterId clusterId, ServiceType serviceType, ClusterParams clusterParams) {
            this.clusterParams.put(new ServiceClusterKey(clusterId, serviceType), clusterParams);
            return this;
        }

        public ApplicationParams build() {
            return new ApplicationParams(clusterParams);
        }
    }

    public static ApplicationParams getDefault() {
        return DEFAULT;
    }

    private ApplicationParams(Map<ServiceClusterKey, ClusterParams> clusterParams) {
        this.clusterParams = Map.copyOf(clusterParams);
    }

    public ClusterParams clusterParamsFor(ServiceCluster serviceCluster) {
        return clusterParamsFor(serviceCluster.clusterId(), serviceCluster.serviceType());
    }

    public ClusterParams clusterParamsFor(ClusterId clusterId, ServiceType serviceType) {
        var key = new ServiceClusterKey(clusterId, serviceType);
        return clusterParams.getOrDefault(key, ClusterParams.getDefault());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ApplicationParams that = (ApplicationParams) o;
        return clusterParams.equals(that.clusterParams);
    }

    @Override
    public int hashCode() {
        return Objects.hash(clusterParams);
    }
}