Committed by
Gerrit Code Review
ONOS-3340 IOException throwing in case of no response from NETCONF device on given ip:port
Change-Id: I0fcc6be38e138703d14ef987bfeef9857945a0b5
Showing
3 changed files
with
27 additions
and
19 deletions
... | @@ -19,6 +19,7 @@ package org.onosproject.netconf; | ... | @@ -19,6 +19,7 @@ package org.onosproject.netconf; |
19 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
21 | 21 | ||
22 | +import java.io.IOException; | ||
22 | import java.util.Map; | 23 | import java.util.Map; |
23 | 24 | ||
24 | /** | 25 | /** |
... | @@ -48,7 +49,7 @@ public interface NetconfController { | ... | @@ -48,7 +49,7 @@ public interface NetconfController { |
48 | * @param deviceInfo info about the device to add | 49 | * @param deviceInfo info about the device to add |
49 | * @return NetconfDevice Netconf device | 50 | * @return NetconfDevice Netconf device |
50 | */ | 51 | */ |
51 | - NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo); | 52 | + NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws IOException; |
52 | 53 | ||
53 | /** | 54 | /** |
54 | * Removes a Netconf device. | 55 | * Removes a Netconf device. | ... | ... |
... | @@ -91,9 +91,9 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -91,9 +91,9 @@ public class NetconfControllerImpl implements NetconfController { |
91 | } | 91 | } |
92 | 92 | ||
93 | @Override | 93 | @Override |
94 | - public NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) { | 94 | + public NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws IOException { |
95 | if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) { | 95 | if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) { |
96 | - log.warn("Device {} is already present"); | 96 | + log.info("Device {} is already present"); |
97 | return netconfDeviceMap.get(deviceInfo.getDeviceId()); | 97 | return netconfDeviceMap.get(deviceInfo.getDeviceId()); |
98 | } else { | 98 | } else { |
99 | log.info("Creating NETCONF device {}", deviceInfo); | 99 | log.info("Creating NETCONF device {}", deviceInfo); |
... | @@ -110,19 +110,13 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -110,19 +110,13 @@ public class NetconfControllerImpl implements NetconfController { |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | - private NetconfDevice createDevice(NetconfDeviceInfo deviceInfo) { | 113 | + private NetconfDevice createDevice(NetconfDeviceInfo deviceInfo) throws IOException { |
114 | NetconfDevice netconfDevice = null; | 114 | NetconfDevice netconfDevice = null; |
115 | - try { | 115 | + netconfDevice = new NetconfDeviceImpl(deviceInfo); |
116 | - netconfDevice = new NetconfDeviceImpl(deviceInfo); | 116 | + for (NetconfDeviceListener l : netconfDeviceListeners) { |
117 | - for (NetconfDeviceListener l : netconfDeviceListeners) { | 117 | + l.deviceAdded(deviceInfo); |
118 | - l.deviceAdded(deviceInfo); | ||
119 | - } | ||
120 | - netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice); | ||
121 | - } catch (IOException e) { | ||
122 | - throw new IllegalStateException("Cannot create NETCONF device " + | ||
123 | - "with device Info: " + | ||
124 | - deviceInfo + " \n" + e); | ||
125 | } | 118 | } |
119 | + netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice); | ||
126 | return netconfDevice; | 120 | return netconfDevice; |
127 | } | 121 | } |
128 | 122 | ... | ... |
... | @@ -49,6 +49,7 @@ import org.onosproject.netconf.NetconfDeviceInfo; | ... | @@ -49,6 +49,7 @@ import org.onosproject.netconf.NetconfDeviceInfo; |
49 | import org.onosproject.netconf.NetconfDeviceListener; | 49 | import org.onosproject.netconf.NetconfDeviceListener; |
50 | import org.slf4j.Logger; | 50 | import org.slf4j.Logger; |
51 | 51 | ||
52 | +import java.io.IOException; | ||
52 | import java.util.Map; | 53 | import java.util.Map; |
53 | 54 | ||
54 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; | 55 | import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; |
... | @@ -192,11 +193,23 @@ public class NetconfDeviceProvider extends AbstractProvider | ... | @@ -192,11 +193,23 @@ public class NetconfDeviceProvider extends AbstractProvider |
192 | if (cfg != null) { | 193 | if (cfg != null) { |
193 | log.info("cfg {}", cfg); | 194 | log.info("cfg {}", cfg); |
194 | try { | 195 | try { |
195 | - cfg.getDevicesAddresses().stream().forEach(addr -> controller | 196 | + cfg.getDevicesAddresses().stream() |
196 | - .connectDevice(new NetconfDeviceInfo(addr.name(), | 197 | + .forEach(addr -> { |
197 | - addr.password(), | 198 | + try { |
198 | - addr.ip(), | 199 | + controller.connectDevice( |
199 | - addr.port()))); | 200 | + new NetconfDeviceInfo(addr.name(), |
201 | + addr.password(), | ||
202 | + addr.ip(), | ||
203 | + addr.port())); | ||
204 | + } catch (IOException e) { | ||
205 | + log.warn("Can't connect to NETCONF " + | ||
206 | + "device on {}:{}", | ||
207 | + addr.ip(), | ||
208 | + addr.port()); | ||
209 | + } | ||
210 | + } | ||
211 | + ); | ||
212 | + | ||
200 | } catch (ConfigException e) { | 213 | } catch (ConfigException e) { |
201 | log.error("Cannot read config error " + e); | 214 | log.error("Cannot read config error " + e); |
202 | } | 215 | } | ... | ... |
-
Please register or login to post a comment