aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/vcmr/VespaChangeRequest.java
blob: c7e84d4f9c4d061b1ddb153f4e0ea48f9793d143 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.vcmr;

import com.yahoo.config.provision.zone.ZoneId;

import java.util.List;
import java.util.Objects;

/**
 * @author olaa
 */
public class VespaChangeRequest extends ChangeRequest {

    private final Status status;
    private final ZoneId zoneId;
    // TODO: Create applicationActionPlan
    private final List<HostAction> hostActionPlan;

    public VespaChangeRequest(String id, ChangeRequestSource changeRequestSource, List<String> impactedSwitches, List<String> impactedHosts, Approval approval, Impact impact, Status status, List<HostAction> hostActionPlan, ZoneId zoneId) {
        super(id, changeRequestSource, impactedSwitches, impactedHosts, approval, impact);
        this.status = status;
        this.hostActionPlan = hostActionPlan;
        this.zoneId = zoneId;
    }
    public VespaChangeRequest(ChangeRequest changeRequest, ZoneId zoneId) {
        this(changeRequest.getId(), changeRequest.getChangeRequestSource(), changeRequest.getImpactedSwitches(),
                changeRequest.getImpactedHosts(), changeRequest.getApproval(), changeRequest.getImpact(), Status.PENDING_ASSESSMENT, List.of(), zoneId);
    }

    public Status getStatus() {
        return status;
    }

    public List<HostAction> getHostActionPlan() {
        return hostActionPlan;
    }

    public ZoneId getZoneId() {
        return zoneId;
    }

    public VespaChangeRequest withStatus(Status status) {
        return new VespaChangeRequest(getId(), getChangeRequestSource(), getImpactedSwitches(), getImpactedHosts(), getApproval(), getImpact(), status, hostActionPlan, zoneId);
    }

    public VespaChangeRequest withSource(ChangeRequestSource source) {
        return new VespaChangeRequest(getId(), source, getImpactedSwitches(), getImpactedHosts(), getApproval(), getImpact(), status, hostActionPlan, zoneId);
    }

    public VespaChangeRequest withImpact(Impact impact) {
        return new VespaChangeRequest(getId(), getChangeRequestSource(), getImpactedSwitches(), getImpactedHosts(), getApproval(), impact, status, hostActionPlan, zoneId);
    }

    public VespaChangeRequest withApproval(Approval approval) {
        return new VespaChangeRequest(getId(), getChangeRequestSource(), getImpactedSwitches(), getImpactedHosts(), approval, getImpact(), status, hostActionPlan, zoneId);
    }

    public VespaChangeRequest withActionPlan(List<HostAction> hostActionPlan) {
        return new VespaChangeRequest(getId(), getChangeRequestSource(), getImpactedSwitches(), getImpactedHosts(), getApproval(), getImpact(), status, hostActionPlan, zoneId);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        VespaChangeRequest that = (VespaChangeRequest) o;
        return status == that.status &&
                Objects.equals(hostActionPlan, that.hostActionPlan) &&
                Objects.equals(zoneId, that.zoneId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), status, hostActionPlan, zoneId);
    }

    @Override
    public String toString() {
        return "VespaChangeRequest{" +
                "id='" + getId() + '\'' +
                ", changeRequestSource=" + getChangeRequestSource() +
                ", impactedSwitches=" + getImpactedSwitches() +
                ", impactedHosts=" + getImpactedHosts() +
                ", approval=" + getApproval() +
                ", impact=" + getImpact() +
                ", status=" + status +
                ", zoneId=" + zoneId +
                ", hostActionPlan=" + hostActionPlan +
                '}';
    }

    public enum Status {
        COMPLETED,
        READY,
        IN_PROGRESS,
        PENDING_ACTION,
        PENDING_ASSESSMENT,
        REQUIRES_OPERATOR_ACTION,
        OUT_OF_SYNC,
        NOOP
    }
}