aboutsummaryrefslogtreecommitdiffstats
path: root/grToolkit/provider/src/main/java/org/onap/ccsdk/sli/plugins/grtoolkit/data/ClusterActor.java
blob: 7cd503a950df27f5e0b7f45393ced934bbc28966 (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*-
 * ============LICENSE_START=======================================================
 * openECOMP : SDN-C
 * ================================================================================
 * Copyright (C) 2018 AT&T Intellectual Property. All rights
 * 			reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.ccsdk.sli.plugins.grtoolkit.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ClusterActor {
    private String node;
    private String member;
    private String site;
    private String akkaPort;
    private boolean voting;
    private boolean up;
    private boolean unreachable;
    private ArrayList<String> shardLeader;
    private ArrayList<String> replicaShards;
    private ArrayList<String> nonReplicaShards;
    private HashMap<String, Integer> commits;

    public static final String SITE_1 = "Site 1";
    public static final String SITE_2 = "Site 2";

    public ClusterActor() {
        node = "";
        member = "";
        site = "";
        voting = false;
        up = false;
        unreachable = false;
        shardLeader = new ArrayList<>();
        replicaShards = new ArrayList<>();
        nonReplicaShards = new ArrayList<>();
        commits = new HashMap<>();
    }

    public String getNode() {
        return node;
    }

    public void setNode(String node) {
        this.node = node;
    }

    public String getMember() {
        return member;
    }

    public void setMember(String member) {
        this.member = member;
    }

    public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public String getAkkaPort() {
        return akkaPort;
    }

    public void setAkkaPort(String akkaPort) {
        this.akkaPort = akkaPort;
    }

    public boolean isVoting() {
        return voting;
    }

    public void setVoting(boolean voting) {
        this.voting = voting;
    }

    public boolean isUp() {
        return up;
    }

    public void setUp(boolean up) {
        this.up = up;
    }

    public boolean isUnreachable() {
        return unreachable;
    }

    public void setUnreachable(boolean unreachable) {
        this.unreachable = unreachable;
    }

    public List<String> getShardLeader() {
        return shardLeader;
    }

    public void setShardLeader(List<String> shardLeader) {
        this.shardLeader = (ArrayList<String>) shardLeader;
    }

    public List<String> getReplicaShards() {
        return replicaShards;
    }

    public void setReplicaShards(List<String> replicaShards) {
        this.replicaShards = (ArrayList<String>) replicaShards;
    }

    public List<String> getNonReplicaShards() {
        return nonReplicaShards;
    }

    public void setNonReplicaShards(List<String> nonReplicaShards) {
        this.nonReplicaShards = (ArrayList<String>) nonReplicaShards;
    }

    public Map<String, Integer> getCommits() {
        return commits;
    }

    public void setCommits(Map<String, Integer> commits) {
        this.commits = (HashMap<String, Integer>) commits;
    }

    public void flush() {
        shardLeader.clear();
        replicaShards.clear();
        nonReplicaShards.clear();
        commits.clear();
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("[ ");
        builder.append(this.member);
        builder.append(" ] ");

        builder.append(this.node);
        builder.append(":");
        builder.append(this.akkaPort);
        builder.append(" is");
        if(up)
            builder.append(" Up");
        else
            builder.append(" Down");
        if(unreachable)
            builder.append(" [ UNREACHABLE ]");

        if(voting)
            builder.append(" (Voting)");

        builder.append("\n");

        for(String l : this.shardLeader) {
            builder.append("\tLeader: ");
            builder.append(l);
            builder.append("\n");
        }

        for(String r : this.replicaShards) {
            builder.append("\tReplicating: ");
            builder.append(r);
            builder.append("\n");
        }

        for(String n : this.nonReplicaShards) {
            builder.append("\tNot replicating: ");
            builder.append(n);
            builder.append("\n");
        }

        for(Map.Entry<String, Integer> entry : commits.entrySet()) {
            String key = entry.getKey();
            int value = entry.getValue();
            if(value > 0) {
                builder.append("\t");
                builder.append(value);
                builder.append(" commits ahead of ");
                builder.append(key);
                builder.append("\n");
            }
            else if(value < 0) {
                builder.append("\t");
                builder.append(value);
                builder.append(" commits behind ");
                builder.append(key);
                builder.append("\n");
            }
        }

        return builder.toString();
    }
}