summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/dcae/controller/AccessController.java22
-rw-r--r--src/main/java/org/onap/dcae/controller/PersistentEventConnection.java113
-rw-r--r--src/test/java/org/onap/dcae/common/EventProcessorTest.java14
3 files changed, 106 insertions, 43 deletions
diff --git a/src/main/java/org/onap/dcae/controller/AccessController.java b/src/main/java/org/onap/dcae/controller/AccessController.java
index 226ead5..1c78d99 100644
--- a/src/main/java/org/onap/dcae/controller/AccessController.java
+++ b/src/main/java/org/onap/dcae/controller/AccessController.java
@@ -165,15 +165,19 @@ public class AccessController {
for (int j = 0; j < eventlists.length(); j++) {
JSONObject event = eventlists.getJSONObject(j);
String name = event.get("event_name").toString();
- PersistentEventConnection conn = new PersistentEventConnection(name,
- event.get("event_description").toString(),
- Boolean.parseBoolean(event.get("event_sseventUrlEmbed").toString()),
- event.get("event_sseventsField").toString(),
- event.get("event_sseventsUrl").toString(),
- event.get("event_subscriptionTemplate").toString(),
- event.get("event_unSubscriptionTemplate").toString(),
- event.get("event_ruleId").toString(),
- this);
+ PersistentEventConnection conn =
+ new PersistentEventConnection.PersistentEventConnectionBuilder().setEventName(name)
+ .setEventDescription(event.get("event_description").toString())
+ .setEventSseventUrlEmbed(
+ Boolean.parseBoolean(event.get("event_sseventUrlEmbed").toString()))
+ .setEventSseventsField(event.get("event_sseventsField").toString())
+ .setEventSseventsUrl(event.get("event_sseventsUrl").toString())
+ .setEventSubscriptionTemplate(
+ event.get("event_subscriptionTemplate").toString())
+ .setEventUnSubscriptionTemplate(
+ event.get("event_unSubscriptionTemplate").toString())
+ .setEventRuleId(event.get("event_ruleId").toString()).setParentCtrllr(this)
+ .createPersistentEventConnection();
eventList.put(name, conn);
executor.execute(conn);
diff --git a/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java b/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
index 047936d..860c0c9 100644
--- a/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
+++ b/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
@@ -61,34 +61,91 @@ public class PersistentEventConnection implements Runnable {
private AccessController parentCtrllr;
private Map<String, String> eventParaMap;
- public PersistentEventConnection(String event_name,
- String event_description,
- boolean event_sseventUrlEmbed,
- String event_sseventsField,
- String event_sseventsUrl,
- String event_subscriptionTemplate,
- String event_unSubscriptionTemplate,
- String event_ruleId,
- AccessController parentCtrllr) {
- this.event_name = event_name;
- this.event_description = event_description;
- this.event_sseventUrlEmbed = event_sseventUrlEmbed;
- this.event_sseventsField = event_sseventsField;
- this.event_sseventsUrl = event_sseventsUrl;
- this.event_subscriptionTemplate = event_subscriptionTemplate;
- this.event_unSubscriptionTemplate = event_unSubscriptionTemplate;
- this.event_ruleId = event_ruleId;
- this.state = EventConnectionState.INIT;
-
- this.ctx = new RestConfContext();
- for (String s : parentCtrllr.getCtx().getAttributeKeySet()) {
- this.ctx.setAttribute(s, ctx.getAttribute(s));
- }
- this.parentCtrllr = parentCtrllr;
- this.eventParaMap = new HashMap<>();
- this.eventParaMap.putAll(parentCtrllr.getParaMap());
- printEventParamMap();
- log.info("New persistent connection created " + event_name);
+
+ public static class PersistentEventConnectionBuilder {
+ private String event_name;
+ private String event_description;
+ private boolean event_sseventUrlEmbed;
+ private String event_sseventsField;
+ private String event_sseventsUrl;
+ private String event_subscriptionTemplate;
+ private String event_unSubscriptionTemplate;
+ private String event_ruleId;
+ private AccessController parentCtrllr;
+
+ public PersistentEventConnectionBuilder setEventName(String event_name) {
+ this.event_name = event_name;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setEventDescription(String event_description) {
+ this.event_description = event_description;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setEventSseventUrlEmbed(boolean event_sseventUrlEmbed) {
+ this.event_sseventUrlEmbed = event_sseventUrlEmbed;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setEventSseventsField(String event_sseventsField) {
+ this.event_sseventsField = event_sseventsField;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setEventSseventsUrl(String event_sseventsUrl) {
+ this.event_sseventsUrl = event_sseventsUrl;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setEventSubscriptionTemplate(String event_subscriptionTemplate) {
+ this.event_subscriptionTemplate = event_subscriptionTemplate;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setEventUnSubscriptionTemplate(String event_unSubscriptionTemplate) {
+ this.event_unSubscriptionTemplate = event_unSubscriptionTemplate;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setEventRuleId(String event_ruleId) {
+ this.event_ruleId = event_ruleId;
+ return this;
+ }
+
+ public PersistentEventConnectionBuilder setParentCtrllr(AccessController parentCtrllr) {
+ this.parentCtrllr = parentCtrllr;
+ return this;
+ }
+
+ public PersistentEventConnection createPersistentEventConnection() {
+ return new PersistentEventConnection(this);
+ }
+ }
+
+
+ private PersistentEventConnection(PersistentEventConnectionBuilder builder){
+
+ this.event_name = builder.event_name;
+ this.event_description = builder.event_description;
+ this.event_sseventUrlEmbed = builder.event_sseventUrlEmbed;
+ this.event_sseventsField = builder.event_sseventsField;
+ this.event_sseventsUrl = builder.event_sseventsUrl;
+ this.event_subscriptionTemplate = builder.event_subscriptionTemplate;
+ this.event_unSubscriptionTemplate = builder.event_unSubscriptionTemplate;
+ this.event_ruleId = builder.event_ruleId;
+ this.state = EventConnectionState.INIT;
+
+ this.ctx = new RestConfContext();
+ for (String s : builder.parentCtrllr.getCtx().getAttributeKeySet()) {
+ this.ctx.setAttribute(s, ctx.getAttribute(s));
+ }
+ this.parentCtrllr = builder.parentCtrllr;
+ this.eventParaMap = new HashMap<>();
+ this.eventParaMap.putAll(builder.parentCtrllr.getParaMap());
+ printEventParamMap();
+ log.info("New persistent connection created " + event_name);
+
}
@Override
diff --git a/src/test/java/org/onap/dcae/common/EventProcessorTest.java b/src/test/java/org/onap/dcae/common/EventProcessorTest.java
index 406a0fe..4d9fade 100644
--- a/src/test/java/org/onap/dcae/common/EventProcessorTest.java
+++ b/src/test/java/org/onap/dcae/common/EventProcessorTest.java
@@ -86,12 +86,14 @@ 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());
- 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);
-
- PersistentEventConnection p = new PersistentEventConnection("","",true, "",
- "","","","1234646346", acClr);
+ 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);
+
+ PersistentEventConnection p = new PersistentEventConnection.PersistentEventConnectionBuilder().setEventName("")
+ .setEventDescription("").setEventSseventUrlEmbed(true).setEventSseventsField("").setEventSseventsUrl("")
+ .setEventSubscriptionTemplate("").setEventUnSubscriptionTemplate("").setEventRuleId("1234646346")
+ .setParentCtrllr(acClr).createPersistentEventConnection();
p.getEventParamMapValue("restapiUrl");
p.modifyEventParamMap("restapiUrl", "10.118.191.43:26335");
RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4);