Cleaner warning if a NETCONF session to Juniper device not yet established.
Old version gave in logs ...
2019-06-06T09:34:46,730 | WARN | FlowRuleDriverProvider-0 | FlowRuleDriverProvider | 191 - org.onosproject.onos-core-net - 2.2.0.SNAPSHOT | Exception thrown while polling netconf:172.26.138.38:830
java.lang.NullPointerException: null
at org.onosproject.drivers.juniper.FlowRuleJuniperImpl.getFlowEntries(FlowRuleJuniperImpl.java:92) ~[?:?]
at org.onosproject.net.flow.impl.FlowRuleDriverProvider.pollDeviceFlowEntries(FlowRuleDriverProvider.java:193) ~[?:?]
at org.onosproject.net.flow.impl.FlowRuleDriverProvider.access$500(FlowRuleDriverProvider.java:63) ~[?:?]
at org.onosproject.net.flow.impl.FlowRuleDriverProvider$InternalDeviceListener.handleEvent(FlowRuleDriverProvider.java:249) ~[?:?]
at org.onosproject.net.flow.impl.FlowRuleDriverProvider$InternalDeviceListener.lambda$event$0(FlowRuleDriverProvider.java:233) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:?]
at java.lang.Thread.run(Thread.java:745) [?:?]
New version gives ...
2019-06-07T09:36:07,924 | WARN | FlowRuleDriverProvider-0 | JuniperAbstractHandlerBehaviour | 218 - org.onosproject.onos-drivers-juniper - 2.2.0.SNAPSHOT | NETCONF session to device netconf:172.26.138.68:830 not yet established, will be retried
Note in new version this lookup code refactored to be in one place.
Change-Id: Ic78c5ecc67e8e98d14da845d0541d980296750a5
diff --git a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/DeviceDiscoveryJuniperImpl.java b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/DeviceDiscoveryJuniperImpl.java
index 3c254c5..bd87be8 100644
--- a/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/DeviceDiscoveryJuniperImpl.java
+++ b/drivers/juniper/src/main/java/org/onosproject/drivers/juniper/DeviceDiscoveryJuniperImpl.java
@@ -23,15 +23,12 @@
import org.onosproject.net.device.DeviceDescription;
import org.onosproject.net.device.DeviceDescriptionDiscovery;
import org.onosproject.net.device.PortDescription;
-import org.onosproject.net.driver.AbstractHandlerBehaviour;
-import org.onosproject.netconf.NetconfController;
import org.onosproject.netconf.NetconfException;
import org.onosproject.netconf.NetconfSession;
import org.slf4j.Logger;
import java.util.List;
-import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.drivers.juniper.JuniperUtils.REQ_IF_INFO;
import static org.onosproject.drivers.juniper.JuniperUtils.REQ_MAC_ADD_INFO;
import static org.onosproject.drivers.juniper.JuniperUtils.REQ_SYS_INFO;
@@ -44,7 +41,7 @@
* Tested with MX240 junos 14.2
*/
@Beta
-public class DeviceDiscoveryJuniperImpl extends AbstractHandlerBehaviour
+public class DeviceDiscoveryJuniperImpl extends JuniperAbstractHandlerBehaviour
implements DeviceDescriptionDiscovery {
private final Logger log = getLogger(getClass());
@@ -52,8 +49,7 @@
@Override
public DeviceDescription discoverDeviceDetails() {
DeviceId devId = handler().data().deviceId();
- NetconfController controller = checkNotNull(handler().get(NetconfController.class));
- NetconfSession session = controller.getDevicesMap().get(devId).getSession();
+ NetconfSession session = lookupNetconfSession(devId);
String sysInfo;
String chassisMacAddresses;
try {
@@ -75,8 +71,7 @@
@Override
public List<PortDescription> discoverPortDetails() {
DeviceId devId = handler().data().deviceId();
- NetconfController controller = checkNotNull(handler().get(NetconfController.class));
- NetconfSession session = controller.getDevicesMap().get(devId).getSession();
+ NetconfSession session = lookupNetconfSession(devId);
String reply;
try {
reply = session.get(requestBuilder(REQ_IF_INFO));