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

import java.util.Optional;

public class NodeEvent implements Event {

    private final NodeInfo node;
    private final String description;
    private final long eventTime;
    private final Optional<String> bucketSpace;

    public enum Type {
        REPORTED,
        CURRENT,
        WANTED
    }

    private final Type type;

    private NodeEvent(NodeInfo node, String description, Type type, long currentTime) {
        this.node = node;
        this.description = description;
        this.eventTime = currentTime;
        this.type = type;
        this.bucketSpace = Optional.empty();
    }

    private NodeEvent(NodeInfo node, String bucketSpace, String description, Type type, long currentTime) {
        this.node = node;
        this.description = description;
        this.eventTime = currentTime;
        this.type = type;
        this.bucketSpace = Optional.of(bucketSpace);
    }

    public static NodeEvent forBaseline(NodeInfo node, String description, Type type, long currentTime) {
        return new NodeEvent(node, description, type, currentTime);
    }

    public static NodeEvent forBucketSpace(NodeInfo node, String bucketSpace, String description, Type type, long currentTime) {
        return new NodeEvent(node, bucketSpace, description, type, currentTime);
    }

    public NodeInfo getNode() {
        return node;
    }

    @Override
    public long getTimeMs() {
        return eventTime;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return "Event: " + getNodeBucketSpaceDescription() + ": " + description;
    }

    private String getNodeBucketSpaceDescription() {
        if (bucketSpace.isPresent()) {
            return node.getNode() + " (" + bucketSpace.get() + ")";
        }
        return node.getNode().toString();
    }

    @Override
    public String getCategory() {
        return type.toString();
    }

    public Type getType() {
        return type;
    }

    public Optional<String> getBucketSpace() {
        return bucketSpace;
    }

}