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 org.onap.dmaap.dbcapi.service.MirrorMakerService;
25 import java.util.ArrayList;
27 public class MirrorMaker extends DmaapObject {
30 private String sourceCluster;
31 private String targetCluster;
32 private String mmName;
33 private ArrayList<String> topics; //re-using this var name for backwards DB compatibility
40 public MirrorMaker(String source, String target, int i) {
41 initMM( source, target );
42 // original mm names did not have any index, so leave off index 0 for
43 // backwards compatibility
45 String n = this.getMmName() + "_" + i;
49 public MirrorMaker(String source, String target) {
50 initMM( source, target );
53 private void initMM(String source, String target) {
54 sourceCluster = source;
55 targetCluster = target;
56 mmName = genKey(source, target);
57 topics = new ArrayList<>();
61 public String getMmName() {
65 public void setMmName(String mmName) {
70 // returns the JSON for MM message containing which Topics to replicate
78 "name":"Global1ToGlobal3",
79 "whitelist":"org.openecomp.dcae.topic1,org.openecomp.dcae.topic2"
83 public String getWhitelistUpdateJSON() {
84 StringBuilder str = new StringBuilder( "{ \"messageID\": \"" + MirrorMakerService.genTransactionId() + "\", \"updateWhiteList\": {" );
85 str.append( " \"name\": \"" + this.getMmName() + "\", \"whitelist\": \"" );
88 for (String rv: topics) {
89 if ( numTargets > 0 ) {
95 str.append( "\" } }" );
97 return str.toString();
100 // returns the JSON for MM message indicating that a MM agent is needed between two clusters
108 "name":"Global1ToGlobal2",
109 "consumer":"192.168.0.1:2181",
110 "producer":"192.168.0.2:9092"
114 public String createMirrorMaker( String consumerPort, String producerPort ) {
115 StringBuilder str = new StringBuilder( "{ \"messageID\": \"" + MirrorMakerService.genTransactionId() + "\", \"createMirrorMaker\": {" );
116 str.append( " \"name\": \"" + this.getMmName() + "\", " );
117 str.append( " \"consumer\": \"" + this.sourceCluster + ":" + consumerPort + "\", " );
118 str.append( " \"producer\": \"" + this.targetCluster + ":" + producerPort + "\", ");
120 str.append( " \"numStreams\": \"10\" } }" );
122 return str.toString();
126 public String getSourceCluster() {
127 return sourceCluster;
130 public void setSourceCluster(String sourceCluster) {
131 this.sourceCluster = sourceCluster;
134 public String getTargetCluster() {
135 return targetCluster;
138 public void setTargetCluster(String targetCluster) {
139 this.targetCluster = targetCluster;
143 public ArrayList<String> getTopics() {
148 public void setTopics(ArrayList<String> topics) {
149 this.topics = topics;
153 public static String genKey( String s, String t) {
154 StringBuilder str = new StringBuilder();
158 return str.toString();
163 public void addTopic( String topic ) {
164 if ( ! topics.contains(topic)) {
167 logger.info( "Mirrormaker.addTopic: topic=" + topic + " . Now have " + topics.size() + " topics" );
170 public int getTopicCount() {
171 return topics.size();