Merge "Bug 4868 - Extend netconf-node-topology model to distinguish user overriden...
[netconf.git] / netconf / netconf-console / src / main / java / org / opendaylight / netconf / console / impl / NetconfConsoleProvider.java
1 /*
2  * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.netconf.console.impl;
10
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
15 import org.opendaylight.netconf.console.api.NetconfCommands;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.FrameworkUtil;
18 import org.osgi.framework.ServiceRegistration;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class NetconfConsoleProvider implements BindingAwareProvider, AutoCloseable {
23
24     private static final Logger LOG = LoggerFactory.getLogger(NetconfConsoleProvider.class);
25     private ServiceRegistration<NetconfCommands> netconfConsoleRegistration;
26
27     @Override
28     public void onSessionInitiated(ProviderContext session) {
29         LOG.info("NetconfProvider Session Initiated");
30
31         // Retrieve DataBroker service to interact with md-sal
32         final DataBroker dataBroker =  session.getSALService(DataBroker.class);
33
34         // Retrieve MountPointService to interact with NETCONF remote devices connected to ODL and register it
35         final MountPointService mountService = session.getSALService(MountPointService.class);
36         final BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
37
38         // Initialization of NETCONF Console Provider service implementation
39         initializeNetconfConsoleProvider(dataBroker, context, mountService);
40     }
41
42     private void initializeNetconfConsoleProvider(DataBroker dataBroker, BundleContext context, MountPointService mountService) {
43         // Initialize NetconfConsoleProviderImpl class
44         final NetconfCommandsImpl consoleProvider = new NetconfCommandsImpl(dataBroker, mountService);
45
46         // Register the NetconfConsoleProvider service
47         netconfConsoleRegistration = context.registerService(NetconfCommands.class, consoleProvider, null);
48     }
49
50     @Override
51     public void close() throws Exception {
52         LOG.info("NetconfProvider closed.");
53         netconfConsoleRegistration.unregister();
54     }
55 }