******************************************************************************/
-package org.onap.dmaap.datarouter.provisioning;
+package org.onap.dmaap.datarouter.provisioning.utils;
import static org.onap.dmaap.datarouter.provisioning.BaseServlet.TEXT_CT;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeSet;
-
import javax.servlet.http.HttpServletResponse;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
+import org.onap.dmaap.datarouter.provisioning.BaseServlet;
+import org.onap.dmaap.datarouter.provisioning.ProvRunner;
import org.onap.dmaap.datarouter.provisioning.beans.EgressRoute;
import org.onap.dmaap.datarouter.provisioning.beans.Feed;
import org.onap.dmaap.datarouter.provisioning.beans.Group;
import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
import org.onap.dmaap.datarouter.provisioning.beans.Syncable;
-import org.onap.dmaap.datarouter.provisioning.utils.AafPropsUtils;
-import org.onap.dmaap.datarouter.provisioning.utils.DB;
-import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
-import org.onap.dmaap.datarouter.provisioning.utils.RLEBitSet;
-import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
/**
* This class handles synchronization between provisioning servers (PODs). It has three primary functions:
private SynchronizerTask() {
logger = EELFManager.getInstance().getLogger("InternalLog");
rolex = new Timer();
- spooldir = (new DB()).getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
+ spooldir = ProvRunner.getProvProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
podState = UNKNOWN_POD;
doFetch = true; // start off with a fetch
nextsynctime = 0;
try {
// Set up keystore
String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY;
- String store = Main.aafPropsUtils.getKeystorePathProperty();
- String pass = Main.aafPropsUtils.getKeystorePassProperty();
+ String store = ProvRunner.getAafPropsUtils().getKeystorePathProperty();
+ String pass = ProvRunner.getAafPropsUtils().getKeystorePassProperty();
KeyStore keyStore = KeyStore.getInstance(type);
try (FileInputStream instream = new FileInputStream(new File(store))) {
keyStore.load(instream, pass.toCharArray());
}
// Set up truststore
- store = Main.aafPropsUtils.getTruststorePathProperty();
- pass = Main.aafPropsUtils.getTruststorePassProperty();
+ store = ProvRunner.getAafPropsUtils().getTruststorePathProperty();
+ pass = ProvRunner.getAafPropsUtils().getTruststorePassProperty();
KeyStore trustStore = null;
if (store != null && store.length() > 0) {
trustStore = KeyStore.getInstance(AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY);
// We are connecting with the node name, but the certificate will have the CNAME
// So we need to accept a non-matching certificate name
- String keystorepass = Main.aafPropsUtils.getKeystorePassProperty();
+ String keystorepass = ProvRunner.getAafPropsUtils().getKeystorePassProperty();
try (AbstractHttpClient hc = new DefaultHttpClient()) {
SSLSocketFactory socketFactory =
(trustStore == null)
hc.getConnectionManager().getSchemeRegistry().register(sch);
httpclient = hc;
}
- setSynchTimer(new DB().getProperties().getProperty(
+ setSynchTimer(ProvRunner.getProvProperties().getProperty(
"org.onap.dmaap.datarouter.provserver.sync_interval", "5000"));
} catch (Exception e) {
logger.warn("PROV5005: Problem starting the synchronizer: " + e);
* This method is used to signal that another POD (the active POD) has sent us a /fetchProv request, and that we
* should re-synchronize with the master.
*/
- void doFetch() {
+ public void doFetch() {
doFetch = true;
}
*
* @return the current podState
*/
- int lookupState() {
+ public int lookupState() {
int newPodState = UNKNOWN_POD;
try {
InetAddress myaddr = InetAddress.getLocalHost();
Map<String, Syncable> oldmap = getMap(oldc);
Set<String> union = new TreeSet<>(newmap.keySet());
union.addAll(oldmap.keySet());
- DB db = new DB();
- @SuppressWarnings("resource")
- Connection conn = db.getConnection();
for (String n : union) {
Syncable newobj = newmap.get(n);
Syncable oldobj = oldmap.get(n);
if (oldobj == null) {
- changes = insertRecord(conn, newobj);
+ try (Connection conn = ProvDbUtils.getInstance().getConnection()) {
+ changes = insertRecord(conn, newobj);
+ }
} else if (newobj == null) {
- changes = deleteRecord(conn, oldobj);
+ try (Connection conn = ProvDbUtils.getInstance().getConnection()) {
+ changes = deleteRecord(conn, oldobj);
+ }
} else if (!newobj.equals(oldobj)) {
- changes = updateRecord(conn, newobj, oldobj);
+ try (Connection conn = ProvDbUtils.getInstance().getConnection()) {
+ changes = updateRecord(conn, newobj, oldobj);
+ }
}
}
- db.release(conn);
} catch (SQLException e) {
logger.warn("PROV5009: problem during sync, exception: " + e);
}
*
* @return the bitset
*/
- RLEBitSet readRemoteLoglist() {
+ public RLEBitSet readRemoteLoglist() {
RLEBitSet bs = new RLEBitSet();
String url = URLUtilities.generatePeerLogsURL();
*
* @param bs the bitset (an RELBitSet) of log records to fetch
*/
- void replicateDataRouterLogs(RLEBitSet bs) {
+ public void replicateDataRouterLogs(RLEBitSet bs) {
String url = URLUtilities.generatePeerLogsURL();
HttpPost post = new HttpPost(url);
try {