summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/dcae/ApplicationSettings.java5
-rw-r--r--src/main/java/org/onap/dcae/common/EventProcessor.java79
-rwxr-xr-xsrc/main/java/org/onap/dcae/common/RestapiCallNode.java36
-rw-r--r--src/main/java/org/onap/dcae/controller/AccessController.java2
-rw-r--r--src/main/java/org/onap/dcae/controller/PersistentEventConnection.java32
5 files changed, 141 insertions, 13 deletions
diff --git a/src/main/java/org/onap/dcae/ApplicationSettings.java b/src/main/java/org/onap/dcae/ApplicationSettings.java
index 8bf32c4..9caf2f6 100644
--- a/src/main/java/org/onap/dcae/ApplicationSettings.java
+++ b/src/main/java/org/onap/dcae/ApplicationSettings.java
@@ -171,6 +171,11 @@ public class ApplicationSettings {
return prependWithUserDirOnRelative(properties.getString("collector.dmaapfile", "etc/DmaapConfig.json"));
}
+ public String controllerConfigFileLocation() {
+ return prependWithUserDirOnRelative(properties.getString("collector.eventinfo", "etc/ont_config.json"));
+ }
+
+
public String dMaaPStreamsMapping() {
return properties.getString("collector.rcc.dmaap.streamid", null);
}
diff --git a/src/main/java/org/onap/dcae/common/EventProcessor.java b/src/main/java/org/onap/dcae/common/EventProcessor.java
index cf44921..259e3b2 100644
--- a/src/main/java/org/onap/dcae/common/EventProcessor.java
+++ b/src/main/java/org/onap/dcae/common/EventProcessor.java
@@ -25,9 +25,13 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.onap.dcae.RestConfCollector;
import org.onap.dcae.common.publishing.EventPublisher;
+import org.onap.dcae.controller.PersistentEventConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -65,7 +69,7 @@ public class EventProcessor implements Runnable {
} else {
sendEventsToStreams(streamIdList, ev);
}
- log.info("Event published" + ev.getEventObj());
+
}
} catch (Exception e) {
log.error("EventProcessor InterruptedException" + e.getMessage());
@@ -75,11 +79,24 @@ public class EventProcessor implements Runnable {
private void sendEventsToStreams(String[] streamIdList, EventData ev) {
for (String aStreamIdList : streamIdList) {
- log.info("Invoking publisher for streamId:" + aStreamIdList);
+ log.info("Invoking publisher for streamId: " + aStreamIdList);
if (!ev.getConn().getEventRuleId().equals("")) {
- JSONObject customHeader = new JSONObject();
- customHeader.put("rule-id", ev.getConn().getEventRuleId());
- eventPublisher.sendEvent(overrideEvent(customHeader, ev.getEventObj()), aStreamIdList);
+ JSONObject modifiedObj = ev.getEventObj();
+ if (ev.getConn().isModifyEvent()){
+ try {
+ log.info("Invoking method " + ev.getConn().getModifyMethod() + " isModify " + ev.getConn().isModifyEvent());
+ modifiedObj = (JSONObject)(this.getClass().getMethod(ev.getConn().getModifyMethod(), EventData.class).invoke(this, ev));
+ }catch (Exception e) {
+ log.warn("No such method exist" + e);
+ }
+ }
+ JSONObject addRuleId = new JSONObject();
+ addRuleId.put("rule-id", ev.getConn().getEventRuleId());
+ JSONObject customHeader = overrideEvent(addRuleId, modifiedObj);
+ customHeader.put("notification-id", ev.getEventObj().getJSONObject("notification").get("notification-id"));
+ JSONObject finalObject = overrideEvent(customHeader, addRuleId);
+ log.info("Event published" + finalObject);
+ eventPublisher.sendEvent(finalObject, aStreamIdList);
} else {
eventPublisher.sendEvent(ev.getEventObj(), aStreamIdList);
}
@@ -97,7 +114,57 @@ public class EventProcessor implements Runnable {
} catch (JSONException e) {
throw new RuntimeException("JSON Exception" + e);
}
- log.info("Merged json " + mergedJSON);
+
return mergedJSON;
}
+
+ public JSONObject modifyOntEvent(EventData ev) {
+ PersistentEventConnection conn = ev.getConn();
+ JSONObject json1 = ev.getEventObj();
+ log.info("modifyOntEvent");
+ JSONObject newJSON = new JSONObject();
+ JSONObject finalObj = new JSONObject();
+ Path configFile = Paths.get(conn.getParentCtrllr().getProperties().controllerConfigFileLocation());
+ try {
+ //log.info("Paths " + configFile.toString());
+ String bytes = new String(Files.readAllBytes(configFile));
+ //log.info("Bytes " + bytes);
+ newJSON = new JSONObject(bytes);
+ newJSON.put("serialNumber", json1.getJSONObject("notification").getJSONObject("message").getJSONObject("content").getJSONObject("onu").get("sn"));
+ newJSON.put("softwareVersion", json1.getJSONObject("notification").getJSONObject("message").get("version"));
+
+ String refParentLTPNativeId = json1.getJSONObject("notification").getJSONObject("message").getJSONObject("content").getJSONObject("onu").get("refParentLTPNativeId").toString();
+ String olt_slot = "";
+ String olt_port = "";
+ String[] list = refParentLTPNativeId.split(",");
+ for (String aList : list) {
+ String domain = aList.split("=")[0];
+ String value = aList.substring(aList.indexOf('=') + 1);
+ switch (domain)
+ {
+ case "S":
+ olt_slot = value;
+ break;
+ case "PP":
+ olt_port = value.replaceAll("[^a-zA-Z0-9]", "");
+ break;
+ default:
+ log.info("Field" + domain + " value " + value);
+ break;
+ }
+ }
+ String oltName = json1.getJSONObject("notification").getJSONObject("message").getJSONObject("content").getJSONObject("onu").get("refParentNeNativeId").toString();
+ oltName = oltName.substring(3);
+ JSONObject additionalfields = newJSON.getJSONObject("additionalFields");
+ String attachment_point = oltName + "-" + olt_slot + "-" + olt_port;
+ additionalfields.put("attachment-point", attachment_point);
+ //additionalfields.put("remote-id", attachment-point);
+ } catch (Exception e) {
+ log.info("File reading error " + e);
+ }
+ //log.info("Modified json " + newJSON);
+ finalObj.put("pnfRegistration", newJSON);
+ log.info("final obj"+ finalObj.toString());
+ return finalObj;
+ }
}
diff --git a/src/main/java/org/onap/dcae/common/RestapiCallNode.java b/src/main/java/org/onap/dcae/common/RestapiCallNode.java
index 01da72d..6fb232c 100755
--- a/src/main/java/org/onap/dcae/common/RestapiCallNode.java
+++ b/src/main/java/org/onap/dcae/common/RestapiCallNode.java
@@ -34,10 +34,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
+import javax.net.ssl.*;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MultivaluedMap;
import java.io.FileInputStream;
@@ -46,6 +43,7 @@ import java.net.SocketException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyStore;
+import java.security.cert.X509Certificate;
import java.util.*;
import static org.onap.dcae.common.RestapiCallNodeUtil.getParameters;
@@ -319,6 +317,35 @@ public class RestapiCallNode {
}
protected HttpResponse sendHttpRequest(String request, Parameters p) throws Exception {
+ /* Enable this code if external controller's keyStore file not availabale */
+ /*Create a trust manager that does not validate certificate chains*/
+// TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
+// public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+// return null;
+// }
+// public void checkClientTrusted(X509Certificate[] certs, String authType) {
+// }
+// public void checkServerTrusted(X509Certificate[] certs, String authType) {
+// }
+// }
+// };
+//
+// // Install the all-trusting trust manager
+// SSLContext sc = SSLContext.getInstance("SSL");
+// sc.init(null, trustAllCerts, new java.security.SecureRandom());
+// HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
+//
+// // Create all-trusting host name verifier
+// HostnameVerifier allHostsValid = new HostnameVerifier() {
+// public boolean verify(String hostname, SSLSession session) {
+// return true;
+// }
+// };
+//
+// // Install the all-trusting host verifier
+// log.info("Warning!!! No SSL handshake **************************************");
+// HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
+ /*HELPER CODE END */
ClientConfig config = new DefaultClientConfig();
SSLContext ssl = null;
if (p.ssl && p.restapiUrl.startsWith("https")) {
@@ -330,7 +357,6 @@ public class RestapiCallNode {
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
new HTTPSProperties(hostnameVerifier, ssl));
}
-
logProperties(config.getProperties());
Client client = Client.create(config);
diff --git a/src/main/java/org/onap/dcae/controller/AccessController.java b/src/main/java/org/onap/dcae/controller/AccessController.java
index c77772e..c2ed5e3 100644
--- a/src/main/java/org/onap/dcae/controller/AccessController.java
+++ b/src/main/java/org/onap/dcae/controller/AccessController.java
@@ -176,6 +176,8 @@ public class AccessController {
.setEventUnSubscriptionTemplate(
event.get("event_unSubscriptionTemplate").toString())
.setEventRuleId(event.get("event_ruleId").toString()).setParentCtrllr(this)
+ .setModifyEvent(Boolean.parseBoolean(event.get("modifyData").toString()))
+ .setModifyMethod(event.get("modifyMethod").toString())
.createPersistentEventConnection();
eventList.put(name, conn);
diff --git a/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java b/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
index 860c0c9..c963129 100644
--- a/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
+++ b/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
@@ -55,7 +55,8 @@ public class PersistentEventConnection implements Runnable {
private EventConnectionState state;
private volatile boolean running = true;
private static final Logger log = LoggerFactory.getLogger(PersistentEventConnection.class);
-
+ private boolean modifyEvent;
+ private String modifyMethod;
private RestConfContext ctx;
private AccessController parentCtrllr;
@@ -72,6 +73,8 @@ public class PersistentEventConnection implements Runnable {
private String event_unSubscriptionTemplate;
private String event_ruleId;
private AccessController parentCtrllr;
+ private boolean modifyEvent;
+ private String modifyMethod;
public PersistentEventConnectionBuilder setEventName(String event_name) {
this.event_name = event_name;
@@ -118,9 +121,20 @@ public class PersistentEventConnection implements Runnable {
return this;
}
+ public PersistentEventConnectionBuilder setModifyEvent(boolean modifyEvent) {
+ this.modifyEvent = modifyEvent;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setModifyMethod(String modifyMethod) {
+ this.modifyMethod = modifyMethod;
+ return this;
+ }
public PersistentEventConnection createPersistentEventConnection() {
return new PersistentEventConnection(this);
}
+
+
}
@@ -135,6 +149,8 @@ public class PersistentEventConnection implements Runnable {
this.event_unSubscriptionTemplate = builder.event_unSubscriptionTemplate;
this.event_ruleId = builder.event_ruleId;
this.state = EventConnectionState.INIT;
+ this.modifyEvent = builder.modifyEvent;
+ this.modifyMethod = builder.modifyMethod;
this.ctx = new RestConfContext();
for (String s : builder.parentCtrllr.getCtx().getAttributeKeySet()) {
@@ -144,7 +160,7 @@ public class PersistentEventConnection implements Runnable {
this.eventParaMap = new HashMap<>();
this.eventParaMap.putAll(builder.parentCtrllr.getParaMap());
printEventParamMap();
- log.info("New persistent connection created " + event_name);
+ log.info("New persistent connection created " + event_name + "modify event " + modifyEvent);
}
@@ -254,6 +270,18 @@ public class PersistentEventConnection implements Runnable {
return eventParaMap.get(fieldName);
}
+ public AccessController getParentCtrllr() {
+ return parentCtrllr;
+ }
+
+ public boolean isModifyEvent() {
+ return modifyEvent;
+ }
+
+ public String getModifyMethod() {
+ return modifyMethod;
+ }
+
public void printEventParamMap() {
log.info("----------------Event Param Map-------------------");
for (String name : eventParaMap.keySet()) {