diff options
Diffstat (limited to 'src')
6 files changed, 166 insertions, 15 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()) { diff --git a/src/test/java/org/onap/dcae/common/EventProcessorTest.java b/src/test/java/org/onap/dcae/common/EventProcessorTest.java index 4d9fade..575443f 100644 --- a/src/test/java/org/onap/dcae/common/EventProcessorTest.java +++ b/src/test/java/org/onap/dcae/common/EventProcessorTest.java @@ -86,6 +86,7 @@ public class EventProcessorTest { when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString()); when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString()); when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString()); + when(properties.controllerConfigFileLocation()).thenReturn(Paths.get("etc/ont_config.json").toAbsolutePath().toString()); JSONObject controller = new JSONObject( "{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\",\"event_details\":[{\"event_name\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\"}]}"); AccessController acClr = new AccessController(controller, properties); @@ -93,11 +94,33 @@ public class EventProcessorTest { PersistentEventConnection p = new PersistentEventConnection.PersistentEventConnectionBuilder().setEventName("") .setEventDescription("").setEventSseventUrlEmbed(true).setEventSseventsField("").setEventSseventsUrl("") .setEventSubscriptionTemplate("").setEventUnSubscriptionTemplate("").setEventRuleId("1234646346") - .setParentCtrllr(acClr).createPersistentEventConnection(); + .setParentCtrllr(acClr).setModifyEvent(true).setModifyMethod("modifyOntEvent").createPersistentEventConnection(); p.getEventParamMapValue("restapiUrl"); p.modifyEventParamMap("restapiUrl", "10.118.191.43:26335"); RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4); - RestConfCollector.fProcessingInputQueue.offer(new EventData(p, new JSONObject("{}"))); + RestConfCollector.fProcessingInputQueue.offer(new EventData(p, new JSONObject("{\n" + + " \"notification\" : {\n" + + " \"notification-id\" : \"01010101011\",\n" + + " \"event-time\" : \"2019-3-9T3:30:30.547z\",\n" + + " \"message\" : {\n" + + " \"object-type\" : \"onu\",\n" + + " \"topic\" : \"resources\",\n" + + " \"version\" : \"v1\",\n" + + " \"operation\" : \"create\",\n" + + " \"content\" : {\n" + + " \"onu\" : {\n" + + " \"alias\" : \"\",\n" + + " \"refParentLTP\" : \"gpon.0.5.1\",\n" + + " \"sn\" : \"HWTCC01B7503\",\n" + + " \"refParentLTPNativeId\" : \"NE=167772165,FR=0,S=5,CP=-1,PP=||1|\",\n" + + " \"onuId\": \"\",\n" + + " \"refParentNE\" : \"aaaaaaaaa-aaaaa-aaaa-aaaa-aaa167772165\",\n" + + " \"refParentNeNativeId\": \"NE=167772165\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"))); RestConfCollector.fProcessingInputQueue.offer(new EventData(null, null)); EventProcessor ev = new EventProcessor(eventPublisher, streamMap); ev.run(); |