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