Committed by
Gerrit Code Review
ONOS-3578 Removing netconf device from ONOS core
Change-Id: Ib3165ec26d598ce2f10216a2982dae2cebd539e9
Showing
2 changed files
with
25 additions
and
2 deletions
... | @@ -27,6 +27,8 @@ import org.onosproject.netconf.NetconfDevice; | ... | @@ -27,6 +27,8 @@ import org.onosproject.netconf.NetconfDevice; |
27 | import org.onosproject.netconf.NetconfDeviceFactory; | 27 | import org.onosproject.netconf.NetconfDeviceFactory; |
28 | import org.onosproject.netconf.NetconfDeviceInfo; | 28 | import org.onosproject.netconf.NetconfDeviceInfo; |
29 | import org.onosproject.netconf.NetconfDeviceListener; | 29 | import org.onosproject.netconf.NetconfDeviceListener; |
30 | +import org.onosproject.netconf.NetconfDeviceOutputEvent; | ||
31 | +import org.onosproject.netconf.NetconfDeviceOutputEventListener; | ||
30 | import org.onosproject.netconf.NetconfException; | 32 | import org.onosproject.netconf.NetconfException; |
31 | import org.osgi.service.component.ComponentContext; | 33 | import org.osgi.service.component.ComponentContext; |
32 | import org.slf4j.Logger; | 34 | import org.slf4j.Logger; |
... | @@ -49,6 +51,8 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -49,6 +51,8 @@ public class NetconfControllerImpl implements NetconfController { |
49 | 51 | ||
50 | private Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<>(); | 52 | private Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<>(); |
51 | 53 | ||
54 | + private final NetconfDeviceOutputEventListener downListener = new DeviceDownEventListener(); | ||
55 | + | ||
52 | protected Set<NetconfDeviceListener> netconfDeviceListeners = new CopyOnWriteArraySet<>(); | 56 | protected Set<NetconfDeviceListener> netconfDeviceListeners = new CopyOnWriteArraySet<>(); |
53 | protected NetconfDeviceFactory deviceFactory = new DefaultNetconfDeviceFactory(); | 57 | protected NetconfDeviceFactory deviceFactory = new DefaultNetconfDeviceFactory(); |
54 | 58 | ||
... | @@ -97,7 +101,9 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -97,7 +101,9 @@ public class NetconfControllerImpl implements NetconfController { |
97 | return netconfDeviceMap.get(deviceInfo.getDeviceId()); | 101 | return netconfDeviceMap.get(deviceInfo.getDeviceId()); |
98 | } else { | 102 | } else { |
99 | log.info("Creating NETCONF device {}", deviceInfo); | 103 | log.info("Creating NETCONF device {}", deviceInfo); |
100 | - return createDevice(deviceInfo); | 104 | + NetconfDevice device = createDevice(deviceInfo); |
105 | + device.getSession().addDeviceOutputListener(downListener); | ||
106 | + return device; | ||
101 | } | 107 | } |
102 | } | 108 | } |
103 | 109 | ||
... | @@ -140,4 +146,21 @@ public class NetconfControllerImpl implements NetconfController { | ... | @@ -140,4 +146,21 @@ public class NetconfControllerImpl implements NetconfController { |
140 | return new DefaultNetconfDevice(netconfDeviceInfo); | 146 | return new DefaultNetconfDevice(netconfDeviceInfo); |
141 | } | 147 | } |
142 | } | 148 | } |
149 | + | ||
150 | + //Listener for closed session with devices, gets triggered whe devices goes down | ||
151 | + // or sends the endpattern ]]>]]> | ||
152 | + private class DeviceDownEventListener implements NetconfDeviceOutputEventListener { | ||
153 | + | ||
154 | + @Override | ||
155 | + public void event(NetconfDeviceOutputEvent event) { | ||
156 | + if (event.type().equals(NetconfDeviceOutputEvent.Type.DEVICE_UNREGISTERED)) { | ||
157 | + removeDevice(event.getDeviceInfo()); | ||
158 | + } | ||
159 | + } | ||
160 | + | ||
161 | + @Override | ||
162 | + public boolean isRelevant(NetconfDeviceOutputEvent event) { | ||
163 | + return getDevicesMap().containsKey(event.getDeviceInfo().getDeviceId()); | ||
164 | + } | ||
165 | + } | ||
143 | } | 166 | } | ... | ... |
... | @@ -136,7 +136,7 @@ public class NetconfDeviceProvider extends AbstractProvider | ... | @@ -136,7 +136,7 @@ public class NetconfDeviceProvider extends AbstractProvider |
136 | public boolean isReachable(DeviceId deviceId) { | 136 | public boolean isReachable(DeviceId deviceId) { |
137 | NetconfDevice netconfDevice = controller.getNetconfDevice(deviceId); | 137 | NetconfDevice netconfDevice = controller.getNetconfDevice(deviceId); |
138 | if (netconfDevice == null) { | 138 | if (netconfDevice == null) { |
139 | - log.warn("BAD REQUEST: the requested device id: " | 139 | + log.debug("Requested device id: " |
140 | + deviceId.toString() | 140 | + deviceId.toString() |
141 | + " is not associated to any NETCONF Device"); | 141 | + " is not associated to any NETCONF Device"); |
142 | return false; | 142 | return false; | ... | ... |
-
Please register or login to post a comment