2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.listener;
25 import org.openecomp.appc.configuration.Configuration;
26 import org.openecomp.appc.configuration.ConfigurationFactory;
27 import org.openecomp.appc.listener.impl.ControllerImpl;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
31 import org.osgi.framework.BundleActivator;
32 import org.osgi.framework.BundleContext;
33 import org.osgi.framework.ServiceRegistration;
35 import java.util.HashSet;
36 import java.util.Properties;
40 * This activator is used to initialize and terminate the dmaap listener controller and pool(s)
42 * The DMaaP listener is responsible for listening to a topic on the Universal Event Bus and reading in messages that
43 * conform to the DCAE message format for APPC. These messages will then be parsed and passed along to the APPC Provider
44 * to take action on. The listener will also send messages out on DMaaP during critical phases. The messages sent out will
47 * <li><i>PENDING</i> - The listener has read the message off of DMaaP and has put it in the queue to be processed</li>
48 * <li><i>ACTIVE</i> - The listener has begun actually processing the request and is waiting on the appc provider to
49 * complete the request</li>
50 * <li><i>SUCCESS</i> or <i>FAILURE</i> - The listener has gotten a response back from the appc provider. If it is a
51 * FAILURE, a message should also be included</li>
55 * Activation of the bundle will provision 1 controller that in turn will provision 1 (or in the future more) listener
56 * to interact with DMaaP. Each listener will have a queue of messages read off of DMaaP and a thread pool of workers to
57 * process them. This worker is responsible for contacting appc provider to perform the action
60 * When the bundle is deactivated, the stopNow() method is called and the thread pool is emptied and all remaining jobs
61 * are orphaned. Alternatively stop() could be called which would allow all remaining jobs in the queue to complete at
62 * the cost of longer run time.
68 public class AppcEventListenerActivator implements BundleActivator {
71 * The bundle registration
73 private ServiceRegistration registration = null;
76 * The configuration object
78 private Configuration configuration;
83 private static BundleContext context;
86 * The reference to the actual implementation object that implements the services
88 private Controller adapter;
91 * The logger to be used
93 private final EELFLogger LOG = EELFManager.getInstance().getLogger(AppcEventListenerActivator.class);
96 * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
97 * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
99 * This method must complete and return to its caller in a timely manner.
103 * The execution context of the bundle being started.
104 * @throws java.lang.Exception
105 * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
106 * this bundle's listeners, unregister all services registered by this bundle, and release all services
107 * used by this bundle.
108 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
111 public void start(BundleContext ctx) throws Exception {
112 LOG.info("Starting Bundle " + getName());
116 configuration = ConfigurationFactory.getConfiguration();
118 Properties props = configuration.getProperties();
120 Set<ListenerProperties> listeners = new HashSet<ListenerProperties>();
122 // Configure event listener for the demo use case
123 ListenerProperties demoProps = new ListenerProperties("appc.demo", props);
124 demoProps.setListenerClass(org.openecomp.appc.listener.demo.impl.ListenerImpl.class);
125 listeners.add(demoProps);
127 // ===========================================================================
129 adapter = new ControllerImpl(listeners);
130 if (ctx != null && registration == null) {
131 LOG.info("Registering service DMaaP Controller");
132 registration = ctx.registerService(Controller.class, adapter, null);
136 LOG.info("DMaaP Listener started successfully");
140 * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
141 * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
142 * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
143 * call any Framework objects.
145 * This method must complete and return to its caller in a timely manner.
149 * The execution context of the bundle being stopped.
150 * @throws java.lang.Exception
151 * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
152 * remove the bundle's listeners, unregister all services registered by the bundle, and release all
153 * services used by the bundle. *
154 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
157 public void stop(BundleContext ctx) throws Exception {
158 boolean stopNow = true;
159 LOG.info("Stopping DMaaP Listener. StopNow=" + stopNow);
160 adapter.stop(stopNow);
161 if (registration != null) {
162 registration.unregister();
165 LOG.info("DMaaP Listener stopped successfully");
168 public String getName() {
169 return "DMaaP Listener";