Enable NETCONF Adapter bundle logging
[appc.git] / appc-adapters / appc-netconf-adapter / appc-netconf-adapter-bundle / src / main / java / org / openecomp / appc / adapter / netconf / AppcNetconfAdapterActivator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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  */
21
22 package org.openecomp.appc.adapter.netconf;
23
24 import org.openecomp.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl;
25 import org.openecomp.sdnc.sli.resource.dblib.DbLibService;
26 import org.openecomp.appc.i18n.Msg;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.osgi.framework.BundleActivator;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.framework.ServiceReference;
32 import org.osgi.framework.ServiceRegistration;
33
34 public class AppcNetconfAdapterActivator implements BundleActivator {
35
36     /**
37      * The bundle registration
38      */
39     private ServiceRegistration registration = null;
40     private ServiceRegistration reporterRegistration = null;
41     private ServiceRegistration factoryRegistration = null;
42     private ServiceRegistration dbRegistration = null;
43
44     /**
45      * The reference to the actual implementation object that implements the services
46      */
47     private NetconfClientFactory clientFactory;
48     private NetconfDataAccessService DAService;
49
50     /**
51      * The logger to be used
52      */
53     private static final EELFLogger logger = EELFManager.getInstance().getLogger(AppcNetconfAdapterActivator.class);
54
55     /**
56      * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
57      * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
58      * <p>
59      * This method must complete and return to its caller in a timely manner.
60      * </p>
61      *
62      * @param context
63      *            The execution context of the bundle being started.
64      * @throws java.lang.Exception
65      *             If this method throws an exception, this bundle is marked as stopped and the Framework will remove
66      *             this bundle's listeners, unregister all services registered by this bundle, and release all services
67      *             used by this bundle.
68      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
69      */
70     @Override
71     public void start(BundleContext context) throws Exception {
72
73         if (registration == null) {
74             clientFactory = new NetconfClientFactory();
75             factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
76
77             DAService = new NetconfDataAccessServiceImpl();
78             //set dblib service
79             DbLibService dblibSvc = null;
80             ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
81             dblibSvc  = (DbLibService)context.getService(sref);
82             DAService.setDbLibService(dblibSvc);
83             ///////////////////////////////////
84             factoryRegistration = context.registerService(NetconfDataAccessService.class, DAService, null);
85         }
86
87         logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter");
88     }
89
90     /**
91      * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
92      * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
93      * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
94      * call any Framework objects.
95      * <p>
96      * This method must complete and return to its caller in a timely manner.
97      * </p>
98      *
99      * @param context
100      *            The execution context of the bundle being stopped.
101      * @throws java.lang.Exception
102      *             If this method throws an exception, the bundle is still marked as stopped, and the Framework will
103      *             remove the bundle's listeners, unregister all services registered by the bundle, and release all
104      *             services used by the bundle. *
105      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
106      */
107     @Override
108     public void stop(BundleContext context) throws Exception {
109         if (registration != null) {
110             registration.unregister();
111             registration = null;
112         }
113         if (reporterRegistration != null) {
114             reporterRegistration.unregister();
115             reporterRegistration = null;
116         }
117
118         if (null != factoryRegistration) {
119             factoryRegistration.unregister();
120             factoryRegistration = null;
121         }
122
123         if (dbRegistration != null) {
124             dbRegistration.unregister();
125             dbRegistration = null;
126         }
127     }
128
129     public String getName() {
130         return "APPC NETCONF adapter";
131     }
132
133 }