fixes to catch proper netconf exception
- part of ONOS-7020
Change-Id: I55c02ca9fdb97f1ae12b4e3d7b76da565f9da741
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
index b7651a5..bac6bef 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/cli/impl/NetconfConfigGetCommand.java
@@ -18,14 +18,13 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.netconf.DatastoreId.datastore;
-import java.io.IOException;
-
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.netconf.NetconfController;
import org.onosproject.netconf.NetconfDevice;
+import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession;
/**
@@ -71,7 +70,7 @@
try {
String res = session.getConfig(datastore(cfgType.toLowerCase()));
print("%s", res);
- } catch (IOException e) {
+ } catch (NetconfException e) {
log.error("Configuration could not be retrieved", e);
print("Error occurred retrieving configuration");
}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/DefaultNetconfDevice.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/DefaultNetconfDevice.java
index 362cbac..f700768 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/DefaultNetconfDevice.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/DefaultNetconfDevice.java
@@ -24,8 +24,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-
/**
* Default implementation of a NETCONF device.
*/
@@ -54,7 +52,7 @@
sessionFactory = new NetconfSessionMinaImpl.MinaSshNetconfSessionFactory();
try {
netconfSession = sessionFactory.createNetconfSession(deviceInfo);
- } catch (IOException e) {
+ } catch (NetconfException e) {
deviceState = false;
throw new NetconfException("Cannot create connection and session for device " +
deviceInfo, e);
@@ -78,7 +76,7 @@
sessionFactory = factory;
try {
netconfSession = sessionFactory.createNetconfSession(deviceInfo);
- } catch (IOException e) {
+ } catch (NetconfException e) {
deviceState = false;
throw new NetconfException("Cannot create connection and session for device " +
deviceInfo, e);
@@ -100,7 +98,7 @@
deviceState = false;
try {
netconfSession.close();
- } catch (IOException e) {
+ } catch (NetconfException e) {
log.warn("Cannot communicate with the device {} session already closed", netconfDeviceInfo);
}
}
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionImpl.java
index bb1a4ed..e54e6cd 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionImpl.java
@@ -361,7 +361,7 @@
try {
log.debug("Trying to reopen the Sesion with {}", deviceInfo.getDeviceId());
startSshSession();
- } catch (IOException | IllegalStateException e) {
+ } catch (NetconfException | IllegalStateException e) {
log.debug("Trying to reopen the Connection with {}", deviceInfo.getDeviceId());
try {
connectionActive = false;
@@ -372,7 +372,7 @@
subscriptionConnected = false;
startSubscription(notificationFilterSchema);
}
- } catch (IOException e2) {
+ } catch (NetconfException e2) {
log.error("No connection {} for device {}", netconfConnection, e.getMessage());
throw new NetconfException("Cannot re-open the connection with device" + deviceInfo, e);
}