Convert netconf-console to OSGi DS 05/96905/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Jul 2021 16:36:16 +0000 (18:36 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 16 Jul 2021 17:25:19 +0000 (19:25 +0200)
netconf-console is a very simple component, convert it to OSGi DS.

JIRA: NETCONF-792
Change-Id: Ic92a59b52a85af67a8ed648a53cb11a083928ece
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-console/pom.xml
netconf/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfCommandsImpl.java
netconf/netconf-console/src/main/resources/OSGI-INF/blueprint/netconf-command.xml [deleted file]

index 5c803ddac900501aece1c5984e3a07d2846e5d60..2da7b5f32c74d21fec2f95169c5f48e3b5d51ffd 100644 (file)
@@ -30,6 +30,15 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
           <groupId>org.opendaylight.netconf</groupId>
           <artifactId>sal-netconf-connector</artifactId>
       </dependency>
+      <dependency>
+          <groupId>com.guicedee.services</groupId>
+          <artifactId>javax.inject</artifactId>
+          <optional>true</optional>
+      </dependency>
+      <dependency>
+          <groupId>org.osgi</groupId>
+          <artifactId>org.osgi.service.component.annotations</artifactId>
+      </dependency>
 
       <dependency>
           <groupId>org.opendaylight.yangtools</groupId>
index bc6c527a8501cbe89a7d5e9f53992614c505debe..9f284f2093848c09fd1c9d2b25b0349fc1a27c60 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.console.impl;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.FutureCallback;
@@ -20,6 +22,8 @@ import java.util.Map;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.common.api.CommitInfo;
@@ -44,18 +48,24 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Uint16;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@Singleton
+@Component(immediate = true)
 public class NetconfCommandsImpl implements NetconfCommands {
-
     private static final Logger LOG = LoggerFactory.getLogger(NetconfCommandsImpl.class);
 
     private final DataBroker dataBroker;
 
-    public NetconfCommandsImpl(final DataBroker db) {
+    @Inject
+    @Activate
+    public NetconfCommandsImpl(@Reference final DataBroker db) {
+        this.dataBroker = requireNonNull(db);
         LOG.debug("NetconfConsoleProviderImpl initialized");
-        this.dataBroker = db;
     }
 
     @Override
@@ -192,16 +202,16 @@ public class NetconfCommandsImpl implements NetconfCommands {
 
     @Override
     public boolean disconnectDevice(final String deviceIp, final String devicePort) {
-        final String netconfNodeId = NetconfConsoleUtils
-                .getNetconfNodeFromIpAndPort(deviceIp, devicePort, dataBroker).getNodeId().getValue();
+        final String netconfNodeId = NetconfConsoleUtils.getNetconfNodeFromIpAndPort(deviceIp, devicePort, dataBroker)
+            .getNodeId().getValue();
         return disconnectDevice(netconfNodeId);
     }
 
     @Override
     public String updateDevice(final String netconfNodeId, final String username, final String password,
                                final Map<String, String> updated) {
-        final Node node = NetconfConsoleUtils
-                .read(LogicalDatastoreType.OPERATIONAL, NetconfIidFactory.netconfNodeIid(netconfNodeId), dataBroker);
+        final Node node = NetconfConsoleUtils.read(LogicalDatastoreType.OPERATIONAL,
+            NetconfIidFactory.netconfNodeIid(netconfNodeId), dataBroker);
 
         if (node != null && node.augmentation(NetconfNode.class) != null) {
             final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
diff --git a/netconf/netconf-console/src/main/resources/OSGI-INF/blueprint/netconf-command.xml b/netconf/netconf-console/src/main/resources/OSGI-INF/blueprint/netconf-command.xml
deleted file mode 100644 (file)
index ada935f..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2016 Inocybe Technologies 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
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
-           xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
-           odl:use-default-for-reference-types="true">
-
-    <reference id="dataBroker"
-               interface="org.opendaylight.mdsal.binding.api.DataBroker"
-               odl:type="default"/>
-
-    <bean id="netconfCommandsImpl" class="org.opendaylight.netconf.console.impl.NetconfCommandsImpl">
-        <argument ref="dataBroker"/>
-    </bean>
-    <service ref="netconfCommandsImpl" interface="org.opendaylight.netconf.console.api.NetconfCommands" />
-
-</blueprint>