7cd503a950df27f5e0b7f45393ced934bbc28966
[ccsdk/sli/plugins.git] / grToolkit / provider / src / main / java / org / onap / ccsdk / sli / plugins / grtoolkit / data / ClusterActor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights
6  *                      reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.plugins.grtoolkit.data;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 public class ClusterActor {
30     private String node;
31     private String member;
32     private String site;
33     private String akkaPort;
34     private boolean voting;
35     private boolean up;
36     private boolean unreachable;
37     private ArrayList<String> shardLeader;
38     private ArrayList<String> replicaShards;
39     private ArrayList<String> nonReplicaShards;
40     private HashMap<String, Integer> commits;
41
42     public static final String SITE_1 = "Site 1";
43     public static final String SITE_2 = "Site 2";
44
45     public ClusterActor() {
46         node = "";
47         member = "";
48         site = "";
49         voting = false;
50         up = false;
51         unreachable = false;
52         shardLeader = new ArrayList<>();
53         replicaShards = new ArrayList<>();
54         nonReplicaShards = new ArrayList<>();
55         commits = new HashMap<>();
56     }
57
58     public String getNode() {
59         return node;
60     }
61
62     public void setNode(String node) {
63         this.node = node;
64     }
65
66     public String getMember() {
67         return member;
68     }
69
70     public void setMember(String member) {
71         this.member = member;
72     }
73
74     public String getSite() {
75         return site;
76     }
77
78     public void setSite(String site) {
79         this.site = site;
80     }
81
82     public String getAkkaPort() {
83         return akkaPort;
84     }
85
86     public void setAkkaPort(String akkaPort) {
87         this.akkaPort = akkaPort;
88     }
89
90     public boolean isVoting() {
91         return voting;
92     }
93
94     public void setVoting(boolean voting) {
95         this.voting = voting;
96     }
97
98     public boolean isUp() {
99         return up;
100     }
101
102     public void setUp(boolean up) {
103         this.up = up;
104     }
105
106     public boolean isUnreachable() {
107         return unreachable;
108     }
109
110     public void setUnreachable(boolean unreachable) {
111         this.unreachable = unreachable;
112     }
113
114     public List<String> getShardLeader() {
115         return shardLeader;
116     }
117
118     public void setShardLeader(List<String> shardLeader) {
119         this.shardLeader = (ArrayList<String>) shardLeader;
120     }
121
122     public List<String> getReplicaShards() {
123         return replicaShards;
124     }
125
126     public void setReplicaShards(List<String> replicaShards) {
127         this.replicaShards = (ArrayList<String>) replicaShards;
128     }
129
130     public List<String> getNonReplicaShards() {
131         return nonReplicaShards;
132     }
133
134     public void setNonReplicaShards(List<String> nonReplicaShards) {
135         this.nonReplicaShards = (ArrayList<String>) nonReplicaShards;
136     }
137
138     public Map<String, Integer> getCommits() {
139         return commits;
140     }
141
142     public void setCommits(Map<String, Integer> commits) {
143         this.commits = (HashMap<String, Integer>) commits;
144     }
145
146     public void flush() {
147         shardLeader.clear();
148         replicaShards.clear();
149         nonReplicaShards.clear();
150         commits.clear();
151     }
152
153     @Override
154     public String toString() {
155         StringBuilder builder = new StringBuilder();
156         builder.append("[ ");
157         builder.append(this.member);
158         builder.append(" ] ");
159
160         builder.append(this.node);
161         builder.append(":");
162         builder.append(this.akkaPort);
163         builder.append(" is");
164         if(up)
165             builder.append(" Up");
166         else
167             builder.append(" Down");
168         if(unreachable)
169             builder.append(" [ UNREACHABLE ]");
170
171         if(voting)
172             builder.append(" (Voting)");
173
174         builder.append("\n");
175
176         for(String l : this.shardLeader) {
177             builder.append("\tLeader: ");
178             builder.append(l);
179             builder.append("\n");
180         }
181
182         for(String r : this.replicaShards) {
183             builder.append("\tReplicating: ");
184             builder.append(r);
185             builder.append("\n");
186         }
187
188         for(String n : this.nonReplicaShards) {
189             builder.append("\tNot replicating: ");
190             builder.append(n);
191             builder.append("\n");
192         }
193
194         for(Map.Entry<String, Integer> entry : commits.entrySet()) {
195             String key = entry.getKey();
196             int value = entry.getValue();
197             if(value > 0) {
198                 builder.append("\t");
199                 builder.append(value);
200                 builder.append(" commits ahead of ");
201                 builder.append(key);
202                 builder.append("\n");
203             }
204             else if(value < 0) {
205                 builder.append("\t");
206                 builder.append(value);
207                 builder.append(" commits behind ");
208                 builder.append(key);
209                 builder.append("\n");
210             }
211         }
212
213         return builder.toString();
214     }
215 }