[DMAAP-BC] Consolidate bus controller repos
[dmaap/buscontroller.git] / dmaap-bc / src / main / java / org / onap / dmaap / dbcapi / model / MR_Cluster.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dmaap.dbcapi.model;
22
23 import javax.xml.bind.annotation.XmlRootElement;
24
25 import org.onap.dmaap.dbcapi.util.DmaapConfig;
26 import org.onap.dmaap.dbcapi.util.DmaapTimestamp;
27
28
29
30 @XmlRootElement
31 public class MR_Cluster extends DmaapObject {
32
33         private String dcaeLocationName;
34         private String fqdn;
35         private DmaapTimestamp lastMod;
36         private String  topicProtocol;
37         private String  topicPort;
38         private String  replicationGroup;
39         private String  sourceReplicationPort;
40         private String  targetReplicationPort;
41
42         
43         // TODO: make this a system property
44         private static  String defaultTopicProtocol;
45         private static   String defaultTopicPort;
46         private static  String defaultReplicationGroup;
47         private static  String defaultSourceReplicationPort;
48         private static  String defaultTargetReplicationPort;
49         
50         private static void setDefaults() {
51                 /* boolean been_here = false;
52                 if ( been_here ) {
53                         return;
54                 } */
55                 DmaapConfig dc = (DmaapConfig)DmaapConfig.getConfig();
56                 defaultTopicProtocol = dc.getProperty("MR.TopicProtocol", "https");
57                 defaultTopicPort = dc.getProperty( "MR.TopicPort", "3905");
58                 defaultReplicationGroup = dc.getProperty( "MR.ReplicationGroup", "" );
59                 defaultSourceReplicationPort = dc.getProperty( "MR.SourceReplicationPort", "2181");
60                 defaultTargetReplicationPort = dc.getProperty( "MR.TargetReplicationPort", "9092");
61                 // been_here = true;
62         }
63
64
65         public MR_Cluster() {
66                 setDefaults();
67                 this.topicProtocol = defaultTopicProtocol;
68                 this.topicPort = defaultTopicPort;
69                 this.replicationGroup = null;
70                 this.sourceReplicationPort = defaultSourceReplicationPort;
71                 this.targetReplicationPort = defaultTargetReplicationPort;
72                 this.lastMod = new DmaapTimestamp();
73                 this.lastMod.mark();
74
75                 debugLogger.debug( "MR_Cluster constructor " + this.lastMod );
76                 
77         }
78
79         // new style constructor
80         public MR_Cluster( String dLN,
81                         String f,
82                         String prot,
83                         String port) {
84                 setDefaults();
85                 this.dcaeLocationName = dLN;
86                 this.fqdn = f;
87
88                 if ( prot == null || prot.isEmpty() ) {
89                         this.topicProtocol = defaultTopicProtocol;
90                 } else {
91                         this.topicProtocol = prot;
92                 }
93                 if ( port == null || port.isEmpty() ) {
94                         this.topicPort = defaultTopicPort;
95                 } else {
96                         this.topicPort = port;
97                 }
98
99                 this.replicationGroup = defaultReplicationGroup;
100                 this.sourceReplicationPort = defaultSourceReplicationPort;
101                 this.targetReplicationPort = defaultTargetReplicationPort;
102
103                 this.lastMod = new DmaapTimestamp();
104                 this.lastMod.mark();
105                 
106                 debugLogger.debug( "MR_Cluster constructor w initialization complete" + this.lastMod.getVal() );
107         }
108
109         public MR_Cluster( String dLN,
110                         String f,
111                         String prot,
112                         String port,
113                         String repGroup,
114                         String sourceRepPort,
115                         String targetRepPort ) {
116                 setDefaults();
117                 this.dcaeLocationName = dLN;
118                 this.fqdn = f;
119
120                 if ( prot == null || prot.isEmpty() ) {
121                         this.topicProtocol = defaultTopicProtocol;
122                 } else {
123                         this.topicProtocol = prot;
124                 }
125                 if ( port == null || port.isEmpty() ) {
126                         this.topicPort = defaultTopicPort;
127                 } else {
128                         this.topicPort = port;
129                 }
130                 if ( repGroup == null || repGroup.isEmpty() ) {
131                         this.replicationGroup = defaultReplicationGroup;
132                 } else {
133                         this.replicationGroup = repGroup;
134                 }
135                 if ( sourceRepPort == null || sourceRepPort.isEmpty()) {
136                         this.sourceReplicationPort = defaultSourceReplicationPort;
137                 } else {
138                         this.sourceReplicationPort = sourceRepPort;
139                 }
140                 if ( targetRepPort == null || targetRepPort.isEmpty()) {
141                         this.targetReplicationPort = defaultTargetReplicationPort;
142                 } else {
143                         this.targetReplicationPort = targetRepPort;
144                 }
145                                 
146                 this.lastMod = new DmaapTimestamp();
147                 this.lastMod.mark();
148                 
149                 debugLogger.debug( "MR_Cluster constructor w initialization complete" + this.lastMod.getVal() );
150         }
151         public String getDcaeLocationName() {
152                 return dcaeLocationName;
153         }
154
155         public void setDcaeLocationName(String dcaeLocationName) {
156                 this.dcaeLocationName = dcaeLocationName;
157         }
158
159         public String getFqdn() {
160                 return fqdn;
161         }
162
163         public void setFqdn(String fqdn) {
164                 this.fqdn = fqdn;
165         }
166
167
168         public String getTopicProtocol() {
169                 return topicProtocol;
170         }
171
172         public void setTopicProtocol(String topicProtocol) {
173                 this.topicProtocol = topicProtocol;
174         }
175
176         public String getTopicPort() {
177                 return topicPort;
178         }
179
180         public void setTopicPort(String topicPort) {
181                 this.topicPort = topicPort;
182         }
183
184         public String getReplicationGroup() {
185                 return replicationGroup;
186         }
187
188         public void setReplicationGroup(String replicationGroup) {
189                 this.replicationGroup = replicationGroup;
190         }
191
192
193
194
195         public String getSourceReplicationPort() {
196                 return sourceReplicationPort;
197         }
198
199
200
201         public void setSourceReplicationPort(String sourceReplicationPort) {
202                 this.sourceReplicationPort = sourceReplicationPort;
203         }
204
205
206
207         public String getTargetReplicationPort() {
208                 return targetReplicationPort;
209         }
210
211
212
213         public void setTargetReplicationPort(String targetReplicationPort) {
214                 this.targetReplicationPort = targetReplicationPort;
215         }
216
217
218
219         public String genTopicURL(String overideFqdn, String topic) {
220
221                 StringBuilder str = new StringBuilder( topicProtocol );
222                 str.append("://")
223                         .append( overideFqdn != null ? overideFqdn : fqdn)
224                         .append(":")
225                         .append(topicPort)
226                         .append("/events/")
227                         .append(topic);
228                 
229                 return str.toString();
230
231
232         }
233
234
235 }