2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.dmaap.dbcapi.model;
23 import java.util.ArrayList;
24 import java.util.HashSet;
27 import org.apache.log4j.Logger;
28 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
29 import org.onap.dmaap.dbcapi.service.MirrorMakerService;
31 public class MirrorMaker extends DmaapObject {
34 private String sourceCluster;
35 private String targetCluster;
36 private String mmName;
37 private ArrayList<String> topics; //re-using this var name for backwards DB compatibility
44 public MirrorMaker(String source, String target, int i) {
45 initMM( source, target );
46 // original mm names did not have any index, so leave off index 0 for
47 // backwards compatibility
49 String n = this.getMmName() + "_" + i;
53 public MirrorMaker(String source, String target) {
54 initMM( source, target );
57 private void initMM(String source, String target) {
58 sourceCluster = source;
59 targetCluster = target;
60 mmName = genKey(source, target);
61 topics = new ArrayList<String>();
65 public String getMmName() {
69 public void setMmName(String mmName) {
74 // returns the JSON for MM message containing which Topics to replicate
82 "name":"Global1ToGlobal3",
83 "whitelist":"org.openecomp.dcae.topic1,org.openecomp.dcae.topic2"
87 public String getWhitelistUpdateJSON() {
88 StringBuilder str = new StringBuilder( "{ \"messageID\": \"" + MirrorMakerService.genTransactionId() + "\", \"updateWhiteList\": {" );
89 str.append( " \"name\": \"" + this.getMmName() + "\", \"whitelist\": \"" );
92 //for (ReplicationVector rv: vectors) {
93 for (String rv: topics) {
94 if ( numTargets > 0 ) {
97 //str.append( rv.getFqtn() );
101 str.append( "\" } }" );
103 return str.toString();
106 // returns the JSON for MM message indicating that a MM agent is needed between two clusters
114 "name":"Global1ToGlobal2",
115 "consumer":"192.168.0.1:2181",
116 "producer":"192.168.0.2:9092"
120 public String createMirrorMaker( String consumerPort, String producerPort ) {
121 StringBuilder str = new StringBuilder( "{ \"messageID\": \"" + MirrorMakerService.genTransactionId() + "\", \"createMirrorMaker\": {" );
122 str.append( " \"name\": \"" + this.getMmName() + "\", " );
123 str.append( " \"consumer\": \"" + this.sourceCluster + ":" + consumerPort + "\", " );
124 str.append( " \"producer\": \"" + this.targetCluster + ":" + producerPort + "\", ");
126 str.append( " \"numStreams\": \"10\" } }" );
128 return str.toString();
132 public String getSourceCluster() {
133 return sourceCluster;
136 public void setSourceCluster(String sourceCluster) {
137 this.sourceCluster = sourceCluster;
140 public String getTargetCluster() {
141 return targetCluster;
144 public void setTargetCluster(String targetCluster) {
145 this.targetCluster = targetCluster;
149 public ArrayList<String> getTopics() {
154 public void setTopics(ArrayList<String> topics) {
155 this.topics = topics;
159 public static String genKey( String s, String t) {
160 StringBuilder str = new StringBuilder();
164 return str.toString();
169 public void addTopic( String topic ) {
170 if ( ! topics.contains(topic)) {
173 logger.info( "Mirrormaker.addTopic: topic=" + topic + " . Now have " + topics.size() + " topics" );
176 public int getTopicCount() {
177 return topics.size();