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 {
32 static final Logger logger = Logger.getLogger(MirrorMaker.class);
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
45 public MirrorMaker(String source, String target) {
46 sourceCluster = source;
47 targetCluster = target;
48 mmName = genKey(source, target);
49 topics = new ArrayList<String>();
53 public String getMmName() {
57 public void setMmName(String mmName) {
62 // returns the JSON for MM message containing which Topics to replicate
70 "name":"Global1ToGlobal3",
71 "whitelist":"org.openecomp.dcae.topic1,org.openecomp.dcae.topic2"
75 public String updateWhiteList() {
76 StringBuilder str = new StringBuilder( "{ \"messageID\": \"" + MirrorMakerService.genTransactionId() + "\", \"updateWhiteList\": {" );
77 str.append( " \"name\": \"" + this.getMmName() + "\", \"whitelist\": \"" );
80 //for (ReplicationVector rv: vectors) {
81 for (String rv: topics) {
82 if ( numTargets > 0 ) {
85 //str.append( rv.getFqtn() );
89 str.append( "\" } }" );
91 return str.toString();
94 // returns the JSON for MM message indicating that a MM agent is needed between two clusters
102 "name":"Global1ToGlobal2",
103 "consumer":"192.168.0.1:2181",
104 "producer":"192.168.0.2:9092"
108 public String createMirrorMaker( String consumerPort, String producerPort ) {
109 StringBuilder str = new StringBuilder( "{ \"messageID\": \"" + MirrorMakerService.genTransactionId() + "\", \"createMirrorMaker\": {" );
110 str.append( " \"name\": \"" + this.getMmName() + "\", " );
111 str.append( " \"consumer\": \"" + this.sourceCluster + ":" + consumerPort + "\", " );
112 str.append( " \"producer\": \"" + this.targetCluster + ":" + producerPort + "\" ");
114 str.append( " } }" );
116 return str.toString();
120 public String getSourceCluster() {
121 return sourceCluster;
124 public void setSourceCluster(String sourceCluster) {
125 this.sourceCluster = sourceCluster;
128 public String getTargetCluster() {
129 return targetCluster;
132 public void setTargetCluster(String targetCluster) {
133 this.targetCluster = targetCluster;
137 public ArrayList<String> getTopics() {
142 public void setTopics(ArrayList<String> topics) {
143 this.topics = topics;
147 public static String genKey( String s, String t) {
148 StringBuilder str = new StringBuilder();
152 return str.toString();
157 public void addTopic( String topic ) {
158 if ( ! topics.contains(topic)) {
161 logger.info( "Mirrormaker.addTopic: topic=" + topic + " . Now have " + topics.size() + " topics" );
164 public int getTopicCount() {
165 return topics.size();