aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/vespa/model/application/validation/change/VespaConfigChangeAction.java
blob: 8d06bc19edec9a6de4f729bfc802d3a552bb565f (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
// 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;

import com.yahoo.config.model.api.ConfigChangeAction;
import com.yahoo.config.model.api.ServiceInfo;
import com.yahoo.config.provision.ClusterSpec;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Class containing the action to be performed on the given services to handle a config change
 * between the current active vespa model and the next vespa model to prepare.
 *
 * @author geirst
 */
public abstract class VespaConfigChangeAction implements ConfigChangeAction {

    private final ClusterSpec.Id id;
    private final String message;
    private final List<ServiceInfo> services;

    protected VespaConfigChangeAction(ClusterSpec.Id id, String message, List<ServiceInfo> services) {
        this.id = id;
        this.message = message;
        this.services = services;
    }

    public abstract VespaConfigChangeAction modifyAction(String newMessage, List<ServiceInfo> newServices, String documentType);

    @Override
    public ClusterSpec.Id clusterId() { return id; }

    @Override
    public String getMessage() {
        return message;
    }

    @Override
    public List<ServiceInfo> getServices() {
        return services;
    }

    @Override
    public String toString() {
        return "type='" + getType() + "', message='" + message + "', services=[" +
                services.stream().
                        map(service -> service.getServiceName() + " '" + service.getConfigId() + "'").
                        collect(Collectors.joining(", ")) + "]";
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof VespaConfigChangeAction)) {
            return false;
        }
        VespaConfigChangeAction rhs = (VespaConfigChangeAction)o;
        if (!getType().equals(rhs.getType())) return false;
        if (!message.equals(rhs.message)) return false;
        if (!services.equals(rhs.services)) return false;
        return true;
    }

    @Override
    public int hashCode() {
        int result = getType().hashCode();
        result = 31 * result + message.hashCode();
        result = 31 * result + services.hashCode();
        return result;
    }

}