2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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=========================================================
22 package org.openecomp.appc.listener;
24 import org.openecomp.appc.configuration.Configuration;
25 import org.openecomp.appc.configuration.ConfigurationFactory;
26 import org.openecomp.appc.listener.impl.ControllerImpl;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import org.osgi.framework.BundleActivator;
31 import org.osgi.framework.BundleContext;
32 import org.osgi.framework.ServiceRegistration;
34 import java.util.HashSet;
35 import java.util.Properties;
39 * This activator is used to initialize and terminate the dmaap listener controller and pool(s)
41 * The DMaaP listener is responsible for listening to a topic on the Universal Event Bus and reading in messages that
42 * conform to the DCAE message format for APPC. These messages will then be parsed and passed along to the APPC Provider
43 * to take action on. The listener will also send messages out on DMaaP during critical phases. The messages sent out will
46 * <li><i>PENDING</i> - The listener has read the message off of DMaaP and has put it in the queue to be processed</li>
47 * <li><i>ACTIVE</i> - The listener has begun actually processing the request and is waiting on the appc provider to
48 * complete the request</li>
49 * <li><i>SUCCESS</i> or <i>FAILURE</i> - The listener has gotten a response back from the appc provider. If it is a
50 * FAILURE, a message should also be included</li>
54 * Activation of the bundle will provision 1 controller that in turn will provision 1 (or in the future more) listener
55 * to interact with DMaaP. Each listener will have a queue of messages read off of DMaaP and a thread pool of workers to
56 * process them. This worker is responsible for contacting appc provider to perform the action
59 * When the bundle is deactivated, the stopNow() method is called and the thread pool is emptied and all remaining jobs
60 * are orphaned. Alternatively stop() could be called which would allow all remaining jobs in the queue to complete at
61 * the cost of longer run time.
67 public class AppcEventListenerActivator implements BundleActivator {
70 * The bundle registration
72 private ServiceRegistration registration = null;
75 * The configuration object
77 private Configuration configuration;
82 private static BundleContext context;
85 * The reference to the actual implementation object that implements the services
87 private Controller adapter;
90 * The logger to be used
92 private final EELFLogger LOG = EELFManager.getInstance().getLogger(AppcEventListenerActivator.class);
95 * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
96 * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
98 * This method must complete and return to its caller in a timely manner.
102 * The execution context of the bundle being started.
103 * @throws java.lang.Exception
104 * If this method throws an exception, this bundle is marked as stopped and the Framework will remove
105 * this bundle's listeners, unregister all services registered by this bundle, and release all services
106 * used by this bundle.
107 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
110 public void start(BundleContext ctx) throws Exception {
111 LOG.info("Starting Bundle " + getName());
115 configuration = ConfigurationFactory.getConfiguration();
117 Properties props = configuration.getProperties();
119 Set<ListenerProperties> listeners = new HashSet<ListenerProperties>();
121 // Configure event listener for the demo use case
122 ListenerProperties demoProps = new ListenerProperties("appc.demo", props);
123 demoProps.setListenerClass(org.openecomp.appc.listener.demo.impl.ListenerImpl.class);
124 listeners.add(demoProps);
126 // ===========================================================================
128 adapter = new ControllerImpl(listeners);
129 if (ctx != null && registration == null) {
130 LOG.info("Registering service DMaaP Controller");
131 registration = ctx.registerService(Controller.class, adapter, null);
135 LOG.info("DMaaP Listener started successfully");
139 * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
140 * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
141 * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
142 * call any Framework objects.
144 * This method must complete and return to its caller in a timely manner.
148 * The execution context of the bundle being stopped.
149 * @throws java.lang.Exception
150 * If this method throws an exception, the bundle is still marked as stopped, and the Framework will
151 * remove the bundle's listeners, unregister all services registered by the bundle, and release all
152 * services used by the bundle. *
153 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
156 public void stop(BundleContext ctx) throws Exception {
157 boolean stopNow = true;
158 LOG.info("Stopping DMaaP Listener. StopNow=" + stopNow);
159 adapter.stop(stopNow);
160 if (registration != null) {
161 registration.unregister();
164 LOG.info("DMaaP Listener stopped successfully");
167 public String getName() {
168 return "DMaaP Listener";