Second part of onap rename
[appc.git] / appc-adapters / appc-netconf-adapter / appc-netconf-adapter-bundle / src / main / java / org / onap / appc / adapter / netconf / AppcNetconfAdapterActivator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.adapter.netconf;
26
27 import org.onap.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl;
28 import org.onap.ccsdk.sli.core.dblib.DbLibService;
29 import org.onap.appc.i18n.Msg;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import org.osgi.framework.BundleActivator;
33 import org.osgi.framework.BundleContext;
34 import org.osgi.framework.ServiceReference;
35 import org.osgi.framework.ServiceRegistration;
36
37 public class AppcNetconfAdapterActivator implements BundleActivator {
38
39     /**
40      * The bundle registration
41      */
42     private ServiceRegistration registration = null;
43     private ServiceRegistration reporterRegistration = null;
44     private ServiceRegistration factoryRegistration = null;
45     private ServiceRegistration dbRegistration = null;
46
47     /**
48      * The reference to the actual implementation object that implements the services
49      */
50     private NetconfClientFactory clientFactory;
51     private NetconfDataAccessService DAService;
52
53     /**
54      * The logger to be used
55      */
56     private static final EELFLogger logger = EELFManager.getInstance().getLogger(AppcNetconfAdapterActivator.class);
57
58     /**
59      * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
60      * this bundle. This method can be used to register services or to allocate any resources that this bundle needs.
61      * <p>
62      * This method must complete and return to its caller in a timely manner.
63      * </p>
64      *
65      * @param context
66      *            The execution context of the bundle being started.
67      * @throws java.lang.Exception
68      *             If this method throws an exception, this bundle is marked as stopped and the Framework will remove
69      *             this bundle's listeners, unregister all services registered by this bundle, and release all services
70      *             used by this bundle.
71      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
72      */
73     @Override
74     public void start(BundleContext context) throws Exception {
75         if (registration == null) {
76             clientFactory = new NetconfClientFactory();
77             factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
78
79             DAService = new NetconfDataAccessServiceImpl();
80             //set dblib service
81             DbLibService dblibSvc = null;
82             ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
83             try{
84             dblibSvc  = (DbLibService)context.getService(sref);
85             }catch(Exception e){
86                 logger.error(e.getMessage());
87             }
88             DAService.setDbLibService(dblibSvc);
89             ///////////////////////////////////
90             factoryRegistration = context.registerService(NetconfDataAccessService.class, DAService, null);
91         }
92
93         logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter");
94     }
95
96     /**
97      * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop
98      * the bundle. In general, this method should undo the work that the BundleActivator.start method started. There
99      * should be no active threads that were started by this bundle when this bundle returns. A stopped bundle must not
100      * call any Framework objects.
101      * <p>
102      * This method must complete and return to its caller in a timely manner.
103      * </p>
104      *
105      * @param context
106      *            The execution context of the bundle being stopped.
107      * @throws java.lang.Exception
108      *             If this method throws an exception, the bundle is still marked as stopped, and the Framework will
109      *             remove the bundle's listeners, unregister all services registered by the bundle, and release all
110      *             services used by the bundle. *
111      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
112      */
113     @Override
114     public void stop(BundleContext context) throws Exception {
115         if (registration != null) {
116             registration.unregister();
117             registration = null;
118         }
119         if (reporterRegistration != null) {
120             reporterRegistration.unregister();
121             reporterRegistration = null;
122         }
123
124         if (null != factoryRegistration) {
125             factoryRegistration.unregister();
126             factoryRegistration = null;
127         }
128
129         if (dbRegistration != null) {
130             dbRegistration.unregister();
131             dbRegistration = null;
132         }
133     }
134
135     public String getName() {
136         return "APPC NETCONF adapter";
137     }
138
139 }