2 * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
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
9 package org.opendaylight.netconf.console.impl;
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;
22 public class NetconfConsoleProvider implements BindingAwareProvider, AutoCloseable {
24 private static final Logger LOG = LoggerFactory.getLogger(NetconfConsoleProvider.class);
25 private ServiceRegistration<NetconfCommands> netconfConsoleRegistration;
28 public void onSessionInitiated(ProviderContext session) {
29 LOG.info("NetconfProvider Session Initiated");
31 // Retrieve DataBroker service to interact with md-sal
32 final DataBroker dataBroker = session.getSALService(DataBroker.class);
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();
38 // Initialization of NETCONF Console Provider service implementation
39 initializeNetconfConsoleProvider(dataBroker, context, mountService);
42 private void initializeNetconfConsoleProvider(DataBroker dataBroker, BundleContext context, MountPointService mountService) {
43 // Initialize NetconfConsoleProviderImpl class
44 final NetconfCommandsImpl consoleProvider = new NetconfCommandsImpl(dataBroker, mountService);
46 // Register the NetconfConsoleProvider service
47 netconfConsoleRegistration = context.registerService(NetconfCommands.class, consoleProvider, null);
51 public void close() throws Exception {
52 LOG.info("NetconfProvider closed.");
53 netconfConsoleRegistration.unregister();