chengfan
Committed by Gerrit Code Review

[ONOS-4946] fix bug: GetTunnelCount cast exception when getting the device prope…

…rty panel details in WEB GUI

add a judgement, only OpticalTunnelEndpoint has a deviceId

Change-Id: Iff91b0b5f37d2ae838229f4e11e970cd70dd6ae1
...@@ -31,6 +31,7 @@ import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint; ...@@ -31,6 +31,7 @@ import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
31 import org.onosproject.incubator.net.tunnel.Tunnel; 31 import org.onosproject.incubator.net.tunnel.Tunnel;
32 import org.onosproject.incubator.net.tunnel.TunnelService; 32 import org.onosproject.incubator.net.tunnel.TunnelService;
33 import org.onosproject.mastership.MastershipService; 33 import org.onosproject.mastership.MastershipService;
34 +import org.onosproject.net.ElementId;
34 import org.onosproject.net.Annotated; 35 import org.onosproject.net.Annotated;
35 import org.onosproject.net.AnnotationKeys; 36 import org.onosproject.net.AnnotationKeys;
36 import org.onosproject.net.Annotations; 37 import org.onosproject.net.Annotations;
...@@ -77,6 +78,7 @@ import java.util.Iterator; ...@@ -77,6 +78,7 @@ import java.util.Iterator;
77 import java.util.List; 78 import java.util.List;
78 import java.util.Map; 79 import java.util.Map;
79 import java.util.Set; 80 import java.util.Set;
81 +import java.util.Optional;
80 import java.util.concurrent.ConcurrentHashMap; 82 import java.util.concurrent.ConcurrentHashMap;
81 83
82 import static com.google.common.base.Preconditions.checkNotNull; 84 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -395,7 +397,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -395,7 +397,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
395 return new PropertyPanel("ONOS Summary", "node") 397 return new PropertyPanel("ONOS Summary", "node")
396 .addProp(Properties.VERSION, version) 398 .addProp(Properties.VERSION, version)
397 .addSeparator() 399 .addSeparator()
398 - .addProp(Properties.DEVICES, deviceService.getDeviceCount()) 400 + .addProp(Properties.DEVICES, deviceService.getDeviceCount())
399 .addProp(Properties.LINKS, topology.linkCount()) 401 .addProp(Properties.LINKS, topology.linkCount())
400 .addProp(Properties.HOSTS, hostService.getHostCount()) 402 .addProp(Properties.HOSTS, hostService.getHostCount())
401 .addProp(Properties.TOPOLOGY_SSCS, topology.clusterCount()) 403 .addProp(Properties.TOPOLOGY_SSCS, topology.clusterCount())
...@@ -457,12 +459,20 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { ...@@ -457,12 +459,20 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler {
457 int count = 0; 459 int count = 0;
458 Collection<Tunnel> tunnels = tunnelService.queryAllTunnels(); 460 Collection<Tunnel> tunnels = tunnelService.queryAllTunnels();
459 for (Tunnel tunnel : tunnels) { 461 for (Tunnel tunnel : tunnels) {
460 - OpticalTunnelEndPoint src = (OpticalTunnelEndPoint) tunnel.src(); 462 + //Only OpticalTunnelEndPoint has a device
461 - OpticalTunnelEndPoint dst = (OpticalTunnelEndPoint) tunnel.dst(); 463 + if (!(tunnel.src() instanceof OpticalTunnelEndPoint) ||
462 - DeviceId srcDevice = (DeviceId) src.elementId().get(); 464 + !(tunnel.dst() instanceof OpticalTunnelEndPoint)) {
463 - DeviceId dstDevice = (DeviceId) dst.elementId().get(); 465 + continue;
464 - if (srcDevice.toString().equals(deviceId.toString()) || 466 + }
465 - dstDevice.toString().equals(deviceId.toString())) { 467 +
468 + Optional<ElementId> srcElementId = ((OpticalTunnelEndPoint) tunnel.src()).elementId();
469 + Optional<ElementId> dstElementId = ((OpticalTunnelEndPoint) tunnel.dst()).elementId();
470 + if (!srcElementId.isPresent() || !dstElementId.isPresent()) {
471 + continue;
472 + }
473 + DeviceId srcDeviceId = (DeviceId) srcElementId.get();
474 + DeviceId dstDeviceId = (DeviceId) dstElementId.get();
475 + if (srcDeviceId.equals(deviceId) || dstDeviceId.equals(deviceId)) {
466 count++; 476 count++;
467 } 477 }
468 } 478 }
......