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;
* @author Robert Eby
* @version $Id: SynchronizerTask.java,v 1.10 2014/03/21 13:50:10 eby Exp $
*/
+
public class SynchronizerTask extends TimerTask {
/**
logger.info("PROV5000: Sync task starting, server podState is UNKNOWN_POD");
try {
- Properties props = (new DB()).getProperties();
- String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks");
- String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY);
- String pass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
+ // Set up keystore
+ String type = AafPropsUtils.KEYSTORE_TYPE_PROPERTY;
+ String store = Main.aafPropsUtils.getKeystorePathProperty();
+ String pass = Main.aafPropsUtils.getKeystorePassProperty();
KeyStore keyStore = KeyStore.getInstance(type);
try (FileInputStream instream = new FileInputStream(new File(store))) {
keyStore.load(instream, pass.toCharArray());
}
- store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
- pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY);
+ // Set up truststore
+ store = Main.aafPropsUtils.getTruststorePathProperty();
+ pass = Main.aafPropsUtils.getTruststorePassProperty();
KeyStore trustStore = null;
if (store != null && store.length() > 0) {
- trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ trustStore = KeyStore.getInstance(AafPropsUtils.TRUESTSTORE_TYPE_PROPERTY);
try (FileInputStream instream = new FileInputStream(new File(store))) {
trustStore.load(instream, pass.toCharArray());
// 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 = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
+ String keystorepass = Main.aafPropsUtils.getKeystorePassProperty();
try (AbstractHttpClient hc = new DefaultHttpClient()) {
SSLSocketFactory socketFactory =
(trustStore == null)
hc.getConnectionManager().getSchemeRegistry().register(sch);
httpclient = hc;
}
- setSynchTimer(props);
+ setSynchTimer(new DB().getProperties().getProperty(
+ "org.onap.dmaap.datarouter.provserver.sync_interval", "5000"));
} catch (Exception e) {
logger.warn("PROV5005: Problem starting the synchronizer: " + e);
}
}
- private void setSynchTimer(Properties props) {
+ private void setSynchTimer(String strInterval) {
// Run once every 5 seconds to check DNS, etc.
long interval;
try {
- String s = props.getProperty("org.onap.dmaap.datarouter.provserver.sync_interval", "5000");
- interval = Long.parseLong(s);
+ interval = Long.parseLong(strInterval);
} catch (NumberFormatException e) {
interval = 5000L;
}
Collection<Syncable> coll = new ArrayList<>();
for (int n = 0; n < ja.length(); n++) {
try {
- Feed f = new Feed(ja.getJSONObject(n));
- coll.add(f);
+ Feed feed = new Feed(ja.getJSONObject(n));
+ coll.add(feed);
} catch (Exception e) {
logger.warn("PROV5004: Invalid object in feed: " + ja.optJSONObject(n), e);
}
for (int n = 0; n < ja.length(); n++) {
try {
//Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
- JSONObject j = ja.getJSONObject(n);
- j.put("sync", "true");
- Subscription s = new Subscription(j);
- coll.add(s);
+ JSONObject jsonObject = ja.getJSONObject(n);
+ jsonObject.put("sync", "true");
+ Subscription sub = new Subscription(jsonObject);
+ coll.add(sub);
} catch (Exception e) {
logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n), e);
}
Collection<Syncable> coll = new ArrayList<>();
for (int n = 0; n < ja.length(); n++) {
try {
- Group g = new Group(ja.getJSONObject(n));
- coll.add(g);
+ Group group = new Group(ja.getJSONObject(n));
+ coll.add(group);
} catch (Exception e) {
logger.warn("PROV5004: Invalid object in group: " + ja.optJSONObject(n), e);
}
private void syncParams(JSONObject jo) {
Collection<Syncable> coll = new ArrayList<>();
for (String k : jo.keySet()) {
- String v = "";
+ String val = "";
try {
- v = jo.getString(k);
+ val = jo.getString(k);
} catch (JSONException e) {
logger.warn("PROV5004: Invalid object in parameters: " + jo.optJSONObject(k), e);
try {
- v = "" + jo.getInt(k);
+ val = "" + jo.getInt(k);
} catch (JSONException e1) {
logger.warn("PROV5004: Invalid object in parameters: " + jo.optInt(k), e1);
JSONArray ja = jo.getJSONArray(k);
for (int i = 0; i < ja.length(); i++) {
if (i > 0) {
- v += "|";
+ val += "|";
}
- v += ja.getString(i);
+ val += ja.getString(i);
}
}
}
- coll.add(new Parameters(k, v));
+ coll.add(new Parameters(k, val));
}
if (sync(coll, Parameters.getParameterCollection())) {
BaseServlet.provisioningDataChanged();
return newobj.doInsert(conn);
}
- private Map<String, Syncable> getMap(Collection<? extends Syncable> c) {
+ private Map<String, Syncable> getMap(Collection<? extends Syncable> coll) {
Map<String, Syncable> map = new HashMap<>();
- for (Syncable v : c) {
+ for (Syncable v : coll) {
map.put(v.getKey(), v);
}
return map;
String url = URLUtilities.generatePeerLogsURL();
HttpPost post = new HttpPost(url);
try {
- String t = bs.toString();
- HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create(TEXT_CT));
+ String str = bs.toString();
+ HttpEntity body = new ByteArrayEntity(str.getBytes(), ContentType.create(TEXT_CT));
post.setEntity(body);
if (logger.isDebugEnabled()) {
- logger.debug("Requesting records: " + t);
+ logger.debug("Requesting records: " + str);
}
HttpResponse response = httpclient.execute(post);