From 201c71af265bea1af1188b788199a86e2dfb63b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20de=20Talhou=C3=ABt?= Date: Fri, 16 Sep 2016 09:50:38 -0400 Subject: [PATCH] Add blueprint wiring for netconf-console MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also fix potential NPE when netconf:list-device is called before the topology-netconf is initialized Change-Id: Ic4e33ea7717511c26aa9cc9cbde4148f3e5549ac Signed-off-by: Alexis de Talhouët --- features/netconf-connector/pom.xml | 8 --- .../src/main/features/features.xml | 1 - .../src/main/config/default-config.xml | 28 --------- .../console/commands/NetconfCommandUtils.java | 3 +- .../NetconfDisconnectDeviceCommand.java | 3 +- .../commands/NetconfListDevicesCommand.java | 2 - .../commands/NetconfUpdateDeviceCommand.java | 1 - .../console/impl/NetconfCommandsImpl.java | 8 +-- .../console/impl/NetconfConsoleProvider.java | 55 ----------------- .../NetconfConsoleProviderModule.java | 25 -------- .../NetconfConsoleProviderModuleFactory.java | 13 ---- .../resources/OSGI-INF/blueprint/commands.xml | 32 ---------- .../blueprint/netconf-command.xml | 52 ++++++++++++++++ .../yang/netconf-console-provider-impl.yang | 30 ---------- .../console/impl/NetconfCommandsImplTest.java | 3 +- .../impl/NetconfConsoleProviderTest.java | 59 ------------------- 16 files changed, 59 insertions(+), 264 deletions(-) delete mode 100644 netconf/netconf-console/src/main/config/default-config.xml delete mode 100644 netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfConsoleProvider.java delete mode 100644 netconf/netconf-console/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/netconf/console/provider/impl/rev160323/NetconfConsoleProviderModule.java delete mode 100644 netconf/netconf-console/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/netconf/console/provider/impl/rev160323/NetconfConsoleProviderModuleFactory.java delete mode 100644 netconf/netconf-console/src/main/resources/OSGI-INF/blueprint/commands.xml create mode 100755 netconf/netconf-console/src/main/resources/org/opendaylight/blueprint/netconf-command.xml delete mode 100644 netconf/netconf-console/src/main/yang/netconf-console-provider-impl.yang delete mode 100644 netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfConsoleProviderTest.java diff --git a/features/netconf-connector/pom.xml b/features/netconf-connector/pom.xml index cf4131026b..5931f6e975 100644 --- a/features/netconf-connector/pom.xml +++ b/features/netconf-connector/pom.xml @@ -36,7 +36,6 @@ 01-netconf.xml 02-netconf-topology.xml 99-netconf-connector.xml - 100-netconf-console.xml @@ -104,13 +103,6 @@ netconf-console ${project.version} - - ${project.groupId} - netconf-console - ${project.version} - config - xml - ${project.groupId} abstract-topology diff --git a/features/netconf-connector/src/main/features/features.xml b/features/netconf-connector/src/main/features/features.xml index fe3e66dba3..49dfa56735 100644 --- a/features/netconf-connector/src/main/features/features.xml +++ b/features/netconf-connector/src/main/features/features.xml @@ -66,7 +66,6 @@ odl-netconf-connector-all odl-netconf-topology mvn:org.opendaylight.netconf/netconf-console/{{VERSION}} - mvn:org.opendaylight.netconf/netconf-console/{{VERSION}}/xml/config diff --git a/netconf/netconf-console/src/main/config/default-config.xml b/netconf/netconf-console/src/main/config/default-config.xml deleted file mode 100644 index 4f27421f3d..0000000000 --- a/netconf/netconf-console/src/main/config/default-config.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - urn:opendaylight:netconf:console:provider:impl?module=netconf-console-provider-impl&revision=2016-03-23 - urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28 - - - - - - - prefix:netconf-console-provider-impl - netconf-console-default - - binding:binding-broker-osgi-registry - binding-osgi-broker - - - - - - \ No newline at end of file diff --git a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfCommandUtils.java b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfCommandUtils.java index 40ac48f17c..96715193b5 100644 --- a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfCommandUtils.java +++ b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfCommandUtils.java @@ -8,11 +8,10 @@ package org.opendaylight.netconf.console.commands; +import com.google.common.base.Strings; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.google.common.base.Strings; - public class NetconfCommandUtils { private static final Pattern IP_PATTERN = Pattern.compile( diff --git a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfDisconnectDeviceCommand.java b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfDisconnectDeviceCommand.java index b1abf2fa25..20f1234ac9 100644 --- a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfDisconnectDeviceCommand.java +++ b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfDisconnectDeviceCommand.java @@ -9,13 +9,12 @@ package org.opendaylight.netconf.console.commands; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Strings; import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Option; import org.apache.karaf.shell.console.AbstractAction; import org.opendaylight.netconf.console.api.NetconfCommands; -import com.google.common.base.Strings; - @Command(name = "netconf:disconnect-device", scope = "netconf", description = "Disconnect netconf device.") public class NetconfDisconnectDeviceCommand extends AbstractAction { diff --git a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfListDevicesCommand.java b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfListDevicesCommand.java index fd52e651e2..7a1ec73f45 100644 --- a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfListDevicesCommand.java +++ b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfListDevicesCommand.java @@ -9,9 +9,7 @@ package org.opendaylight.netconf.console.commands; import java.util.Map; - import javax.annotation.Nonnull; - import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.console.AbstractAction; import org.apache.karaf.shell.table.ShellTable; diff --git a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfUpdateDeviceCommand.java b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfUpdateDeviceCommand.java index 79b6bb498e..c890a39884 100644 --- a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfUpdateDeviceCommand.java +++ b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfUpdateDeviceCommand.java @@ -11,7 +11,6 @@ package org.opendaylight.netconf.console.commands; import com.google.common.annotations.VisibleForTesting; import java.util.HashMap; import java.util.Map; - import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Option; import org.apache.karaf.shell.console.AbstractAction; diff --git a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfCommandsImpl.java b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfCommandsImpl.java index d830e9d097..14a2412592 100644 --- a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfCommandsImpl.java +++ b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfCommandsImpl.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.MountPointService; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; @@ -50,17 +49,18 @@ public class NetconfCommandsImpl implements NetconfCommands { private static final Logger LOG = LoggerFactory.getLogger(NetconfCommandsImpl.class); private final DataBroker dataBroker; - private final MountPointService mountPointService; - public NetconfCommandsImpl(final DataBroker db, final MountPointService mountPointService) { + public NetconfCommandsImpl(final DataBroker db) { LOG.debug("NetconfConsoleProviderImpl initialized"); this.dataBroker = db; - this.mountPointService = mountPointService; } @Override public Map> listDevices() { final Topology topology = NetconfConsoleUtils.read(LogicalDatastoreType.OPERATIONAL, NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker); + if (topology == null) { + return new HashMap<>(); + } final Map> netconfNodes = new HashMap<>(); for (final Node node : topology.getNode()) { final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class); diff --git a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfConsoleProvider.java b/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfConsoleProvider.java deleted file mode 100644 index 0f15ef4b2d..0000000000 --- a/netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfConsoleProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.netconf.console.impl; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.MountPointService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; -import org.opendaylight.netconf.console.api.NetconfCommands; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class NetconfConsoleProvider implements BindingAwareProvider, AutoCloseable { - - private static final Logger LOG = LoggerFactory.getLogger(NetconfConsoleProvider.class); - private ServiceRegistration netconfConsoleRegistration; - - @Override - public void onSessionInitiated(ProviderContext session) { - LOG.info("NetconfProvider Session Initiated"); - - // Retrieve DataBroker service to interact with md-sal - final DataBroker dataBroker = session.getSALService(DataBroker.class); - - // Retrieve MountPointService to interact with NETCONF remote devices connected to ODL and register it - final MountPointService mountService = session.getSALService(MountPointService.class); - final BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); - - // Initialization of NETCONF Console Provider service implementation - initializeNetconfConsoleProvider(dataBroker, context, mountService); - } - - private void initializeNetconfConsoleProvider(DataBroker dataBroker, BundleContext context, MountPointService mountService) { - // Initialize NetconfConsoleProviderImpl class - final NetconfCommandsImpl consoleProvider = new NetconfCommandsImpl(dataBroker, mountService); - - // Register the NetconfConsoleProvider service - netconfConsoleRegistration = context.registerService(NetconfCommands.class, consoleProvider, null); - } - - @Override - public void close() throws Exception { - LOG.info("NetconfProvider closed."); - netconfConsoleRegistration.unregister(); - } -} diff --git a/netconf/netconf-console/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/netconf/console/provider/impl/rev160323/NetconfConsoleProviderModule.java b/netconf/netconf-console/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/netconf/console/provider/impl/rev160323/NetconfConsoleProviderModule.java deleted file mode 100644 index 39f54090b0..0000000000 --- a/netconf/netconf-console/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/netconf/console/provider/impl/rev160323/NetconfConsoleProviderModule.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.console.provider.impl.rev160323; - -import org.opendaylight.netconf.console.impl.NetconfConsoleProvider; - -public class NetconfConsoleProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.console.provider.impl.rev160323.AbstractNetconfConsoleProviderModule { - public NetconfConsoleProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - } - - public NetconfConsoleProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.console.provider.impl.rev160323.NetconfConsoleProviderModule oldModule, java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - } - - @Override - public void customValidation() { - // add custom validation form module attributes here. - } - - @Override - public java.lang.AutoCloseable createInstance() { - final NetconfConsoleProvider provider = new NetconfConsoleProvider(); - getBrokerDependency().registerProvider(provider); - return provider; - } -} diff --git a/netconf/netconf-console/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/netconf/console/provider/impl/rev160323/NetconfConsoleProviderModuleFactory.java b/netconf/netconf-console/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/netconf/console/provider/impl/rev160323/NetconfConsoleProviderModuleFactory.java deleted file mode 100644 index 01c4b5f5d7..0000000000 --- a/netconf/netconf-console/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/netconf/console/provider/impl/rev160323/NetconfConsoleProviderModuleFactory.java +++ /dev/null @@ -1,13 +0,0 @@ -/* -* Generated file -* -* Generated from: yang module name: netconf-console-provider-impl yang module local name: netconf-console-provider-impl -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Wed Mar 23 18:01:12 EDT 2016 -* -* Do not modify this file unless it is present under src/main directory -*/ -package org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.console.provider.impl.rev160323; -public class NetconfConsoleProviderModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.console.provider.impl.rev160323.AbstractNetconfConsoleProviderModuleFactory { - -} diff --git a/netconf/netconf-console/src/main/resources/OSGI-INF/blueprint/commands.xml b/netconf/netconf-console/src/main/resources/OSGI-INF/blueprint/commands.xml deleted file mode 100644 index 51e07b0186..0000000000 --- a/netconf/netconf-console/src/main/resources/OSGI-INF/blueprint/commands.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/netconf/netconf-console/src/main/resources/org/opendaylight/blueprint/netconf-command.xml b/netconf/netconf-console/src/main/resources/org/opendaylight/blueprint/netconf-command.xml new file mode 100755 index 0000000000..68d319d244 --- /dev/null +++ b/netconf/netconf-console/src/main/resources/org/opendaylight/blueprint/netconf-command.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/netconf/netconf-console/src/main/yang/netconf-console-provider-impl.yang b/netconf/netconf-console/src/main/yang/netconf-console-provider-impl.yang deleted file mode 100644 index bbe7ea60d4..0000000000 --- a/netconf/netconf-console/src/main/yang/netconf-console-provider-impl.yang +++ /dev/null @@ -1,30 +0,0 @@ -module netconf-console-provider-impl { - namespace "urn:opendaylight:netconf:console:provider:impl"; - prefix "netconf-console-provider-impl"; - - import config { prefix config; revision-date 2013-04-05; } - import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; } - - revision 2016-03-23 { - description "Initial revision"; - } - - identity netconf-console-provider-impl { - base config:module-type; - config:java-name-prefix NetconfConsoleProvider; - } - - augment "/config:modules/config:module/config:configuration" { - case netconf-console-provider-impl { - when "/config:modules/config:module/config:type = 'netconf-console-provider-impl'"; - container broker { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity mdsal:binding-broker-osgi-registry; - } - } - } - } - } -} \ No newline at end of file diff --git a/netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfCommandsImplTest.java b/netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfCommandsImplTest.java index 1ccd575c78..bafcd9bc32 100644 --- a/netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfCommandsImplTest.java +++ b/netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfCommandsImplTest.java @@ -121,8 +121,7 @@ public class NetconfCommandsImplTest { bindingToNormalized.onGlobalContextUpdated(schemaContext); dataBroker = new BindingDOMDataBrokerAdapter(cDOMDataBroker, bindingToNormalized); - final MountPointService mountPointService = mock(MountPointService.class); - netconfCommands = new NetconfCommandsImpl(dataBroker, mountPointService); + netconfCommands = new NetconfCommandsImpl(dataBroker); } @Test diff --git a/netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfConsoleProviderTest.java b/netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfConsoleProviderTest.java deleted file mode 100644 index ef20f81def..0000000000 --- a/netconf/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfConsoleProviderTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.netconf.console.impl; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.powermock.api.mockito.PowerMockito.when; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.BDDMockito; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.MountPointService; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.netconf.console.api.NetconfCommands; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(FrameworkUtil.class) -public class NetconfConsoleProviderTest { - - @Test - public void testProvider() throws Exception { - final NetconfConsoleProvider netconfConsoleProvider = new NetconfConsoleProvider(); - - PowerMockito.mockStatic(FrameworkUtil.class); - - final BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class); - final MountPointService mountPointService = mock(MountPointService.class); - final BundleContext bundleContext = mock(BundleContext.class); - final DataBroker dataBroker = mock(DataBroker.class); - final Bundle bundle = mock(Bundle.class); - - doReturn(dataBroker).when(session).getSALService(DataBroker.class); - doReturn(mountPointService).when(session).getSALService(MountPointService.class); - BDDMockito.given(FrameworkUtil.getBundle(any())).willReturn(bundle); - when(bundle.getBundleContext()).thenReturn(bundleContext); - - netconfConsoleProvider.onSessionInitiated(session); - - verify(bundleContext, times(1)).registerService(eq(NetconfCommands.class), any(NetconfCommandsImpl.class), eq(null)); - - } -} -- 2.36.6