34a51192f7cb75094c9825563637f3fd3d24a8a4
[ccsdk/sli/plugins.git] / grToolkit / provider / src / main / java / org / onap / ccsdk / sli / plugins / 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.data;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26
27 public class ClusterActor {
28     private String node;
29     private String member;
30     private String site;
31     private String akkaPort;
32     private boolean voting;
33     private boolean up;
34     private boolean unreachable;
35     private ArrayList<String> shardLeader;
36     private ArrayList<String> replicaShards;
37     private ArrayList<String> nonReplicaShards;
38     private HashMap<String, Integer> commits;
39
40     public static final String SITE_1 = "Site 1";
41     public static final String SITE_2 = "Site 2";
42
43     public ClusterActor() {
44         node = "";
45         member = "";
46         site = "";
47         voting = false;
48         up = false;
49         unreachable = false;
50         shardLeader = new ArrayList<>();
51         replicaShards = new ArrayList<>();
52         nonReplicaShards = new ArrayList<>();
53         commits = new HashMap<>();
54     }
55
56     public String getNode() {
57         return node;
58     }
59
60     public void setNode(String node) {
61         this.node = node;
62     }
63
64     public String getMember() {
65         return member;
66     }
67
68     public void setMember(String member) {
69         this.member = member;
70     }
71
72     public String getSite() {
73         return site;
74     }
75
76     public void setSite(String site) {
77         this.site = site;
78     }
79
80     public String getAkkaPort() {
81         return akkaPort;
82     }
83
84     public void setAkkaPort(String akkaPort) {
85         this.akkaPort = akkaPort;
86     }
87
88     public boolean isVoting() {
89         return voting;
90     }
91
92     public void setVoting(boolean voting) {
93         this.voting = voting;
94     }
95
96     public boolean isUp() {
97         return up;
98     }
99
100     public void setUp(boolean up) {
101         this.up = up;
102     }
103
104     public boolean isUnreachable() {
105         return unreachable;
106     }
107
108     public void setUnreachable(boolean unreachable) {
109         this.unreachable = unreachable;
110     }
111
112     public ArrayList<String> getShardLeader() {
113         return shardLeader;
114     }
115
116     public void setShardLeader(ArrayList<String> shardLeader) {
117         this.shardLeader = shardLeader;
118     }
119
120     public ArrayList<String> getReplicaShards() {
121         return replicaShards;
122     }
123
124     public void setReplicaShards(ArrayList<String> replicaShards) {
125         this.replicaShards = replicaShards;
126     }
127
128     public ArrayList<String> getNonReplicaShards() {
129         return nonReplicaShards;
130     }
131
132     public void setNonReplicaShards(ArrayList<String> nonReplicaShards) {
133         this.nonReplicaShards = nonReplicaShards;
134     }
135
136     public HashMap<String, Integer> getCommits() {
137         return commits;
138     }
139
140     public void setCommits(HashMap<String, Integer> commits) {
141         this.commits = commits;
142     }
143
144     public void flush() {
145         shardLeader.clear();
146         replicaShards.clear();
147         nonReplicaShards.clear();
148         commits.clear();
149     }
150
151     @Override
152     public String toString() {
153         StringBuilder builder = new StringBuilder();
154         builder.append("[ ");
155         builder.append(this.member);
156         builder.append(" ] ");
157
158         builder.append(this.node);
159         builder.append(":");
160         builder.append(this.akkaPort);
161         builder.append(" is");
162         if(up)
163             builder.append(" Up");
164         else
165             builder.append(" Down");
166         if(unreachable)
167             builder.append(" [ UNREACHABLE ]");
168
169         if(voting)
170             builder.append(" (Voting)");
171
172         builder.append("\n");
173
174         for(String l : this.shardLeader) {
175             builder.append("\tLeader: ");
176             builder.append(l);
177             builder.append("\n");
178         }
179
180         for(String r : this.replicaShards) {
181             builder.append("\tReplicating: ");
182             builder.append(r);
183             builder.append("\n");
184         }
185
186         for(String n : this.nonReplicaShards) {
187             builder.append("\tNot replicating: ");
188             builder.append(n);
189             builder.append("\n");
190         }
191
192         for(String key : commits.keySet()) {
193             int value = commits.get(key);
194             if(value > 0) {
195                 builder.append("\t");
196                 builder.append(value);
197                 builder.append(" commits ahead of ");
198                 builder.append(key);
199                 builder.append("\n");
200             }
201             else if(value < 0) {
202                 builder.append("\t");
203                 builder.append(value);
204                 builder.append(" commits behind ");
205                 builder.append(key);
206                 builder.append("\n");
207             }
208         }
209
210         return builder.toString();
211     }
212 }