Andrea Campanella
Committed by Gerrit Code Review

ONOS-3340 IOException throwing in case of no response from NETCONF device on given ip:port

Change-Id: I0fcc6be38e138703d14ef987bfeef9857945a0b5
......@@ -19,6 +19,7 @@ package org.onosproject.netconf;
import org.onlab.packet.IpAddress;
import org.onosproject.net.DeviceId;
import java.io.IOException;
import java.util.Map;
/**
......@@ -48,7 +49,7 @@ public interface NetconfController {
* @param deviceInfo info about the device to add
* @return NetconfDevice Netconf device
*/
NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo);
NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws IOException;
/**
* Removes a Netconf device.
......
......@@ -91,9 +91,9 @@ public class NetconfControllerImpl implements NetconfController {
}
@Override
public NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) {
public NetconfDevice connectDevice(NetconfDeviceInfo deviceInfo) throws IOException {
if (netconfDeviceMap.containsKey(deviceInfo.getDeviceId())) {
log.warn("Device {} is already present");
log.info("Device {} is already present");
return netconfDeviceMap.get(deviceInfo.getDeviceId());
} else {
log.info("Creating NETCONF device {}", deviceInfo);
......@@ -110,19 +110,13 @@ public class NetconfControllerImpl implements NetconfController {
}
}
private NetconfDevice createDevice(NetconfDeviceInfo deviceInfo) {
private NetconfDevice createDevice(NetconfDeviceInfo deviceInfo) throws IOException {
NetconfDevice netconfDevice = null;
try {
netconfDevice = new NetconfDeviceImpl(deviceInfo);
for (NetconfDeviceListener l : netconfDeviceListeners) {
l.deviceAdded(deviceInfo);
}
netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice);
} catch (IOException e) {
throw new IllegalStateException("Cannot create NETCONF device " +
"with device Info: " +
deviceInfo + " \n" + e);
netconfDevice = new NetconfDeviceImpl(deviceInfo);
for (NetconfDeviceListener l : netconfDeviceListeners) {
l.deviceAdded(deviceInfo);
}
netconfDeviceMap.put(deviceInfo.getDeviceId(), netconfDevice);
return netconfDevice;
}
......
......@@ -49,6 +49,7 @@ import org.onosproject.netconf.NetconfDeviceInfo;
import org.onosproject.netconf.NetconfDeviceListener;
import org.slf4j.Logger;
import java.io.IOException;
import java.util.Map;
import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
......@@ -192,11 +193,23 @@ public class NetconfDeviceProvider extends AbstractProvider
if (cfg != null) {
log.info("cfg {}", cfg);
try {
cfg.getDevicesAddresses().stream().forEach(addr -> controller
.connectDevice(new NetconfDeviceInfo(addr.name(),
addr.password(),
addr.ip(),
addr.port())));
cfg.getDevicesAddresses().stream()
.forEach(addr -> {
try {
controller.connectDevice(
new NetconfDeviceInfo(addr.name(),
addr.password(),
addr.ip(),
addr.port()));
} catch (IOException e) {
log.warn("Can't connect to NETCONF " +
"device on {}:{}",
addr.ip(),
addr.port());
}
}
);
} catch (ConfigException e) {
log.error("Cannot read config error " + e);
}
......