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 App-C Closed Loop Listener
 
 122 /*        ListenerProperties clProps = new ListenerProperties("appc.ClosedLoop", props);
 
 123         clProps.setListenerClass(org.openecomp.appc.listener.CL.impl.ListenerImpl.class);
 
 124         listeners.add(clProps);*/
 
 126         // Configure App-C 1607 Closed Loop Listener
 
 127         ListenerProperties cl1607Props = new ListenerProperties("appc.ClosedLoop1607", props);
 
 128         cl1607Props.setListenerClass(org.openecomp.appc.listener.CL1607.impl.ListenerImpl.class);
 
 129         listeners.add(cl1607Props);                                                             
 
 132 /*        ListenerProperties clLCMProps = new ListenerProperties("appc.LCM", props);
 
 133         clLCMProps.setListenerClass(org.openecomp.appc.listener.LCM.impl.ListenerImpl.class);
 
 134         listeners.add(clLCMProps);*/
 
 137         ListenerProperties clLCMProps1607 = new ListenerProperties("appc.LCM1607", props);
 
 138         clLCMProps1607.setListenerClass(org.openecomp.appc.listener.LCM1607.impl.ListenerImpl.class);
 
 139         listeners.add(clLCMProps1607);
 
 142         adapter = new ControllerImpl(listeners);
 
 143         if (ctx != null && registration == null) {
 
 144             LOG.info("Registering service DMaaP Controller");
 
 145             registration = ctx.registerService(Controller.class, adapter, null);
 
 149         LOG.info("DMaaP Listener started successfully");
 
 153      * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
 
 154      * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
 
 155      * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
 
 156      * call any Framework objects.
 
 158      * This method must complete and return to its caller in a timely manner.
 
 162      *            The execution context of the bundle being stopped.
 
 163      * @throws java.lang.Exception
 
 164      *             If this method throws an exception, the bundle is still marked as stopped, and the Framework will
 
 165      *             remove the bundle's listeners, unregister all services registered by the bundle, and release all
 
 166      *             services used by the bundle. *
 
 167      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
 
 170     public void stop(BundleContext ctx) throws Exception {
 
 171         boolean stopNow = true;
 
 172         LOG.info("Stopping DMaaP Listener. StopNow=" + stopNow);
 
 173         adapter.stop(stopNow);
 
 174         if (registration != null) {
 
 175             registration.unregister();
 
 178         LOG.info("DMaaP Listener stopped successfully");
 
 181     public String getName() {
 
 182         return "DMaaP Listener";