Bump mdsal to 5.0.2
[netconf.git] / netconf / netconf-console / src / main / java / org / opendaylight / netconf / console / impl / NetconfCommandsImpl.java
index 8954e4a2947cc3c20a10108447e8d617b315fa83..50adf4b2007d401af900059ced278ee228725ef0 100644 (file)
@@ -5,13 +5,11 @@
  * 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 com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -20,11 +18,12 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-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;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netconf.console.api.NetconfCommands;
 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
 import org.opendaylight.netconf.console.utils.NetconfConsoleUtils;
@@ -45,6 +44,7 @@ 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.NodeBuilder;
 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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,7 +68,7 @@ public class NetconfCommandsImpl implements NetconfCommands {
         }
         final Map<String, Map<String, String>> netconfNodes = new HashMap<>();
         for (final Node node : topology.getNode()) {
-            final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+            final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
             final Map<String, String> attributes = new HashMap<>();
             attributes.put(NetconfConsoleConstants.NETCONF_ID, node.getNodeId().getValue());
             attributes.put(NetconfConsoleConstants.NETCONF_IP,
@@ -93,7 +93,7 @@ public class NetconfCommandsImpl implements NetconfCommands {
         if (nodeList != null) {
             for (final Node node : nodeList) {
                 if (node != null) {
-                    final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+                    final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
                     final Map<String, List<String>> attributes = new HashMap<>();
                     attributes.put(NetconfConsoleConstants.NETCONF_ID, ImmutableList.of(node.getNodeId().getValue()));
                     attributes.put(NetconfConsoleConstants.NETCONF_IP,
@@ -123,7 +123,7 @@ public class NetconfCommandsImpl implements NetconfCommands {
         final List<Node> nodeList = NetconfConsoleUtils.getNetconfNodeFromId(deviceId, dataBroker);
         if (nodeList != null && nodeList.size() > 0) {
             for (final Node node : nodeList) {
-                final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+                final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
                 final Map<String, List<String>> attributes = new HashMap<>();
                 attributes.put(NetconfConsoleConstants.NETCONF_ID, ImmutableList.of(node.getNodeId().getValue()));
                 attributes.put(NetconfConsoleConstants.NETCONF_IP,
@@ -146,7 +146,7 @@ public class NetconfCommandsImpl implements NetconfCommands {
     }
 
     @Override
-    public void connectDevice(NetconfNode netconfNode, String netconfNodeId) {
+    public void connectDevice(final NetconfNode netconfNode, final String netconfNodeId) {
         final NodeId nodeId;
         if (!Strings.isNullOrEmpty(netconfNodeId)) {
             nodeId = new NodeId(netconfNodeId);
@@ -154,7 +154,7 @@ public class NetconfCommandsImpl implements NetconfCommands {
             nodeId = new NodeId(UUID.randomUUID().toString().replace("-", ""));
         }
         final Node node = new NodeBuilder()
-                .setKey(new NodeKey(nodeId))
+                .withKey(new NodeKey(nodeId))
                 .setNodeId(nodeId)
                 .addAugmentation(NetconfNode.class, netconfNode)
                 .build();
@@ -162,36 +162,33 @@ public class NetconfCommandsImpl implements NetconfCommands {
         final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
         transaction.put(LogicalDatastoreType.CONFIGURATION, NetconfIidFactory.netconfNodeIid(nodeId.getValue()), node);
 
-        Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
-
+        transaction.commit().addCallback(new FutureCallback<CommitInfo>() {
             @Override
-            public void onSuccess(Void result) {
+            public void onSuccess(final CommitInfo result) {
                 LOG.debug("NetconfNode={} created successfully", netconfNode);
             }
 
             @Override
-            public void onFailure(Throwable throwable) {
-                LOG.error("Failed to created NetconfNode={}", netconfNode);
-                throw new RuntimeException(throwable);
+            public void onFailure(final Throwable throwable) {
+                LOG.error("Failed to created NetconfNode={}", netconfNode, throwable);
             }
         }, MoreExecutors.directExecutor());
     }
 
     @Override
-    public boolean disconnectDevice(String netconfNodeId) {
-        boolean result = false;
+    public boolean disconnectDevice(final String netconfNodeId) {
         final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
-        InstanceIdentifier<Node> iid = NetconfIidFactory.netconfNodeIid(netconfNodeId);
+        final InstanceIdentifier<Node> iid = NetconfIidFactory.netconfNodeIid(netconfNodeId);
         transaction.delete(LogicalDatastoreType.CONFIGURATION, iid);
 
         try {
             LOG.debug("Deleting netconf node: {}", netconfNodeId);
-            transaction.submit().checkedGet();
-            result = true;
-        } catch (final TransactionCommitFailedException e) {
+            transaction.commit().get();
+            return true;
+        } catch (final InterruptedException | ExecutionException e) {
             LOG.error("Unable to remove node with Iid {}", iid, e);
+            return false;
         }
-        return result;
     }
 
     @Override
@@ -202,13 +199,13 @@ public class NetconfCommandsImpl implements NetconfCommands {
     }
 
     @Override
-    public String updateDevice(final String netconfNodeId, String username, String password,
-                               Map<String, String> updated) {
+    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);
 
-        if (node != null && node.getAugmentation(NetconfNode.class) != null) {
-            final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class);
+        if (node != null && node.augmentation(NetconfNode.class) != null) {
+            final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
 
             // Get NETCONF attributes to update if present else get their original values from NetconfNode instance
             final String deviceIp = Strings.isNullOrEmpty(updated.get(NetconfConsoleConstants.NETCONF_IP))
@@ -228,14 +225,14 @@ public class NetconfCommandsImpl implements NetconfCommands {
                     new LoginPasswordBuilder().setPassword(newPassword).setUsername(newUsername).build();
             final NetconfNode updatedNetconfNode = new NetconfNodeBuilder()
                     .setHost(new Host(new IpAddress(new Ipv4Address(deviceIp))))
-                    .setPort(new PortNumber(Integer.decode(devicePort)))
+                    .setPort(new PortNumber(Uint16.valueOf(Integer.decode(devicePort))))
                     .setTcpOnly(tcpOnly)
                     .setSchemaless(isSchemaless)
                     .setCredentials(credentials)
                     .build();
 
             final Node updatedNode = new NodeBuilder()
-                    .setKey(node.getKey())
+                    .withKey(node.key())
                     .setNodeId(node.getNodeId())
                     .addAugmentation(NetconfNode.class, updatedNetconfNode)
                     .build();
@@ -244,17 +241,15 @@ public class NetconfCommandsImpl implements NetconfCommands {
             transaction.put(LogicalDatastoreType.CONFIGURATION,
                     NetconfIidFactory.netconfNodeIid(updatedNode.getNodeId().getValue()), updatedNode);
 
-            Futures.addCallback(transaction.submit(), new FutureCallback<Void>() {
-
+            transaction.commit().addCallback(new FutureCallback<CommitInfo>() {
                 @Override
-                public void onSuccess(Void result) {
+                public void onSuccess(final CommitInfo result) {
                     LOG.debug("NetconfNode={} updated successfully", netconfNode);
                 }
 
                 @Override
-                public void onFailure(Throwable throwable) {
-                    LOG.error("Failed to updated NetconfNode={}", netconfNode);
-                    throw new RuntimeException(throwable);
+                public void onFailure(final Throwable throwable) {
+                    LOG.error("Failed to updated NetconfNode={}", netconfNode, throwable);
                 }
             }, MoreExecutors.directExecutor());