becfbc5a4b51eb994ac13ea872094342e325d9c0
[dmaap/messagerouter/mirroragent.git] / src / main / java / org / onap / dmaap / mr / dmaapMMAgent / MirrorMakerAgent.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 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  *        http://www.apache.org/licenses/LICENSE-2.0
11  *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package org.onap.dmaap.mr.dmaapMMAgent;
23
24 import java.io.BufferedReader;
25 import java.io.DataOutputStream;
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.InputStreamReader;
32 import java.io.OutputStream;
33 import java.net.HttpURLConnection;
34 import java.net.URL;
35 import java.util.ArrayList;
36 import java.util.Properties;
37 //import org.json.JSONObject;
38 //import org.apache.log4j.Logger;
39 //import org.jasypt.util.text.BasicTextEncryptor;
40
41 import org.onap.dmaap.mr.dmaapMMAgent.dao.CreateMirrorMaker;
42 import org.onap.dmaap.mr.dmaapMMAgent.dao.DeleteMirrorMaker;
43 import org.onap.dmaap.mr.dmaapMMAgent.dao.ListMirrorMaker;
44 import org.onap.dmaap.mr.dmaapMMAgent.dao.MirrorMaker;
45 import org.onap.dmaap.mr.dmaapMMAgent.dao.UpdateMirrorMaker;
46 import org.onap.dmaap.mr.dmaapMMAgent.dao.UpdateWhiteList;
47 import org.onap.dmaap.mr.dmaapMMAgent.utils.MirrorMakerProcessHandler;
48 import com.google.gson.Gson;
49 import com.google.gson.JsonArray;
50 import com.google.gson.internal.LinkedTreeMap;
51 import com.sun.org.apache.xerces.internal.impl.dtd.models.CMAny;
52 import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
53
54 public class MirrorMakerAgent {/*
55         static final Logger logger = Logger.getLogger(MirrorMakerAgent.class);
56         Properties mirrorMakerProperties = new Properties();
57         ListMirrorMaker mirrorMakers = null;
58         String mmagenthome = "";
59         String kafkahome = "";
60         String topicURL = "";
61         String topicname = "";
62         String mechid = "";
63         String password = "";
64         String grepLog = "";
65         private static String secret = "utdfpWlgyDQ2ZB8SLVRtmN834I1JcT9J";
66
67         public static void main(String[] args) {
68                 if (args != null && args.length == 2) {
69                         if (args[0].equals("-encrypt")) {
70                                 BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
71                                 textEncryptor.setPassword(secret);
72                                 String plainText = textEncryptor.encrypt(args[1]);
73                                 System.out.println("Encrypted Password is :" + plainText);
74                                 return;
75                         }
76                 } else if (args != null && args.length > 0) {
77                         System.out.println(
78                                         "Usage: ./mmagent to run with the configuration \n -encrypt <password> to Encrypt Password for config ");
79                         return;
80                 }
81                 MirrorMakerAgent agent = new MirrorMakerAgent();
82                 if (agent.checkStartup()) {
83                         logger.info("mmagent started, loading properties");
84                         try {
85                                 agent.checkAgentProcess();
86                         } catch (Exception e) {
87                                 
88                                 e.printStackTrace();
89                         }
90                         agent.readAgentTopic();
91                 } else {
92                         System.out.println(
93                                         "ERROR: mmagent startup unsuccessful, please make sure the mmagenthome /etc/mmagent.config is set and mechid have the rights to the topic");
94                 }
95         }
96
97         private boolean checkStartup() {
98                 FileInputStream input = null;
99                 try {
100                         this.mmagenthome = System.getProperty("MMAGENTHOME");
101                         input = new FileInputStream(mmagenthome + "/etc/mmagent.config");
102                         logger.info("mmagenthome is set :" + mmagenthome + " loading properties at /etc/mmagent.config");
103                 } catch (IOException ex) {
104                         logger.error(mmagenthome + "/etc/mmagent.config not found.  Set -DMMAGENTHOME and check the config file");
105                         return false;
106                 } finally {
107                         if (input != null) {
108                                 try {
109                                         input.close();
110                                 } catch (IOException e) {
111                                         e.printStackTrace();
112                                 }
113                         }
114                 }
115                 loadProperties();
116                 input = null;
117                 try {
118                         input = new FileInputStream(kafkahome + "/bin/kafka-run-class.sh");
119                         logger.info("kakahome is set :" + kafkahome);
120                 } catch (IOException ex) {
121                         logger.error(kafkahome + "/bin/kafka-run-class.sh not found.  Make sure kafka home is set correctly");
122                         return false;
123                 } finally {
124                         if (input != null) {
125                                 try {
126                                         input.close();
127                                 } catch (IOException e) {
128                                         e.printStackTrace();
129                                 }
130                         }
131                 }
132                 String response = publishTopic("{\"test\":\"test\"}");
133                 if (response.startsWith("ERROR:")) {
134                         logger.error("Problem publishing to topic, please verify the config " + this.topicname + " MR URL is:"
135                                         + this.topicURL + " Error is:  " + response);
136                         return false;
137                 }
138                 logger.info("Published to Topic :" + this.topicname + " Successfully");
139                 response = subscribeTopic("1");
140                 if (response != null && response.startsWith("ERROR:")) {
141                         logger.error("Problem subscribing to topic, please verify the config " + this.topicname + " MR URL is:"
142                                         + this.topicURL + " Error is:  " + response);
143                         return false;
144                 }
145                 logger.info("Subscribed to Topic :" + this.topicname + " Successfully");
146                 return true;
147         }
148
149         private void checkPropertiesFile(MirrorMaker mm, String propName, boolean refresh) {
150                 InputStream input = null;
151                 OutputStream out = null;
152                 try {
153                         if (refresh) {
154                                 throw new IOException();
155                         }
156                         input = new FileInputStream(mmagenthome + "/etc/" + mm.name + propName + ".properties");
157                 } catch (IOException ex) {
158                         try {
159                                 input = new FileInputStream(mmagenthome + "/etc/" + propName + ".properties");
160                                 Properties prop = new Properties();
161                                 prop.load(input);
162                                 if (propName.equals("consumer")) {
163                                 prop.setProperty("group.id", mm.name);
164           
165                                  prop.setProperty("bootstrap.servers", mm.consumer);
166                                   prop.setProperty("client.id", mm.name + "MM_consumer");
167                                   } else {
168                                         prop.setProperty("bootstrap.servers", mm.producer);
169           prop.setProperty("client.id", mm.name + "MM_producer");
170                                 
171                                 }
172                                 out = new FileOutputStream(mmagenthome + "/etc/" + mm.name + propName + ".properties");
173                                 prop.store(out, "");
174
175                         } catch (Exception e) {
176                                 e.printStackTrace();
177                         }
178                 } finally {
179                         if (input != null) {
180                                 try {
181                                         input.close();
182                                 } catch (IOException e) {
183                                         e.printStackTrace();
184                                 }
185                         }
186                         if (out != null) {
187                                 try {
188                                         out.close();
189                                 } catch (IOException e) {
190                                         e.printStackTrace();
191                                 }
192                         }
193                 }
194         }
195
196         private void checkAgentProcess() throws Exception {
197                 logger.info("Checking MirrorMaker Process");
198                 if (mirrorMakers != null) {
199                         int mirrorMakersCount = mirrorMakers.getListMirrorMaker().size();
200                         for (int i = 0; i < mirrorMakersCount; i++) {
201                                 MirrorMaker mm = mirrorMakers.getListMirrorMaker().get(i);
202                                 if (MirrorMakerProcessHandler.checkMirrorMakerProcess(mm.name,mm.enablelogCheck,this.grepLog) == false) {
203                                         checkPropertiesFile(mm, "consumer", false);
204                                         checkPropertiesFile(mm, "producer", false);
205
206                                         if (mm.whitelist != null && !mm.whitelist.equals("")) {
207                                                 logger.info("MirrorMaker " + mm.name + " is not running, restarting.  Check Logs for more Details");
208                                                 MirrorMakerProcessHandler.startMirrorMaker(this.mmagenthome, this.kafkahome, mm.name,
209                                                                 mmagenthome + "/etc/" + mm.name + "consumer.properties",
210                                                                 mmagenthome + "/etc/" + mm.name + "producer.properties",mm.numStreams, mm.whitelist);
211                                                 mm.setStatus("RESTARTING");
212
213                                         } else {
214                                                 logger.info("MirrorMaker " + mm.name + " is STOPPED");
215                                                 mm.setStatus("STOPPED");
216                                         }
217                                         try {
218                                                 Thread.sleep(1000);
219                                         } catch (InterruptedException e) {
220                                         }
221                                         mirrorMakers.getListMirrorMaker().set(i, mm);
222                                 } else {
223                                         logger.info("MirrorMaker " + mm.name + " is running");
224                                         mm.setStatus("RUNNING");
225                                         mirrorMakers.getListMirrorMaker().set(i, mm);
226                                 }
227                         }
228                 }
229                 // Gson g = new Gson();
230                 // System.out.println(g.toJson(mirrorMakers));
231         }
232
233         private String subscribeTopic(String timeout) {
234                 String response = "";
235                 try {
236                         String requestURL = this.topicURL + "/events/" + this.topicname + "/mirrormakeragent/1?timeout=" + timeout
237                                         + "&limit=1";
238                         String authString = this.mechid + ":" + this.password;
239                         String authStringEnc = Base64.encode(authString.getBytes());
240                         URL url = new URL(requestURL);
241                         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
242                         connection.setRequestMethod("GET");
243                         connection.setDoOutput(true);
244                         connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
245                         connection.setRequestProperty("Content-Type", "application/json");
246                         InputStream content = (InputStream) connection.getInputStream();
247                         BufferedReader in = new BufferedReader(new InputStreamReader(content));
248                         String line;
249
250                         while ((line = in.readLine()) != null) {
251                                 response = response + line;
252                         }
253                         Gson g = new Gson();
254                         //Get message as JSON Array
255                         JsonArray topicMessage = g.fromJson(response, JsonArray.class);
256                          if (topicMessage.size() != 0) {
257                                  return topicMessage.get(0).toString();
258                          }
259                         
260                         // get message as JSON String Array
261                         String[] topicMessage = g.fromJson(response, String[].class);
262                         if (topicMessage.length != 0) {
263                                 return topicMessage[0];
264                         }
265                 } catch (Exception e) {
266                         return "ERROR:" + e.getMessage() + " Server Response is:" + response;
267                 }
268                 return null;
269         }
270
271         private String publishTopic(String message) {
272                 try {
273                         String requestURL = this.topicURL + "/events/" + this.topicname;
274                         String authString = this.mechid + ":" + this.password;
275                         String authStringEnc = Base64.encode(authString.getBytes());
276                         URL url = new URL(requestURL);
277                         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
278                         connection.setRequestMethod("POST");
279                         connection.setDoOutput(true);
280                         connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
281                         connection.setRequestProperty("Content-Type", "application/json");
282                         connection.setRequestProperty("Content-Length", Integer.toString(message.length()));
283                         DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
284                         wr.write(message.getBytes());
285
286                         InputStream content = (InputStream) connection.getInputStream();
287                         BufferedReader in = new BufferedReader(new InputStreamReader(content));
288                         String line;
289                         String response = "";
290                         while ((line = in.readLine()) != null) {
291                                 response = response + line;
292                         }
293                         return response;
294
295                 } catch (Exception e) {
296                         return "ERROR:" + e.getLocalizedMessage();
297                 }
298         }
299
300         private void readAgentTopic() {
301                 try {
302                         int connectionattempt = 0;
303                         while (true) {
304                                 logger.info("--------------------------------");
305                                 logger.info("Waiting for Messages for 60 secs");
306                                 String topicMessage = subscribeTopic("60000");
307                                 Gson g = new Gson();
308                                 LinkedTreeMap<?, ?> object = null;
309                                 if (topicMessage != null) {
310                                         try {
311                                                 //Check and parse if String object returned by consumer API
312                                                 //else use the jsonObject
313                                                  if( topicMessage.startsWith("\""))
314                                                     {
315                                                         topicMessage = g.fromJson(topicMessage.toString(), String.class);
316                                                     }
317                                                 object = g.fromJson(topicMessage, LinkedTreeMap.class);
318
319                                                 // Cast the 1st item (since limit=1 and see the type of
320                                                 // object
321                                                 if (object.get("createMirrorMaker") != null) {
322                                                         logger.info("Received createMirrorMaker request from topic");
323                                                         CreateMirrorMaker m = g.fromJson(topicMessage, CreateMirrorMaker.class);
324                                                         createMirrorMaker(m.getCreateMirrorMaker());
325                                                         checkAgentProcess();
326                                                         mirrorMakers.setMessageID(m.getMessageID());
327                                                         publishTopic(g.toJson(mirrorMakers));
328                                                         mirrorMakers.setMessageID("");
329                                                 } else if (object.get("updateMirrorMaker") != null) {
330                                                         logger.info("Received updateMirrorMaker request from topic");
331                                                         UpdateMirrorMaker m = g.fromJson(topicMessage, UpdateMirrorMaker.class);
332                                                         JSONObject json = new JSONObject(topicMessage);
333                                                         JSONObject json2 = (JSONObject) json.get("updateMirrorMaker");
334                                                         if(!json2.has("numStreams")){
335                                                                 m.getUpdateMirrorMaker().setNumStreams(0);
336                                                         }
337                                                         updateMirrorMaker(m.getUpdateMirrorMaker());
338                                                         checkAgentProcess();
339                                                         mirrorMakers.setMessageID(m.getMessageID());
340                                                         publishTopic(g.toJson(mirrorMakers));
341                                                         mirrorMakers.setMessageID("");
342                                                 } else if (object.get("deleteMirrorMaker") != null) {
343                                                         logger.info("Received deleteMirrorMaker request from topic");
344                                                         DeleteMirrorMaker m = g.fromJson(topicMessage, DeleteMirrorMaker.class);
345                                                         deleteMirrorMaker(m.getDeleteMirrorMaker());
346                                                         checkAgentProcess();
347                                                         mirrorMakers.setMessageID(m.getMessageID());
348                                                         publishTopic(g.toJson(mirrorMakers));
349                                                         mirrorMakers.setMessageID("");
350                                                 } else if (object.get("listAllMirrorMaker") != null) {
351                                                         logger.info("Received listALLMirrorMaker request from topic");
352                                                         checkAgentProcess();
353                                                         mirrorMakers.setMessageID((String) object.get("messageID"));
354                                                         publishTopic(g.toJson(mirrorMakers));
355                                                         mirrorMakers.setMessageID("");
356                                                 } else if (object.get("updateWhiteList") != null) {
357                                                         logger.info("Received updateWhiteList request from topic");
358                                                         UpdateWhiteList m = g.fromJson(topicMessage, UpdateWhiteList.class);
359                                                         updateWhiteList(m.getUpdateWhiteList());
360                                                         checkAgentProcess();
361                                                         mirrorMakers.setMessageID(m.getMessageID());
362                                                         publishTopic(g.toJson(mirrorMakers));
363                                                         mirrorMakers.setMessageID("");
364                                                 } else if (object.get("listMirrorMaker") != null) {
365                                                         logger.info("Received listMirrorMaker from topic, skipping messages");
366                                                 } else {
367                                                         logger.info("Received unknown request from topic");
368                                                 }
369                                         } catch (Exception ex) {
370                                                 connectionattempt++;
371                                                 if (connectionattempt > 5) {
372                                                         logger.info("Can't connect to the topic, mmagent shutting down , " + topicMessage);
373                                                         return;
374                                                 }
375                                                 logger.info("Can't connect to the topic, " + topicMessage + " Retrying " + connectionattempt
376                                                                 + " of 5 times in 1 minute" + " Error:" + ex.getLocalizedMessage());
377                                                 Thread.sleep(60000);
378                                         }
379                                 } else {
380                                         // Check all MirrorMaker every min
381                                         connectionattempt = 0;
382                                         checkAgentProcess();
383                                 }
384
385                         }
386                 } catch (Exception e) {
387                         e.printStackTrace();
388                 }
389
390         }
391
392         private void createMirrorMaker(MirrorMaker newMirrorMaker) {
393                 boolean exists = false;
394                 if (mirrorMakers != null) {
395                         int mirrorMakersCount = mirrorMakers.getListMirrorMaker().size();
396                         for (int i = 0; i < mirrorMakersCount; i++) {
397                                 MirrorMaker mm = mirrorMakers.getListMirrorMaker().get(i);
398                                 if (mm.name.equals(newMirrorMaker.name)) {
399                                         exists = true;
400                                         logger.info("MirrorMaker already exist for:" + newMirrorMaker.name);
401                                         return;
402                                 }
403                         }
404                 }
405                 logger.info("Adding new MirrorMaker:" + newMirrorMaker.name);
406                 if (exists == false && mirrorMakers != null) {
407                         mirrorMakers.getListMirrorMaker().add(newMirrorMaker);
408                 } else if (exists == false && mirrorMakers == null) {
409                         mirrorMakers = new ListMirrorMaker();
410                         ArrayList<MirrorMaker> list = mirrorMakers.getListMirrorMaker();
411                         list = new ArrayList<MirrorMaker>();
412                         list.add(newMirrorMaker);
413                         mirrorMakers.setListMirrorMaker(list);
414                 }
415                 checkPropertiesFile(newMirrorMaker, "consumer",  true);
416                 checkPropertiesFile(newMirrorMaker, "producer",  true);
417
418                 Gson g = new Gson();
419                 mirrorMakerProperties.setProperty("mirrormakers", g.toJson(this.mirrorMakers));
420                 OutputStream out = null;
421                 try {
422                         out = new FileOutputStream(mmagenthome + "/etc/mmagent.config");
423                         mirrorMakerProperties.store(out, "");
424                 } catch (IOException ex) {
425                         ex.printStackTrace();
426                 } finally {
427                         if (out != null) {
428                                 try {
429                                         out.close();
430                                 } catch (IOException e) {
431                                         e.printStackTrace();
432                                 }
433                         }
434                 }
435         }
436
437         private void updateMirrorMaker(MirrorMaker newMirrorMaker) {
438                 boolean exists = false;
439                 if (mirrorMakers != null) {
440                         int mirrorMakersCount = mirrorMakers.getListMirrorMaker().size();
441                         for (int i = 0; i < mirrorMakersCount; i++) {
442                                 MirrorMaker mm = mirrorMakers.getListMirrorMaker().get(i);
443                                 if (mm.name.equals(newMirrorMaker.name)) {
444                                         exists = true;
445                                         if(null!=newMirrorMaker.getConsumer()) 
446                                         {
447                                                 mm.setConsumer(newMirrorMaker.getConsumer());
448                                         }
449                                         if(null!=newMirrorMaker.getProducer())
450                                         {
451                                                 mm.setProducer(newMirrorMaker.getProducer());
452                                         }
453                                         if(newMirrorMaker.getNumStreams()>=1) 
454                                         {
455                                                 mm.setNumStreams(newMirrorMaker.getNumStreams());
456                                         } 
457                                         
458                                         mm.setEnablelogCheck(newMirrorMaker.enablelogCheck);
459                                         
460                                         mirrorMakers.getListMirrorMaker().set(i, mm);
461                                         newMirrorMaker=mm;
462                                         logger.info("Updating MirrorMaker:" + newMirrorMaker.name);
463                                 }
464                         }
465                 }
466                 if (exists) {
467                         checkPropertiesFile(newMirrorMaker, "consumer", true);
468                         checkPropertiesFile(newMirrorMaker, "producer", true);
469
470                         Gson g = new Gson();
471                         mirrorMakerProperties.setProperty("mirrormakers", g.toJson(this.mirrorMakers));
472                         OutputStream out = null;
473                         try {
474                                 out = new FileOutputStream(mmagenthome + "/etc/mmagent.config");
475                                 mirrorMakerProperties.store(out, "");
476                                 MirrorMakerProcessHandler.stopMirrorMaker(newMirrorMaker.name);
477                                 try {
478                                         Thread.sleep(1000);
479                                 } catch (InterruptedException e) {
480                                 }
481                         } catch (IOException ex) {
482                                 ex.printStackTrace();
483                         } finally {
484                                 if (out != null) {
485                                         try {
486                                                 out.close();
487                                         } catch (IOException e) {
488                                                 e.printStackTrace();
489                                         }
490                                 }
491                         }
492                 } else {
493                         logger.info("MirrorMaker Not found for:" + newMirrorMaker.name);
494                 }
495         }
496
497         private void updateWhiteList(MirrorMaker newMirrorMaker) {
498                 boolean exists = false;
499                 if (mirrorMakers != null) {
500                         int mirrorMakersCount = mirrorMakers.getListMirrorMaker().size();
501                         for (int i = 0; i < mirrorMakersCount; i++) {
502                                 MirrorMaker mm = mirrorMakers.getListMirrorMaker().get(i);
503                                 if (mm.name.equals(newMirrorMaker.name)) {
504                                         exists = true;
505                                         mm.setWhitelist(newMirrorMaker.whitelist);
506                                         mirrorMakers.getListMirrorMaker().set(i, mm);
507                                         logger.info("Updating MirrorMaker WhiteList:" + newMirrorMaker.name + " WhiteList:"
508                                                         + newMirrorMaker.whitelist);
509                                 }
510                         }
511                 }
512                 if (exists) {
513                         Gson g = new Gson();
514                         mirrorMakerProperties.setProperty("mirrormakers", g.toJson(this.mirrorMakers));
515                         OutputStream out = null;
516                         try {
517                                 out = new FileOutputStream(mmagenthome + "/etc/mmagent.config");
518                                 mirrorMakerProperties.store(out, "");
519                                 MirrorMakerProcessHandler.stopMirrorMaker(newMirrorMaker.name);
520                                 try {
521                                         Thread.sleep(1000);
522                                 } catch (InterruptedException e) {
523                                 }
524                         } catch (IOException ex) {
525                                 ex.printStackTrace();
526                         } finally {
527                                 if (out != null) {
528                                         try {
529                                                 out.close();
530                                         } catch (IOException e) {
531                                                 e.printStackTrace();
532                                         }
533                                 }
534                         }
535                 } else {
536                         logger.info("MirrorMaker Not found for:" + newMirrorMaker.name);
537                 }
538         }
539
540         private void deleteMirrorMaker(MirrorMaker newMirrorMaker) {
541                 boolean exists = false;
542                 if (mirrorMakers != null) {
543                         int mirrorMakersCount = mirrorMakers.getListMirrorMaker().size();
544                         for (int i = 0; i < mirrorMakersCount; i++) {
545                                 MirrorMaker mm = mirrorMakers.getListMirrorMaker().get(i);
546                                 if (mm.name.equals(newMirrorMaker.name)) {
547                                         exists = true;
548                                         mirrorMakers.getListMirrorMaker().remove(i);
549                                         logger.info("Removing MirrorMaker:" + newMirrorMaker.name);
550                                         i = mirrorMakersCount;
551                                 }
552                         }
553                 }
554                 if (exists) {
555                         try {
556                                 String path = mmagenthome + "/etc/" + newMirrorMaker.name + "consumer" + ".properties";
557                                 File file = new File(path);
558                                 file.delete();
559                         } catch (Exception ex) {
560                         }
561                         try {
562                                 String path = mmagenthome + "/etc/" + newMirrorMaker.name + "producer" + ".properties";
563                                 File file = new File(path);
564                                 file.delete();
565                         } catch (Exception ex) {
566                         }
567                         Gson g = new Gson();
568                         mirrorMakerProperties.setProperty("mirrormakers", g.toJson(this.mirrorMakers));
569                         OutputStream out = null;
570                         try {
571                                 out = new FileOutputStream(mmagenthome + "/etc/mmagent.config");
572                                 mirrorMakerProperties.store(out, "");
573                                 MirrorMakerProcessHandler.stopMirrorMaker(newMirrorMaker.name);
574                         } catch (IOException ex) {
575                                 ex.printStackTrace();
576                         } finally {
577                                 if (out != null) {
578                                         try {
579                                                 out.close();
580                                         } catch (IOException e) {
581                                                 e.printStackTrace();
582                                         }
583                                 }
584                         }
585                 } else {
586                         logger.info("MirrorMaker Not found for:" + newMirrorMaker.name);
587                 }
588         }
589
590         private void loadProperties() {
591                 InputStream input = null;
592                 try {
593
594                         input = new FileInputStream(mmagenthome + "/etc/mmagent.config");
595                         mirrorMakerProperties.load(input);
596                         Gson g = new Gson();
597                         if (mirrorMakerProperties.getProperty("mirrormakers") == null) {
598                                 this.mirrorMakers = new ListMirrorMaker();
599                                 ArrayList<MirrorMaker> list = this.mirrorMakers.getListMirrorMaker();
600                                 list = new ArrayList<MirrorMaker>();
601                                 this.mirrorMakers.setListMirrorMaker(list);
602                         } else {
603                                 this.mirrorMakers = g.fromJson(mirrorMakerProperties.getProperty("mirrormakers"),
604                                                 ListMirrorMaker.class);
605                         }
606
607                         this.kafkahome = mirrorMakerProperties.getProperty("kafkahome");
608                         this.topicURL = mirrorMakerProperties.getProperty("topicURL");
609                         this.topicname = mirrorMakerProperties.getProperty("topicname");
610                         this.mechid = mirrorMakerProperties.getProperty("mechid");
611                         this.grepLog= mirrorMakerProperties.getProperty("grepLog");
612
613                         BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
614                         textEncryptor.setPassword(secret);
615                         this.password = textEncryptor.decrypt(mirrorMakerProperties.getProperty("password"));
616                 } catch (IOException ex) {
617                         // ex.printStackTrace();
618                 } finally {
619                         if (input != null) {
620                                 try {
621                                         input.close();
622                                 } catch (IOException e) {
623                                         // e.printStackTrace();
624                                 }
625                         }
626                 }
627
628         }
629 */}

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use