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

import com.yahoo.vdslib.state.NodeType;

/**
 * Class representations of resources in State Rest API.
 *
 * Note that the toString() implementation will put out a slash separated list of the tokens,
 * and thus be compatible with the link format.
 */
public class Id {

    public static class Cluster extends Id {
        private final String id;

        public Cluster(String id) { this.id = id; }

        public final String getClusterId() { return id; }
        public String toString() { return id; }
    }

    public static class Service extends Cluster {
        private final NodeType id;

        public Service(Cluster c, NodeType service) {
            super(c.getClusterId());
            id = service;
        }

        public final NodeType getService() { return id; }
        public String toString() { return super.toString() + "/" + id; }
    }

    public static class Node extends Service {
        private final int id;

        public Node(Service service, int nodeIndex) {
            super(service, service.id);
            this.id = nodeIndex;
        }

        /**
         * Looks bad with name overlap here, but everywhere else Node will have to be
         * referred to as Id.Node, so users won't get conflicts.
         */
        public final com.yahoo.vdslib.state.Node getNode() {
            return new com.yahoo.vdslib.state.Node(getService(), id);
        }

        public String toString() { return super.toString() + "/" + id; }
    }

    public static class Partition extends Node {
        private final int id;

        public Partition(Node n, int partition) {
            super(n, n.id);
            this.id = partition;
        }

        public String toString() { return super.toString() + "/" + id; }
    }

}