summaryrefslogtreecommitdiffstats
path: root/appc-event-listener
diff options
context:
space:
mode:
authorRY303T <RY303T@att.com>2018-02-21 16:42:18 -0500
committerPatrick Brady <pb071s@att.com>2018-02-22 23:41:58 +0000
commit5a99e9824824b2fa5f22945cd58cd5e3ee0df1ef (patch)
treeb9c916228c3440d70bbf9e34ab57df731934ca8d /appc-event-listener
parent7353bcd8f2b85a50720b7cc7ca04c837c7b1796a (diff)
modify listeners to only start when props present
Change-Id: If4ba1552eb6bc78a95f1b53292752181bc29cb2d Issue-ID: APPC-564 Signed-off-by: RY303T <RY303T@att.com>
Diffstat (limited to 'appc-event-listener')
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java34
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java36
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java10
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/TestAppcDmaapListenerActivator.java40
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/default.properties51
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/empty.properties33
6 files changed, 165 insertions, 39 deletions
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java
index a65b315e4..7795825b6 100644
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -108,25 +108,32 @@ public class AppcEventListenerActivator implements BundleActivator {
public void start(BundleContext ctx) throws Exception {
LOG.info("Starting Bundle " + getName());
- configuration = ConfigurationFactory.getConfiguration();
-
- Properties props = configuration.getProperties();
+ Properties props = getProperties();
Set<ListenerProperties> listeners = new HashSet<>();
// Configure event listener for the demo use case
ListenerProperties demoProps = new ListenerProperties("appc.demo", props);
- demoProps.setListenerClass(org.onap.appc.listener.demo.impl.ListenerImpl.class);
- listeners.add(demoProps);
+ // Only add the listener if properties are set
+ if (!demoProps.getProperties().isEmpty()) {
+ demoProps.setListenerClass(org.onap.appc.listener.demo.impl.ListenerImpl.class);
+ listeners.add(demoProps);
+ }
+
ListenerProperties clLCMProps = new ListenerProperties("appc.LCM", props);
- clLCMProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class);
- listeners.add(clLCMProps);
+ // Only add the listener if properties are set
+ if (!clLCMProps.getProperties().isEmpty()) {
+ clLCMProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class);
+ listeners.add(clLCMProps);
+ }
+
// Configure the OAM properties
String oamPropKeyPrefix = "appc.OAM";
ListenerProperties oamProps = new ListenerProperties(oamPropKeyPrefix, props);
- if (isAppcOamPropsListenerEnabled(oamProps)) {
+ // Only add the listener if properties are set and enabled is true
+ if (!oamProps.getProperties().isEmpty() && isAppcOamPropsListenerEnabled(oamProps)) {
oamProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class);
listeners.add(oamProps);
} else {
@@ -195,4 +202,13 @@ public class AppcEventListenerActivator implements BundleActivator {
return result;
}
+
+ /**
+ * Get properties from configuration
+ */
+ Properties getProperties() {
+ configuration = ConfigurationFactory.getConfiguration();
+ return configuration.getProperties();
+ }
+
}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java
index cc77eb91d..0cb470a8e 100644
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -69,17 +69,21 @@ public class ControllerImpl implements Controller {
} else {
LOG.error(String.format(
"The ListenerProperties %s has no Listener class associated with it and will not run.", props));
+ properties.remove(props);
}
}
LISTENER_COUNT = properties.size();
+ // Only create executor if listeners are configured
+ if (LISTENER_COUNT > 0) {
executor = new ThreadPoolExecutor(LISTENER_COUNT, LISTENER_COUNT, 1, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(LISTENER_COUNT));
// Custom Named thread factory
BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("Appc-Listener-%d").build();
executor.setThreadFactory(threadFactory);
+ }
}
@Override
@@ -107,28 +111,30 @@ public class ControllerImpl implements Controller {
Iterator<Listener> itr = listeners.values().iterator();
while (itr.hasNext()) {
Listener l = itr.next();
- if (stopNow) {
+ if (stopNow && l != null) {
l.stopNow();
- } else {
+ } else if(l!=null){
l.stop();
}
itr.remove();
}
// disable new tasks from being submitted
- executor.shutdown();
- int timeout=300;
- try {
- if (!executor.awaitTermination(timeout, TimeUnit.SECONDS)) {
- LOG.error("Not all tasks completed execution after " + timeout + " seconds. " +
- "Attempting to stop all actively executing tasks.");
+ if(executor != null) {
+ executor.shutdown();
+ int timeout=300;
+ try {
+ if (!executor.awaitTermination(timeout, TimeUnit.SECONDS)) {
+ LOG.error("Not all tasks completed execution after " + timeout + " seconds. " +
+ "Attempting to stop all actively executing tasks.");
+ executor.shutdownNow();
+ }
+ if (!executor.awaitTermination(timeout, TimeUnit.SECONDS)) {
+ LOG.error("Could not terminate all tasks after " + (timeout*2) + " seconds.");
+ }
+ } catch (InterruptedException e) {
executor.shutdownNow();
+ Thread.currentThread().interrupt();
}
- if (!executor.awaitTermination(timeout, TimeUnit.SECONDS)) {
- LOG.error("Could not terminate all tasks after " + (timeout*2) + " seconds.");
- }
- } catch (InterruptedException e) {
- executor.shutdownNow();
- Thread.currentThread().interrupt();
}
}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java
index 4b4959725..e8fe15f20 100644
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -36,6 +36,7 @@ import org.onap.appc.listener.EventHandler;
import org.onap.appc.listener.ListenerProperties;
import org.onap.appc.listener.util.Mapper;
import org.onap.appc.logging.LoggingConstants;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
@@ -206,7 +207,12 @@ public class EventHandlerImpl implements EventHandler {
}
Consumer out = null;
- BundleContext ctx = FrameworkUtil.getBundle(EventHandlerImpl.class).getBundleContext();
+ BundleContext ctx = null;
+ Bundle bundle = FrameworkUtil.getBundle(EventHandlerImpl.class);
+ if(bundle != null) {
+ ctx = bundle.getBundleContext();
+ }
+
if (ctx != null) {
ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName());
if (svcRef != null) {
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/TestAppcDmaapListenerActivator.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/TestAppcDmaapListenerActivator.java
index 6bb96b95c..f8cbdb3dc 100644
--- a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/TestAppcDmaapListenerActivator.java
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/TestAppcDmaapListenerActivator.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -27,18 +27,25 @@ package org.onap.appc.listener;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.mockito.Mockito.doReturn;
+
import org.onap.appc.listener.AppcEventListenerActivator;
public class TestAppcDmaapListenerActivator {
@Test
- public void testStartStop() {
- // TODO - How do we tests activators
+ public void testStartStopDefaultProperties() {
AppcEventListenerActivator appc = new AppcEventListenerActivator();
try {
appc.start(null);
- Thread.sleep(2000);
+ Thread.sleep(1000);
appc.stop(null);
} catch (Exception e) {
e.printStackTrace();
@@ -46,4 +53,29 @@ public class TestAppcDmaapListenerActivator {
}
assertNotNull(appc.getName());
}
+
+ @Test
+ public void testStartStopEmptyProperties() {
+ InputStream input = getClass().getResourceAsStream("/org/onap/appc/empty.properties");
+ Properties props = new Properties();
+ try {
+ props.load(input);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ AppcEventListenerActivator appc = new AppcEventListenerActivator();
+ AppcEventListenerActivator spyAppc = Mockito.spy(appc);
+ doReturn(props).when(spyAppc).getProperties();
+
+ try {
+ spyAppc.start(null);
+ Thread.sleep(1000);
+ spyAppc.stop(null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(spyAppc.getName());
+ }
}
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/default.properties b/appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/default.properties
index 3bd5bf409..5929f287e 100644
--- a/appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/default.properties
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/default.properties
@@ -2,7 +2,7 @@
# ============LICENSE_START=======================================================
# ONAP : APPC
# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Copyright (C) 2017 Amdocs
# =============================================================================
@@ -81,12 +81,45 @@ appc.ClosedLoop1607.threads.poolsize.min=1
appc.ClosedLoop1607.threads.poolsize.max=2
appc.ClosedLoop1607.provider.url=https://admin:password@localhost:8443/restconf/operations/appc-provider:topology-operation
+### ###
+### LCM properties ###
+### ###
+appc.LCM.disabled=true
+appc.LCM.poolMembers=192.168.1.2:3904
+appc.LCM.topic.read=MY_DMAAP_TOPIC
+appc.LCM.topic.write=MY_DMAAP_TOPIC
+appc.LCM.topic.read.filter={"class":"Unassigned","field":"Status"}
+appc.LCM.client.name=DMAAP-CLIENT-NAME
+appc.LCM.client.name.id=0
+appc.LCM.threads.queuesize.min=1
+appc.LCM.threads.queuesize.max=1000
+appc.LCM.threads.poolsize.min=1
+appc.LCM.threads.poolsize.max=2
+appc.LCM.provider.url=https://admin:password@localhost:8443/restconf/operations/appc-provider:topology-operation
-
-
-
-### ###
-### POINT TO AN ACTIVE TEST VM IN OPENSTACK INSTANCE ###
-### ###
-test.vm_url=https://example.com/v2/123/servers/123-345
-
+### ###
+### DEMO properties ###
+### ###
+appc.demo.poolMembers=192.168.1.2:3904
+appc.demo.topic.read=MY_DMAAP_TOPIC
+appc.demo.topic.write=MY_DMAAP_TOPIC
+appc.demo.topic.read.filter={"class":"Unassigned","field":"Status"}
+appc.demo.client.name=DMAAP-CLIENT-NAME
+appc.demo.client.name.id=0
+appc.demo.threads.queuesize.min=1
+appc.demo.threads.queuesize.max=1000
+appc.demo.threads.poolsize.min=1
+appc.demo.threads.poolsize.max=2
+
+# OAM Listener
+#########################
+appc.OAM.disabled=false
+appc.OAM.poolMembers=192.168.1.2:3904
+appc.OAM.topic.read=OAM_TOPIC
+appc.OAM.topic.write=OAM_TOPIC
+appc.OAM.client.name=OAM_CLIENT
+#appc.OAM.provider.url=
+#appc.OAM.provider.user=m97292@appc.att.com
+#appc.OAM.provider.pass=enc:DBE7PBN7EAN+Pwom
+
+appc.demo.provider.url=https://admin:password@localhost:8443/restconf/operations/appc-provider:topology-operation \ No newline at end of file
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/empty.properties b/appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/empty.properties
new file mode 100644
index 000000000..674c1197a
--- /dev/null
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/resources/org/onap/appc/empty.properties
@@ -0,0 +1,33 @@
+###
+# ============LICENSE_START=======================================================
+# ONAP : APPC
+# ================================================================================
+# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# ================================================================================
+# Copyright (C) 2017 Amdocs
+# =============================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+# ============LICENSE_END=========================================================
+###
+
+
+
+
+
+### ###
+### ###
+###Properties below are default values to be provided with real valuesin appc.properties###
+### ###
+### ###