Ray Milkey
Committed by Gerrit Code Review

Fix unhandled exception during shutdown due to provider service being unavailable

Change-Id: I891b2d3c64576fe7cace80ff7907551b46054db6
...@@ -177,6 +177,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -177,6 +177,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
177 @Deactivate 177 @Deactivate
178 public void deactivate(ComponentContext context) { 178 public void deactivate(ComponentContext context) {
179 cfgService.unregisterProperties(getClass(), false); 179 cfgService.unregisterProperties(getClass(), false);
180 + listener.disable();
180 controller.removeListener(listener); 181 controller.removeListener(listener);
181 providerRegistry.unregister(this); 182 providerRegistry.unregister(this);
182 collectors.values().forEach(PortStatsCollector::stop); 183 collectors.values().forEach(PortStatsCollector::stop);
...@@ -344,6 +345,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -344,6 +345,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
344 private class InternalDeviceProvider implements OpenFlowSwitchListener, OpenFlowEventListener { 345 private class InternalDeviceProvider implements OpenFlowSwitchListener, OpenFlowEventListener {
345 346
346 private HashMap<Dpid, List<OFPortStatsEntry>> portStatsReplies = new HashMap<>(); 347 private HashMap<Dpid, List<OFPortStatsEntry>> portStatsReplies = new HashMap<>();
348 + private boolean isDisabled = false;
347 349
348 @Override 350 @Override
349 public void switchAdded(Dpid dpid) { 351 public void switchAdded(Dpid dpid) {
...@@ -773,30 +775,43 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -773,30 +775,43 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
773 775
774 @Override 776 @Override
775 public void handleMessage(Dpid dpid, OFMessage msg) { 777 public void handleMessage(Dpid dpid, OFMessage msg) {
776 - switch (msg.getType()) { 778 + if (isDisabled) {
777 - case STATS_REPLY: 779 + return;
778 - if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) { 780 + }
779 - OFPortStatsReply portStatsReply = (OFPortStatsReply) msg; 781 +
780 - List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid); 782 + try {
781 - if (portStatsReplyList == null) { 783 + switch (msg.getType()) {
782 - portStatsReplyList = Lists.newArrayList(); 784 + case STATS_REPLY:
785 + if (((OFStatsReply) msg).getStatsType() == OFStatsType.PORT) {
786 + OFPortStatsReply portStatsReply = (OFPortStatsReply) msg;
787 + List<OFPortStatsEntry> portStatsReplyList = portStatsReplies.get(dpid);
788 + if (portStatsReplyList == null) {
789 + portStatsReplyList = Lists.newArrayList();
790 + }
791 + portStatsReplyList.addAll(portStatsReply.getEntries());
792 + portStatsReplies.put(dpid, portStatsReplyList);
793 + if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
794 + pushPortMetrics(dpid, portStatsReplies.get(dpid));
795 + portStatsReplies.get(dpid).clear();
796 + }
783 } 797 }
784 - portStatsReplyList.addAll(portStatsReply.getEntries()); 798 + break;
785 - portStatsReplies.put(dpid, portStatsReplyList); 799 + case ERROR:
786 - if (!portStatsReply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { 800 + if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) {
787 - pushPortMetrics(dpid, portStatsReplies.get(dpid)); 801 + LOG.error("port mod failed");
788 - portStatsReplies.get(dpid).clear();
789 } 802 }
790 - } 803 + default:
791 - break; 804 + break;
792 - case ERROR: 805 + }
793 - if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) { 806 + } catch (IllegalStateException e) {
794 - LOG.error("port mod failed"); 807 + // system is shutting down and the providerService is no longer
795 - } 808 + // valid. Messages cannot be processed.
796 - default:
797 - break;
798 } 809 }
799 } 810 }
811 +
812 + private void disable() {
813 + isDisabled = true;
814 + }
800 } 815 }
801 816
802 817
......