*******************************************************************************/
package org.onap.dmaap.mr.dmaapMMAgent;
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Properties;
-import org.json.JSONObject;
+
import org.apache.log4j.Logger;
import org.jasypt.util.text.BasicTextEncryptor;
-
+import org.json.JSONObject;
import org.onap.dmaap.mr.dmaapMMAgent.dao.CreateMirrorMaker;
import org.onap.dmaap.mr.dmaapMMAgent.dao.DeleteMirrorMaker;
import org.onap.dmaap.mr.dmaapMMAgent.dao.ListMirrorMaker;
import org.onap.dmaap.mr.dmaapMMAgent.dao.UpdateMirrorMaker;
import org.onap.dmaap.mr.dmaapMMAgent.dao.UpdateWhiteList;
import org.onap.dmaap.mr.dmaapMMAgent.utils.MirrorMakerProcessHandler;
+
import com.google.gson.Gson;
-import com.google.gson.JsonArray;
import com.google.gson.internal.LinkedTreeMap;
-import com.sun.org.apache.xerces.internal.impl.dtd.models.CMAny;
-import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
-
public class MirrorMakerAgent {
static final Logger logger = Logger.getLogger(MirrorMakerAgent.class);
Properties mirrorMakerProperties = new Properties();
try {
agent.checkAgentProcess();
} catch (Exception e) {
-
- e.printStackTrace();
+ logger.error("exception occured in checkAgentProcess ", e);
}
agent.readAgentTopic();
} else {
private boolean checkStartup() {
FileInputStream input = null;
try {
- //this.mmagenthome = System.getProperty("MMAGENTHOME");
input = new FileInputStream(mmagenthome + "/etc/mmagent.config");
logger.info("mmagenthome is set :" + mmagenthome + " loading properties at /etc/mmagent.config");
} catch (IOException ex) {
- logger.error(mmagenthome + "/etc/mmagent.config not found. Set -DMMAGENTHOME and check the config file");
+ logger.error(mmagenthome + "/etc/mmagent.config not found.", ex);
return false;
} finally {
if (input != null) {
input = null;
try {
input = new FileInputStream(kafkahome + "/bin/kafka-run-class.sh");
- logger.info("kakahome is set :" + kafkahome);
+ logger.info("kafkahome is set :" + kafkahome);
} catch (IOException ex) {
- logger.error(kafkahome + "/bin/kafka-run-class.sh not found. Make sure kafka home is set correctly");
+ logger.error(kafkahome + "/bin/kafka-run-class.sh not found. Make sure kafka home is set correctly", ex);
return false;
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("exception occured in checkPropertiesFile ", e);
}
}
if (out != null) {
}
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("exception occured in readAgentTopic ", e);
}
}
out = new FileOutputStream(mmagenthome + "/etc/mmagent.config");
mirrorMakerProperties.store(out, "");
} catch (IOException ex) {
- ex.printStackTrace();
+ logger.error("exception occured in createMirrorMaker ", ex);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("exception occured in createMirrorMaker ", e);
}
}
}
} catch (InterruptedException e) {
}
} catch (IOException ex) {
- ex.printStackTrace();
+ logger.error("exception occured in updateMirrorMaker ", ex);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("exception occured in updateMirrorMaker ", e);
}
}
}
} catch (InterruptedException e) {
}
} catch (IOException ex) {
- ex.printStackTrace();
+ logger.error("exception occured in updateWhiteList ", ex);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("exception occured in updateWhiteList ", e);
}
}
}
File file = new File(path);
file.delete();
} catch (Exception ex) {
+ logger.error("exception occured in deleteMirrorMaker ", ex);
}
try {
String path = mmagenthome + "/etc/" + newMirrorMaker.name + "producer" + ".properties";
File file = new File(path);
file.delete();
} catch (Exception ex) {
+ logger.error("exception occured in deleteMirrorMaker ", ex);
}
Gson g = new Gson();
mirrorMakerProperties.setProperty("mirrormakers", g.toJson(this.mirrorMakers));
mirrorMakerProperties.store(out, "");
MirrorMakerProcessHandler.stopMirrorMaker(newMirrorMaker.name);
} catch (IOException ex) {
- ex.printStackTrace();
+ logger.error("exception occured in deleteMirrorMaker ", ex);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
- e.printStackTrace();
+ logger.error("exception occured in deleteMirrorMaker ", e);
}
}
}
if (mirrorMakerProperties.getProperty("mirrormakers") == null) {
this.mirrorMakers = new ListMirrorMaker();
ArrayList<MirrorMaker> list = this.mirrorMakers.getListMirrorMaker();
- list = new ArrayList<MirrorMaker>();
+ list = new ArrayList<>();
this.mirrorMakers.setListMirrorMaker(list);
} else {
this.mirrorMakers = g.fromJson(mirrorMakerProperties.getProperty("mirrormakers"),
textEncryptor.setPassword(secret);
this.password = textEncryptor.decrypt(mirrorMakerProperties.getProperty("password"));
} catch (Exception ex) {
- // ex.printStackTrace();
+ logger.error("exception occured in loadProperties ", ex);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
- // e.printStackTrace();
+ logger.error("exception occured in loadProperties ", e);
}
}
}